#![allow(clippy::redundant_closure)]
pub mod build;
mod generate;
mod login;
mod pack;
pub mod publish;
pub mod test;
pub mod utils;
use self::build::{Build, BuildOptions};
use self::generate::generate;
use self::login::login;
use self::pack::pack;
use self::publish::{access::Access, publish};
use self::test::{Test, TestOptions};
use crate::install::InstallMode;
use anyhow::Result;
use clap::Subcommand;
use log::info;
use std::path::PathBuf;
#[derive(Debug, Subcommand)]
pub enum Command {
#[clap(name = "build", alias = "init")]
Build(BuildOptions),
#[clap(name = "pack")]
Pack {
#[clap(long = "pkg-dir", short = 'd', default_value = "pkg")]
pkg_directory: PathBuf,
#[clap()]
path: Option<PathBuf>,
},
#[clap(name = "new")]
Generate {
name: String,
#[clap(
long = "template",
default_value = "https://github.com/drager/wasm-pack-template"
)]
template: String,
#[clap(long = "mode", short = 'm', default_value = "normal")]
mode: InstallMode,
},
#[clap(name = "publish")]
Publish {
#[clap(long = "target", short = 't', default_value = "bundler")]
target: String,
#[clap(long = "access", short = 'a')]
access: Option<Access>,
#[clap(long = "tag")]
tag: Option<String>,
#[clap(long = "pkg-dir", short = 'd', default_value = "pkg")]
pkg_directory: PathBuf,
#[clap()]
path: Option<PathBuf>,
},
#[clap(name = "login", alias = "adduser", alias = "add-user")]
Login {
#[clap(long = "registry", short = 'r')]
registry: Option<String>,
#[clap(long = "scope", short = 's')]
scope: Option<String>,
#[clap(long = "auth-type", short = 't')]
auth_type: Option<String>,
},
#[clap(name = "test")]
Test(TestOptions),
}
pub fn run_wasm_pack(command: Command) -> Result<()> {
match command {
Command::Build(build_opts) => {
info!("Running build command...");
Build::try_from_opts(build_opts).and_then(|mut b| b.run())
}
Command::Pack {
path,
pkg_directory,
} => {
info!("Running pack command...");
info!("Path: {:?}", &path);
pack(path, pkg_directory)
}
Command::Generate {
template,
name,
mode,
} => {
info!("Running generate command...");
info!("Template: {:?}", &template);
info!("Name: {:?}", &name);
generate(template, name, mode.install_permitted())
}
Command::Publish {
target,
path,
access,
tag,
pkg_directory,
} => {
info!("Running publish command...");
info!("Path: {:?}", &path);
publish(&target, path, access, tag, pkg_directory)
}
Command::Login {
registry,
scope,
auth_type,
} => {
info!("Running login command...");
info!(
"Registry: {:?}, Scope: {:?}, Auth Type: {:?}",
®istry, &scope, &auth_type
);
login(registry, &scope, &auth_type)
}
Command::Test(test_opts) => {
info!("Running test command...");
Test::try_from_opts(test_opts).and_then(|t| t.run())
}
}
}