UNPKG

1.22 kBJavaScriptView Raw
1#! /usr/bin/env node
2
3const appDir = process.cwd(),
4 path = require("path"),
5 shell = require("shelljs");
6
7// adds scripts and meta information to package.json
8const pkg = JSON.parse(shell.cat("package.json"));
9const canon = JSON.parse(shell.cat(path.join(__dirname, "../package.json")));
10pkg.main = "src/index.js";
11Object.keys(canon.bin).forEach(script => {
12 pkg.scripts[script.split("-")[1]] = `${script === "canon-build" ? "NODE_OPTIONS=--max-old-space-size=4096 " : ""}${script}`;
13});
14pkg.scripts.start = "node index.js";
15
16new shell.ShellString(JSON.stringify(pkg, null, 2)).to("package.json");
17
18// copies over files from bin/scaffold
19shell.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});