@@ -19,12 +19,16 @@ struct Cli {
1919enum Commands {
2020 /// Create a new edge application project
2121 New {
22- /// Template type (cloudflare, fastly, spin)
22+ /// Template type (cloudflare, cloudrun, fastly, spin, serviceworker, webworker )
2323 #[ arg( short, long) ]
2424 template : String ,
2525
2626 /// Project name, which will be used as the directory name
2727 project_name : String ,
28+
29+ /// Destination directory (defaults to project_name)
30+ #[ arg( short, long) ]
31+ dest_dir : Option < String > ,
2832 } ,
2933}
3034
@@ -35,8 +39,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3539 Commands :: New {
3640 template,
3741 project_name,
42+ dest_dir,
3843 } => {
39- create_project ( & template, & project_name) ?;
44+ let dest = dest_dir. as_deref ( ) . unwrap_or ( & project_name) ;
45+ create_project ( & template, & project_name, dest) ?;
4046 }
4147 }
4248
@@ -50,17 +56,21 @@ fn available_templates() -> Vec<&'static str> {
5056 . collect ( )
5157}
5258
53- fn create_project ( template : & str , project_name : & str ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
59+ fn create_project (
60+ template : & str ,
61+ project_name : & str ,
62+ dest_dir : & str ,
63+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
5464 // Check if template exists
5565 let template_dir = TEMPLATES . get_dir ( template) . ok_or_else ( || {
5666 eprintln ! ( "Available templates: {:?}" , available_templates( ) ) ;
5767 format ! ( "Template '{}' not found" , template, )
5868 } ) ?;
5969
6070 // Check if target directory already exists
61- let target_path = Path :: new ( project_name ) ;
71+ let target_path = Path :: new ( dest_dir ) ;
6272 if target_path. exists ( ) {
63- return Err ( format ! ( "Directory '{}' already exists" , project_name ) . into ( ) ) ;
73+ return Err ( format ! ( "Directory '{}' already exists" , dest_dir ) . into ( ) ) ;
6474 }
6575
6676 // Create target directory
@@ -69,13 +79,13 @@ fn create_project(template: &str, project_name: &str) -> Result<(), Box<dyn std:
6979 println ! ( "Creating project '{}'..." , project_name) ;
7080
7181 // Copy template files recursively
72- copy_dir_recursive ( template_dir, target_path, project_name, Path :: new ( "" ) ) ?;
82+ copy_dir_recursive ( template_dir, target_path, project_name, dest_dir , Path :: new ( "" ) ) ?;
7383
7484 println ! (
7585 "\n ✓ Successfully created project from template '{}'" ,
7686 template
7787 ) ;
78- println ! ( " Run 'cd {}' to get started!" , project_name ) ;
88+ println ! ( " Run 'cd {}' to get started!" , dest_dir ) ;
7989 print_project_next_steps ( template, project_name) ;
8090
8191 Ok ( ( ) )
@@ -85,6 +95,7 @@ fn copy_dir_recursive(
8595 source : & Dir ,
8696 target : & Path ,
8797 project_name : & str ,
98+ dest_dir : & str ,
8899 relative_path : & Path ,
89100) -> Result < ( ) , Box < dyn std:: error:: Error > > {
90101 // Copy all files in current directory
@@ -120,7 +131,7 @@ fn copy_dir_recursive(
120131
121132 println ! (
122133 " \x1b [1mgenerate\x1b [0m {}/{}" ,
123- project_name ,
134+ dest_dir ,
124135 display_path. display( )
125136 ) ;
126137 }
@@ -132,7 +143,7 @@ fn copy_dir_recursive(
132143 let new_relative_path = relative_path. join ( dir_name) ;
133144
134145 fs:: create_dir_all ( & target_subdir) ?;
135- copy_dir_recursive ( dir, & target_subdir, project_name, & new_relative_path) ?;
146+ copy_dir_recursive ( dir, & target_subdir, project_name, dest_dir , & new_relative_path) ?;
136147 }
137148
138149 Ok ( ( ) )
@@ -155,6 +166,9 @@ fn print_project_next_steps(template: &str, project_name: &str) {
155166 println ! (
156167 " \x1b [36mcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\x1b [0m"
157168 ) ;
169+ println ! (
170+ " \x1b [36mrustup target add wasm32-unknown-unknown\x1b [0m"
171+ ) ;
158172 println ! ( " • Node.js tools:" ) ;
159173 println ! ( " \x1b [36mnpm install -g pnpm wrangler\x1b [0m" ) ;
160174 println ! ( ) ;
@@ -193,6 +207,9 @@ fn print_project_next_steps(template: &str, project_name: &str) {
193207 println ! (
194208 " \x1b [36mcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\x1b [0m"
195209 ) ;
210+ println ! (
211+ " \x1b [36mrustup target add wasm32-wasip1\x1b [0m"
212+ ) ;
196213 println ! ( " • Fastly CLI:" ) ;
197214 println ! ( " \x1b [36mbrew install fastly/tap/fastly\x1b [0m" ) ;
198215 println ! ( " Or visit: https://www.fastly.com/documentation/reference/tools/cli/" ) ;
@@ -210,6 +227,9 @@ fn print_project_next_steps(template: &str, project_name: &str) {
210227 println ! (
211228 " \x1b [36mcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\x1b [0m"
212229 ) ;
230+ println ! (
231+ " \x1b [36mrustup target add wasm32-wasip1\x1b [0m"
232+ ) ;
213233 println ! ( " • Spin CLI:" ) ;
214234 println ! (
215235 " \x1b [36mcurl -fsSL https://developer.fermyon.com/downloads/install.sh | bash\x1b [0m"
@@ -223,13 +243,37 @@ fn print_project_next_steps(template: &str, project_name: &str) {
223243 println ! ( " 3. Deploy to Fermyon Cloud:" ) ;
224244 println ! ( " \x1b [36mspin deploy\x1b [0m" ) ;
225245 }
246+ "serviceworker" | "webworker" => {
247+ println ! ( " 0. Install required tools (if not installed):" ) ;
248+ println ! ( " • Rust & Cargo:" ) ;
249+ println ! (
250+ " \x1b [36mcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh\x1b [0m"
251+ ) ;
252+ println ! (
253+ " \x1b [36mrustup target add wasm32-unknown-unknown\x1b [0m"
254+ ) ;
255+ println ! ( ) ;
256+ println ! ( " 1. Build WebAssembly:" ) ;
257+ println ! ( " \x1b [36mmake wasm\x1b [0m" ) ;
258+ println ! ( " 2. Start local server:" ) ;
259+ println ! ( " \x1b [36mmake serve\x1b [0m" ) ;
260+ }
226261 _ => {
227262 unreachable ! ( " Unknown template: {}" , template) ;
228263 }
229264 }
230265
231266 println ! ( ) ;
232- println ! (
233- " • After trying to bootstrap, edit \x1b [33mlib/app.rb\x1b [0m to develop your custom application"
234- ) ;
267+ match template {
268+ "serviceworker" | "webworker" => {
269+ println ! (
270+ " • After trying to bootstrap, edit \x1b [33mlib/app.rb\x1b [0m and \x1b [33mpublic/index.html\x1b [0m to develop your custom SPA application"
271+ ) ;
272+ }
273+ _ => {
274+ println ! (
275+ " • After trying to bootstrap, edit \x1b [33mlib/app.rb\x1b [0m to develop your custom application"
276+ ) ;
277+ }
278+ }
235279}
0 commit comments