-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
91 lines (68 loc) · 1.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env node
/// <reference path="./types.d.ts" />
import fs from 'node:fs';
import path from 'node:path';
import minimist from 'minimist';
import './scripts/deno-polyfills.js';
import {
promptOptions,
promptOnInvalidTemplate,
promptOnMissingTargetDir
} from './scripts/prompt.js';
import {
exitOnError,
getCommandsFor,
fillPlaceholders,
renameIgnoreFiles,
resolveTemplatePath,
readScaffoldingConfigOnce
} from './scripts/utils.js';
const DEFAULT_TARGET_DIR = 'elysia-project';
try {
/**
* @type {{ _: string[], template?: Template }}
*/
const argv = minimist(process.argv.slice(2));
/**
* @type {Options}
*/
const options = argv.template
? {
targetDir: argv._[0],
template: argv.template
}
: await promptOptions(DEFAULT_TARGET_DIR);
if (!options.targetDir) {
options.targetDir = await promptOnMissingTargetDir(DEFAULT_TARGET_DIR);
}
const CWD = process.cwd();
let templatePath = resolveTemplatePath(options.template);
if (!fs.existsSync(templatePath)) {
options.template = await promptOnInvalidTemplate(options.template);
templatePath = resolveTemplatePath(options.template);
}
const targetDirPath = path.resolve(CWD, options.targetDir);
console.log(`\nScaffolding project in ${targetDirPath}...`);
if (options.targetDir !== '.') {
fs.mkdirSync(targetDirPath);
}
fs.cpSync(templatePath, targetDirPath, { recursive: true });
const config = readScaffoldingConfigOnce(targetDirPath);
fillPlaceholders(
targetDirPath,
{
$PROJECT_NAME$: path.basename(targetDirPath)
},
config
);
renameIgnoreFiles(targetDirPath, config);
const commands = getCommandsFor(options)
.map((command) => `\t${command}`)
.join('\n');
console.log(`
✅ Done. Now run:
${commands}
`);
} catch (error) {
exitOnError(error);
}