Skip to content

Commit

Permalink
feat: qwik cli manifest (QwikDev#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat authored May 21, 2022
1 parent cd279e1 commit 121e9a1
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM node:17.9.0-buster
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.59.0
RUST_VERSION=1.61.0

RUN set -eux; \
dpkgArch="$(dpkg --print-architecture)"; \
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
toolchain: 1.59.0
target: wasm32-unknown-unknown

- name: Cache cargo dependencies
Expand Down Expand Up @@ -229,8 +227,6 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
override: true
toolchain: 1.59.0
target: ${{ matrix.settings.target }}

- name: Pull Latest Image
Expand Down Expand Up @@ -505,9 +501,8 @@ jobs:
if: ${{ needs.changes.outputs.fullbuild == 'true' }}
uses: actions-rs/toolchain@v1
with:
toolchain: 1.59.0
profile: default
override: true
profile: minimal
components: rustfmt, clippy

- name: Cache cargo dependencies
if: ${{ needs.changes.outputs.fullbuild == 'true' }}
Expand Down
83 changes: 11 additions & 72 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/qwik/src/optimizer/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "3.0.0-beta.5"
clap = "3.1.8"
qwik-core = { path = "../core", features = ["fs", "parallel"] }
path-absolutize = "3.0.11"
56 changes: 30 additions & 26 deletions packages/qwik/src/optimizer/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use std::path::PathBuf;

use clap::{App, AppSettings, Arg};
use clap::{Arg, Command};
use path_absolutize::Absolutize;
use qwik_core::{transform_fs, EntryStrategy, MinifyMode, TransformFsOptions};

struct OptimizerInput {
glob: Option<String>,
manifest: Option<String>,
src: PathBuf,
dest: PathBuf,
strategy: EntryStrategy,
Expand All @@ -20,58 +21,56 @@ struct OptimizerInput {
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let matches = App::new("qwik")
let matches = Command::new("qwik")
.version("1.0")
.setting(
AppSettings::ArgRequiredElseHelp
| AppSettings::SubcommandRequiredElseHelp
| AppSettings::InferSubcommands
| AppSettings::DisableHelpSubcommand,

)
.arg_required_else_help(true)
.subcommand_required(true)
.infer_subcommands(true)
.disable_help_subcommand(true)
.subcommand_required(true).arg_required_else_help(true)
.about("Qwik CLI allows to optimize qwik projects before bundling")
.subcommand(
App::new("optimize")
Command::new("optimize")
.about("takes a source directory of qwik code and outputs an optimized version that lazy loads")
.setting(AppSettings::ArgRequiredElseHelp)
.arg_required_else_help(true)
.arg(
Arg::new("src")
.short('s')
.long("src")
.default_value(".")
.takes_value(true)
.about("relative path to the source directory"),
.help("relative path to the source directory"),
)
.arg(
Arg::new("dest")
.short('d')
.long("dest")
.required(true)
.takes_value(true)
.about("relative path to the output directory"),
)
.arg(
Arg::new("glob")
.short('g')
.long("glob")
.takes_value(true)
.about("glob used to match files within the source directory"),
.help("relative path to the output directory"),
)
.arg(
Arg::new("strategy")
.long("strategy")
.possible_values(["single", "hook", "smart", "component"])
.takes_value(true)
.about("entry strategy used to group hooks"),
.help("entry strategy used to group hooks"),
)
.arg(
Arg::new("manifest")
.short('m')
.long("manifest")
.takes_value(true)
.help("filename of the manifest"),
)
.arg(
Arg::new("no-transpile")
.long("no-transpile")
.about("transpile TS and JSX into JS").takes_value(false)
.help("transpile TS and JSX into JS").takes_value(false)
)
.arg(Arg::new("minify").long("minify").possible_values(["minify", "simplify", "none"]).takes_value(true).about("outputs minified source code"))
.arg(Arg::new("sourcemaps").long("sourcemaps").about("generates sourcemaps").takes_value(false))
.arg(Arg::new("extensions").long("extensions").about("keep explicit extensions on imports").takes_value(false)),
.arg(Arg::new("minify").long("minify").possible_values(["minify", "simplify", "none"]).takes_value(true).help("outputs minified source code"))
.arg(Arg::new("sourcemaps").long("sourcemaps").help("generates sourcemaps").takes_value(false))
.arg(Arg::new("extensions").long("extensions").help("keep explicit extensions on imports").takes_value(false)),
)
.get_matches();

Expand All @@ -80,6 +79,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if let Some(matches) = matches.subcommand_matches("optimize") {
// "$ myapp test" was run
let strategy = match matches.value_of("strategy") {
Some("inline") => EntryStrategy::Inline,
Some("hook") => EntryStrategy::Hook,
Some("single") => EntryStrategy::Single,
Some("component") => EntryStrategy::Component,
Expand All @@ -95,6 +95,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
optimize(OptimizerInput {
src: matches.value_of_t_or_exit("src"),
dest: matches.value_of_t_or_exit("dest"),
manifest: matches.value_of("manifest").map(|s| s.into()),
glob: None,
strategy,
minify,
Expand Down Expand Up @@ -124,6 +125,9 @@ fn optimize(
scope: None,
})?;

result.write_to_fs(&current_dir.join(optimizer_input.dest).absolutize()?)?;
result.write_to_fs(
&current_dir.join(optimizer_input.dest).absolutize()?,
optimizer_input.manifest,
)?;
Ok(result)
}
2 changes: 1 addition & 1 deletion packages/qwik/src/optimizer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ swc_common = { version = "0.18.1", features = ["sourcemap"] }
swc_atoms = "0.2.11"
serde = "1.0.137"
serde_bytes = "0.11.6"
serde_json = "1.0.81"
simple-error = "0.2.3"
base64 = "0.13.0"
pathdiff = "0.2.1"
Expand All @@ -30,7 +31,6 @@ path-slash="0.1.4"

[dev-dependencies]
insta = "1.14.0"
serde_json = "1.0.81"

[features]
fs=[]
Expand Down
1 change: 1 addition & 0 deletions packages/qwik/src/optimizer/core/benches/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ fn transform_todo_app(b: &mut Bencher) {
transpile: true,
entry_strategy: EntryStrategy::Single,
dev: true,
scope: None,
})
});
}
1 change: 1 addition & 0 deletions packages/qwik/src/optimizer/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(clippy::all)]
#![deny(clippy::perf)]
#![deny(clippy::nursery)]
#![allow(clippy::use_self)]

#[cfg(test)]
mod test;
Expand Down
Loading

0 comments on commit 121e9a1

Please sign in to comment.