-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
95 lines (79 loc) · 2.56 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
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
#!/usr/bin/env node
const commander = require("commander");
const {
checkNodeVersion,
ensureAngularCLIInstalled,
createAngularApp,
removeJasmineAndKarma,
installJest,
updateAngularJson,
createJestConfig,
updateTsConfig,
updatePackageJson,
commitJestFiles,
AppError,
} = require("./utils");
// Main function to scaffold Jest with Angular
async function scaffoldJestWithAngular() {
const program = new commander.Command();
program
.argument("[app-name]", "Name of the Angular app")
.option("--verbose", "Enable verbose mode")
.option("--no-commit", "Skip committing Jest-related files to Git")
.action((appName, options) => {
const { verbose, commit } = options;
if (!appName) {
console.log("No app name provided.");
appName = "angular-jest-starter";
}
console.log(`Using app name: ${appName}`);
try {
// Step 1: Check Node.js version
checkNodeVersion(">=18.0.0");
// Step 2: Ensure Angular CLI is installed
ensureAngularCLIInstalled();
// Step 3: Create Angular app
createAngularApp(appName, program.rawArgs.slice(3));
// Step 4: Remove Jasmine and Karma
removeJasmineAndKarma();
// Step 5: Install Jest
installJest();
// Step 6: Update angular.json to use Jest
updateAngularJson();
// Step 7: Create Jest configuration files
createJestConfig();
// Step 8: Update TypeScript configurations for Jest
updateTsConfig();
// Step 9: Update package.json to use Jest configuration
updatePackageJson();
// Step 10: Commit Jest-related files to Git (optional)
if (commit) {
commitJestFiles();
}
console.log("Jest setup completed.");
console.log("========================================================");
console.log(
"Run `npm install` and then `ng test` to start testing with Jest."
);
} catch (error) {
if (error instanceof AppError) {
console.error("Error:", error.message);
} else {
console.error("Unexpected Error:", error);
}
process.exit(error.statusCode);
}
});
program.parse(process.argv);
}
// Handle global errors
process.on("uncaughtException", (error) => {
console.error("Uncaught Exception:", error.message);
process.exit(1);
});
process.on("unhandledRejection", (reason) => {
console.error("Unhandled Rejection:", reason);
process.exit(1);
});
// Execute the Jest scaffolding process
scaffoldJestWithAngular();