1 | #! /usr/bin/env node
|
2 |
|
3 | const appDir = process.cwd(),
|
4 | path = require("path"),
|
5 | shell = require("shelljs");
|
6 |
|
7 |
|
8 | const pkg = JSON.parse(shell.cat("package.json"));
|
9 | const canon = JSON.parse(shell.cat(path.join(__dirname, "../package.json")));
|
10 | pkg.main = "src/index.js";
|
11 | Object.keys(canon.bin).forEach(script => {
|
12 | pkg.scripts[script.split("-")[1]] = `${script === "canon-build" ? "NODE_OPTIONS=--max-old-space-size=4096 " : ""}${script}`;
|
13 | });
|
14 | pkg.scripts.start = "node index.js";
|
15 |
|
16 | new shell.ShellString(JSON.stringify(pkg, null, 2)).to("package.json");
|
17 |
|
18 |
|
19 | shell.ls("-AR", path.join(__dirname, "scaffold/")).forEach(fileName => {
|
20 | const oldPath = path.join(__dirname, `scaffold/${fileName}`);
|
21 | fileName = fileName.replace("dot_", ".");
|
22 | const newPath = path.join(appDir, fileName);
|
23 | if (shell.test("-d", oldPath)) shell.mkdir("-p", newPath);
|
24 | else if (!shell.test("-e", newPath) || fileName.indexOf(".") === 0) {
|
25 | const contents = shell.cat(oldPath)
|
26 | .replace(/\{\{pkg.name\}\}/g, pkg.name)
|
27 | .replace(/\{\{pkg.description\}\}/g, pkg.description);
|
28 | new shell.ShellString(contents).to(newPath);
|
29 | }
|
30 | });
|