-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
74 lines (62 loc) · 1.82 KB
/
index.ts
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
#!/usr/bin/env node
import path from "node:path";
import fse from "fs-extra";
import meow from "meow";
import inquirer from "inquirer";
const help = `
Create a new codes for front-end app
Usage:
$ npx create-codes [<dir>] [flags...]
Flags:
--help, -h Show this help message
--version, -v Show the version of this script
`;
const TEMPLATE_DIR = path.resolve(__dirname, "../templates/react");
const TEMPLATE_SHARE_DIR = path.resolve(__dirname, "../templates/__shared");
async function run() {
const { input } = meow(help, {
flags: {
help: { type: "boolean", default: false, alias: "h" },
version: { type: "boolean", default: false, alias: "v" },
},
});
const [dir] = input;
console.log("\nCreate Codes\n");
console.log("Welcome!\n");
const appDir = path.resolve(
process.cwd(),
dir
? dir
: (
await inquirer.prompt<{ dir: string }>([
{
type: "input",
name: "dir",
message: "Where would you like to create your app?",
default: "./my-app",
},
])
).dir
);
fse.copySync(TEMPLATE_DIR, appDir, {
filter: (src) =>
!["node_modules", "dist", ".turbo"].includes(path.basename(src)),
});
fse.copySync(TEMPLATE_SHARE_DIR, appDir);
// Rename dot files
fse.renameSync(
path.join(appDir, "gitignore"),
path.join(appDir, ".gitignore")
);
console.log();
console.log(`Success! Created a new app at "${path.basename(appDir)}".`);
console.log("Inside this directory, you can run:");
console.log();
console.log(` pnpm run build`);
console.log(` Build directory with a production build of your app`);
console.log();
console.log(` pnpm run dev`);
console.log(` Develop your app with development server`);
console.log();
}
run();