Skip to content

Commit

Permalink
Merge pull request #9 from metacall/fix-create
Browse files Browse the repository at this point in the history
fix(creator): exclude `node_modules` and `dist` during loading templates
  • Loading branch information
hulxv authored Aug 24, 2024
2 parents 2f4c85c + d4f2656 commit d691fa7
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 36 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
/node_modules
/dist
target
node_modules
dist
.vscode
5 changes: 5 additions & 0 deletions crates/metassr-create/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ fn main() {
.into_iter()
.filter_map(Result::ok)
.filter(|e| e.file_type().is_file())
.filter(|e| {
!e.path().components().any(|component| {
component.as_os_str() == "node_modules" || component.as_os_str() == "dist"
})
})
{
let path = entry.path();
let relative_path = path.strip_prefix(templates_dir).unwrap().to_str().unwrap();
Expand Down
15 changes: 4 additions & 11 deletions crates/metassr-create/templates/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
"scripts": {
"run": "metassr-cli --debug-mode=http run",
"build:ssr": "metassr-cli --debug-mode=metacall build -t ssr",
"serve:ssg": "metassr-cli --debug-mode=http run --serve",
"build:ssg": "metassr-cli --debug-mode=metacall build -t ssg",
"dev": "rspack --watch"
"serve": "metassr-cli --debug-mode=http run --serve",
"build:ssg": "metassr-cli --debug-mode=metacall build -t ssg"
},
"devDependencies": {
"@rspack/cli": "^0.7.5",
"@rspack/core": "^0.7.5",
"@swc/cli": "^0.3.12",
"@swc/core": "^1.4.16",
"@swc/helpers": "^0.5.11",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8"
"@rspack/core": "^0.7.5"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
}
}
6 changes: 0 additions & 6 deletions crates/metassr-create/templates/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
"dev": "rspack --watch"
},
"devDependencies": {
"@rspack/cli": "^0.7.5",
"@rspack/core": "^0.7.5",
"@swc/cli": "^0.3.12",
"@swc/core": "^1.4.16",
"@swc/helpers": "^0.5.11",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8"
},
"dependencies": {
"react": "^18.3.1",
Expand Down
6 changes: 5 additions & 1 deletion crates/metassr-utils/src/cache_dir.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use anyhow::Result;
use std::{
collections::HashMap, ffi::OsStr, fs::{self, File}, io::{Read, Write}, path::{Path, PathBuf}
collections::HashMap,
ffi::OsStr,
fs::{self, File},
io::{Read, Write},
path::{Path, PathBuf},
};
use walkdir::WalkDir;

Expand Down
2 changes: 1 addition & 1 deletion metassr-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Args {
pub log_file: Option<String>,

#[command(subcommand)]
pub commands: Option<Commands>,
pub commands: Commands,
}

#[derive(Debug, ValueEnum, PartialEq, Eq, Clone)]
Expand Down
14 changes: 6 additions & 8 deletions metassr-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn main() -> Result<()> {
[Some(DebugMode::All), Some(DebugMode::Metacall)].contains(&args.debug_mode);
let allow_http_debug = [Some(DebugMode::All), Some(DebugMode::Http)].contains(&args.debug_mode);

if let Some(Commands::Create { .. }) = args.commands {
if let Commands::Create { .. } = args.commands {
tracing_subscriber::fmt()
.with_target(false)
.without_time()
Expand All @@ -45,28 +45,26 @@ async fn main() -> Result<()> {
set_var("METACALL_DEBUG", "1");
}
}

match args.commands {
Some(Commands::Build {
Commands::Build {
out_dir,
build_type,
}) => {
} => {
cli::Builder::new(build_type, out_dir).exec()?;
}
Some(Commands::Run { port, serve }) => {
Commands::Run { port, serve } => {
cli::Runner::new(port, serve, allow_http_debug)
.exec()
.await?;
}
Some(Commands::Create {
Commands::Create {
project_name,
version,
description,
template,
}) => {
} => {
cli::Creator::new(project_name, version, description, template).exec()?;
}
_ => {}
};

Ok(())
Expand Down
10 changes: 4 additions & 6 deletions tests/web-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
"description": "",
"main": "App.tsx",
"scripts": {
"build": "node scripts/build.js"
"build": "../../target/debug/metassr-cli --debug-mode=metacall build",
"build:ssg": "../../target/debug/metassr-cli --debug-mode=metacall build -t ssg",
"run": "../../target/debug/metassr-cli --debug-mode=metacall run ",
"run:ssg": "../../target/debug/metassr-cli --debug-mode=metacall run --serve"
},
"devDependencies": {
"@swc/cli": "^0.3.12",
"@swc/core": "^1.4.16",
"@swc/helpers": "^0.5.11",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8"
},
"dependencies": {
"typescript": "^4.6.4",
"react": "^18.3.1",
"@rspack/core": "^0.7.5",
"react-dom": "^18.3.1"
}
}

0 comments on commit d691fa7

Please sign in to comment.