Skip to content

Commit

Permalink
update cli Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Nov 20, 2024
1 parent fbc3536 commit e1a3e3f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 85 deletions.
92 changes: 86 additions & 6 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ daikoku environments add --name=<ENVIRONMENT_NAME> --server=<ENVIROMNENT_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
Expand Down Expand Up @@ -130,17 +131,18 @@ 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.

You can create separate UIs for each route using page.html files. `page.html` is a special CLI file that contains html content.

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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 `<parameter>` with `--parameter=value`.

# PROJECT commands
```sh
daikoku cms init <NAME> <PATH>
daikoku cms migrate <NAME> <PATH> <SERVER> <APIKEY>

daikoku cms list
daikoku cms add <NAME> <PATH> <OVERWRITE>
daikoku cms switch <NAME>
daikoku cms remove <NAME> <REMOVE_FILES>
daikoku cms clear <FORCE>
```

# PUSH commands
```sh
daikoku push <DRY_RUN> <FILEPATH>
```

# ASSETS commands
```sh
daikoku assets push <FILENAME> <TITLE> <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
Expand Down
81 changes: 10 additions & 71 deletions cli/src/commands/cms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion cli/src/commands/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand Down
8 changes: 2 additions & 6 deletions cli/src/commands/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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('"', "&quot;");
// .replace("&", "&amp;")

let source = src.replace('"', "&quot;");

// let source = src.replace("\"", "&quot;");

let children: String = if SourceExtension::from_str(&page.content_type()).unwrap()
== SourceExtension::HTML
{
Expand All @@ -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()
Expand Down

0 comments on commit e1a3e3f

Please sign in to comment.