-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] Add cargo-generate
workflow
#10
Open
nuke-web3
wants to merge
6
commits into
pop-os:main
Choose a base branch
from
nuke-web3:n/initial-cargo-generate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5227fcd
feat: add cargo-generate config with README template and template var…
nuke-web3 7a4f032
feat: add rhai scpripts to handle license, file renames, and cleanup
nuke-web3 0699292
fix: use correct placeholder, rm broken default
nuke-web3 e06e62c
refactor: remove license files and move to placeholders only
nuke-web3 a0a73dc
Update generate/README.md
nuke-web3 4086768
Update license.rhai
nuke-web3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
# COSMIC Application Template | ||
|
||
A template for developing applications for the COSMIC™ desktop environment. | ||
A template for developing applications for the COSMIC™ desktop environment using [libcosmic][libcosmic]. | ||
|
||
## Documentation | ||
|
||
Refer to the [libcosmic API documentation][api-docs] and [book][book] for help with building applications with [libcosmic][libcosmic]. | ||
|
||
## Getting Started | ||
|
||
Log into your GitHub account and click the "Use this template" button above. This will create a new repository in your account. Choose a name for this repository, and then clone it locally onto your system. Make the following changes after cloning it: | ||
To generate a new project based on this template, [install `cargo generate`][cargo-generate-install] and run: | ||
|
||
- In `Cargo.toml`, change the `name` and set your `license` and `repository`. | ||
- Create a `LICENSE` file containing your chosen software license. | ||
- Rename the file `i18n/en/cosmic_app_template.ftl` by replacing the `cosmic_app_template` portion with the new crate `name` you set in `Cargo.toml`. | ||
- In `justfile`, change the `name` and `appid` variables with your own. | ||
- In `src/app.rs`, change the `APP_ID` value in the `Application` implementation of the `AppModel`. | ||
- In `src/app.rs`, change the `REPOSITORY` const with the URL to your application's git repository. | ||
- In `res/app.desktop`, change the `Name=`, `Exec=`, and `Icon=` fields | ||
- Set your license within the SPDX tags at the top of each source file | ||
```bash | ||
cargo generate gh:pop-os/cosmic-app-template | ||
``` | ||
|
||
A [justfile](./justfile) is included by default with common recipes used by other COSMIC projects. Install from [casey/just][just] | ||
Then follow the prompts to pre-populate and customize your project. | ||
|
||
- `just` builds the application with the default `just build-release` recipe | ||
- `just run` builds and runs the application | ||
- `just install` installs the project into the system | ||
- `just vendor` creates a vendored tarball | ||
- `just build-vendored` compiles with vendored dependencies from that tarball | ||
- `just check` runs clippy on the project to check for linter warnings | ||
- `just check-json` can be used by IDEs that support LSP | ||
### Manual Template Configuration | ||
|
||
## Documentation | ||
If you choose not to use `cargo generate`, you may still use this template. | ||
|
||
Refer to the [libcosmic API documentation][api-docs] and [book][book] for help with building applications with [libcosmic][libcosmic]. | ||
Log into your GitHub account and navigate to [this template there][app-template] and click the "Use this template" button above. This will create a new repository in your account. Choose a name for this repository, and then clone it locally onto your system. After cloning it, you must: | ||
|
||
- Manually replace all template fields matching `{{ <some field> }}` (regex `\{\{ .*\}\}`) in all source files. | ||
- Create a `LICENSE` file containing your chosen software license. | ||
- Rename the file `i18n/en/cosmic_app_template.ftl` by replacing the `cosmic_app_template` portion with the new crate `name` you set in `Cargo.toml`. | ||
- Set your license within the SPDX tags at the top of each source file | ||
- Replace this `README.md` with your own, optionally based on `README.md.liquid`, removing the postfix. | ||
- Delete the `generate/` directory. | ||
|
||
[api-docs]: https://pop-os.github.io/libcosmic/cosmic/ | ||
[book]: https://pop-os.github.io/libcosmic-book/ | ||
[libcosmic]: https://github.com/pop-os/libcosmic/ | ||
[just]: https://github.com/casey/just | ||
[cargo-generate-install]: https://cargo-generate.github.io/cargo-generate/installation.html | ||
[app-template]: https://github.com/pop-os/cosmic-app-template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[template] | ||
cargo_generate_version = ">=0.22" | ||
|
||
[placeholders] | ||
description = { type = "string", prompt = "App description:", default = "An App built for COSMIC, based on the [`libcosmic` template](https://github.com/pop-os/cosmic-app-template/" } | ||
repository-url = { type = "string", prompt = "Repository URL (https://*)", regex = "^https?:\\/\\/(www\\.)?[\\w\\-]+(\\.[\\w\\-]+)+[/#?]?.*$" } | ||
app-id = { type = "string", prompt = "App ID (com.example.MyCosmicApp)", regex = "^[a-zA-Z0-9]+\\.[a-zA-Z0-9]+\\.[a-zA-Z0-9]+$" } | ||
|
||
[hooks] | ||
pre = [ | ||
"generate/license.rhai", | ||
"generate/rename.rhai", | ||
] | ||
post = [ | ||
"generate/cleanup.rhai", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Cargo Generate Artifacts | ||
|
||
See usage and docs for Rhai scripts: | ||
|
||
- https://cargo-generate.github.io/cargo-generate/templates/scripting.rhai-extensions.html | ||
- https://rhai.rs/book/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Cleanup cargo generate artifacts | ||
file::delete("generate"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This example script asks the users selection of license | ||
|
||
let license = variable::prompt("Which license do you want to use?", | ||
"MPL-2.0", | ||
["MPL-2.0", | ||
"MIT", | ||
"AGPL-3.0", | ||
"Apache-2.0", | ||
"Unlicense", | ||
"(Other)", | ||
"None" | ||
] | ||
); | ||
|
||
if license == "(Other)" { | ||
license = variable::prompt("Please define *a valid* identifier from <https://github.com/spdx/license-list-data/blob/v3.20/licenses.md>") | ||
} | ||
|
||
print(`📝 Remeber to add a correct LICENSE file for ${license} - found at <https://github.com/spdx/license-list-data/blob/v3.20/licenses.md> `); | ||
variable::set("license", license); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Rename and move files | ||
|
||
let project_name = variable::get("project-name"); | ||
file::rename("i18n/en/cosmic_app_template.ftl", `i18n/en/${project_name}.ftl`); | ||
|
||
file::rename("generate/template-README.md", "README.md"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# {{ project-name | title_case }} | ||
|
||
{{ description }} | ||
|
||
> Built using the [COSMIC™ App Template](https://github.com/pop-os/cosmic-app-template) | ||
|
||
## Getting Started | ||
|
||
A [justfile](./justfile) is included by default with common recipes used by other COSMIC projects. Install from [casey/just][just] | ||
|
||
```sh | ||
# Builds the application with the default `just build-release` recipe | ||
just | ||
|
||
# Lists all commands | ||
just --list | ||
``` | ||
|
||
## Documentation | ||
|
||
Refer to the [libcosmic API documentation][api-docs] and [book][book] for help with building applications with [libcosmic][libcosmic]. | ||
|
||
[api-docs]: https://pop-os.github.io/libcosmic/cosmic/ | ||
[book]: https://pop-os.github.io/libcosmic-book/ | ||
[libcosmic]: https://github.com/pop-os/libcosmic/ | ||
[just]: https://github.com/casey/just |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
fallback_language = "en" | ||
|
||
[fluent] | ||
assets_dir = "i18n" | ||
assets_dir = "i18n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
app-title = COSMIC App Template | ||
about = About | ||
app-title = {{ project-name | title_case }} | ||
about = Built using COSMIC | ||
view = View | ||
welcome = Welcome to COSMIC! ✨ | ||
welcome = Welcome to the {{ project-name | title_case }} COSMIC App! ✨ | ||
page-id = Page { $num } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
[Desktop Entry] | ||
Name={{APP_NAME}} | ||
Exec={{APP_BINARY}} %F | ||
Name={{ project-name | title_case }} | ||
Exec={{ project-name }} %F | ||
Terminal=false | ||
Type=Application | ||
StartupNotify=true | ||
Icon={{APP_ID}} | ||
Icon={{ app_id }} | ||
Categories=COSMIC; | ||
Keywords= | ||
MimeType= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// SPDX-License-Identifier: {{LICENSE}} | ||
// SPDX-License-Identifier: {{ license }} | ||
|
||
mod app; | ||
mod config; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting came from a run of https://dprint.dev/ on md and toml files