rsw/
lib.rs

1//! Usage
2//!
3//! ```bash
4//! #! help
5//! rsw -h
6//!
7//! #! new help
8//! rsw new -h
9//!
10//! #! dev
11//! rsw watch
12//!
13//! #! release
14//! rsw build
15//!
16//! #! generate a project quickly
17//! rsw new <name>
18//!
19//! #! clean - link & build
20//! rsw clean
21//! ```
22//!
23//! ----------
24//!
25//! rsw.toml
26//!
27//! <https://github.com/lencx/rsw-rs/blob/main/src/template/rsw.toml>
28//!
29//! ```toml
30//! name = "rsw"
31//! version = "0.1.0"
32//!
33//! #! time interval for file changes to trigger wasm-pack build, default `50` milliseconds
34//! interval = 50
35//!
36//! #! link
37//! #! npm link @see https://docs.npmjs.com/cli/v8/commands/npm-link
38//! #! yarn link @see https://classic.yarnpkg.com/en/docs/cli/link
39//! #! pnpm link @see https://pnpm.io/cli/link
40//! #! The link command will only be executed if `[[crates]] link = true`
41//! #! cli: `npm` | `yarn` | `pnpm`, default is `npm`
42//! cli = "npm"
43//!
44//! #! ---------------------------
45//!
46//! #! rsw new <name>
47//! [new]
48//! #! @see https://rustwasm.github.io/docs/wasm-pack/commands/new.html
49//! #! using: `wasm-pack` | `rsw` | `user`, default is `wasm-pack`
50//! #! 1. wasm-pack: `rsw new <name> --template <template> --mode <normal|noinstall|force>`
51//! #! 2. rsw: `rsw new <name>`, built-in templates
52//! #! 3. user: `rsw new <name>`, if `dir` is not configured, use `wasm-pack new <name>` to initialize the project
53//! using = "wasm-pack"
54//! #! this field needs to be configured when `using = "user"`
55//! #! `using = "wasm-pack"` or `using = "rsw"`, this field will be ignored
56//! #! copy all files in this directory
57//! dir = "my-template"
58//!
59//! #! ################# NPM Package #################
60//!
61//! #! When there is only `name`, other fields will use the default configuration
62//! #! -------- package: rsw-hello --------
63//! [[crates]]
64//! #! npm package name
65//! name = "rsw-hello"
66//! #! run `npm link`: `true` | `false`, default is `false`
67//! link = false
68//!
69//! #! =======================================================
70//!
71//! #! -------- package: @rsw/hello --------
72//! # [[crates]]
73//! # #! npm package name
74//! # name = "@rsw/hello"
75//! # #! default is `.`
76//! # root = "."
77//! # #! default is `pkg`
78//! # out-dir = "pkg"
79//! # #! target: bundler | nodejs | web | no-modules, default is `web`
80//! # target = "web"
81//! #! run `npm link`: `true` | `false`, default is `false`
82//! # link = false
83//! # #! rsw watch
84//! # [crates.watch]
85//! # #! default is `true`
86//! # run = false
87//! # #! profile: `dev` | `profiling`, default is `dev`
88//! # profile = "dev"
89//! # #! rsw build
90//! # [crates.build]
91//! # run = false
92//! # #! profile: `release` | `profiling`, default is `release`
93//! # profile = "release"
94//! ```
95
96pub mod config;
97pub mod core;
98pub mod template;
99pub mod utils;
100
101#[macro_use]
102extern crate serde_derive;
103#[macro_use]
104extern crate log;
105
106use crate::core::RswErr;
107use crate::utils::print;
108
109pub use crate::core::Cli;
110
111pub fn rsw_cli() {
112    utils::init_logger();
113
114    if !utils::check_env_cmd("wasm-pack") {
115        // TODO: ask if you want to install `wasm-pack` now
116        print(RswErr::WasmPack);
117        std::process::exit(1);
118    }
119
120    Cli::new();
121}