@@ -11,23 +11,29 @@ const PRETTIER: &str = ".prettierrc.json";
1111const CI_WORKFLOW : & str = ".github/workflows/ci.yml" ;
1212const GITIGNORE : & str = ".gitignore" ;
1313
14- pub fn install ( ) -> Result < ( ) > {
15- ensure_file ( GITIGNORE , "typescript/.gitignore" ) ?;
16- ensure_file ( ESLINT , "typescript/eslint.config.ts" ) ?;
17- ensure_file ( TSCONFIG , "typescript/tsconfig.json" ) ?;
18- ensure_file ( VITEST , "typescript/vitest.config.ts" ) ?;
19- ensure_file ( PRETTIER , "typescript/prettierrc.json" ) ?;
20- ensure_ci_workflow ( ) ?;
14+ pub fn install ( force : bool ) -> Result < ( ) > {
15+ ensure_file ( GITIGNORE , "typescript/.gitignore" , force ) ?;
16+ ensure_file ( ESLINT , "typescript/eslint.config.ts" , force ) ?;
17+ ensure_file ( TSCONFIG , "typescript/tsconfig.json" , force ) ?;
18+ ensure_file ( VITEST , "typescript/vitest.config.ts" , force ) ?;
19+ ensure_file ( PRETTIER , "typescript/prettierrc.json" , force ) ?;
20+ ensure_ci_workflow ( force ) ?;
2121
2222 println ! ( "TypeScript scaffolding complete" ) ;
2323 Ok ( ( ) )
2424}
2525
26- fn ensure_ci_workflow ( ) -> Result < ( ) > {
27- let destination = Utf8Path :: new ( CI_WORKFLOW ) ;
28- if destination. exists ( ) {
29- return Ok ( ( ) ) ;
30- }
26+ fn ensure_ci_workflow ( force : bool ) -> Result < ( ) > {
27+ let destination = Utf8Path :: new ( CI_WORKFLOW ) ;
28+ if destination. exists ( ) {
29+ if force {
30+ write_template ( destination, "typescript/.github/workflows/ci.yml" ) ?;
31+ println ! ( " overwritten {}" , destination) ;
32+ } else {
33+ println ! ( " skipped {}" , destination) ;
34+ }
35+ return Ok ( ( ) ) ;
36+ }
3137
3238 if let Some ( parent) = destination. parent ( ) {
3339 fs:: create_dir_all ( parent) ?;
@@ -38,11 +44,17 @@ fn ensure_ci_workflow() -> Result<()> {
3844 Ok ( ( ) )
3945}
4046
41- fn ensure_file ( target : & str , template : & str ) -> Result < ( ) > {
42- let destination = Utf8Path :: new ( target) ;
43- if destination. exists ( ) {
44- return Ok ( ( ) ) ;
45- }
47+ fn ensure_file ( target : & str , template : & str , force : bool ) -> Result < ( ) > {
48+ let destination = Utf8Path :: new ( target) ;
49+ if destination. exists ( ) {
50+ if force {
51+ write_template ( destination, template) ?;
52+ println ! ( " overwritten {}" , destination) ;
53+ } else {
54+ println ! ( " skipped {}" , destination) ;
55+ }
56+ return Ok ( ( ) ) ;
57+ }
4658
4759 write_template ( destination, template) ?;
4860 println ! ( " created {}" , destination) ;
0 commit comments