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

Context struct proof of concept #122

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
9cecbfc
Removed 'NOT IMPLEMENTED' flags from commands that are now implemented.
data-pup May 3, 2018
7ce2674
FIXUP COMMIT: Starting work on adding a lazy static variable to repre…
data-pup May 3, 2018
7a050bb
Build an NpmPackage object -from- a CargoManifesto, rather than conve…
data-pup May 4, 2018
ba9d881
Fixed some compilation errors, this does not pass tests but will now …
data-pup May 4, 2018
2424d04
The CARGO_TOML file will need to be used in the other files, so this …
data-pup May 4, 2018
637d4ef
Reordered some things in the manifest file, structs/functions/impl's …
data-pup May 4, 2018
f01464c
Minor change, the filenames can be wrapped up in a struct rather than…
data-pup May 4, 2018
cf93e54
Run function now accepts the Cli object itself. Not sure if this is a
data-pup May 4, 2018
5f2855b
Added some context scaffolding. Thinking about whether commands will …
data-pup May 4, 2018
a0dbe0e
This commit makes a number of changes. The primary goal of this commi…
data-pup May 4, 2018
4cd3675
This commit removes the duplicate definition of the NpmPackage struct
data-pup May 5, 2018
011c23d
This commit adjusts the API of the context struct. Rather than accepting
data-pup May 5, 2018
86d9701
Adjusted the run command, rather than accepting the entire Cli object…
data-pup May 5, 2018
5f6602e
Verbosity is given to the context constructor.
data-pup May 5, 2018
00318d8
The manifest.rs file was getting to be a little large, so I have move…
data-pup May 5, 2018
f5343cc
Manifest is now divided into separate files for representing Cargo.to…
data-pup May 5, 2018
87fc158
Formatted codebase.
data-pup May 5, 2018
a26a41e
Following the same logic as in manifest, breaking the command module …
data-pup May 5, 2018
b45704d
Crate path is now set by the context struct. This means that the comm…
data-pup May 5, 2018
ec73357
Now that these are not options, I adjusted the command functions to a…
data-pup May 5, 2018
6f72ec0
Divided the init command out into a new component. Build has also bee…
data-pup May 5, 2018
0ed96ad
Formatting change.
data-pup May 5, 2018
c2a0670
Added a new module for the manifest things. Still some rough edges to…
data-pup May 5, 2018
48b3c08
Quieting linting warnings about unused imports and variables.
data-pup May 5, 2018
53758d8
Formatted code, added some (temporary) banners etc.
data-pup May 5, 2018
dcf4d61
Added some further scaffolding. This will make adding timers to funct…
data-pup May 5, 2018
19f9936
The from trait is now implemented for the Cli object instead. I think…
data-pup May 6, 2018
7b7caf1
Moved the progress bar messages into the Context's init method.
data-pup May 6, 2018
2cefbcc
FIXUP COMMIT: This is a large commit, and represents a majority of th…
data-pup May 6, 2018
79e4823
Oops. Removed a broken mod link.
data-pup May 6, 2018
9272ba2
Moved the progress bar file into the context module, now that this is…
data-pup May 6, 2018
6fe3a81
Formatting.
data-pup May 6, 2018
257711f
Moved the init wrapper method and its helpers into a separate functio…
data-pup May 6, 2018
04f7de3
Adding some documentation to the helper methods.
data-pup May 6, 2018
626ded1
Documenting things some more.
data-pup May 6, 2018
1c5a61f
Renamed bindgen related functions.
data-pup May 6, 2018
1e761bf
Action might as well derive debug, even if the context itself cannot.
data-pup May 6, 2018
897412b
Added two other helper files for the context's subcommand wrapper met…
data-pup May 6, 2018
b8afa5a
Removed a number of unused imports, as well as getting rid of the pac…
data-pup May 6, 2018
34f3d87
More lint/warning cleanup.
data-pup May 6, 2018
738bf9a
Moving the command helper functions into the command submodule. It mi…
data-pup May 6, 2018
15a1467
Added progress bar message to the publish command. (Accidentally remo…
data-pup May 6, 2018
d1097c4
Removed fixup notes from the test file, this is going to be fixed now.
data-pup May 6, 2018
387d1b9
get_crate_name function should not be used anymore, removing this fro…
data-pup May 6, 2018
98303cd
readme tests are going to need rethinking. That file is not really a …
data-pup May 6, 2018
5b70460
Formatting.
data-pup May 6, 2018
42fd9be
Removed banner comment.
data-pup May 6, 2018
ba00a62
Removed another comment, this doesn't seem so bad, imo.
data-pup May 6, 2018
eb6558b
While thinking about how to test this design, I had a little bit of a…
data-pup May 6, 2018
ef37211
Cleaning up some more details. Maybe this isn't such a bad idea?
data-pup May 7, 2018
72bcfcb
I think this is about wrapped up as far as restructuring goes. Hmm.
data-pup May 7, 2018
1b320e0
Removed the old Cargo.toml reading file, this is now in the context s…
data-pup May 7, 2018
b18b9f9
Added a noop, this is speculative, but should help with testing.
data-pup May 7, 2018
4c97696
Command no longer needs to be a submodule.
data-pup May 7, 2018
8e8b54a
First chunk of work on refactoring the test suite to interact with th…
data-pup May 7, 2018
c8e4f33
Trying to move some of the important logic out to the init file. This…
data-pup May 7, 2018
d42e382
Blegh. The manifest thing is not awesome. Figuring out how I can work…
data-pup May 7, 2018
faff198
Tests are passing :) There is cleanup, but I am going to check and se…
data-pup May 7, 2018
62fa416
Adding fixup notes.
data-pup May 7, 2018
16453a6
Formatting.
data-pup May 7, 2018
7e12290
Removed unused imports.
data-pup May 7, 2018
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
53 changes: 0 additions & 53 deletions src/bindgen.rs

This file was deleted.

49 changes: 0 additions & 49 deletions src/build.rs

This file was deleted.

111 changes: 3 additions & 108 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -1,124 +1,19 @@
use bindgen;
use build;
use console::style;
use emoji;
use error::Error;
use indicatif::HumanDuration;
use manifest;
use npm;
#[allow(unused)]
use quicli::prelude::*;
use readme;
use std::fs;
use std::result;
use std::time::Instant;
use PBAR;

#[derive(Debug, StructOpt)]
pub enum Command {
#[structopt(name = "init")]
/// 🐣 initialize a package.json based on your compiled wasm
/// 🐣 initialize a package.json based on your compiled wasm!
Init {
path: Option<String>,
#[structopt(long = "scope", short = "s")]
scope: Option<String>,
},
#[structopt(name = "pack")]
/// 🍱 create a tar of your npm package but don't publish! [NOT IMPLEMENTED]
/// 🍱 create a tar of your npm package but don't publish!
Pack { path: Option<String> },
#[structopt(name = "publish")]
/// 🎆 pack up your npm package and publish! [NOT IMPLEMENTED]
/// 🎆 pack up your npm package and publish!
Publish { path: Option<String> },
}

pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> {
// Run the correct command based off input and store the result of it so that we can clear
// the progress bar then return it
let status = match command {
Command::Init { path, scope } => init(path, scope),
Command::Pack { path } => pack(path),
Command::Publish { path } => publish(path),
};

match status {
Ok(_) => {}
Err(ref e) => {
PBAR.error(e.error_type());
}
}

// Make sure we always clear the progress bar before we abort the program otherwise
// stderr and stdout output get eaten up and nothing will work. If this part fails
// to work and clear the progress bars then you're really having a bad day with your tools.
PBAR.done()?;

// Return the actual status of the program to the main function
status
}

// quicli::prelude::* imports a different result struct which gets
// precedence over the std::result::Result, so have had to specify
// the correct type here.
pub fn create_pkg_dir(path: &str) -> result::Result<(), Error> {
let step = format!(
"{} {}Creating a pkg directory...",
style("[3/7]").bold().dim(),
emoji::FOLDER
);
let pb = PBAR.message(&step);
let pkg_dir_path = format!("{}/pkg", path);
fs::create_dir_all(pkg_dir_path)?;
pb.finish();
Ok(())
}

fn init(path: Option<String>, scope: Option<String>) -> result::Result<(), Error> {
let started = Instant::now();

let crate_path = set_crate_path(path);

build::rustup_add_wasm_target()?;
build::cargo_build_wasm(&crate_path)?;
create_pkg_dir(&crate_path)?;
manifest::write_package_json(&crate_path, scope)?;
readme::copy_from_crate(&crate_path)?;
bindgen::cargo_install_wasm_bindgen()?;
let name = manifest::get_crate_name(&crate_path)?;
bindgen::wasm_bindgen_build(&crate_path, &name)?;
PBAR.message(&format!(
"{} Done in {}",
emoji::SPARKLE,
HumanDuration(started.elapsed())
));
PBAR.message(&format!(
"{} Your WASM pkg is ready to publish at {}/pkg",
emoji::PACKAGE,
&crate_path
));
Ok(())
}

fn pack(path: Option<String>) -> result::Result<(), Error> {
let crate_path = set_crate_path(path);

npm::npm_pack(&crate_path)?;
PBAR.message("🎒 packed up your package!");
Ok(())
}

fn publish(path: Option<String>) -> result::Result<(), Error> {
let crate_path = set_crate_path(path);

npm::npm_publish(&crate_path)?;
PBAR.message("💥 published your package!");
Ok(())
}

fn set_crate_path(path: Option<String>) -> String {
let crate_path = match path {
Some(p) => p,
None => ".".to_string(),
};

crate_path
}
43 changes: 43 additions & 0 deletions src/context/from_cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::convert::From;

use super::{Action, Context};
use command::Command;
use context::progressbar::ProgressOutput;
use Cli;

impl From<Cli> for Context {
fn from(args: Cli) -> Context {
let pbar = ProgressOutput::new();
let Cli { cmd, verbosity } = args;
match cmd {
Command::Init { path, scope } => Context {
action: Action::Init,
manifest: None,
path: crate_path(path),
pbar,
scope: scope.clone(),
_verbosity: verbosity,
},
Command::Pack { path } => Context {
action: Action::Pack,
manifest: None,
path: crate_path(path),
pbar,
scope: None,
_verbosity: verbosity,
},
Command::Publish { path } => Context {
action: Action::Publish,
manifest: None,
path: crate_path(path),
pbar,
scope: None,
_verbosity: verbosity,
},
}
}
}

fn crate_path(path_arg: Option<String>) -> String {
path_arg.unwrap_or(".".to_string())
}
Loading