Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·117 lines (97 loc) · 2.93 KB
/
Copy pathindex.js
File metadata and controls
executable file
·117 lines (97 loc) · 2.93 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env node
import { program } from "commander";
import shelljs from "shelljs";
import {
ANGULAR_CLI_MAJOR_VERSION,
commit,
ensureAngularCliVersion,
execOrFail,
gitignore,
logWarn,
startSpinner,
succeedSpinner,
} from "./helpers/index.js";
import { addPrettier } from "./prettier/index.js";
import { addStylelint } from "./stylelint/index.js";
import { execFileSync } from "child_process";
import { addEslint } from "./eslint/index.js";
import { addLefthook } from "./lefthook/index.js";
import { addJest } from "./jest/index.js";
import { addStorybook } from "./storybook/index.js";
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const packageJson = require("./package.json");
const VALID_STYLES = ["scss", "css", "less", "sass"];
program
.name("scaffold-angular")
.description(
"Scaffold a new Angular application with ESLint, Prettier, Stylelint, Jest, Storybook, and Lefthook pre-configured",
)
.version(packageJson.version)
.argument("<app-name>", "Name of the Angular application to create")
.option(
"-s, --style <style>",
`Style preprocessor to use (${VALID_STYLES.join(", ")})`,
"scss",
)
.action(async (appName, options) => {
const style = options.style.toLowerCase();
if (!VALID_STYLES.includes(style)) {
console.error(
`Error: Invalid style "${style}". Valid options are: ${VALID_STYLES.join(", ")}`,
);
process.exit(1);
}
await ensureAngularCliVersion();
startSpinner("Scaffolding Angular application...");
execFileSync(
"npx",
[
`@angular/cli@${ANGULAR_CLI_MAJOR_VERSION}`,
"new",
appName,
"--style",
style,
"--minimal",
],
{ stdio: "inherit" },
);
succeedSpinner("Angular application scaffolded");
shelljs.cd(appName);
await addEslint();
commit("Add ESLint");
gitignore(`# lint caches
.eslintcache`);
commit("Add .eslintcache to .gitignore");
await addPrettier();
commit("Add Prettier");
await addStylelint({ style });
commit("Add Stylelint");
gitignore(`.stylelintcache`);
commit("Add .stylelintcache to .gitignore");
await execOrFail({
cmd: "npm i -D svgo@4",
startMsg: "Installing SVGO",
errorMsg: "Error during SVGO installation",
endMsg: "SVGO installed",
});
commit("Add SVGo");
await addJest();
commit("Add Jest");
await addStorybook();
commit("Add Storybook");
await addLefthook();
commit("Add Lefthook");
await execOrFail({
cmd: "npx prettier --write .",
startMsg: "Formatting files with Prettier",
errorMsg: "Error during Prettier formatting",
endMsg: "Files formatted",
});
commit("Format files with Prettier");
logWarn(
"Note: src/stories/ is excluded from ESLint. Update or move stories as needed.",
);
console.log("\n✨ Ready to work!\n");
});
program.parse();