Skip to content
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

Add skip-gitignore cli arg #1131

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct Build {
pub crate_data: manifest::CrateData,
pub scope: Option<String>,
pub disable_dts: bool,
pub skip_gitignore: bool,
pub target: Target,
pub profile: BuildProfile,
pub mode: InstallMode,
Expand Down Expand Up @@ -132,6 +133,10 @@ pub struct BuildOptions {
/// this flag will disable generating this TypeScript file.
pub disable_dts: bool,

#[structopt(long = "skip-gitignore")]
/// Skips generating .gitignore file.
pub skip_gitignore: bool,

#[structopt(long = "target", short = "t", default_value = "bundler")]
/// Sets the target environment. [possible values: bundler, nodejs, web, no-modules]
pub target: Target,
Expand Down Expand Up @@ -173,6 +178,7 @@ impl Default for BuildOptions {
scope: None,
mode: InstallMode::default(),
disable_dts: false,
skip_gitignore: false,
target: Target::default(),
debug: false,
dev: false,
Expand Down Expand Up @@ -217,6 +223,7 @@ impl Build {
crate_data,
scope: build_opts.scope,
disable_dts: build_opts.disable_dts,
skip_gitignore: build_opts.skip_gitignore,
target: build_opts.target,
profile,
mode: build_opts.mode,
Expand Down Expand Up @@ -334,7 +341,7 @@ impl Build {

fn step_create_dir(&mut self) -> Result<(), Error> {
info!("Creating a pkg directory...");
create_pkg_dir(&self.out_dir)?;
create_pkg_dir(&self.out_dir, self.skip_gitignore)?;
info!("Created a pkg directory at {:#?}.", &self.crate_path);
Ok(())
}
Expand Down
6 changes: 4 additions & 2 deletions src/command/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ fn find_manifest_from_cwd() -> Result<PathBuf, failure::Error> {
}

/// Construct our `pkg` directory in the crate.
pub fn create_pkg_dir(out_dir: &Path) -> Result<(), failure::Error> {
pub fn create_pkg_dir(out_dir: &Path, skip_gitignore: bool) -> Result<(), failure::Error> {
let _ = fs::remove_file(out_dir.join("package.json")); // Clean up package.json from previous runs
fs::create_dir_all(&out_dir)?;
fs::write(out_dir.join(".gitignore"), "*")?;
if !skip_gitignore {
fs::write(out_dir.join(".gitignore"), "*")?;
};
Ok(())
}

Expand Down
28 changes: 14 additions & 14 deletions tests/all/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn it_creates_a_package_json_default_path() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, Target::Bundler)
.is_ok());
Expand Down Expand Up @@ -113,7 +113,7 @@ fn it_creates_a_package_json_provided_path() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, Target::Bundler)
.is_ok());
Expand Down Expand Up @@ -142,7 +142,7 @@ fn it_creates_a_package_json_provided_path_with_scope() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &Some("test".to_string()), false, Target::Bundler,)
.is_ok());
Expand Down Expand Up @@ -171,7 +171,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, Target::Nodejs)
.is_ok());
Expand Down Expand Up @@ -205,7 +205,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, Target::NoModules)
.is_ok());
Expand Down Expand Up @@ -239,7 +239,7 @@ fn it_creates_a_package_json_with_correct_files_when_out_name_is_provided() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, Some("index".to_owned())).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, Target::Bundler)
.is_ok());
Expand Down Expand Up @@ -271,7 +271,7 @@ fn it_creates_a_pkg_json_in_out_dir() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("./custom/out");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, false, Target::Bundler)
.is_ok());
Expand All @@ -286,7 +286,7 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
assert!(crate_data
.write_package_json(&out_dir, &None, true, Target::Bundler)
.is_ok());
Expand Down Expand Up @@ -319,7 +319,7 @@ fn it_creates_a_package_json_with_npm_dependencies_provided_by_wasm_bindgen() {
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
// Write a `package.json` in the out_dir, as wasm-bindgen does:
utils::manifest::create_wbg_package_json(
&out_dir,
Expand Down Expand Up @@ -399,7 +399,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() {
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();

wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, Target::Bundler)
.unwrap();
Expand All @@ -415,7 +415,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() {
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();

wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, Target::Bundler)
.unwrap();
Expand Down Expand Up @@ -454,7 +454,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() {
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();

wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, Target::Bundler)
.unwrap();
Expand All @@ -472,7 +472,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() {
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();

wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, Target::Bundler)
.unwrap();
Expand Down Expand Up @@ -572,7 +572,7 @@ fn it_lists_license_files_in_files_field_of_package_json() {

let crate_data = manifest::CrateData::new(&fixture.path, None).unwrap();

wasm_pack::command::utils::create_pkg_dir(&out_dir).unwrap();
wasm_pack::command::utils::create_pkg_dir(&out_dir, false).unwrap();
license::copy_from_crate(&crate_data, &fixture.path, &out_dir).unwrap();
crate_data
.write_package_json(&out_dir, &None, false, Target::Bundler)
Expand Down