@@ -5,7 +5,7 @@ import { type Target, replacableIndicator, repos } from '@/lib/repos.js';
5
5
import { spinner } from '@/lib/spinner.js' ;
6
6
import { Future } from '@swan-io/boxed' ;
7
7
import chalk from 'chalk' ;
8
- import { exists , readdir , writeFile } from 'fs-extra' ;
8
+ import { copyFile , exists , readdir , writeFile } from 'fs-extra' ;
9
9
import ky from 'ky' ;
10
10
import { moveFile } from 'move-file' ;
11
11
import { extract } from 'tar' ;
@@ -50,11 +50,7 @@ export const downloadAndSaveRepoTarball = async ({
50
50
const targetInfos = repos [ target ] ;
51
51
const repoUrl = targetInfos . url . replace ( replacableIndicator , branch ) ;
52
52
53
- const responseResult = await Future . fromPromise (
54
- ky ( repoUrl , {
55
- responseType : 'stream' ,
56
- } ) . arrayBuffer ( ) ,
57
- ) ;
53
+ const responseResult = await Future . fromPromise ( ky ( repoUrl , { responseType : 'stream' } ) . arrayBuffer ( ) ) ;
58
54
if ( responseResult . isError ( ) ) {
59
55
debug ( 'Cannot download template from repository' , responseResult . error ) ;
60
56
spinner . fail (
@@ -63,6 +59,7 @@ export const downloadAndSaveRepoTarball = async ({
63
59
process . exit ( 1 ) ;
64
60
}
65
61
62
+ // [TODO]: prefer to use a standardized alternative instead of Buffer
66
63
const saveFileResult = await Future . fromPromise ( writeFile ( tmpFilePath , Buffer . from ( responseResult . value ) ) ) ;
67
64
if ( saveFileResult . isError ( ) ) {
68
65
debug ( 'Cannot saved downloaded template file' , saveFileResult . error ) ;
@@ -131,3 +128,18 @@ export const copyFilesToNewProject = async ({
131
128
} ,
132
129
} ) ;
133
130
} ;
131
+
132
+ /**
133
+ * Utility to create the file associated
134
+ * to its .example sibling.
135
+ *
136
+ * `ensureExampleFile('.env.example')` will create `.env` file next to the .example one.
137
+ */
138
+ export const ensureExampleFile = async ( filePath : string ) => {
139
+ // Make sure there is a file to copy
140
+
141
+ // get the path for the final file name (without .example)
142
+ const filePathWithoutExample = filePath . replace ( '.example' , '' ) ;
143
+
144
+ return Future . fromPromise ( copyFile ( filePath , filePathWithoutExample ) ) ;
145
+ } ;
0 commit comments