@m2c2kit/cli 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +31 -12
- package/package.json +11 -9
package/dist/cli.js
CHANGED
|
@@ -8,9 +8,11 @@ import handlebars from "handlebars";
|
|
|
8
8
|
import { dirname } from "path";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import { spawn } from "child_process";
|
|
11
|
+
import ora from "ora";
|
|
12
|
+
import chalk from "chalk";
|
|
11
13
|
const packageHomeFolderPath = dirname(fileURLToPath(import.meta.url));
|
|
12
14
|
const yarg = yargs(hideBin(process.argv));
|
|
13
|
-
|
|
15
|
+
yarg
|
|
14
16
|
.command("new <name>", "create a new m2c2kit app", (yarg) => {
|
|
15
17
|
yarg.positional("name", {
|
|
16
18
|
describe: "name of new app",
|
|
@@ -20,8 +22,8 @@ const argv = yarg
|
|
|
20
22
|
const appName = argv["name"];
|
|
21
23
|
const newFolderPath = path.join(path.resolve(), appName);
|
|
22
24
|
if (fs.existsSync(newFolderPath)) {
|
|
23
|
-
console.log(
|
|
24
|
-
yarg.exit(1, new Error("
|
|
25
|
+
console.log(`${chalk.red("ERROR")}: folder ${newFolderPath} already exists. Please remove this folder and try again.`);
|
|
26
|
+
yarg.exit(1, new Error("folder exists"));
|
|
25
27
|
}
|
|
26
28
|
fs.mkdirSync(newFolderPath);
|
|
27
29
|
fs.mkdirSync(path.join(newFolderPath, "src"));
|
|
@@ -62,13 +64,25 @@ const argv = yarg
|
|
|
62
64
|
destinationFilePath: path.join(newFolderPath, ".vscode", "launch.json"),
|
|
63
65
|
},
|
|
64
66
|
];
|
|
67
|
+
let errorProcessingTemplates = false;
|
|
65
68
|
templates.forEach((t) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
try {
|
|
70
|
+
const contents = applyValuesToTemplate(t.templateFilePath, {
|
|
71
|
+
appName: appName,
|
|
72
|
+
});
|
|
73
|
+
fs.writeFileSync(t.destinationFilePath, contents);
|
|
74
|
+
console.log(`${chalk.green("CREATE")} ${t.destinationFilePath} (${contents.length} bytes)`);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
errorProcessingTemplates = true;
|
|
78
|
+
console.log(`${chalk.red("ERROR")} ${t.destinationFilePath}`);
|
|
79
|
+
}
|
|
71
80
|
});
|
|
81
|
+
if (errorProcessingTemplates) {
|
|
82
|
+
console.log(`${chalk.red("ERROR")}: could not generate files`);
|
|
83
|
+
yarg.exit(1, new Error("template error"));
|
|
84
|
+
}
|
|
85
|
+
const spinner = ora("Installing packages (npm)...").start();
|
|
72
86
|
let npm;
|
|
73
87
|
if (process.platform === "win32") {
|
|
74
88
|
npm = spawn(`npm`, ["install"], { shell: true, cwd: newFolderPath });
|
|
@@ -76,15 +90,20 @@ const argv = yarg
|
|
|
76
90
|
else {
|
|
77
91
|
npm = spawn(`npm`, ["install"], { cwd: newFolderPath });
|
|
78
92
|
}
|
|
93
|
+
let npmOut = "";
|
|
79
94
|
npm.stdout.on("data", (data) => {
|
|
80
|
-
|
|
95
|
+
npmOut = npmOut + data.toString();
|
|
81
96
|
});
|
|
82
97
|
npm.stderr.on("data", (data) => {
|
|
83
|
-
|
|
98
|
+
npmOut = npmOut + data.toString();
|
|
84
99
|
});
|
|
85
100
|
npm.on("exit", (code) => {
|
|
86
|
-
if (code
|
|
87
|
-
|
|
101
|
+
if (code === 0) {
|
|
102
|
+
spinner.succeed("Packages installed successfully");
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
spinner.fail("Error during package installation");
|
|
106
|
+
console.log(npmOut);
|
|
88
107
|
}
|
|
89
108
|
});
|
|
90
109
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m2c2kit/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "m2c2kit command line interface",
|
|
5
5
|
"module": "dist/cli.js",
|
|
6
6
|
"files": [
|
|
@@ -19,15 +19,17 @@
|
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"handlebars": "^4.7.7"
|
|
22
|
+
"chalk": "^5.0.0",
|
|
23
|
+
"handlebars": "^4.7.7",
|
|
24
|
+
"ora": "^6.0.1",
|
|
25
|
+
"yargs": "^17.3.0"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"rimraf": "^3.0.2",
|
|
27
|
-
"typescript": "^4.5.2",
|
|
28
|
-
"copyfiles": "^2.4.1",
|
|
29
|
-
"yargs": "^17.3.0",
|
|
30
28
|
"@types/node": "^16.11.12",
|
|
31
|
-
"@types/yargs": "^17.0.7"
|
|
29
|
+
"@types/yargs": "^17.0.7",
|
|
30
|
+
"copyfiles": "^2.4.1",
|
|
31
|
+
"rimraf": "^3.0.2",
|
|
32
|
+
"tslib": "~2.3.1",
|
|
33
|
+
"typescript": "^4.5.2"
|
|
32
34
|
}
|
|
33
|
-
}
|
|
35
|
+
}
|