@@ -6,70 +6,70 @@ import { oraPromise } from "ora";
66import { prettyPath } from "react-native-node-api" ;
77
88export const initCommand = new Command ( "init" )
9- . description ( "Generate the project scaffold" )
10- . argument ( "<name>" , "Type the project name" )
11- . action ( async ( str ) => {
12- const projectName = str && str . length > 0 ? str : "ferric_project" ;
13- const generatePath = path . join ( process . cwd ( ) , projectName ) ;
14- await oraPromise (
15- generateProject ( { outputPath : generatePath , projectName } ) ,
16- {
17- text : "Generating project" ,
18- successText : `Generated project ${ prettyPath ( generatePath ) } ` ,
19- failText : ( error ) => `Failed to generate the project: ${ error . message } ` ,
20- } ,
21- ) ;
22- } ) ;
9+ . description ( "Generate the project scaffold" )
10+ . argument ( "<name>" , "Type the project name" )
11+ . action ( async ( str ) => {
12+ const projectName = str && str . length > 0 ? str : "ferric_project" ;
13+ const generatePath = path . join ( process . cwd ( ) , projectName ) ;
14+ await oraPromise (
15+ generateProject ( { outputPath : generatePath , projectName } ) ,
16+ {
17+ text : "Generating project" ,
18+ successText : `Generated project ${ prettyPath ( generatePath ) } ` ,
19+ failText : ( error ) => `Failed to generate the project: ${ error . message } ` ,
20+ } ,
21+ ) ;
22+ } ) ;
2323
2424async function replaceStrInFile (
25- filePath : string ,
26- oldStr : string ,
27- newStr : string ,
25+ filePath : string ,
26+ oldStr : string ,
27+ newStr : string ,
2828) {
29- const content = await fsPromise . readFile ( filePath , "utf8" ) ;
30- const updatedContent = content . replace ( `/ ${ oldStr } /gi` , newStr ) ;
31- await fsPromise . writeFile ( filePath , updatedContent , "utf8" ) ;
29+ const content = await fsPromise . readFile ( filePath , "utf8" ) ;
30+ const updatedContent = content . replaceAll ( oldStr , newStr ) ;
31+ await fsPromise . writeFile ( filePath , updatedContent , "utf8" ) ;
3232}
3333
3434function createFolder ( path : string ) {
35- if ( ! fs . existsSync ( path ) ) {
36- fs . mkdirSync ( path ) ;
37- }
35+ if ( ! fs . existsSync ( path ) ) {
36+ fs . mkdirSync ( path ) ;
37+ }
3838}
3939
4040async function copyAllTemplateFiles ( outputFilePath : string ) {
41- const templateDir = path . join ( import . meta. dirname , "templates" ) ;
42- await fsPromise . cp ( templateDir , outputFilePath , {
43- recursive : true ,
44- } ) ;
45- await fsPromise . rename (
46- `${ outputFilePath } /lib.rs` ,
47- `${ outputFilePath } /src/lib.rs` ,
48- ) ;
49- await fsPromise . rename (
50- `${ outputFilePath } /gitignore` ,
51- `${ outputFilePath } /.gitignore` ,
52- ) ;
41+ const templateDir = path . join ( import . meta. dirname , "templates" ) ;
42+ await fsPromise . cp ( templateDir , outputFilePath , {
43+ recursive : true ,
44+ } ) ;
45+ await fsPromise . rename (
46+ `${ outputFilePath } /lib.rs` ,
47+ `${ outputFilePath } /src/lib.rs` ,
48+ ) ;
49+ await fsPromise . rename (
50+ `${ outputFilePath } /gitignore` ,
51+ `${ outputFilePath } /.gitignore` ,
52+ ) ;
5353}
5454
5555async function generateProject ( {
56- outputPath,
57- projectName,
56+ outputPath,
57+ projectName,
5858} : {
59- outputPath : string ;
60- projectName : string ;
59+ outputPath : string ;
60+ projectName : string ;
6161} ) {
62- createFolder ( outputPath ) ;
63- createFolder ( `${ outputPath } /src` ) ;
64- await copyAllTemplateFiles ( outputPath ) ;
65- await replaceStrInFile (
66- `${ outputPath } /package.json` ,
67- "project_name" ,
68- projectName ,
69- ) ;
70- await replaceStrInFile (
71- `${ outputPath } /Cargo.toml` ,
72- "project_name" ,
73- projectName ,
74- ) ;
62+ createFolder ( outputPath ) ;
63+ createFolder ( `${ outputPath } /src` ) ;
64+ await copyAllTemplateFiles ( outputPath ) ;
65+ await replaceStrInFile (
66+ `${ outputPath } /package.json` ,
67+ "project_name" ,
68+ projectName ,
69+ ) ;
70+ await replaceStrInFile (
71+ `${ outputPath } /Cargo.toml` ,
72+ "project_name" ,
73+ projectName ,
74+ ) ;
7575}
0 commit comments