@@ -5,7 +5,7 @@ import { type Target, replacableIndicator, repos } from '@/lib/repos.js';
55import { spinner } from '@/lib/spinner.js' ;
66import { Future } from '@swan-io/boxed' ;
77import chalk from 'chalk' ;
8- import { exists , readdir , writeFile } from 'fs-extra' ;
8+ import { copyFile , exists , readdir , writeFile } from 'fs-extra' ;
99import ky from 'ky' ;
1010import { moveFile } from 'move-file' ;
1111import { extract } from 'tar' ;
@@ -50,11 +50,7 @@ export const downloadAndSaveRepoTarball = async ({
5050 const targetInfos = repos [ target ] ;
5151 const repoUrl = targetInfos . url . replace ( replacableIndicator , branch ) ;
5252
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 ( ) ) ;
5854 if ( responseResult . isError ( ) ) {
5955 debug ( 'Cannot download template from repository' , responseResult . error ) ;
6056 spinner . fail (
@@ -63,6 +59,7 @@ export const downloadAndSaveRepoTarball = async ({
6359 process . exit ( 1 ) ;
6460 }
6561
62+ // [TODO]: prefer to use a standardized alternative instead of Buffer
6663 const saveFileResult = await Future . fromPromise ( writeFile ( tmpFilePath , Buffer . from ( responseResult . value ) ) ) ;
6764 if ( saveFileResult . isError ( ) ) {
6865 debug ( 'Cannot saved downloaded template file' , saveFileResult . error ) ;
@@ -131,3 +128,18 @@ export const copyFilesToNewProject = async ({
131128 } ,
132129 } ) ;
133130} ;
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