diff --git a/cli/README.md b/cli/README.md index e03656d4b..edaa9e5e9 100644 --- a/cli/README.md +++ b/cli/README.md @@ -61,7 +61,8 @@ daikoku environments add --name= --server= you can sync the new project with your Daikoku instance and fetch mails and apis ```sh -daikoku pull +daikoku pull apis +daikoku pull mails ``` you can start to develop and watch file changes @@ -130,7 +131,7 @@ The CMS projects adhere to the following strict file structure: - `styles`: Contains CSS files. - `documentations` : Contains files that can be used as documentation page of APIs -# Nested routing +# Dynamic nested routing The CLI uses file-system routing where folders are used to create nested routes. Each folder represents a route segment that maps to a URL segment. @@ -138,9 +139,10 @@ You can create separate UIs for each route using page.html files. `page.html` is To create a nested route, you can nest folders inside each other and add page.html files inside them. For example: -`src/pages/page.html`: is associated with the `/` path. -`src/pages/invoices/page.html`: is associated with the `/invoices` path. -`src/pages/offres.html`: is associated with the `/offres` path. +`src/pages/page.html`: can be reach on `/` path. +`src/pages/invoices/page.html`: can be reach on `/invoices` path. +`src/pages/offres.html`: can be reach on `/offres` path. +`src/pages/apis/api/[apiId]`: can be reach on `/apis/api/any-kind-of-api` and the apiId value can be use in the page as mustache variable using {{apiId}} # Manage your assets @@ -173,6 +175,18 @@ If you prefer to synchronize all assets with a single command, it offers speed a daikoku assets sync ``` +# Manage documentation pages + +You already have many choices in Daikoku to create the APIs's documentation. But, with the release of the CMS, you can now write your documentation with it. The documentations pages have to be written in the `src/documentations` folder and can be named as you wish. + +The recommended usage to create a new documentation page is to use the CLI as following : + +```sh +daikoku generate documentation --filename=my-new-documentation-page \ + --title="Title of the page" \ + --desc="The description of this page" +``` + # CMS Directives ## daikoku-user @@ -507,13 +521,79 @@ When you have an user returned from directive, you can use the following fields This project is licensed under the Apache 2.0 license with the LLVM exception. + +# Commands + +The following commands must be run, replacing `` with `--parameter=value`. + +# PROJECT commands +```sh +daikoku cms init +daikoku cms migrate + +daikoku cms list +daikoku cms add +daikoku cms switch +daikoku cms remove +daikoku cms clear +``` + +# PUSH commands +```sh +daikoku push +``` + +# ASSETS commands +```sh +daikoku assets push <DESC> <PATH> <SLUG> +daikoku assets remove <FILENAME> <PATH> <SLUG> +daikoku assets list +daikoku assets sync +``` + +# ENVIRONMENTS commands +```sh +daikoku environments clear <FORCE> +daikoku environments add <NAME> <SERVER> <OVERWRITE> +daikoku environments switch <NAME> +daikoku environments remove <NAME> +daikoku environments info <NAME> <FULL> +daikoku environments list +daikoku environments config <APIKEY> +``` + +# GENERATE commands +```sh +daikoku generate documentation <FILENAME> <TITLE> <DESC> +``` + +# LOGIN +```sh +daikoku login +``` + +# PULL commands +```sh +daikoku pull apis +daikoku pull mails +``` + +# VERSION commands +```sh +daikoku version +``` + +# WATCH commands +```sh +daikoku watch +``` + ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions. - #### Run tests ``` cargo test --test <filename> -- --nocapture --test-threads 1 diff --git a/cli/src/commands/cms.rs b/cli/src/commands/cms.rs index 3d467fe37..1f290847e 100644 --- a/cli/src/commands/cms.rs +++ b/cli/src/commands/cms.rs @@ -145,7 +145,6 @@ pub(crate) fn get_default_project() -> DaikokuResult<Project> { match (&project["name"], &project["path"]) { (Some(_name), Some(path)) => Ok(Project { - // name: name.to_string(), path: path.to_string(), }), (_, _) => Err(DaikokuCliError::Configuration( @@ -215,20 +214,17 @@ pub(crate) fn get_project(name: String) -> DaikokuResult<Project> { ))?; match projects.get(&name) { - Some(project) => { - match (&project["name"], &project["path"]) { - (Some(_name), Some(path)) => { - logger::info(serde_json::to_string_pretty(&project).unwrap()); - Ok(Project { - // name: name.to_string(), - path: path.to_string(), - }) - } - (_, _) => Err(DaikokuCliError::Configuration( - "missing project or values in project.".to_string(), - )), + Some(project) => match (&project["name"], &project["path"]) { + (Some(_name), Some(path)) => { + logger::info(serde_json::to_string_pretty(&project).unwrap()); + Ok(Project { + path: path.to_string(), + }) } - } + (_, _) => Err(DaikokuCliError::Configuration( + "missing project or values in project.".to_string(), + )), + }, None => { return Err(DaikokuCliError::Configuration( "project is missing".to_string(), @@ -697,62 +693,6 @@ async fn create_cms_pages( convert_cms_pages(new_pages, sources_path.clone()) } -// fn clone_new_project(items: Vec<CmsPage>, project_path: &PathBuf) -> DaikokuResult<()> { -// println!("cloning new project"); - -// items -// .iter() -// .filter(|item| { -// !item.path.clone().unwrap().starts_with("apis") -// && !item.path.clone().unwrap().starts_with("mails") -// }) -// .for_each(|item| { -// let extension = SourceExtension::from_str(&item.content_type).unwrap(); - -// let item_path = item.path.clone().unwrap().clone(); - -// // Remove the slash if the path starts with one. -// let mut file_path = project_path.clone().join(if item_path.starts_with("/") { -// &item_path[1..item_path.len()] -// } else { -// item_path.as_str() -// }); - -// let split_path = item_path.split("/"); - -// // if the path didn't start with folder, we will place the page in the default pages folder -// if split_path -// .clone() -// .into_iter() -// .find(|part| part.is_empty()) -// .is_some() -// || split_path.collect::<Vec<&str>>().len() == 1 -// { -// file_path = -// project_path -// .clone() -// .join("pages") -// .join(if item_path.starts_with("/") { -// &item_path[1..item_path.len()] -// } else { -// item_path.as_str() -// }); -// } - -// let metadata = extract_metadata(item).unwrap_or(HashMap::new()); - -// let _ = create_path_and_file( -// file_path, -// item.content.clone(), -// item.name.clone(), -// metadata, -// extension, -// ); -// }); - -// Ok(()) -// } - fn convert_cms_pages(items: Vec<CmsPage>, project_path: PathBuf) -> DaikokuResult<()> { items.iter().for_each(|item| { let extension = SourceExtension::from_str(&item.content_type).unwrap(); @@ -829,7 +769,6 @@ fn get_cms_page_path(item: &CmsPage) -> DaikokuResult<PathBuf> { pub fn create_path_and_file( file_buf: PathBuf, content: String, - // item: &CmsPage, name: String, metadata: HashMap<String, String>, content_type: SourceExtension, diff --git a/cli/src/commands/commands.md b/cli/src/commands/commands.md index bad9a83be..39f27d76a 100644 --- a/cli/src/commands/commands.md +++ b/cli/src/commands/commands.md @@ -28,7 +28,6 @@ daikoku environments remove <NAME> daikoku environments info <NAME> <FULL> // rename from env daikoku environments list daikoku environments config <APIKEY> -// editer le .gitignore pour mettre le .secrets du .daikoku # GENERATE daikoku generate documentation <FILENAME> <TITLE> <DESC> diff --git a/cli/src/commands/environments.rs b/cli/src/commands/environments.rs index 8c148229d..f6b890f4e 100644 --- a/cli/src/commands/environments.rs +++ b/cli/src/commands/environments.rs @@ -185,7 +185,6 @@ async fn add(name: String, server: String, overwrite: bool, apikey: String) -> D } else { "<green>New entry</> added".to_string() }); - // logger::info(serde_json::to_string_pretty(&get(name)?).unwrap()); Ok(()) } Err(err) => Err(DaikokuCliError::Configuration(err.to_string())), diff --git a/cli/src/commands/watch.rs b/cli/src/commands/watch.rs index 007c5544b..d48187f0c 100644 --- a/cli/src/commands/watch.rs +++ b/cli/src/commands/watch.rs @@ -446,12 +446,10 @@ async fn render_page( .unwrap()) } else { let src = String::from_utf8(result).unwrap(); - // let source = html_escape::encode_text(&src); - // src.replace('"', """); - // .replace("&", "&") + let source = src.replace('"', """); - // let source = src.replace("\"", """); + let children: String = if SourceExtension::from_str(&page.content_type()).unwrap() == SourceExtension::HTML { @@ -461,9 +459,7 @@ async fn render_page( }; Ok(Response::builder() - // .header(header::CONTENT_TYPE, &page.content_type()) .header(header::CONTENT_TYPE, "text/html") - // .body(Full::new(Bytes::from(result))) .body(Full::new(Bytes::from( String::from_utf8(MANAGER_PAGE.to_vec()) .unwrap()