Skip to content

Commit

Permalink
feat: add Config.enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Oct 4, 2023
1 parent c259500 commit 1809f10
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changes/config-enabled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-packager-config": "minor"
---

Add `Config.enabled` field control whether this config is enabled or not
5 changes: 5 additions & 0 deletions .changes/packager-enabled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-packager": "patch"
---

Respect the `config.enabled` option.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ cargo install cargo-packager --locked

### Usage

```sh
cargo packager
```
1. Add `Packager.toml` or `packager.json` in your project or modify Cargo.toml and include

```toml
[package.metadata.packager]
enabled = true
```

2. Run the CLI

```sh
cargo packager
```

### Supported pacakges

Expand Down
9 changes: 7 additions & 2 deletions crates/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"description": "The packaging config.",
"type": "object",
"properties": {
"enabled": {
"description": "Whether this config is enabled or not. Defaults to `true`.",
"default": true,
"type": "boolean"
},
"$schema": {
"description": "The JSON schema for the config.\n\nSetting this field has no effect, this just exists so we can parse the JSON correct when it has `$schema` field set.",
"type": [
Expand Down Expand Up @@ -343,14 +348,14 @@
"description": "The type of the package we're packaging.",
"oneOf": [
{
"description": "All available package formats for the current platform.\n\nSee [`PackageFornat::platform_all`]",
"description": "All available package formats for the current platform.\n\nSee [`PackageFormat::platform_all`]",
"type": "string",
"enum": [
"all"
]
},
{
"description": "The default list of package formats for the current platform.\n\nSee [`PackageFornat::platform_default`]",
"description": "The default list of package formats for the current platform.\n\nSee [`PackageFormat::platform_default`]",
"type": "string",
"enum": [
"default"
Expand Down
7 changes: 5 additions & 2 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ pub use category::AppCategory;
pub enum PackageFormat {
/// All available package formats for the current platform.
///
/// See [`PackageFornat::platform_all`]
/// See [`PackageFormat::platform_all`]
All,
/// The default list of package formats for the current platform.
///
/// See [`PackageFornat::platform_default`]
/// See [`PackageFormat::platform_default`]
Default,
/// The macOS application bundle (.app).
App,
Expand Down Expand Up @@ -664,6 +664,9 @@ pub enum HookCommand {
#[derive(Deserialize, Serialize, Default, Debug, Clone, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Config {
/// Whether this config is enabled or not. Defaults to `true`.
#[serde(default = "default_true")]
pub enabled: bool,
/// The JSON schema for the config.
///
/// Setting this field has no effect, this just exists so
Expand Down
15 changes: 12 additions & 3 deletions crates/packager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ cargo install cargo-packager --locked

### Usage

```sh
cargo packager
```
1. Add `Packager.toml` or `packager.json` in your project or modify Cargo.toml and include

```toml
[package.metadata.packager]
enabled = true
```

2. Run the CLI

```sh
cargo packager
```

### Supported pacakges

Expand Down
9 changes: 7 additions & 2 deletions crates/packager/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"description": "The packaging config.",
"type": "object",
"properties": {
"enabled": {
"description": "Whether this config is enabled or not. Defaults to `true`.",
"default": true,
"type": "boolean"
},
"$schema": {
"description": "The JSON schema for the config.\n\nSetting this field has no effect, this just exists so we can parse the JSON correct when it has `$schema` field set.",
"type": [
Expand Down Expand Up @@ -343,14 +348,14 @@
"description": "The type of the package we're packaging.",
"oneOf": [
{
"description": "All available package formats for the current platform.\n\nSee [`PackageFornat::platform_all`]",
"description": "All available package formats for the current platform.\n\nSee [`PackageFormat::platform_all`]",
"type": "string",
"enum": [
"all"
]
},
{
"description": "The default list of package formats for the current platform.\n\nSee [`PackageFornat::platform_default`]",
"description": "The default list of package formats for the current platform.\n\nSee [`PackageFormat::platform_default`]",
"type": "string",
"enum": [
"default"
Expand Down
5 changes: 5 additions & 0 deletions crates/packager/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ pub fn load_configs_from_cargo_workspace(
if config.version.is_empty() {
config.version = package.version.to_string();
}
if config.identifier.is_none() {
config
.identifier
.replace(format!("com.{}.app", package.name));
}
if config.out_dir.as_os_str().is_empty() {
config.out_dir = metadata
.target_directory
Expand Down
28 changes: 16 additions & 12 deletions crates/packager/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,28 @@ fn try_run(cli: Cli) -> Result<()> {
.concat()
.into_iter()
.filter(|(_, c)| {
// skip if this package was not specified in the explicit packages to build
// otherwise we should package it if `cli_packages` was `None`
cli.packages
.as_ref()
.map(|p| {
c.name
.as_ref()
.map(|name| p.contains(name))
.unwrap_or(false)
})
.unwrap_or(true)
// skip if this config is not enabled
// or if this package was in the explicit
// packages list specified on the CLI,
// otherwise build all if no packages were specified on the CLI
c.enabled
&& (cli
.packages
.as_ref()
.map(|cli_packages| {
c.name
.as_ref()
.map(|name| cli_packages.contains(name))
.unwrap_or(false)
})
.unwrap_or(true))
})
.collect()
}
};

if configs.is_empty() {
tracing::warn!("Couldn't detect a valid configuration file! Nothing to do here.");
tracing::debug!("Couldn't detect a valid configuration file or all configurations are disabled! Nothing to do here.");
return Ok(());
}

Expand Down
15 changes: 12 additions & 3 deletions crates/packager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@
//!
//! ### Usage
//!
//! ```sh
//! cargo packager
//! ```
//! 1. Add `Packager.toml` or `packager.json` in your project or modify Cargo.toml and include
//!
//! ```toml
//! [package.metadata.packager]
//! enabled = true
//! ```
//!
//! 2. Run the CLI
//!
//! ```sh
//! cargo packager
//! ```
//!
//! ### Supported pacakges
//!
Expand Down

0 comments on commit 1809f10

Please sign in to comment.