Skip to content

Commit ac2281c

Browse files
committed
feat: create config files (copy .example files)
1 parent 2920248 commit ac2281c

File tree

4 files changed

+187
-8
lines changed

4 files changed

+187
-8
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333
"commander": "13.1.0",
3434
"conf": "13.1.0",
3535
"execa": "9.5.2",
36+
"fast-glob": "3.3.3",
3637
"fs-extra": "11.2.0",
3738
"ky": "1.7.4",
3839
"move-file": "3.1.0",
3940
"ora": "8.1.1",
4041
"tar": "7.4.3",
41-
"tempy": "3.1.0"
42+
"tempy": "3.1.0",
43+
"ts-pattern": "5.7.0"
4244
},
4345
"devDependencies": {
4446
"@biomejs/biome": "1.9.4",

pnpm-lock.yaml

Lines changed: 145 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/functions.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { type Target, replacableIndicator, repos } from '@/lib/repos.js';
55
import { spinner } from '@/lib/spinner.js';
66
import { Future } from '@swan-io/boxed';
77
import chalk from 'chalk';
8-
import { exists, readdir, writeFile } from 'fs-extra';
8+
import { copyFile, exists, readdir, writeFile } from 'fs-extra';
99
import ky from 'ky';
1010
import { moveFile } from 'move-file';
1111
import { 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

Comments
 (0)