@abp/ng.schematics 5.0.1 → 5.0.2

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.
Files changed (141) hide show
  1. package/README.md +3 -3
  2. package/collection.json +29 -29
  3. package/commands/api/files-enum/proxy/__namespace@dir__/__name@kebab__.enum.ts.template +8 -8
  4. package/commands/api/files-model/proxy/__namespace@dir__/models.ts.template +9 -9
  5. package/commands/api/files-service/proxy/__namespace@dir__/__name@kebab__.service.ts.template +25 -25
  6. package/commands/api/index.d.ts +2 -2
  7. package/commands/api/index.js +112 -112
  8. package/commands/api/schema.json +45 -45
  9. package/commands/proxy-add/index.d.ts +2 -2
  10. package/commands/proxy-add/index.js +41 -41
  11. package/commands/proxy-add/schema.json +45 -45
  12. package/commands/proxy-index/index.d.ts +4 -4
  13. package/commands/proxy-index/index.js +14 -14
  14. package/commands/proxy-index/schema.json +18 -18
  15. package/commands/proxy-refresh/index.d.ts +3 -3
  16. package/commands/proxy-refresh/index.js +27 -27
  17. package/commands/proxy-refresh/schema.json +45 -45
  18. package/commands/proxy-remove/index.d.ts +3 -3
  19. package/commands/proxy-remove/index.js +33 -33
  20. package/commands/proxy-remove/schema.json +45 -45
  21. package/constants/api.d.ts +1 -1
  22. package/constants/api.js +4 -4
  23. package/constants/index.d.ts +4 -4
  24. package/constants/index.js +16 -16
  25. package/constants/proxy.d.ts +4 -4
  26. package/constants/proxy.js +24 -24
  27. package/constants/system-types.d.ts +1 -1
  28. package/constants/system-types.js +27 -27
  29. package/constants/volo.d.ts +1 -1
  30. package/constants/volo.js +4 -4
  31. package/enums/binding-source-id.d.ts +6 -6
  32. package/enums/binding-source-id.js +10 -10
  33. package/enums/exception.d.ts +16 -16
  34. package/enums/exception.js +2 -2
  35. package/enums/import-keyword.d.ts +4 -4
  36. package/enums/import-keyword.js +8 -8
  37. package/enums/index.d.ts +4 -4
  38. package/enums/index.js +16 -16
  39. package/enums/method-modifier.d.ts +6 -6
  40. package/enums/method-modifier.js +10 -10
  41. package/index.d.ts +1 -1
  42. package/index.js +2 -2
  43. package/models/api-definition.d.ts +72 -72
  44. package/models/api-definition.js +2 -2
  45. package/models/generate-proxy-schema.d.ts +18 -18
  46. package/models/generate-proxy-schema.js +2 -2
  47. package/models/import.d.ts +11 -11
  48. package/models/import.js +13 -13
  49. package/models/index.d.ts +10 -10
  50. package/models/index.js +22 -22
  51. package/models/method.d.ts +31 -31
  52. package/models/method.js +61 -61
  53. package/models/model.d.ts +48 -48
  54. package/models/model.js +71 -71
  55. package/models/project.d.ts +5 -5
  56. package/models/project.js +2 -2
  57. package/models/proxy-config.d.ts +4 -4
  58. package/models/proxy-config.js +2 -2
  59. package/models/service.d.ts +21 -21
  60. package/models/service.js +11 -11
  61. package/models/tree.d.ts +1 -1
  62. package/models/tree.js +2 -2
  63. package/models/util.d.ts +7 -7
  64. package/models/util.js +2 -2
  65. package/package.json +1 -1
  66. package/test-setup.d.ts +1 -1
  67. package/test-setup.js +3 -3
  68. package/utils/angular/ast-utils.d.ts +115 -115
  69. package/utils/angular/ast-utils.js +598 -598
  70. package/utils/angular/change.d.ts +66 -66
  71. package/utils/angular/change.js +96 -96
  72. package/utils/angular/config.d.ts +455 -455
  73. package/utils/angular/config.js +70 -70
  74. package/utils/angular/dependencies.d.ts +23 -23
  75. package/utils/angular/dependencies.js +58 -58
  76. package/utils/angular/find-module.d.ts +35 -35
  77. package/utils/angular/find-module.js +105 -105
  78. package/utils/angular/index.d.ts +17 -17
  79. package/utils/angular/index.js +29 -29
  80. package/utils/angular/json-file.d.ts +23 -23
  81. package/utils/angular/json-file.js +61 -61
  82. package/utils/angular/json-utils.d.ts +14 -14
  83. package/utils/angular/json-utils.js +158 -158
  84. package/utils/angular/latest-versions.d.ts +18 -18
  85. package/utils/angular/latest-versions.js +26 -26
  86. package/utils/angular/lint-fix.d.ts +9 -9
  87. package/utils/angular/lint-fix.js +41 -41
  88. package/utils/angular/ng-ast-utils.d.ts +5 -5
  89. package/utils/angular/ng-ast-utils.js +75 -75
  90. package/utils/angular/parse-name.d.ts +13 -13
  91. package/utils/angular/parse-name.js +21 -21
  92. package/utils/angular/paths.d.ts +8 -8
  93. package/utils/angular/paths.js +21 -21
  94. package/utils/angular/project-targets.d.ts +9 -9
  95. package/utils/angular/project-targets.js +15 -15
  96. package/utils/angular/tsconfig.d.ts +16 -16
  97. package/utils/angular/tsconfig.js +62 -62
  98. package/utils/angular/validation.d.ts +4 -4
  99. package/utils/angular/validation.js +73 -73
  100. package/utils/angular/workspace-models.d.ts +159 -159
  101. package/utils/angular/workspace-models.js +29 -29
  102. package/utils/angular/workspace.d.ts +18 -18
  103. package/utils/angular/workspace.js +75 -75
  104. package/utils/api.d.ts +2 -2
  105. package/utils/api.js +8 -8
  106. package/utils/ast.d.ts +4 -4
  107. package/utils/ast.js +23 -23
  108. package/utils/barrel.d.ts +4 -4
  109. package/utils/barrel.js +92 -92
  110. package/utils/common.d.ts +6 -6
  111. package/utils/common.js +33 -33
  112. package/utils/enum.d.ts +18 -18
  113. package/utils/enum.js +40 -40
  114. package/utils/file.d.ts +2 -2
  115. package/utils/file.js +9 -9
  116. package/utils/generics.d.ts +24 -24
  117. package/utils/generics.js +87 -87
  118. package/utils/import.d.ts +3 -3
  119. package/utils/import.js +11 -11
  120. package/utils/index.d.ts +19 -19
  121. package/utils/index.js +31 -31
  122. package/utils/model.d.ts +11 -11
  123. package/utils/model.js +141 -141
  124. package/utils/namespace.d.ts +1 -1
  125. package/utils/namespace.js +18 -18
  126. package/utils/path.d.ts +2 -2
  127. package/utils/path.js +36 -36
  128. package/utils/rule.d.ts +4 -4
  129. package/utils/rule.js +27 -27
  130. package/utils/service.d.ts +6 -6
  131. package/utils/service.js +82 -82
  132. package/utils/source.d.ts +13 -13
  133. package/utils/source.js +162 -162
  134. package/utils/text.d.ts +9 -9
  135. package/utils/text.js +46 -46
  136. package/utils/tree.d.ts +13 -13
  137. package/utils/tree.js +56 -56
  138. package/utils/type.d.ts +12 -12
  139. package/utils/type.js +102 -102
  140. package/utils/workspace.d.ts +8 -8
  141. package/utils/workspace.js +66 -66
package/utils/model.js CHANGED
@@ -1,142 +1,142 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRefToImportReducerCreator = exports.createImportRefToInterfaceReducerCreator = exports.createImportRefsToModelReducer = void 0;
4
- const constants_1 = require("../constants");
5
- const models_1 = require("../models");
6
- const generics_1 = require("./generics");
7
- const namespace_1 = require("./namespace");
8
- const path_1 = require("./path");
9
- const text_1 = require("./text");
10
- const tree_1 = require("./tree");
11
- const type_1 = require("./type");
12
- // eslint-disable-next-line @typescript-eslint/no-var-requires
13
- const shouldQuote = require('should-quote');
14
- function createImportRefsToModelReducer(params) {
15
- const reduceImportRefsToInterfaces = createImportRefToInterfaceReducerCreator(params);
16
- const createRefToImportReducer = createRefToImportReducerCreator(params);
17
- const { solution, types } = params;
18
- return (models, importRefs) => {
19
- const enums = [];
20
- const interfaces = importRefs.reduce(reduceImportRefsToInterfaces, []);
21
- sortInterfaces(interfaces);
22
- interfaces.forEach(_interface => {
23
- if (constants_1.VOLO_REGEX.test(_interface.ref))
24
- return;
25
- if (types[_interface.ref].isEnum) {
26
- if (!enums.includes(_interface.ref))
27
- enums.push(_interface.ref);
28
- return;
29
- }
30
- const index = models.findIndex(m => m.namespace === _interface.namespace);
31
- if (index > -1) {
32
- if (models[index].interfaces.some(i => i.identifier === _interface.identifier))
33
- return;
34
- models[index].interfaces.push(_interface);
35
- }
36
- else {
37
- const { namespace } = _interface;
38
- models.push(new models_1.Model({
39
- interfaces: [_interface],
40
- namespace,
41
- path: path_1.relativePathToModel(namespace, namespace),
42
- }));
43
- }
44
- });
45
- models.forEach(model => {
46
- const toBeImported = [];
47
- model.interfaces.forEach(_interface => {
48
- const { baseType } = types[_interface.ref];
49
- if (baseType && namespace_1.parseNamespace(solution, baseType) !== model.namespace)
50
- toBeImported.push({
51
- type: baseType.split('<')[0],
52
- isEnum: false,
53
- });
54
- [..._interface.properties, ..._interface.generics].forEach(prop => {
55
- prop.refs.forEach(ref => {
56
- const propType = types[ref];
57
- if (!propType)
58
- return;
59
- if (propType.isEnum)
60
- toBeImported.push({ type: ref, isEnum: true });
61
- else if (namespace_1.parseNamespace(solution, ref) !== model.namespace)
62
- toBeImported.push({ type: ref, isEnum: false });
63
- });
64
- });
65
- });
66
- if (!toBeImported.length)
67
- return;
68
- const reduceRefToImport = createRefToImportReducer(model.namespace);
69
- reduceRefToImport(model.imports, toBeImported);
70
- });
71
- return models;
72
- };
73
- }
74
- exports.createImportRefsToModelReducer = createImportRefsToModelReducer;
75
- function sortInterfaces(interfaces) {
76
- interfaces.sort((a, b) => (a.identifier > b.identifier ? 1 : -1));
77
- }
78
- function createImportRefToInterfaceReducerCreator(params) {
79
- const { solution, types } = params;
80
- const parseType = type_1.createTypeParser(type_1.removeTypeModifiers);
81
- const simplifyType = type_1.createTypeSimplifier();
82
- const getIdentifier = (type) => type_1.removeTypeModifiers(simplifyType(type));
83
- const genericsCollector = new generics_1.GenericsCollector(getIdentifier);
84
- return reduceRefsToInterfaces;
85
- function reduceRefsToInterfaces(interfaces, ref) {
86
- var _a;
87
- const typeDef = types[ref];
88
- if (!typeDef)
89
- return interfaces;
90
- const namespace = namespace_1.parseNamespace(solution, ref);
91
- let { baseType: base, genericArguments } = typeDef;
92
- genericArguments = genericArguments || [];
93
- let identifier = getIdentifier(ref);
94
- identifier = generics_1.replacePlaceholdersWithGenerics(identifier, genericArguments, genericsCollector);
95
- if (base) {
96
- if (type_1.extendsSelf(ref, base)) {
97
- genericsCollector.collect(generics_1.extractGenerics(base).generics, genericArguments);
98
- return reduceRefsToInterfaces(interfaces, generics_1.generateRefWithPlaceholders(base));
99
- }
100
- else {
101
- base = getIdentifier(base);
102
- }
103
- }
104
- const { generics } = genericsCollector;
105
- const _interface = new models_1.Interface({ identifier, base, namespace, ref, generics });
106
- genericsCollector.reset();
107
- (_a = typeDef.properties) === null || _a === void 0 ? void 0 : _a.forEach(prop => {
108
- let name = prop.jsonName || text_1.camel(prop.name);
109
- name = shouldQuote(name) ? `'${name}'` : name;
110
- const type = simplifyType(prop.typeSimple);
111
- const refs = parseType(prop.type).reduce((acc, r) => acc.concat(tree_1.parseGenerics(r).toGenerics()), []);
112
- const property = new models_1.Property({ name, type, refs });
113
- property.setOptional(isOptionalProperty(prop));
114
- _interface.properties.push(property);
115
- });
116
- interfaces.push(_interface);
117
- return [..._interface.properties, ..._interface.generics]
118
- .reduce((refs, prop) => {
119
- prop.refs.forEach(type => {
120
- var _a;
121
- if ((_a = types[type]) === null || _a === void 0 ? void 0 : _a.isEnum)
122
- return;
123
- if (interfaces.some(i => i.ref === type))
124
- return;
125
- refs.push(type);
126
- });
127
- return refs;
128
- }, [])
129
- .concat(base ? tree_1.parseGenerics(typeDef.baseType).toGenerics() : [])
130
- .reduce(reduceRefsToInterfaces, interfaces);
131
- }
132
- }
133
- exports.createImportRefToInterfaceReducerCreator = createImportRefToInterfaceReducerCreator;
134
- function createRefToImportReducerCreator(params) {
135
- const { solution } = params;
136
- return (namespace) => type_1.createTypesToImportsReducer(solution, namespace);
137
- }
138
- exports.createRefToImportReducerCreator = createRefToImportReducerCreator;
139
- function isOptionalProperty(prop) {
140
- return (prop.typeSimple.endsWith('?') || (prop.typeSimple === 'string' && prop.isRequired === false));
141
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRefToImportReducerCreator = exports.createImportRefToInterfaceReducerCreator = exports.createImportRefsToModelReducer = void 0;
4
+ const constants_1 = require("../constants");
5
+ const models_1 = require("../models");
6
+ const generics_1 = require("./generics");
7
+ const namespace_1 = require("./namespace");
8
+ const path_1 = require("./path");
9
+ const text_1 = require("./text");
10
+ const tree_1 = require("./tree");
11
+ const type_1 = require("./type");
12
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
13
+ const shouldQuote = require('should-quote');
14
+ function createImportRefsToModelReducer(params) {
15
+ const reduceImportRefsToInterfaces = createImportRefToInterfaceReducerCreator(params);
16
+ const createRefToImportReducer = createRefToImportReducerCreator(params);
17
+ const { solution, types } = params;
18
+ return (models, importRefs) => {
19
+ const enums = [];
20
+ const interfaces = importRefs.reduce(reduceImportRefsToInterfaces, []);
21
+ sortInterfaces(interfaces);
22
+ interfaces.forEach(_interface => {
23
+ if (constants_1.VOLO_REGEX.test(_interface.ref))
24
+ return;
25
+ if (types[_interface.ref].isEnum) {
26
+ if (!enums.includes(_interface.ref))
27
+ enums.push(_interface.ref);
28
+ return;
29
+ }
30
+ const index = models.findIndex(m => m.namespace === _interface.namespace);
31
+ if (index > -1) {
32
+ if (models[index].interfaces.some(i => i.identifier === _interface.identifier))
33
+ return;
34
+ models[index].interfaces.push(_interface);
35
+ }
36
+ else {
37
+ const { namespace } = _interface;
38
+ models.push(new models_1.Model({
39
+ interfaces: [_interface],
40
+ namespace,
41
+ path: path_1.relativePathToModel(namespace, namespace),
42
+ }));
43
+ }
44
+ });
45
+ models.forEach(model => {
46
+ const toBeImported = [];
47
+ model.interfaces.forEach(_interface => {
48
+ const { baseType } = types[_interface.ref];
49
+ if (baseType && namespace_1.parseNamespace(solution, baseType) !== model.namespace)
50
+ toBeImported.push({
51
+ type: baseType.split('<')[0],
52
+ isEnum: false,
53
+ });
54
+ [..._interface.properties, ..._interface.generics].forEach(prop => {
55
+ prop.refs.forEach(ref => {
56
+ const propType = types[ref];
57
+ if (!propType)
58
+ return;
59
+ if (propType.isEnum)
60
+ toBeImported.push({ type: ref, isEnum: true });
61
+ else if (namespace_1.parseNamespace(solution, ref) !== model.namespace)
62
+ toBeImported.push({ type: ref, isEnum: false });
63
+ });
64
+ });
65
+ });
66
+ if (!toBeImported.length)
67
+ return;
68
+ const reduceRefToImport = createRefToImportReducer(model.namespace);
69
+ reduceRefToImport(model.imports, toBeImported);
70
+ });
71
+ return models;
72
+ };
73
+ }
74
+ exports.createImportRefsToModelReducer = createImportRefsToModelReducer;
75
+ function sortInterfaces(interfaces) {
76
+ interfaces.sort((a, b) => (a.identifier > b.identifier ? 1 : -1));
77
+ }
78
+ function createImportRefToInterfaceReducerCreator(params) {
79
+ const { solution, types } = params;
80
+ const parseType = type_1.createTypeParser(type_1.removeTypeModifiers);
81
+ const simplifyType = type_1.createTypeSimplifier();
82
+ const getIdentifier = (type) => type_1.removeTypeModifiers(simplifyType(type));
83
+ const genericsCollector = new generics_1.GenericsCollector(getIdentifier);
84
+ return reduceRefsToInterfaces;
85
+ function reduceRefsToInterfaces(interfaces, ref) {
86
+ var _a;
87
+ const typeDef = types[ref];
88
+ if (!typeDef)
89
+ return interfaces;
90
+ const namespace = namespace_1.parseNamespace(solution, ref);
91
+ let { baseType: base, genericArguments } = typeDef;
92
+ genericArguments = genericArguments || [];
93
+ let identifier = getIdentifier(ref);
94
+ identifier = generics_1.replacePlaceholdersWithGenerics(identifier, genericArguments, genericsCollector);
95
+ if (base) {
96
+ if (type_1.extendsSelf(ref, base)) {
97
+ genericsCollector.collect(generics_1.extractGenerics(base).generics, genericArguments);
98
+ return reduceRefsToInterfaces(interfaces, generics_1.generateRefWithPlaceholders(base));
99
+ }
100
+ else {
101
+ base = getIdentifier(base);
102
+ }
103
+ }
104
+ const { generics } = genericsCollector;
105
+ const _interface = new models_1.Interface({ identifier, base, namespace, ref, generics });
106
+ genericsCollector.reset();
107
+ (_a = typeDef.properties) === null || _a === void 0 ? void 0 : _a.forEach(prop => {
108
+ let name = prop.jsonName || text_1.camel(prop.name);
109
+ name = shouldQuote(name) ? `'${name}'` : name;
110
+ const type = simplifyType(prop.typeSimple);
111
+ const refs = parseType(prop.type).reduce((acc, r) => acc.concat(tree_1.parseGenerics(r).toGenerics()), []);
112
+ const property = new models_1.Property({ name, type, refs });
113
+ property.setOptional(isOptionalProperty(prop));
114
+ _interface.properties.push(property);
115
+ });
116
+ interfaces.push(_interface);
117
+ return [..._interface.properties, ..._interface.generics]
118
+ .reduce((refs, prop) => {
119
+ prop.refs.forEach(type => {
120
+ var _a;
121
+ if ((_a = types[type]) === null || _a === void 0 ? void 0 : _a.isEnum)
122
+ return;
123
+ if (interfaces.some(i => i.ref === type))
124
+ return;
125
+ refs.push(type);
126
+ });
127
+ return refs;
128
+ }, [])
129
+ .concat(base ? tree_1.parseGenerics(typeDef.baseType).toGenerics() : [])
130
+ .reduce(reduceRefsToInterfaces, interfaces);
131
+ }
132
+ }
133
+ exports.createImportRefToInterfaceReducerCreator = createImportRefToInterfaceReducerCreator;
134
+ function createRefToImportReducerCreator(params) {
135
+ const { solution } = params;
136
+ return (namespace) => type_1.createTypesToImportsReducer(solution, namespace);
137
+ }
138
+ exports.createRefToImportReducerCreator = createRefToImportReducerCreator;
139
+ function isOptionalProperty(prop) {
140
+ return (prop.typeSimple.endsWith('?') || (prop.typeSimple === 'string' && prop.isRequired === false));
141
+ }
142
142
  //# sourceMappingURL=model.js.map
@@ -1 +1 @@
1
- export declare function parseNamespace(solution: string, type: string): string;
1
+ export declare function parseNamespace(solution: string, type: string): string;
@@ -1,19 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseNamespace = void 0;
4
- const type_1 = require("./type");
5
- function parseNamespace(solution, type) {
6
- const parseType = type_1.createTypeParser(type_1.removeGenerics);
7
- let namespace = parseType(type)[0].split('.').slice(0, -1).join('.');
8
- if (solution === namespace)
9
- return '';
10
- solution.split('.').reduceRight((acc, part) => {
11
- acc = `${part}\\.${acc}`;
12
- const regex = new RegExp(`^${acc}(Controllers\\.)?`);
13
- namespace = namespace.replace(regex, '');
14
- return acc;
15
- }, '');
16
- return namespace;
17
- }
18
- exports.parseNamespace = parseNamespace;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseNamespace = void 0;
4
+ const type_1 = require("./type");
5
+ function parseNamespace(solution, type) {
6
+ const parseType = type_1.createTypeParser(type_1.removeGenerics);
7
+ let namespace = parseType(type)[0].split('.').slice(0, -1).join('.');
8
+ if (solution === namespace)
9
+ return '';
10
+ solution.split('.').reduceRight((acc, part) => {
11
+ acc = `${part}\\.${acc}`;
12
+ const regex = new RegExp(`^${acc}(Controllers\\.)?`);
13
+ namespace = namespace.replace(regex, '');
14
+ return acc;
15
+ }, '');
16
+ return namespace;
17
+ }
18
+ exports.parseNamespace = parseNamespace;
19
19
  //# sourceMappingURL=namespace.js.map
package/utils/path.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare function relativePathToEnum(namespace: string, enumNamespace: string, enumName: string): string;
2
- export declare function relativePathToModel(namespace: string, modelNamespace: string): string;
1
+ export declare function relativePathToEnum(namespace: string, enumNamespace: string, enumName: string): string;
2
+ export declare function relativePathToModel(namespace: string, modelNamespace: string): string;
package/utils/path.js CHANGED
@@ -1,37 +1,37 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.relativePathToModel = exports.relativePathToEnum = void 0;
4
- const core_1 = require("@angular-devkit/core");
5
- const text_1 = require("./text");
6
- function relativePathToEnum(namespace, enumNamespace, enumName) {
7
- const path = calculateRelativePath(namespace, enumNamespace);
8
- return path + `/${text_1.kebab(enumName)}.enum`;
9
- }
10
- exports.relativePathToEnum = relativePathToEnum;
11
- function relativePathToModel(namespace, modelNamespace) {
12
- const path = calculateRelativePath(namespace, modelNamespace);
13
- return path + '/models';
14
- }
15
- exports.relativePathToModel = relativePathToModel;
16
- function calculateRelativePath(ns1, ns2) {
17
- if (ns1 === ns2)
18
- return '.';
19
- const parts1 = ns1 ? ns1.split('.') : [];
20
- const parts2 = ns2 ? ns2.split('.') : [];
21
- while (parts1.length && parts2.length) {
22
- if (parts1[0] !== parts2[0])
23
- break;
24
- parts1.shift();
25
- parts2.shift();
26
- }
27
- const up = '../'.repeat(parts1.length) || '.';
28
- const down = parts2.reduce((acc, p) => acc + '/' + core_1.strings.dasherize(p), '');
29
- return removeTrailingSlash(removeDoubleSlash(up + down));
30
- }
31
- function removeDoubleSlash(path) {
32
- return path.replace(/\/{2,}/g, '/');
33
- }
34
- function removeTrailingSlash(path) {
35
- return path.replace(/\/+$/, '');
36
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.relativePathToModel = exports.relativePathToEnum = void 0;
4
+ const core_1 = require("@angular-devkit/core");
5
+ const text_1 = require("./text");
6
+ function relativePathToEnum(namespace, enumNamespace, enumName) {
7
+ const path = calculateRelativePath(namespace, enumNamespace);
8
+ return path + `/${text_1.kebab(enumName)}.enum`;
9
+ }
10
+ exports.relativePathToEnum = relativePathToEnum;
11
+ function relativePathToModel(namespace, modelNamespace) {
12
+ const path = calculateRelativePath(namespace, modelNamespace);
13
+ return path + '/models';
14
+ }
15
+ exports.relativePathToModel = relativePathToModel;
16
+ function calculateRelativePath(ns1, ns2) {
17
+ if (ns1 === ns2)
18
+ return '.';
19
+ const parts1 = ns1 ? ns1.split('.') : [];
20
+ const parts2 = ns2 ? ns2.split('.') : [];
21
+ while (parts1.length && parts2.length) {
22
+ if (parts1[0] !== parts2[0])
23
+ break;
24
+ parts1.shift();
25
+ parts2.shift();
26
+ }
27
+ const up = '../'.repeat(parts1.length) || '.';
28
+ const down = parts2.reduce((acc, p) => acc + '/' + core_1.strings.dasherize(p), '');
29
+ return removeTrailingSlash(removeDoubleSlash(up + down));
30
+ }
31
+ function removeDoubleSlash(path) {
32
+ return path.replace(/\/{2,}/g, '/');
33
+ }
34
+ function removeTrailingSlash(path) {
35
+ return path.replace(/\/+$/, '');
36
+ }
37
37
  //# sourceMappingURL=path.js.map
package/utils/rule.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Rule, SchematicContext, Source, Tree } from '@angular-devkit/schematics';
2
- export declare function applyWithOverwrite(source: Source, rules: Rule[]): Rule;
3
- export declare function mergeAndAllowDelete(host: Tree, rule: Rule): (tree: Tree, context: SchematicContext) => Promise<void>;
4
- export declare function overwriteFileIfExists(tree: Tree): Rule;
1
+ import { Rule, SchematicContext, Source, Tree } from '@angular-devkit/schematics';
2
+ export declare function applyWithOverwrite(source: Source, rules: Rule[]): Rule;
3
+ export declare function mergeAndAllowDelete(host: Tree, rule: Rule): (tree: Tree, context: SchematicContext) => Promise<void>;
4
+ export declare function overwriteFileIfExists(tree: Tree): Rule;
package/utils/rule.js CHANGED
@@ -1,28 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.overwriteFileIfExists = exports.mergeAndAllowDelete = exports.applyWithOverwrite = void 0;
4
- const schematics_1 = require("@angular-devkit/schematics");
5
- function applyWithOverwrite(source, rules) {
6
- return (tree, _context) => {
7
- const rule = schematics_1.mergeWith(schematics_1.apply(source, [...rules, overwriteFileIfExists(tree)]));
8
- return rule(tree, _context);
9
- };
10
- }
11
- exports.applyWithOverwrite = applyWithOverwrite;
12
- function mergeAndAllowDelete(host, rule) {
13
- return async (tree, context) => {
14
- const nextTree = await schematics_1.callRule(rule, tree, context).toPromise();
15
- host.merge(nextTree, schematics_1.MergeStrategy.AllowDeleteConflict);
16
- };
17
- }
18
- exports.mergeAndAllowDelete = mergeAndAllowDelete;
19
- function overwriteFileIfExists(tree) {
20
- return schematics_1.forEach(fileEntry => {
21
- if (!tree.exists(fileEntry.path))
22
- return fileEntry;
23
- tree.overwrite(fileEntry.path, fileEntry.content);
24
- return null;
25
- });
26
- }
27
- exports.overwriteFileIfExists = overwriteFileIfExists;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.overwriteFileIfExists = exports.mergeAndAllowDelete = exports.applyWithOverwrite = void 0;
4
+ const schematics_1 = require("@angular-devkit/schematics");
5
+ function applyWithOverwrite(source, rules) {
6
+ return (tree, _context) => {
7
+ const rule = schematics_1.mergeWith(schematics_1.apply(source, [...rules, overwriteFileIfExists(tree)]));
8
+ return rule(tree, _context);
9
+ };
10
+ }
11
+ exports.applyWithOverwrite = applyWithOverwrite;
12
+ function mergeAndAllowDelete(host, rule) {
13
+ return async (tree, context) => {
14
+ const nextTree = await schematics_1.callRule(rule, tree, context).toPromise();
15
+ host.merge(nextTree, schematics_1.MergeStrategy.AllowDeleteConflict);
16
+ };
17
+ }
18
+ exports.mergeAndAllowDelete = mergeAndAllowDelete;
19
+ function overwriteFileIfExists(tree) {
20
+ return schematics_1.forEach(fileEntry => {
21
+ if (!tree.exists(fileEntry.path))
22
+ return fileEntry;
23
+ tree.overwrite(fileEntry.path, fileEntry.content);
24
+ return null;
25
+ });
26
+ }
27
+ exports.overwriteFileIfExists = overwriteFileIfExists;
28
28
  //# sourceMappingURL=rule.js.map
@@ -1,6 +1,6 @@
1
- import { Action, Body, Controller, Method, Property, Service, ServiceGeneratorParams, Signature } from '../models';
2
- export declare function serializeParameters(parameters: Property[]): string;
3
- export declare function createControllerToServiceMapper({ solution, types, apiName, }: ServiceGeneratorParams): (controller: Controller) => Service;
4
- export declare function createActionToMethodMapper(): (action: Action) => Method;
5
- export declare function createActionToBodyMapper(): ({ httpMethod, parameters, returnValue, url }: Action) => Body;
6
- export declare function createActionToSignatureMapper(): (action: Action) => Signature;
1
+ import { Action, Body, Controller, Method, Property, Service, ServiceGeneratorParams, Signature } from '../models';
2
+ export declare function serializeParameters(parameters: Property[]): string;
3
+ export declare function createControllerToServiceMapper({ solution, types, apiName, }: ServiceGeneratorParams): (controller: Controller) => Service;
4
+ export declare function createActionToMethodMapper(): (action: Action) => Method;
5
+ export declare function createActionToBodyMapper(): ({ httpMethod, parameters, returnValue, url }: Action) => Body;
6
+ export declare function createActionToSignatureMapper(): (action: Action) => Signature;