-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (33 loc) · 1.47 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
#!/usr/bin/env node
const spawn = require("cross-spawn");
const fs = require("fs");
const path = require("path");
const projectName = process.argv[2]; // get project name
const currentDir = process.cwd(); // get current dir
const projectDir = path.resolve(currentDir, projectName || "create-tse");
fs.mkdirSync(projectDir, { recursive: true });
const templateDir = path.resolve(__dirname, "src", "node-express");
fs.cpSync(templateDir, projectDir, { recursive: true });
// It is good practice to have dotfiles stored in the
// template without the dot (so they do not get picked
// up by the starter template repository). We can rename
// the dotfiles after we have copied them over to the
// new project directory.
// fs.renameSync(
// path.join(projectDir, "gitignore"),
// path.join(projectDir, ".gitignore")
// );
// const projectPackageJson = require(path.join(projectDir, "package.json"));
// // Update the project's package.json with the new project name
// projectPackageJson.name = projectName;
// fs.writeFileSync(
// path.join(projectDir, "package.json"),
// JSON.stringify(projectPackageJson, null, 2)
// );
// Run `npm install` in the project directory to install
// the dependencies. We are using a third-party library
// called `cross-spawn` for cross-platform support.
// (Node has issues spawning child processes in Windows).
process.chdir(projectDir);
spawn.sync("npm", ["install"], { stdio: "inherit" });
console.log("Node + Express Typescript Initialize Successfully");