UNPKG

3.54 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const color_1 = require("@angular/cli/utilities/color");
4const schematics_1 = require("@angular-devkit/schematics");
5const tasks_1 = require("@angular-devkit/schematics/tasks");
6const utils_1 = require("../utils");
7const node_1 = require("../utils/node");
8const V = 13;
9function genRules(options) {
10 return () => {
11 const rules = [];
12 const applicationOptions = Object.assign({}, options);
13 rules.push((0, schematics_1.schematic)('application', applicationOptions));
14 if (options.codeStyle) {
15 rules.push((0, schematics_1.schematic)('plugin', { name: 'codeStyle', type: 'add' }));
16 }
17 if (options.defaultLanguage) {
18 rules.push((0, schematics_1.schematic)('plugin', {
19 name: 'defaultLanguage',
20 type: 'add',
21 defaultLanguage: options.defaultLanguage
22 }));
23 }
24 if (options.npm) {
25 rules.push((0, schematics_1.schematic)('plugin', {
26 name: 'networkEnv',
27 type: 'add',
28 packageManager: 'npm'
29 }));
30 }
31 if (options.yarn) {
32 rules.push((0, schematics_1.schematic)('plugin', {
33 name: 'networkEnv',
34 type: 'add',
35 packageManager: 'yarn'
36 }));
37 }
38 return (0, schematics_1.chain)(rules);
39 };
40}
41function isYarn(tree) {
42 var _a, _b;
43 return ((_b = (_a = (0, utils_1.readJSON)(tree, '/angular.json')) === null || _a === void 0 ? void 0 : _a.cli) === null || _b === void 0 ? void 0 : _b.packageManager) === 'yarn';
44}
45function finished() {
46 return (_, context) => {
47 context.addTask(new tasks_1.NodePackageInstallTask());
48 context.logger.info(color_1.colors.green(`
49✓ Congratulations, NG-ALAIN scaffold generation complete 🎉.
50
51NG-ALAIN documentation site: https://ng-alain.com
52`));
53 };
54}
55function default_1(options) {
56 return (tree, context) => {
57 if (!isYarn(tree)) {
58 context.logger.warn(`TIPS:: Please use yarn instead of NPM to install dependencies`);
59 }
60 const nodeVersion = (0, node_1.getNodeMajorVersion)();
61 const allowNodeVersions = [12, 14, 16];
62 if (!allowNodeVersions.some(v => nodeVersion === v)) {
63 const versions = allowNodeVersions.join(', ');
64 throw new schematics_1.SchematicsException(`Sorry, currently only supports ${versions} major version number of node (Got ${process.version}), pls refer to https://gist.github.com/LayZeeDK/c822cc812f75bb07b7c55d07ba2719b3`);
65 }
66 const pkg = (0, utils_1.readPackage)(tree);
67 if (pkg.devDependencies['ng-alain']) {
68 throw new schematics_1.SchematicsException(`Already an NG-ALAIN project and can't be executed again: ng add ng-alain`);
69 }
70 let ngCoreVersion = pkg.dependencies['@angular/core'];
71 if (/^[\^|\~]/g.test(ngCoreVersion)) {
72 ngCoreVersion = ngCoreVersion.substring(1);
73 }
74 if (!ngCoreVersion.startsWith(`${V}.`)) {
75 throw new schematics_1.SchematicsException(`Sorry, the current version only supports angular ${V}.x, pls downgrade the global Anguar-cli version: [yarn global add @angular/cli@${V}] (or via npm: [npm install -g @angular/cli@${V}])`);
76 }
77 return (0, schematics_1.chain)([genRules(options), finished()])(tree, context);
78 };
79}
80exports.default = default_1;
81//# sourceMappingURL=index.js.map
\No newline at end of file