Merge pull request #67 from jamiebuilds/pack-and-publish

init pack and publish
master
ashley williams 7 years ago committed by GitHub
commit 3c2447e2bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      README.md
  2. 1
      src/lib.rs
  3. 26
      src/main.rs
  4. 32
      src/npm.rs

@ -20,9 +20,16 @@ this project is written in rust. [get rust] to work on this project.
[get rust]: https://www.rustup.rs/
if you want to publish packages, you'll also need an account on [npm] and have
[node/npm] installed.
[npm]: https://www.npmjs.com
[node/npm]: https://nodejs.org/
## 🏃 up and running
1. fork and clone this repository
2. install [node/npm]
2. `cd wasm-pack`
3. `cargo run`
@ -39,10 +46,8 @@ this project is written in rust. [get rust] to work on this project.
wasm-pack init examples/scopes-hello-world --scope test
```
generates a `package.json` for an npm package called `@test/scopes-hello-world`
#### to be implemented
- 🍱 `pack`: create a tarball but don't push to the npm registry [NOT IMPLEMENTED]
- 🎆 `publish`: create a tarball and publish to the npm registry [NOT IMPLEMENTED]
- 🍱 `pack`: create a tarball but don't push to the npm registry (see https://docs.npmjs.com/cli/pack)
- 🎆 `publish`: create a tarball and publish to the npm registry (see https://docs.npmjs.com/cli/publish)
## ⚙ how to use
@ -82,8 +87,8 @@ this project is written in rust. [get rust] to work on this project.
5. install this tool: `cargo install wasm-pack`
6. run `wasm-pack init`, optionally, pass a path to a dir or a scope (see above for details)
7. this tool generates files in a `pkg` dir. to publish to npm, `cd pkg` and then `npm publish`
(in the future you'll be able to use this tool to publish)
7. this tool generates files in a `pkg` dir
8. to publish to npm, run `wasm-pack publish` (making sure you are logged in with npm)
[rust-wasm/36]: https://github.com/rust-lang-nursery/rust-wasm/issues/36
[wasm-bindgen]: https://github.com/alexcrichton/wasm-bindgen

@ -10,6 +10,7 @@ pub mod bindgen;
pub mod build;
pub mod emoji;
pub mod manifest;
pub mod npm;
pub mod progressbar;
pub mod readme;

@ -8,7 +8,7 @@ use std::time::Instant;
use indicatif::HumanDuration;
use quicli::prelude::*;
use wasm_pack::{bindgen, build, emoji, manifest, readme};
use wasm_pack::{bindgen, build, emoji, manifest, npm, readme};
/// 📦 ✨ pack and publish your wasm!
#[derive(Debug, StructOpt)]
@ -31,10 +31,10 @@ enum Command {
},
#[structopt(name = "pack")]
/// 🍱 create a tar of your npm package but don't publish! [NOT IMPLEMENTED]
Pack {},
Pack { path: Option<String> },
#[structopt(name = "publish")]
/// 🎆 pack up your npm package and publish! [NOT IMPLEMENTED]
Publish {},
Publish { path: Option<String> },
}
main!(|args: Cli, log_level: verbosity| match args.cmd {
@ -65,12 +65,20 @@ main!(|args: Cli, log_level: verbosity| match args.cmd {
&crate_path
)
}
Command::Pack { .. } => {
println!("🙅 whoops! this is not implemented yet! sorry!");
//println!("🎒 packed up your package!");
Command::Pack { path } => {
let crate_path = match path {
Some(p) => p,
None => ".".to_string(),
};
npm::npm_pack(&crate_path);
println!("🎒 packed up your package!");
}
Command::Publish { .. } => {
println!("🙅 whoops! this is not implemented yet! sorry!");
//println!("💥 published your package!");
Command::Publish { path } => {
let crate_path = match path {
Some(p) => p,
None => ".".to_string(),
};
npm::npm_publish(&crate_path);
println!("💥 published your package!");
}
});

@ -0,0 +1,32 @@
use emoji;
use std::process::Command;
pub fn npm_pack(path: &str) {
let pkg_file_path = format!("{}/pkg", path);
let output = Command::new("npm")
.current_dir(pkg_file_path)
.arg("pack")
.output()
.unwrap_or_else(|e| panic!("{} failed to execute process: {}", emoji::ERROR, e));
if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr);
print!("{} npm_pack failed and stderr was:\n{}", emoji::ERROR, s);
}
}
pub fn npm_publish(path: &str) {
let pkg_file_path = format!("{}/pkg", path);
let output = Command::new("npm")
.current_dir(pkg_file_path)
.arg("publish")
.output()
.unwrap_or_else(|e| panic!("{} failed to execute process: {}", emoji::ERROR, e));
if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr);
print!(
"{} npm_publish failed and stderr was:\n{}",
emoji::ERROR,
s
);
}
}
Loading…
Cancel
Save