-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathplayground.js
49 lines (42 loc) · 1.32 KB
/
playground.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
#!/usr/bin/env node
let path = require("node:path");
let fse = require("fs-extra");
let prompts = require("prompts");
let chalk = require("chalk");
copyPlayground();
async function copyPlayground() {
let playgroundRootDir = path.join(__dirname, "../playground");
let { templateName, playgroundName } = await prompts([
{
type: "select",
name: "templateName",
message: "Select a playground to copy",
choices: fse.readdirSync(playgroundRootDir).map((value) => ({ value })),
},
{
type: "text",
name: "playgroundName",
message: "Enter a name for your playground",
initial: (templateName) => `${templateName}-${Date.now()}`,
},
]);
let srcDir = path.join(playgroundRootDir, templateName);
let destDir = path.join(__dirname, "../playground-local", playgroundName);
let relativeDestDir = destDir.replace(process.cwd(), ".");
if (await fse.pathExists(destDir)) {
throw new Error(
`A local playground with the name "${playgroundName}" already exists. Delete it first or use a different name.`
);
}
await fse.copy(srcDir, destDir, {});
console.log(
[
"",
chalk.green`Created local copy of "${templateName}"`,
chalk.green`To start playground, run:`,
"",
`cd ${relativeDestDir}`,
"pnpm dev",
].join("\n")
);
}