-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
43 lines (34 loc) · 1.19 KB
/
Copy pathcli.js
File metadata and controls
43 lines (34 loc) · 1.19 KB
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
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const args = process.argv.slice(2);
const command = args[0];
const projectName = args[1];
if (command === "create") {
if (!projectName) {
console.error("Please provide a project name.");
process.exit(1);
}
const currentDir = process.cwd();
const projectDir = path.resolve(currentDir, projectName);
fs.mkdirSync(projectDir, { recursive: true });
const templateDir = path.resolve(__dirname, "template");
fs.cpSync(templateDir, projectDir, { recursive: true });
const projectPackageJsonPath = path.join(projectDir, "package.json");
let projectPackageJson = JSON.parse(
fs.readFileSync(projectPackageJsonPath, "utf8")
);
projectPackageJson.name = projectName;
fs.writeFileSync(
projectPackageJsonPath,
JSON.stringify(projectPackageJson, null, 2)
);
console.log("Success! Your new jutter project has been created.");
console.log(`To get started, run the following commands:`);
console.log(`cd ${projectName}`);
console.log(`npm install`);
console.log(`npm run start`);
} else {
console.log("Unknown command. Did you mean:");
console.log("npx jutter create <project-name>");
}