ng-alain 13.0.0 → 13.2.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/README.md +1 -1
- package/application/files/root/.husky/pre-commit +1 -1
- package/application/files/root/.stylelintrc +1 -0
- package/application/files/src/app/layout/passport/passport.component.less +14 -0
- package/application/files/src/app/routes/passport/lock/lock.component.less +1 -0
- package/application/files/src/app/routes/passport/login/login.component.less +12 -2
- package/application/files/src/app/routes/passport/register/register.component.less +9 -0
- package/application/index.js +1 -1
- package/application/index.js.map +1 -1
- package/application/index.ts +1 -1
- package/curd/index.js +1 -1
- package/curd/index.js.map +1 -1
- package/curd/index.ts +1 -1
- package/curd/schema.json +16 -1
- package/curd/schema.ts +1 -0
- package/docs/generate.en-US.md +3 -0
- package/docs/generate.zh-CN.md +3 -0
- package/edit/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.service.ts.template +9 -0
- package/edit/schema.json +16 -1
- package/edit/schema.ts +1 -0
- package/empty/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.service.ts.template +9 -0
- package/empty/index.spec.ts +25 -5
- package/empty/schema.json +16 -1
- package/empty/schema.ts +1 -0
- package/list/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.service.ts.template +9 -0
- package/list/index.spec.ts +7 -0
- package/list/schema.json +16 -1
- package/list/schema.ts +1 -0
- package/module/files/__name@dasherize@if-flat__/__name@dasherize__.service.ts.template +9 -0
- package/module/index.js +29 -3
- package/module/index.js.map +1 -1
- package/module/index.spec.ts +16 -0
- package/module/index.ts +33 -5
- package/module/schema.json +16 -0
- package/module/schema.ts +3 -1
- package/package.json +1 -1
- package/tpl/schema.json +0 -1
- package/utils/alain.js +34 -8
- package/utils/alain.js.map +1 -1
- package/utils/alain.ts +44 -8
- package/utils/code-style.js +1 -1
- package/utils/code-style.js.map +1 -1
- package/utils/code-style.ts +1 -1
- package/utils/lib-versions.js +2 -2
- package/utils/lib-versions.ts +2 -2
- package/utils/versions.js +1 -1
- package/utils/versions.ts +1 -1
- package/view/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.service.ts.template +9 -0
- package/view/schema.json +16 -1
- package/view/schema.ts +1 -0
package/module/index.js
CHANGED
|
@@ -45,6 +45,7 @@ function addDeclarationToNgModule(options) {
|
|
|
45
45
|
}
|
|
46
46
|
function addRoutingModuleToTop(options) {
|
|
47
47
|
return (tree) => {
|
|
48
|
+
var _a;
|
|
48
49
|
const modulePath = (0, core_1.normalize)(`${options.path}/routes-routing.module.ts`);
|
|
49
50
|
if (!tree.exists(modulePath)) {
|
|
50
51
|
return tree;
|
|
@@ -66,14 +67,33 @@ function addRoutingModuleToTop(options) {
|
|
|
66
67
|
}
|
|
67
68
|
const recorder = tree.beginUpdate(modulePath);
|
|
68
69
|
const moduleName = core_1.strings.classify(`${options.name}Module`);
|
|
69
|
-
const code = `{ path: '${options.name}', loadChildren: () => import('./${options.name}/${options.name}.module').then((m) => m.${moduleName}) },`;
|
|
70
70
|
let pos = childrenNode.parent.end;
|
|
71
|
+
const validLines = childrenNode.parent
|
|
72
|
+
.getText()
|
|
73
|
+
.trim()
|
|
74
|
+
.split('\n')
|
|
75
|
+
.map(v => v.trim())
|
|
76
|
+
.filter(v => v.length > 1 && !v.startsWith('//'));
|
|
77
|
+
const comma = ((_a = validLines.pop()) === null || _a === void 0 ? void 0 : _a.endsWith(',')) === false ? ', ' : '';
|
|
78
|
+
const code = `${comma} { path: '${options.name}', loadChildren: () => import('./${options.name}/${options.name}.module').then((m) => m.${moduleName}) }`;
|
|
71
79
|
// Insert it just before the `]`.
|
|
72
|
-
recorder.insertRight(
|
|
80
|
+
recorder.insertRight(pos - 1, code);
|
|
73
81
|
tree.commitUpdate(recorder);
|
|
74
82
|
return tree;
|
|
75
83
|
};
|
|
76
84
|
}
|
|
85
|
+
function addServiceToNgModule(options) {
|
|
86
|
+
return (tree) => {
|
|
87
|
+
if (options.service !== 'none')
|
|
88
|
+
return tree;
|
|
89
|
+
const basePath = `/${options.path}/${options.flat ? '' : `${core_1.strings.dasherize(options.name)}/`}${core_1.strings.dasherize(options.name)}`;
|
|
90
|
+
const servicePath = (0, core_1.normalize)(`${basePath}.service`);
|
|
91
|
+
const importModulePath = (0, core_1.normalize)(`${basePath}.module`);
|
|
92
|
+
const importServicePath = (0, find_module_1.buildRelativePath)(importModulePath, servicePath);
|
|
93
|
+
(0, utils_1.addProviderToModule)(tree, `${importModulePath}.ts`, core_1.strings.classify(`${options.name}Service`), importServicePath);
|
|
94
|
+
return tree;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
77
97
|
function default_1(schema) {
|
|
78
98
|
return (tree) => __awaiter(this, void 0, void 0, function* () {
|
|
79
99
|
const proj = yield (0, utils_1.getProject)(tree, schema.project);
|
|
@@ -87,12 +107,18 @@ function default_1(schema) {
|
|
|
87
107
|
schema.routing = true;
|
|
88
108
|
schema.flat = false;
|
|
89
109
|
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
110
|
+
schema.service === 'ignore' ? (0, schematics_1.filter)(filePath => !filePath.endsWith('.service.ts.template')) : (0, schematics_1.noop)(),
|
|
90
111
|
schema.routing ? (0, schematics_1.noop)() : (0, schematics_1.filter)(path => !path.endsWith('-routing.module.ts')),
|
|
91
112
|
(0, schematics_1.applyTemplates)(Object.assign(Object.assign(Object.assign({}, core_1.strings), { 'if-flat': (s) => (schema.flat ? '' : s) }), schema)),
|
|
92
113
|
(0, schematics_1.move)(parsedPath.path)
|
|
93
114
|
]);
|
|
94
115
|
return (0, schematics_1.chain)([
|
|
95
|
-
(0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
|
|
116
|
+
(0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
|
|
117
|
+
addDeclarationToNgModule(schema),
|
|
118
|
+
addRoutingModuleToTop(schema),
|
|
119
|
+
(0, schematics_1.mergeWith)(templateSource),
|
|
120
|
+
addServiceToNgModule(schema)
|
|
121
|
+
]))
|
|
96
122
|
]);
|
|
97
123
|
});
|
|
98
124
|
}
|
package/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../schematics/module/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+CAAuF;AACvF,2DAaoC;AACpC,qEAAoF;AACpF,+DAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../schematics/module/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+CAAuF;AACvF,2DAaoC;AACpC,qEAAoF;AACpF,+DAAkE;AAClE,yEAAmG;AACnG,uEAAmE;AACnE,iCAAiC;AAEjC,oCAA4E;AAG5E,SAAS,wBAAwB,CAAC,OAAqB;IACrD,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACnB,OAAO,IAAI,CAAC;SACb;QAED,MAAM,UAAU,GAAG,IAAA,gBAAS,EAAC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAEnD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnC,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,MAAM,IAAI,gCAAmB,CAAC,QAAQ,UAAU,kBAAkB,CAAC,CAAC;SACrE;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAEzF,MAAM,gBAAgB,GAAG,IAAA,gBAAS,EAChC,IAAI,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,cAAO,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,GAAG,cAAO,C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CAAC;YAC9E,IAAA,2BAAc,gDACT,cAAO,KACV,SAAS,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7C,MAAM,EACT;YACF,IAAA,iBAAI,EAAC,UAAU,CAAC,IAAI,CAAC;SACtB,CAAC,CAAC;QAEH,OAAO,IAAA,kBAAK,EAAC;YACX,IAAA,2BAAc,EACZ,IAAA,kBAAK,EAAC;gBACJ,wBAAwB,CAAC,MAAM,CAAC;gBAChC,qBAAqB,CAAC,MAAM,CAAC;gBAC7B,IAAA,sBAAS,EAAC,cAAc,CAAC;gBACzB,oBAAoB,CAAC,MAAM,CAAC;aAC7B,CAAC,CACH;SACF,CAAC,CAAC;IACL,CAAC,CAAA,CAAC;AACJ,CAAC;AAvCD,4BAuCC"}
|
package/module/index.spec.ts
CHANGED
|
@@ -33,4 +33,20 @@ describe('NgAlainSchematic: module', () => {
|
|
|
33
33
|
const content = tree.readContent('/projects/foo/src/app/app.module.ts');
|
|
34
34
|
expect(content).toContain(`import { TradeModule } from './trade/trade.module';`);
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
it('shuold be include service', async () => {
|
|
38
|
+
tree = await runner.runSchematicAsync('module', { ...defaultOptions, service: 'none' }, tree).toPromise();
|
|
39
|
+
const content = tree.readContent('/projects/foo/src/app/routes/trade/trade.service.ts');
|
|
40
|
+
const contentModule = tree.readContent('/projects/foo/src/app/routes/trade/trade.module.ts');
|
|
41
|
+
expect(content).toContain(`@Injectable()`);
|
|
42
|
+
expect(content).toContain(`TradeService`);
|
|
43
|
+
expect(contentModule).toContain(`import { TradeService } from './trade.service';`);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('shuold be include root service', async () => {
|
|
47
|
+
tree = await runner.runSchematicAsync('module', { ...defaultOptions, service: 'root' }, tree).toPromise();
|
|
48
|
+
const content = tree.readContent('/projects/foo/src/app/routes/trade/trade.service.ts');
|
|
49
|
+
expect(content).toContain(`@Injectable({ providedIn: 'root' })`);
|
|
50
|
+
expect(content).toContain(`TradeService`);
|
|
51
|
+
});
|
|
36
52
|
});
|
package/module/index.ts
CHANGED
|
@@ -15,11 +15,11 @@ import {
|
|
|
15
15
|
} from '@angular-devkit/schematics';
|
|
16
16
|
import { addImportToModule, findNode } from '@schematics/angular/utility/ast-utils';
|
|
17
17
|
import { InsertChange } from '@schematics/angular/utility/change';
|
|
18
|
-
import { findModuleFromOptions } from '@schematics/angular/utility/find-module';
|
|
18
|
+
import { findModuleFromOptions, buildRelativePath } from '@schematics/angular/utility/find-module';
|
|
19
19
|
import { parseName } from '@schematics/angular/utility/parse-name';
|
|
20
20
|
import * as ts from 'typescript';
|
|
21
21
|
|
|
22
|
-
import { getProject, refreshPathRoot } from '../utils';
|
|
22
|
+
import { addProviderToModule, getProject, refreshPathRoot } from '../utils';
|
|
23
23
|
import { Schema as ModuleSchema } from './schema';
|
|
24
24
|
|
|
25
25
|
function addDeclarationToNgModule(options: ModuleSchema): Rule {
|
|
@@ -86,15 +86,37 @@ function addRoutingModuleToTop(options: ModuleSchema): Rule {
|
|
|
86
86
|
}
|
|
87
87
|
const recorder = tree.beginUpdate(modulePath);
|
|
88
88
|
const moduleName = strings.classify(`${options.name}Module`);
|
|
89
|
-
const code = `{ path: '${options.name}', loadChildren: () => import('./${options.name}/${options.name}.module').then((m) => m.${moduleName}) },`;
|
|
90
89
|
let pos = childrenNode.parent.end;
|
|
90
|
+
const validLines = childrenNode.parent
|
|
91
|
+
.getText()
|
|
92
|
+
.trim()
|
|
93
|
+
.split('\n')
|
|
94
|
+
.map(v => v.trim())
|
|
95
|
+
.filter(v => v.length > 1 && !v.startsWith('//'));
|
|
96
|
+
const comma = validLines.pop()?.endsWith(',') === false ? ', ' : '';
|
|
97
|
+
const code = `${comma} { path: '${options.name}', loadChildren: () => import('./${options.name}/${options.name}.module').then((m) => m.${moduleName}) }`;
|
|
91
98
|
// Insert it just before the `]`.
|
|
92
|
-
recorder.insertRight(
|
|
99
|
+
recorder.insertRight(pos - 1, code);
|
|
93
100
|
tree.commitUpdate(recorder);
|
|
94
101
|
return tree;
|
|
95
102
|
};
|
|
96
103
|
}
|
|
97
104
|
|
|
105
|
+
function addServiceToNgModule(options: ModuleSchema): Rule {
|
|
106
|
+
return (tree: Tree) => {
|
|
107
|
+
if (options.service !== 'none') return tree;
|
|
108
|
+
|
|
109
|
+
const basePath = `/${options.path}/${options.flat ? '' : `${strings.dasherize(options.name)}/`}${strings.dasherize(
|
|
110
|
+
options.name
|
|
111
|
+
)}`;
|
|
112
|
+
const servicePath = normalize(`${basePath}.service`);
|
|
113
|
+
const importModulePath = normalize(`${basePath}.module`);
|
|
114
|
+
const importServicePath = buildRelativePath(importModulePath, servicePath);
|
|
115
|
+
addProviderToModule(tree, `${importModulePath}.ts`, strings.classify(`${options.name}Service`), importServicePath);
|
|
116
|
+
return tree;
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
98
120
|
export default function (schema: ModuleSchema): Rule {
|
|
99
121
|
return async (tree: Tree) => {
|
|
100
122
|
const proj = await getProject(tree, schema.project);
|
|
@@ -113,6 +135,7 @@ export default function (schema: ModuleSchema): Rule {
|
|
|
113
135
|
schema.flat = false;
|
|
114
136
|
|
|
115
137
|
const templateSource = apply(url('./files'), [
|
|
138
|
+
schema.service === 'ignore' ? filter(filePath => !filePath.endsWith('.service.ts.template')) : noop(),
|
|
116
139
|
schema.routing ? noop() : filter(path => !path.endsWith('-routing.module.ts')),
|
|
117
140
|
applyTemplates({
|
|
118
141
|
...strings,
|
|
@@ -124,7 +147,12 @@ export default function (schema: ModuleSchema): Rule {
|
|
|
124
147
|
|
|
125
148
|
return chain([
|
|
126
149
|
branchAndMerge(
|
|
127
|
-
chain([
|
|
150
|
+
chain([
|
|
151
|
+
addDeclarationToNgModule(schema),
|
|
152
|
+
addRoutingModuleToTop(schema),
|
|
153
|
+
mergeWith(templateSource),
|
|
154
|
+
addServiceToNgModule(schema)
|
|
155
|
+
])
|
|
128
156
|
)
|
|
129
157
|
]);
|
|
130
158
|
};
|
package/module/schema.json
CHANGED
|
@@ -63,6 +63,22 @@
|
|
|
63
63
|
"description": "Apply lint fixes after generating the module.",
|
|
64
64
|
"x-user-analytics": 15,
|
|
65
65
|
"x-deprecated": "Use \"ng lint --fix\" directly instead."
|
|
66
|
+
},
|
|
67
|
+
"service": {
|
|
68
|
+
"type": "string",
|
|
69
|
+
"description": "The service file to use in the new component.",
|
|
70
|
+
"default": "ignore",
|
|
71
|
+
"enum": ["ignore", "none", "root"],
|
|
72
|
+
"x-prompt": {
|
|
73
|
+
"message": "Which service injectors would you like to use?",
|
|
74
|
+
"type": "list",
|
|
75
|
+
"items": [
|
|
76
|
+
{ "value": "ignore", "label": "Ignore generation of Service files" },
|
|
77
|
+
{ "value": "root", "label": "Use \"@Injectable({ providedIn: 'root' })\"" },
|
|
78
|
+
{ "value": "none", "label": "Use \"@Injectable()\" (Should be automatically register to the nearest module)" }
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
"x-user-analytics": 20
|
|
66
82
|
}
|
|
67
83
|
},
|
|
68
84
|
"required": ["name"]
|
package/module/schema.ts
CHANGED
package/package.json
CHANGED
package/tpl/schema.json
CHANGED
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"description": "Include template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file.",
|
|
45
45
|
"type": "boolean",
|
|
46
46
|
"default": false,
|
|
47
|
-
"alias": "t",
|
|
48
47
|
"x-user-analytics": 10
|
|
49
48
|
},
|
|
50
49
|
"viewEncapsulation": {
|
package/utils/alain.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.buildAlain = exports.addValueToVariable = exports.addImportToModule = exports.refreshPathRoot = void 0;
|
|
12
|
+
exports.buildAlain = exports.addValueToVariable = exports.addProviderToModule = exports.addImportToModule = exports.refreshPathRoot = void 0;
|
|
13
13
|
const core_1 = require("@angular-devkit/core");
|
|
14
14
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
15
15
|
const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
|
|
@@ -45,13 +45,17 @@ function buildSelector(schema, projectPrefix) {
|
|
|
45
45
|
ret.push(core_1.strings.dasherize(schema.name));
|
|
46
46
|
return ret.join('-');
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function buildName(schema, prefix) {
|
|
49
49
|
const ret = schema.withoutModulePrefixInComponentName === true ? [] : [schema.module];
|
|
50
50
|
if (schema.target && schema.target.length > 0) {
|
|
51
51
|
ret.push(...schema.target.split('/'));
|
|
52
52
|
}
|
|
53
53
|
ret.push(schema.name);
|
|
54
|
-
|
|
54
|
+
// 服务类自动过滤 list, empty 两个页面的后缀
|
|
55
|
+
if (prefix === 'Service' && ['list', 'empty'].includes(schema.name)) {
|
|
56
|
+
ret.pop();
|
|
57
|
+
}
|
|
58
|
+
ret.push(prefix);
|
|
55
59
|
return core_1.strings.classify(ret.join('-'));
|
|
56
60
|
}
|
|
57
61
|
function refreshPathRoot(project, schema, alainProject) {
|
|
@@ -101,11 +105,27 @@ function resolveSchema(tree, project, schema, alainProject) {
|
|
|
101
105
|
function addImportToModule(tree, filePath, symbolName, fileName) {
|
|
102
106
|
const source = (0, ast_1.getSourceFile)(tree, filePath);
|
|
103
107
|
const change = (0, ast_utils_1.insertImport)(source, filePath, symbolName, fileName);
|
|
108
|
+
if (change.path == null)
|
|
109
|
+
return;
|
|
104
110
|
const declarationRecorder = tree.beginUpdate(filePath);
|
|
105
111
|
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
106
112
|
tree.commitUpdate(declarationRecorder);
|
|
107
113
|
}
|
|
108
114
|
exports.addImportToModule = addImportToModule;
|
|
115
|
+
function addProviderToModule(tree, filePath, serviceName, importPath) {
|
|
116
|
+
const source = (0, ast_1.getSourceFile)(tree, filePath);
|
|
117
|
+
const changes = (0, ast_utils_1.addProviderToModule)(source, filePath, serviceName, importPath);
|
|
118
|
+
const declarationRecorder = tree.beginUpdate(filePath);
|
|
119
|
+
changes.forEach(change => {
|
|
120
|
+
if (change.path == null)
|
|
121
|
+
return;
|
|
122
|
+
if (change instanceof change_1.InsertChange) {
|
|
123
|
+
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
tree.commitUpdate(declarationRecorder);
|
|
127
|
+
}
|
|
128
|
+
exports.addProviderToModule = addProviderToModule;
|
|
109
129
|
function addValueToVariable(tree, filePath, variableName, text, needWrap = true) {
|
|
110
130
|
const source = (0, ast_1.getSourceFile)(tree, filePath);
|
|
111
131
|
const node = (0, ast_utils_1.findNode)(source, ts.SyntaxKind.Identifier, variableName);
|
|
@@ -120,8 +140,8 @@ function addValueToVariable(tree, filePath, variableName, text, needWrap = true)
|
|
|
120
140
|
tree.commitUpdate(declarationRecorder);
|
|
121
141
|
}
|
|
122
142
|
exports.addValueToVariable = addValueToVariable;
|
|
123
|
-
function getRelativePath(filePath, schema) {
|
|
124
|
-
const importPath = `/${schema.path}/${schema.flat ? '' : `${core_1.strings.dasherize(schema.name)}/`}${core_1.strings.dasherize(schema.name)}
|
|
143
|
+
function getRelativePath(filePath, schema, prefix) {
|
|
144
|
+
const importPath = `/${schema.path}/${schema.flat ? '' : `${core_1.strings.dasherize(schema.name)}/`}${core_1.strings.dasherize(schema.name)}.${prefix}`;
|
|
125
145
|
return (0, find_module_1.buildRelativePath)(filePath, importPath);
|
|
126
146
|
}
|
|
127
147
|
function addDeclaration(schema) {
|
|
@@ -130,14 +150,18 @@ function addDeclaration(schema) {
|
|
|
130
150
|
return tree;
|
|
131
151
|
}
|
|
132
152
|
// imports
|
|
133
|
-
addImportToModule(tree, schema.importModulePath, schema.componentName, getRelativePath(schema.importModulePath, schema));
|
|
153
|
+
addImportToModule(tree, schema.importModulePath, schema.componentName, getRelativePath(schema.importModulePath, schema, 'component'));
|
|
134
154
|
addValueToVariable(tree, schema.importModulePath, 'COMPONENTS', schema.componentName);
|
|
135
155
|
// component
|
|
136
156
|
if (schema.modal !== true) {
|
|
137
157
|
// routing
|
|
138
|
-
addImportToModule(tree, schema.routerModulePath, schema.componentName, getRelativePath(schema.routerModulePath, schema));
|
|
158
|
+
addImportToModule(tree, schema.routerModulePath, schema.componentName, getRelativePath(schema.routerModulePath, schema, 'component'));
|
|
139
159
|
addValueToVariable(tree, schema.routerModulePath, 'routes', `{ path: '${schema.name}', component: ${schema.componentName} }`);
|
|
140
160
|
}
|
|
161
|
+
// service
|
|
162
|
+
if (schema.service === 'none') {
|
|
163
|
+
addProviderToModule(tree, schema.importModulePath, schema.serviceName, getRelativePath(schema.importModulePath, schema, 'service'));
|
|
164
|
+
}
|
|
141
165
|
return tree;
|
|
142
166
|
};
|
|
143
167
|
}
|
|
@@ -149,11 +173,13 @@ function buildAlain(schema) {
|
|
|
149
173
|
}
|
|
150
174
|
const project = res.project;
|
|
151
175
|
resolveSchema(tree, project, schema, res.alainProject);
|
|
152
|
-
schema.componentName =
|
|
176
|
+
schema.componentName = buildName(schema, 'Component');
|
|
177
|
+
schema.serviceName = buildName(schema, 'Service');
|
|
153
178
|
// Don't support inline
|
|
154
179
|
schema.inlineTemplate = false;
|
|
155
180
|
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)(schema._filesPath), [
|
|
156
181
|
(0, schematics_1.filter)(filePath => !filePath.endsWith('.DS_Store')),
|
|
182
|
+
schema.service === 'ignore' ? (0, schematics_1.filter)(filePath => !filePath.endsWith('.service.ts.template')) : (0, schematics_1.noop)(),
|
|
157
183
|
schema.skipTests ? (0, schematics_1.filter)(filePath => !filePath.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
|
|
158
184
|
schema.inlineStyle ? (0, schematics_1.filter)(filePath => !filePath.endsWith('.__style__.template')) : (0, schematics_1.noop)(),
|
|
159
185
|
schema.inlineTemplate ? (0, schematics_1.filter)(filePath => !filePath.endsWith('.html.template')) : (0, schematics_1.noop)(),
|
package/utils/alain.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alain.js","sourceRoot":"","sources":["../../../schematics/utils/alain.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA+C;AAE/C,2DAaoC;AAEpC,
|
|
1
|
+
{"version":3,"file":"alain.js","sourceRoot":"","sources":["../../../schematics/utils/alain.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA+C;AAE/C,2DAaoC;AAEpC,qEAI+C;AAC/C,+DAAkE;AAClE,yEAAkH;AAClH,uEAAmE;AACnE,uEAA8E;AAC9E,yBAAyB;AACzB,6BAA6B;AAC7B,iCAAiC;AAEjC,+BAAsC;AACtC,2CAAmE;AAEnE,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAqB3C,SAAS,aAAa,CAAC,MAAoB,EAAE,aAAqB;IAChE,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;QACzB,IAAI,MAAM,CAAC,MAAM,EAAE;YACjB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACzB;aAAM,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,aAAa,EAAE;YACvD,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;SACzB;KACF;IACD,cAAc;IACd,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KACzB;IACD,cAAc;IACd,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;KACvC;IACD,OAAO;IACP,GAAG,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2BAAc,gDACT,cAAO,KACV,SAAS,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7C,MAAM,EACT;YACF,IAAA,iBAAI,EAAC,IAAK,EAAE,GAAG,MAAM,CAAC,IAAI,GAAG,CAAC;SAC/B,CAAC,CAAC;QAEH,OAAO,IAAA,kBAAK,EAAC,CAAC,IAAA,2BAAc,EAAC,IAAA,kBAAK,EAAC,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,IAAA,sBAAS,EAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7F,CAAC,CAAA,CAAC;AACJ,CAAC;AAlCD,gCAkCC"}
|
package/utils/alain.ts
CHANGED
|
@@ -15,7 +15,11 @@ import {
|
|
|
15
15
|
url
|
|
16
16
|
} from '@angular-devkit/schematics';
|
|
17
17
|
import { Schema as ComponentSchema } from '@schematics/angular/component/schema';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
findNode,
|
|
20
|
+
insertImport,
|
|
21
|
+
addProviderToModule as _addProviderToModule
|
|
22
|
+
} from '@schematics/angular/utility/ast-utils';
|
|
19
23
|
import { InsertChange } from '@schematics/angular/utility/change';
|
|
20
24
|
import { buildRelativePath, findModuleFromOptions, ModuleOptions } from '@schematics/angular/utility/find-module';
|
|
21
25
|
import { parseName } from '@schematics/angular/utility/parse-name';
|
|
@@ -36,12 +40,14 @@ export interface CommonSchema extends ComponentSchema {
|
|
|
36
40
|
schematicName?: string;
|
|
37
41
|
target?: string;
|
|
38
42
|
componentName?: string;
|
|
43
|
+
serviceName?: string;
|
|
39
44
|
importModulePath?: string;
|
|
40
45
|
routerModulePath?: string;
|
|
41
46
|
selector?: string;
|
|
42
47
|
withoutPrefix?: boolean;
|
|
43
48
|
withoutModulePrefixInComponentName?: boolean;
|
|
44
49
|
skipTests?: boolean;
|
|
50
|
+
service?: 'ignore' | 'none' | 'root';
|
|
45
51
|
flat?: boolean;
|
|
46
52
|
modal?: boolean;
|
|
47
53
|
}
|
|
@@ -68,13 +74,17 @@ function buildSelector(schema: CommonSchema, projectPrefix: string): string {
|
|
|
68
74
|
return ret.join('-');
|
|
69
75
|
}
|
|
70
76
|
|
|
71
|
-
function
|
|
77
|
+
function buildName(schema: CommonSchema, prefix: 'Component' | 'Service'): string {
|
|
72
78
|
const ret: string[] = schema.withoutModulePrefixInComponentName === true ? [] : [schema.module!];
|
|
73
79
|
if (schema.target && schema.target.length > 0) {
|
|
74
80
|
ret.push(...schema.target.split('/'));
|
|
75
81
|
}
|
|
76
82
|
ret.push(schema.name!);
|
|
77
|
-
|
|
83
|
+
// 服务类自动过滤 list, empty 两个页面的后缀
|
|
84
|
+
if (prefix === 'Service' && ['list', 'empty'].includes(schema.name)) {
|
|
85
|
+
ret.pop();
|
|
86
|
+
}
|
|
87
|
+
ret.push(prefix);
|
|
78
88
|
return strings.classify(ret.join('-'));
|
|
79
89
|
}
|
|
80
90
|
|
|
@@ -140,11 +150,25 @@ function resolveSchema(
|
|
|
140
150
|
export function addImportToModule(tree: Tree, filePath: string, symbolName: string, fileName: string): void {
|
|
141
151
|
const source = getSourceFile(tree, filePath);
|
|
142
152
|
const change = insertImport(source, filePath, symbolName, fileName) as InsertChange;
|
|
153
|
+
if (change.path == null) return;
|
|
143
154
|
const declarationRecorder = tree.beginUpdate(filePath);
|
|
144
155
|
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
145
156
|
tree.commitUpdate(declarationRecorder);
|
|
146
157
|
}
|
|
147
158
|
|
|
159
|
+
export function addProviderToModule(tree: Tree, filePath: string, serviceName: string, importPath: string): void {
|
|
160
|
+
const source = getSourceFile(tree, filePath);
|
|
161
|
+
const changes = _addProviderToModule(source, filePath, serviceName, importPath);
|
|
162
|
+
const declarationRecorder = tree.beginUpdate(filePath);
|
|
163
|
+
changes.forEach(change => {
|
|
164
|
+
if (change.path == null) return;
|
|
165
|
+
if (change instanceof InsertChange) {
|
|
166
|
+
declarationRecorder.insertLeft(change.pos, change.toAdd);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
tree.commitUpdate(declarationRecorder);
|
|
170
|
+
}
|
|
171
|
+
|
|
148
172
|
export function addValueToVariable(
|
|
149
173
|
tree: Tree,
|
|
150
174
|
filePath: string,
|
|
@@ -171,10 +195,10 @@ export function addValueToVariable(
|
|
|
171
195
|
tree.commitUpdate(declarationRecorder);
|
|
172
196
|
}
|
|
173
197
|
|
|
174
|
-
function getRelativePath(filePath: string, schema: CommonSchema): string {
|
|
198
|
+
function getRelativePath(filePath: string, schema: CommonSchema, prefix: 'component' | 'service'): string {
|
|
175
199
|
const importPath = `/${schema.path}/${schema.flat ? '' : `${strings.dasherize(schema.name!)}/`}${strings.dasherize(
|
|
176
200
|
schema.name!
|
|
177
|
-
)}
|
|
201
|
+
)}.${prefix}`;
|
|
178
202
|
return buildRelativePath(filePath, importPath);
|
|
179
203
|
}
|
|
180
204
|
|
|
@@ -189,7 +213,7 @@ function addDeclaration(schema: CommonSchema): Rule {
|
|
|
189
213
|
tree,
|
|
190
214
|
schema.importModulePath!,
|
|
191
215
|
schema.componentName!,
|
|
192
|
-
getRelativePath(schema.importModulePath!, schema)
|
|
216
|
+
getRelativePath(schema.importModulePath!, schema, 'component')
|
|
193
217
|
);
|
|
194
218
|
addValueToVariable(tree, schema.importModulePath!, 'COMPONENTS', schema.componentName!);
|
|
195
219
|
|
|
@@ -200,7 +224,7 @@ function addDeclaration(schema: CommonSchema): Rule {
|
|
|
200
224
|
tree,
|
|
201
225
|
schema.routerModulePath!,
|
|
202
226
|
schema.componentName!,
|
|
203
|
-
getRelativePath(schema.routerModulePath!, schema)
|
|
227
|
+
getRelativePath(schema.routerModulePath!, schema, 'component')
|
|
204
228
|
);
|
|
205
229
|
addValueToVariable(
|
|
206
230
|
tree,
|
|
@@ -210,6 +234,16 @@ function addDeclaration(schema: CommonSchema): Rule {
|
|
|
210
234
|
);
|
|
211
235
|
}
|
|
212
236
|
|
|
237
|
+
// service
|
|
238
|
+
if (schema.service === 'none') {
|
|
239
|
+
addProviderToModule(
|
|
240
|
+
tree,
|
|
241
|
+
schema.importModulePath!,
|
|
242
|
+
schema.serviceName!,
|
|
243
|
+
getRelativePath(schema.importModulePath!, schema, 'service')
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
213
247
|
return tree;
|
|
214
248
|
};
|
|
215
249
|
}
|
|
@@ -223,13 +257,15 @@ export function buildAlain(schema: CommonSchema): Rule {
|
|
|
223
257
|
const project = res.project;
|
|
224
258
|
resolveSchema(tree, project, schema, res.alainProject);
|
|
225
259
|
|
|
226
|
-
schema.componentName =
|
|
260
|
+
schema.componentName = buildName(schema, 'Component');
|
|
261
|
+
schema.serviceName = buildName(schema, 'Service');
|
|
227
262
|
|
|
228
263
|
// Don't support inline
|
|
229
264
|
schema.inlineTemplate = false;
|
|
230
265
|
|
|
231
266
|
const templateSource = apply(url(schema._filesPath!), [
|
|
232
267
|
filter(filePath => !filePath.endsWith('.DS_Store')),
|
|
268
|
+
schema.service === 'ignore' ? filter(filePath => !filePath.endsWith('.service.ts.template')) : noop(),
|
|
233
269
|
schema.skipTests ? filter(filePath => !filePath.endsWith('.spec.ts.template')) : noop(),
|
|
234
270
|
schema.inlineStyle ? filter(filePath => !filePath.endsWith('.__style__.template')) : noop(),
|
|
235
271
|
schema.inlineTemplate ? filter(filePath => !filePath.endsWith('.html.template')) : noop(),
|
package/utils/code-style.js
CHANGED
|
@@ -4,6 +4,6 @@ exports.LINT_STAGED_CONFIG = exports.LINT_STAGED = void 0;
|
|
|
4
4
|
exports.LINT_STAGED = 'lint-staged';
|
|
5
5
|
exports.LINT_STAGED_CONFIG = {
|
|
6
6
|
'(src)/**/*.{html,ts}': ['eslint --fix'],
|
|
7
|
-
'(src)/**/*.less': ['stylelint --syntax less --fix']
|
|
7
|
+
'(src)/**/*.less': ['npx stylelint --syntax less --fix']
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=code-style.js.map
|
package/utils/code-style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-style.js","sourceRoot":"","sources":["../../../schematics/utils/code-style.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,aAAa,CAAC;AAE5B,QAAA,kBAAkB,GAAG;IAChC,sBAAsB,EAAE,CAAC,cAAc,CAAC;IACxC,iBAAiB,EAAE,CAAC
|
|
1
|
+
{"version":3,"file":"code-style.js","sourceRoot":"","sources":["../../../schematics/utils/code-style.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,aAAa,CAAC;AAE5B,QAAA,kBAAkB,GAAG;IAChC,sBAAsB,EAAE,CAAC,cAAc,CAAC;IACxC,iBAAiB,EAAE,CAAC,mCAAmC,CAAC;CACzD,CAAC"}
|
package/utils/code-style.ts
CHANGED
package/utils/lib-versions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZORROVERSION = exports.VERSION = void 0;
|
|
4
|
-
exports.VERSION = '^13.
|
|
5
|
-
exports.ZORROVERSION = '^13.
|
|
4
|
+
exports.VERSION = '^13.2.1';
|
|
5
|
+
exports.ZORROVERSION = '^13.1.1';
|
|
6
6
|
//# sourceMappingURL=lib-versions.js.map
|
package/utils/lib-versions.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '^13.
|
|
2
|
-
export const ZORROVERSION = '^13.
|
|
1
|
+
export const VERSION = '^13.2.1';
|
|
2
|
+
export const ZORROVERSION = '^13.1.1';
|
package/utils/versions.js
CHANGED
|
@@ -43,7 +43,7 @@ function UpgradeMainVersions(tree, version = lib_versions_1.VERSION) {
|
|
|
43
43
|
`@delon/testing@${version}`
|
|
44
44
|
], 'devDependencies');
|
|
45
45
|
(0, package_1.addPackage)(tree, [
|
|
46
|
-
`ng-zorro-antd@^13.
|
|
46
|
+
`ng-zorro-antd@^13.1.1`,
|
|
47
47
|
'ajv@^8.8.2',
|
|
48
48
|
'ajv-formats@^2.1.1'
|
|
49
49
|
]);
|
package/utils/versions.ts
CHANGED
package/view/schema.json
CHANGED
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"description": "Include template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file.",
|
|
45
45
|
"type": "boolean",
|
|
46
46
|
"default": false,
|
|
47
|
-
"alias": "t",
|
|
48
47
|
"x-user-analytics": 10
|
|
49
48
|
},
|
|
50
49
|
"viewEncapsulation": {
|
|
@@ -141,6 +140,22 @@
|
|
|
141
140
|
"default": true,
|
|
142
141
|
"description": "指定是否使用模态框 (Specifies using modal mode)",
|
|
143
142
|
"x-prompt": "Would you like to modal mode?"
|
|
143
|
+
},
|
|
144
|
+
"service": {
|
|
145
|
+
"type": "string",
|
|
146
|
+
"description": "The service file to use in the new component.",
|
|
147
|
+
"default": "ignore",
|
|
148
|
+
"enum": ["ignore", "none", "root"],
|
|
149
|
+
"x-prompt": {
|
|
150
|
+
"message": "Which service injectors would you like to use?",
|
|
151
|
+
"type": "list",
|
|
152
|
+
"items": [
|
|
153
|
+
{ "value": "ignore", "label": "Ignore generation of Service files" },
|
|
154
|
+
{ "value": "root", "label": "Use \"@Injectable({ providedIn: 'root' })\"" },
|
|
155
|
+
{ "value": "none", "label": "Use \"@Injectable()\" (Should be automatically register to the nearest module)" }
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
"x-user-analytics": 20
|
|
144
159
|
}
|
|
145
160
|
},
|
|
146
161
|
"required": ["name", "module"]
|