-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from radu-matei/feat/wrap-pkg
- Loading branch information
Showing
5 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 +1,3 @@ | ||
pub mod add; | ||
pub mod bindings; | ||
pub mod publish; |
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,51 @@ | ||
use anyhow::Result; | ||
use clap::Args; | ||
use std::path::PathBuf; | ||
use wasm_pkg_client::{Client, Config, PublishOpts}; | ||
use wasm_pkg_common::{package::PackageSpec, registry::Registry}; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct PublishCommand { | ||
/// The registry domain to use. Overrides configuration file(s). | ||
#[arg(long = "registry", value_name = "REGISTRY", env = "WKG_REGISTRY")] | ||
registry: Option<Registry>, | ||
|
||
/// The file to publish | ||
file: PathBuf, | ||
|
||
/// If not provided, the package name and version will be inferred from the Wasm file. | ||
/// Expected format: `<namespace>:<name>@<version>` | ||
#[arg(long, env = "WKG_PACKAGE")] | ||
package: Option<PackageSpec>, | ||
} | ||
|
||
impl PublishCommand { | ||
pub async fn run(self) -> Result<()> { | ||
let client = { | ||
let config = Config::global_defaults()?; | ||
Client::new(config) | ||
}; | ||
|
||
let package = if let Some(package) = self.package { | ||
Some(( | ||
package.package, | ||
package.version.ok_or_else(|| { | ||
anyhow::anyhow!("version is required when manually overriding the package ID") | ||
})?, | ||
)) | ||
} else { | ||
None | ||
}; | ||
let (package, version) = client | ||
.publish_release_file( | ||
&self.file, | ||
PublishOpts { | ||
package, | ||
registry: self.registry, | ||
}, | ||
) | ||
.await?; | ||
println!("Published {}@{}", package, version); | ||
Ok(()) | ||
} | ||
} |
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