@baloise/angular-output-target 1.0.23 → 1.1.0
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/CHANGELOG.md +38 -0
- package/dist/generate-angular-directives-file.js +2 -2
- package/dist/generate-angular-module.d.ts +5 -0
- package/dist/generate-angular-module.js +55 -0
- package/dist/index.cjs.js +94 -8
- package/dist/index.js +94 -8
- package/dist/output-angular.d.ts +1 -0
- package/dist/output-angular.js +38 -6
- package/dist/types.d.ts +12 -0
- package/dist/utils.js +1 -1
- package/package.json +2 -2
- package/resources/control-value-accessors/boolean-value-accessor.ts +1 -1
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,44 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
# [1.1.0](https://github.com/baloise/stencil-ds-output-targets/compare/@baloise/angular-output-target@1.0.26...@baloise/angular-output-target@1.1.0) (2022-01-31)
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* **angular:** add modules for each component ([e6a5cd2](https://github.com/baloise/stencil-ds-output-targets/commit/e6a5cd209dd0d61a4bcbc8855fae965b0ff6f815))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
## [1.0.26](https://github.com/baloise/stencil-ds-output-targets/compare/@baloise/angular-output-target@1.0.25...@baloise/angular-output-target@1.0.26) (2022-01-24)
|
18
|
+
|
19
|
+
**Note:** Version bump only for package @baloise/angular-output-target
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
## [1.0.25](https://github.com/baloise/stencil-ds-output-targets/compare/@baloise/angular-output-target@1.0.24...@baloise/angular-output-target@1.0.25) (2022-01-08)
|
26
|
+
|
27
|
+
|
28
|
+
### Bug Fixes
|
29
|
+
|
30
|
+
* **angular:** change checked to value to add more components than the checkbox ([ff96e74](https://github.com/baloise/stencil-ds-output-targets/commit/ff96e742f1dcb1c8427a67f3a0c96dfe4baf75c5))
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
## [1.0.24](https://github.com/baloise/stencil-ds-output-targets/compare/@baloise/angular-output-target@1.0.23...@baloise/angular-output-target@1.0.24) (2022-01-08)
|
37
|
+
|
38
|
+
**Note:** Version bump only for package @baloise/angular-output-target
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
6
44
|
## [1.0.23](https://github.com/baloise/stencil-ds-output-targets/compare/@baloise/angular-output-target@1.0.22...@baloise/angular-output-target@1.0.23) (2022-01-06)
|
7
45
|
|
8
46
|
**Note:** Version bump only for package @baloise/angular-output-target
|
@@ -6,8 +6,8 @@ export function generateAngularDirectivesFile(compilerCtx, components, outputTar
|
|
6
6
|
}
|
7
7
|
const proxyPath = relativeImport(outputTarget.directivesArrayFile, outputTarget.directivesProxyFile, '.ts');
|
8
8
|
const directives = components
|
9
|
-
.map(
|
10
|
-
.map(
|
9
|
+
.map(cmpMeta => dashToPascalCase(cmpMeta.tagName))
|
10
|
+
.map(className => `d.${className}`)
|
11
11
|
.join(',\n ');
|
12
12
|
const c = `
|
13
13
|
import * as d from '${proxyPath}';
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { dashToPascalCase } from './utils';
|
2
|
+
export const createComponentModule = (groups = {}) => (cmpMeta) => {
|
3
|
+
const isPrivate = Object.values(groups)
|
4
|
+
.flat()
|
5
|
+
.map(o => o.components)
|
6
|
+
.flat()
|
7
|
+
.some(tag => tag === cmpMeta.tagName);
|
8
|
+
if (isPrivate) {
|
9
|
+
return '';
|
10
|
+
}
|
11
|
+
const tagNameAsPascal = dashToPascalCase(cmpMeta.tagName);
|
12
|
+
let cmpImports = [];
|
13
|
+
let cmpDefines = [];
|
14
|
+
if (groups[cmpMeta.tagName] && groups[cmpMeta.tagName].components) {
|
15
|
+
const children = groups[cmpMeta.tagName].components;
|
16
|
+
if (children) {
|
17
|
+
cmpImports = children.map(tag => `${dashToPascalCase(tag)}`);
|
18
|
+
cmpDefines = children.map(tag => ` define${dashToPascalCase(tag)}();`);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
let providers = [];
|
22
|
+
let providerImports = [];
|
23
|
+
if (groups[cmpMeta.tagName] && groups[cmpMeta.tagName].providers) {
|
24
|
+
const children = groups[cmpMeta.tagName].providers;
|
25
|
+
if (children) {
|
26
|
+
providerImports = children.map(p => `import { ${p.name} } from '../${p.import.replace('.ts', '')}'`);
|
27
|
+
providers = children.map(p => p.name);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
let declarations = [];
|
31
|
+
let declarationImports = [];
|
32
|
+
if (groups[cmpMeta.tagName] && groups[cmpMeta.tagName].declarations) {
|
33
|
+
const children = groups[cmpMeta.tagName].declarations;
|
34
|
+
if (children) {
|
35
|
+
declarationImports = children.map(p => `import { ${p.name} } from '../${p.import.replace('.ts', '')}'`);
|
36
|
+
declarations = children.map(p => p.name);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
const finalText = `
|
40
|
+
${providerImports.join('\n ')}
|
41
|
+
${declarationImports.join('\n ')}
|
42
|
+
|
43
|
+
@NgModule({
|
44
|
+
declarations: [${[tagNameAsPascal, ...cmpImports, ...declarations].join(', ')}],
|
45
|
+
exports: [${[tagNameAsPascal, ...cmpImports, ...declarations].join(', ')}],
|
46
|
+
providers: [${providers.join(', ')}],
|
47
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
48
|
+
})
|
49
|
+
export class ${tagNameAsPascal}Module {
|
50
|
+
constructor() {
|
51
|
+
${[` define${tagNameAsPascal}();`, ...cmpDefines].join('\n')}
|
52
|
+
}
|
53
|
+
}`;
|
54
|
+
return finalText;
|
55
|
+
};
|
package/dist/index.cjs.js
CHANGED
@@ -15,7 +15,7 @@ const readFile = util.promisify(fs__default['default'].readFile);
|
|
15
15
|
const toLowerCase = (str) => str.toLowerCase();
|
16
16
|
const dashToPascalCase = (str) => toLowerCase(str)
|
17
17
|
.split('-')
|
18
|
-
.map(
|
18
|
+
.map(segment => segment.charAt(0).toUpperCase() + segment.slice(1))
|
19
19
|
.join('');
|
20
20
|
function sortBy(array, prop) {
|
21
21
|
return array.slice().sort((a, b) => {
|
@@ -167,8 +167,8 @@ function generateAngularDirectivesFile(compilerCtx, components, outputTarget) {
|
|
167
167
|
}
|
168
168
|
const proxyPath = relativeImport(outputTarget.directivesArrayFile, outputTarget.directivesProxyFile, '.ts');
|
169
169
|
const directives = components
|
170
|
-
.map(
|
171
|
-
.map(
|
170
|
+
.map(cmpMeta => dashToPascalCase(cmpMeta.tagName))
|
171
|
+
.map(className => `d.${className}`)
|
172
172
|
.join(',\n ');
|
173
173
|
const c = `
|
174
174
|
import * as d from '${proxyPath}';
|
@@ -235,20 +235,77 @@ const VALUE_ACCESSOR_EVENT = `<VALUE_ACCESSOR_EVENT>`;
|
|
235
235
|
const VALUE_ACCESSOR_TARGETATTR = '<VALUE_ACCESSOR_TARGETATTR>';
|
236
236
|
const VALUE_ACCESSOR_EVENTTARGETS = ` '(<VALUE_ACCESSOR_EVENT>)': 'handleChangeEvent($event.detail)'`;
|
237
237
|
|
238
|
+
const createComponentModule = (groups = {}) => (cmpMeta) => {
|
239
|
+
const isPrivate = Object.values(groups)
|
240
|
+
.flat()
|
241
|
+
.map(o => o.components)
|
242
|
+
.flat()
|
243
|
+
.some(tag => tag === cmpMeta.tagName);
|
244
|
+
if (isPrivate) {
|
245
|
+
return '';
|
246
|
+
}
|
247
|
+
const tagNameAsPascal = dashToPascalCase(cmpMeta.tagName);
|
248
|
+
let cmpImports = [];
|
249
|
+
let cmpDefines = [];
|
250
|
+
if (groups[cmpMeta.tagName] && groups[cmpMeta.tagName].components) {
|
251
|
+
const children = groups[cmpMeta.tagName].components;
|
252
|
+
if (children) {
|
253
|
+
cmpImports = children.map(tag => `${dashToPascalCase(tag)}`);
|
254
|
+
cmpDefines = children.map(tag => ` define${dashToPascalCase(tag)}();`);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
let providers = [];
|
258
|
+
let providerImports = [];
|
259
|
+
if (groups[cmpMeta.tagName] && groups[cmpMeta.tagName].providers) {
|
260
|
+
const children = groups[cmpMeta.tagName].providers;
|
261
|
+
if (children) {
|
262
|
+
providerImports = children.map(p => `import { ${p.name} } from '../${p.import.replace('.ts', '')}'`);
|
263
|
+
providers = children.map(p => p.name);
|
264
|
+
}
|
265
|
+
}
|
266
|
+
let declarations = [];
|
267
|
+
let declarationImports = [];
|
268
|
+
if (groups[cmpMeta.tagName] && groups[cmpMeta.tagName].declarations) {
|
269
|
+
const children = groups[cmpMeta.tagName].declarations;
|
270
|
+
if (children) {
|
271
|
+
declarationImports = children.map(p => `import { ${p.name} } from '../${p.import.replace('.ts', '')}'`);
|
272
|
+
declarations = children.map(p => p.name);
|
273
|
+
}
|
274
|
+
}
|
275
|
+
const finalText = `
|
276
|
+
${providerImports.join('\n ')}
|
277
|
+
${declarationImports.join('\n ')}
|
278
|
+
|
279
|
+
@NgModule({
|
280
|
+
declarations: [${[tagNameAsPascal, ...cmpImports, ...declarations].join(', ')}],
|
281
|
+
exports: [${[tagNameAsPascal, ...cmpImports, ...declarations].join(', ')}],
|
282
|
+
providers: [${providers.join(', ')}],
|
283
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
284
|
+
})
|
285
|
+
export class ${tagNameAsPascal}Module {
|
286
|
+
constructor() {
|
287
|
+
${[` define${tagNameAsPascal}();`, ...cmpDefines].join('\n')}
|
288
|
+
}
|
289
|
+
}`;
|
290
|
+
return finalText;
|
291
|
+
};
|
292
|
+
|
238
293
|
async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
239
294
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
240
295
|
const rootDir = config.rootDir;
|
241
296
|
const pkgData = await readPackageJson(rootDir);
|
242
297
|
const finalText = generateProxies(filteredComponents, pkgData, outputTarget, config.rootDir);
|
298
|
+
const allComponentModule = generateAllComponentModule(filteredComponents, outputTarget);
|
243
299
|
await Promise.all([
|
244
300
|
compilerCtx.fs.writeFile(outputTarget.directivesProxyFile, finalText),
|
301
|
+
compilerCtx.fs.writeFile(outputTarget.directivesProxyFile.replace('.ts', '.module.ts'), allComponentModule),
|
245
302
|
copyResources(config, outputTarget),
|
246
303
|
generateAngularDirectivesFile(compilerCtx, filteredComponents, outputTarget),
|
247
304
|
generateValueAccessors(compilerCtx, filteredComponents, outputTarget, config),
|
248
305
|
]);
|
249
306
|
}
|
250
307
|
function getFilteredComponents(excludeComponents = [], cmps) {
|
251
|
-
return sortBy(cmps,
|
308
|
+
return sortBy(cmps, cmp => cmp.tagName).filter(c => !excludeComponents.includes(c.tagName) && !c.internal);
|
252
309
|
}
|
253
310
|
async function copyResources(config, outputTarget) {
|
254
311
|
if (!config.sys || !config.sys.copy || !config.sys.glob) {
|
@@ -265,23 +322,52 @@ async function copyResources(config, outputTarget) {
|
|
265
322
|
},
|
266
323
|
], srcDirectory);
|
267
324
|
}
|
325
|
+
function generateAllComponentModule(components, outputTarget) {
|
326
|
+
const childComponent = Object.values(outputTarget.componentGroups || {})
|
327
|
+
.flat()
|
328
|
+
.map(o => o.components)
|
329
|
+
.flat();
|
330
|
+
const moduleImports = components
|
331
|
+
.map(c => c.tagName)
|
332
|
+
.filter(c => !childComponent.includes(c))
|
333
|
+
.map(c => ` ${dashToPascalCase(c)}Module,`);
|
334
|
+
return `/* tslint:disable */
|
335
|
+
/* auto-generated angular directive proxies */
|
336
|
+
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
|
337
|
+
import {
|
338
|
+
${moduleImports.join('\n')}
|
339
|
+
} from './proxies'
|
340
|
+
|
341
|
+
const modules = [
|
342
|
+
${moduleImports.join('\n')}
|
343
|
+
]
|
344
|
+
|
345
|
+
@NgModule({
|
346
|
+
imports: [...modules],
|
347
|
+
exports: [...modules],
|
348
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
349
|
+
})
|
350
|
+
export class BalAllComponentModule {}
|
351
|
+
`;
|
352
|
+
}
|
268
353
|
function generateProxies(components, pkgData, outputTarget, rootDir) {
|
269
354
|
const distTypesDir = path__default['default'].dirname(pkgData.types);
|
270
355
|
const dtsFilePath = path__default['default'].join(rootDir, distTypesDir, GENERATED_DTS);
|
271
356
|
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
272
357
|
const imports = `/* tslint:disable */
|
273
358
|
/* auto-generated angular directive proxies */
|
274
|
-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone, EventEmitter } from '@angular/core';
|
359
|
+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone, EventEmitter, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
275
360
|
import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
361
|
+
const componentImports = components.map(c => `import { defineCustomElement as define${dashToPascalCase(c.tagName)} } from '${normalizePath(outputTarget.componentCorePackage || '')}/dist/components/${c.tagName}';`);
|
276
362
|
const typeImports = !outputTarget.componentCorePackage
|
277
363
|
? `import { ${IMPORT_TYPES} } from '${normalizePath(componentsTypeFile)}';`
|
278
364
|
: `import { ${IMPORT_TYPES} } from '${normalizePath(outputTarget.componentCorePackage)}';`;
|
279
365
|
const final = [
|
280
366
|
imports,
|
281
367
|
typeImports,
|
282
|
-
|
283
|
-
|
284
|
-
|
368
|
+
componentImports.join('\n'),
|
369
|
+
components.map(createComponentDefinition(outputTarget.componentCorePackage)).join('\n'),
|
370
|
+
components.map(createComponentModule(outputTarget.componentGroups)).join('\n'),
|
285
371
|
];
|
286
372
|
return final.join('\n') + '\n';
|
287
373
|
}
|
package/dist/index.js
CHANGED
@@ -6,7 +6,7 @@ const readFile = promisify(fs.readFile);
|
|
6
6
|
const toLowerCase = (str) => str.toLowerCase();
|
7
7
|
const dashToPascalCase = (str) => toLowerCase(str)
|
8
8
|
.split('-')
|
9
|
-
.map(
|
9
|
+
.map(segment => segment.charAt(0).toUpperCase() + segment.slice(1))
|
10
10
|
.join('');
|
11
11
|
function sortBy(array, prop) {
|
12
12
|
return array.slice().sort((a, b) => {
|
@@ -158,8 +158,8 @@ function generateAngularDirectivesFile(compilerCtx, components, outputTarget) {
|
|
158
158
|
}
|
159
159
|
const proxyPath = relativeImport(outputTarget.directivesArrayFile, outputTarget.directivesProxyFile, '.ts');
|
160
160
|
const directives = components
|
161
|
-
.map(
|
162
|
-
.map(
|
161
|
+
.map(cmpMeta => dashToPascalCase(cmpMeta.tagName))
|
162
|
+
.map(className => `d.${className}`)
|
163
163
|
.join(',\n ');
|
164
164
|
const c = `
|
165
165
|
import * as d from '${proxyPath}';
|
@@ -226,20 +226,77 @@ const VALUE_ACCESSOR_EVENT = `<VALUE_ACCESSOR_EVENT>`;
|
|
226
226
|
const VALUE_ACCESSOR_TARGETATTR = '<VALUE_ACCESSOR_TARGETATTR>';
|
227
227
|
const VALUE_ACCESSOR_EVENTTARGETS = ` '(<VALUE_ACCESSOR_EVENT>)': 'handleChangeEvent($event.detail)'`;
|
228
228
|
|
229
|
+
const createComponentModule = (groups = {}) => (cmpMeta) => {
|
230
|
+
const isPrivate = Object.values(groups)
|
231
|
+
.flat()
|
232
|
+
.map(o => o.components)
|
233
|
+
.flat()
|
234
|
+
.some(tag => tag === cmpMeta.tagName);
|
235
|
+
if (isPrivate) {
|
236
|
+
return '';
|
237
|
+
}
|
238
|
+
const tagNameAsPascal = dashToPascalCase(cmpMeta.tagName);
|
239
|
+
let cmpImports = [];
|
240
|
+
let cmpDefines = [];
|
241
|
+
if (groups[cmpMeta.tagName] && groups[cmpMeta.tagName].components) {
|
242
|
+
const children = groups[cmpMeta.tagName].components;
|
243
|
+
if (children) {
|
244
|
+
cmpImports = children.map(tag => `${dashToPascalCase(tag)}`);
|
245
|
+
cmpDefines = children.map(tag => ` define${dashToPascalCase(tag)}();`);
|
246
|
+
}
|
247
|
+
}
|
248
|
+
let providers = [];
|
249
|
+
let providerImports = [];
|
250
|
+
if (groups[cmpMeta.tagName] && groups[cmpMeta.tagName].providers) {
|
251
|
+
const children = groups[cmpMeta.tagName].providers;
|
252
|
+
if (children) {
|
253
|
+
providerImports = children.map(p => `import { ${p.name} } from '../${p.import.replace('.ts', '')}'`);
|
254
|
+
providers = children.map(p => p.name);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
let declarations = [];
|
258
|
+
let declarationImports = [];
|
259
|
+
if (groups[cmpMeta.tagName] && groups[cmpMeta.tagName].declarations) {
|
260
|
+
const children = groups[cmpMeta.tagName].declarations;
|
261
|
+
if (children) {
|
262
|
+
declarationImports = children.map(p => `import { ${p.name} } from '../${p.import.replace('.ts', '')}'`);
|
263
|
+
declarations = children.map(p => p.name);
|
264
|
+
}
|
265
|
+
}
|
266
|
+
const finalText = `
|
267
|
+
${providerImports.join('\n ')}
|
268
|
+
${declarationImports.join('\n ')}
|
269
|
+
|
270
|
+
@NgModule({
|
271
|
+
declarations: [${[tagNameAsPascal, ...cmpImports, ...declarations].join(', ')}],
|
272
|
+
exports: [${[tagNameAsPascal, ...cmpImports, ...declarations].join(', ')}],
|
273
|
+
providers: [${providers.join(', ')}],
|
274
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
275
|
+
})
|
276
|
+
export class ${tagNameAsPascal}Module {
|
277
|
+
constructor() {
|
278
|
+
${[` define${tagNameAsPascal}();`, ...cmpDefines].join('\n')}
|
279
|
+
}
|
280
|
+
}`;
|
281
|
+
return finalText;
|
282
|
+
};
|
283
|
+
|
229
284
|
async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
230
285
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
231
286
|
const rootDir = config.rootDir;
|
232
287
|
const pkgData = await readPackageJson(rootDir);
|
233
288
|
const finalText = generateProxies(filteredComponents, pkgData, outputTarget, config.rootDir);
|
289
|
+
const allComponentModule = generateAllComponentModule(filteredComponents, outputTarget);
|
234
290
|
await Promise.all([
|
235
291
|
compilerCtx.fs.writeFile(outputTarget.directivesProxyFile, finalText),
|
292
|
+
compilerCtx.fs.writeFile(outputTarget.directivesProxyFile.replace('.ts', '.module.ts'), allComponentModule),
|
236
293
|
copyResources(config, outputTarget),
|
237
294
|
generateAngularDirectivesFile(compilerCtx, filteredComponents, outputTarget),
|
238
295
|
generateValueAccessors(compilerCtx, filteredComponents, outputTarget, config),
|
239
296
|
]);
|
240
297
|
}
|
241
298
|
function getFilteredComponents(excludeComponents = [], cmps) {
|
242
|
-
return sortBy(cmps,
|
299
|
+
return sortBy(cmps, cmp => cmp.tagName).filter(c => !excludeComponents.includes(c.tagName) && !c.internal);
|
243
300
|
}
|
244
301
|
async function copyResources(config, outputTarget) {
|
245
302
|
if (!config.sys || !config.sys.copy || !config.sys.glob) {
|
@@ -256,23 +313,52 @@ async function copyResources(config, outputTarget) {
|
|
256
313
|
},
|
257
314
|
], srcDirectory);
|
258
315
|
}
|
316
|
+
function generateAllComponentModule(components, outputTarget) {
|
317
|
+
const childComponent = Object.values(outputTarget.componentGroups || {})
|
318
|
+
.flat()
|
319
|
+
.map(o => o.components)
|
320
|
+
.flat();
|
321
|
+
const moduleImports = components
|
322
|
+
.map(c => c.tagName)
|
323
|
+
.filter(c => !childComponent.includes(c))
|
324
|
+
.map(c => ` ${dashToPascalCase(c)}Module,`);
|
325
|
+
return `/* tslint:disable */
|
326
|
+
/* auto-generated angular directive proxies */
|
327
|
+
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
|
328
|
+
import {
|
329
|
+
${moduleImports.join('\n')}
|
330
|
+
} from './proxies'
|
331
|
+
|
332
|
+
const modules = [
|
333
|
+
${moduleImports.join('\n')}
|
334
|
+
]
|
335
|
+
|
336
|
+
@NgModule({
|
337
|
+
imports: [...modules],
|
338
|
+
exports: [...modules],
|
339
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
340
|
+
})
|
341
|
+
export class BalAllComponentModule {}
|
342
|
+
`;
|
343
|
+
}
|
259
344
|
function generateProxies(components, pkgData, outputTarget, rootDir) {
|
260
345
|
const distTypesDir = path.dirname(pkgData.types);
|
261
346
|
const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
|
262
347
|
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
263
348
|
const imports = `/* tslint:disable */
|
264
349
|
/* auto-generated angular directive proxies */
|
265
|
-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone, EventEmitter } from '@angular/core';
|
350
|
+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone, EventEmitter, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
266
351
|
import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
352
|
+
const componentImports = components.map(c => `import { defineCustomElement as define${dashToPascalCase(c.tagName)} } from '${normalizePath(outputTarget.componentCorePackage || '')}/dist/components/${c.tagName}';`);
|
267
353
|
const typeImports = !outputTarget.componentCorePackage
|
268
354
|
? `import { ${IMPORT_TYPES} } from '${normalizePath(componentsTypeFile)}';`
|
269
355
|
: `import { ${IMPORT_TYPES} } from '${normalizePath(outputTarget.componentCorePackage)}';`;
|
270
356
|
const final = [
|
271
357
|
imports,
|
272
358
|
typeImports,
|
273
|
-
|
274
|
-
|
275
|
-
|
359
|
+
componentImports.join('\n'),
|
360
|
+
components.map(createComponentDefinition(outputTarget.componentCorePackage)).join('\n'),
|
361
|
+
components.map(createComponentModule(outputTarget.componentGroups)).join('\n'),
|
276
362
|
];
|
277
363
|
return final.join('\n') + '\n';
|
278
364
|
}
|
package/dist/output-angular.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { CompilerCtx, ComponentCompilerMeta, Config } from '@stencil/core/internal';
|
2
2
|
import type { OutputTargetAngular, PackageJSON } from './types';
|
3
3
|
export declare function angularDirectiveProxyOutput(compilerCtx: CompilerCtx, outputTarget: OutputTargetAngular, components: ComponentCompilerMeta[], config: Config): Promise<void>;
|
4
|
+
export declare function generateAllComponentModule(components: ComponentCompilerMeta[], outputTarget: OutputTargetAngular): string;
|
4
5
|
export declare function generateProxies(components: ComponentCompilerMeta[], pkgData: PackageJSON, outputTarget: OutputTargetAngular, rootDir: string): string;
|
package/dist/output-angular.js
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
import path from 'path';
|
2
|
-
import { relativeImport, normalizePath, sortBy, readPackageJson } from './utils';
|
2
|
+
import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCase } from './utils';
|
3
3
|
import { createComponentDefinition } from './generate-angular-component';
|
4
4
|
import { generateAngularDirectivesFile } from './generate-angular-directives-file';
|
5
5
|
import generateValueAccessors from './generate-value-accessors';
|
6
|
+
import { createComponentModule } from './generate-angular-module';
|
6
7
|
export async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
7
8
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
8
9
|
const rootDir = config.rootDir;
|
9
10
|
const pkgData = await readPackageJson(rootDir);
|
10
11
|
const finalText = generateProxies(filteredComponents, pkgData, outputTarget, config.rootDir);
|
12
|
+
const allComponentModule = generateAllComponentModule(filteredComponents, outputTarget);
|
11
13
|
await Promise.all([
|
12
14
|
compilerCtx.fs.writeFile(outputTarget.directivesProxyFile, finalText),
|
15
|
+
compilerCtx.fs.writeFile(outputTarget.directivesProxyFile.replace('.ts', '.module.ts'), allComponentModule),
|
13
16
|
copyResources(config, outputTarget),
|
14
17
|
generateAngularDirectivesFile(compilerCtx, filteredComponents, outputTarget),
|
15
18
|
generateValueAccessors(compilerCtx, filteredComponents, outputTarget, config),
|
16
19
|
]);
|
17
20
|
}
|
18
21
|
function getFilteredComponents(excludeComponents = [], cmps) {
|
19
|
-
return sortBy(cmps,
|
22
|
+
return sortBy(cmps, cmp => cmp.tagName).filter(c => !excludeComponents.includes(c.tagName) && !c.internal);
|
20
23
|
}
|
21
24
|
async function copyResources(config, outputTarget) {
|
22
25
|
if (!config.sys || !config.sys.copy || !config.sys.glob) {
|
@@ -33,23 +36,52 @@ async function copyResources(config, outputTarget) {
|
|
33
36
|
},
|
34
37
|
], srcDirectory);
|
35
38
|
}
|
39
|
+
export function generateAllComponentModule(components, outputTarget) {
|
40
|
+
const childComponent = Object.values(outputTarget.componentGroups || {})
|
41
|
+
.flat()
|
42
|
+
.map(o => o.components)
|
43
|
+
.flat();
|
44
|
+
const moduleImports = components
|
45
|
+
.map(c => c.tagName)
|
46
|
+
.filter(c => !childComponent.includes(c))
|
47
|
+
.map(c => ` ${dashToPascalCase(c)}Module,`);
|
48
|
+
return `/* tslint:disable */
|
49
|
+
/* auto-generated angular directive proxies */
|
50
|
+
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'
|
51
|
+
import {
|
52
|
+
${moduleImports.join('\n')}
|
53
|
+
} from './proxies'
|
54
|
+
|
55
|
+
const modules = [
|
56
|
+
${moduleImports.join('\n')}
|
57
|
+
]
|
58
|
+
|
59
|
+
@NgModule({
|
60
|
+
imports: [...modules],
|
61
|
+
exports: [...modules],
|
62
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
63
|
+
})
|
64
|
+
export class BalAllComponentModule {}
|
65
|
+
`;
|
66
|
+
}
|
36
67
|
export function generateProxies(components, pkgData, outputTarget, rootDir) {
|
37
68
|
const distTypesDir = path.dirname(pkgData.types);
|
38
69
|
const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
|
39
70
|
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
40
71
|
const imports = `/* tslint:disable */
|
41
72
|
/* auto-generated angular directive proxies */
|
42
|
-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone, EventEmitter } from '@angular/core';
|
73
|
+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone, EventEmitter, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
43
74
|
import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
|
75
|
+
const componentImports = components.map(c => `import { defineCustomElement as define${dashToPascalCase(c.tagName)} } from '${normalizePath(outputTarget.componentCorePackage || '')}/dist/components/${c.tagName}';`);
|
44
76
|
const typeImports = !outputTarget.componentCorePackage
|
45
77
|
? `import { ${IMPORT_TYPES} } from '${normalizePath(componentsTypeFile)}';`
|
46
78
|
: `import { ${IMPORT_TYPES} } from '${normalizePath(outputTarget.componentCorePackage)}';`;
|
47
79
|
const final = [
|
48
80
|
imports,
|
49
81
|
typeImports,
|
50
|
-
|
51
|
-
|
52
|
-
|
82
|
+
componentImports.join('\n'),
|
83
|
+
components.map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir)).join('\n'),
|
84
|
+
components.map(createComponentModule(outputTarget.componentGroups)).join('\n'),
|
53
85
|
];
|
54
86
|
return final.join('\n') + '\n';
|
55
87
|
}
|
package/dist/types.d.ts
CHANGED
@@ -5,6 +5,18 @@ export interface OutputTargetAngular {
|
|
5
5
|
directivesUtilsFile?: string;
|
6
6
|
valueAccessorConfigs?: ValueAccessorConfig[];
|
7
7
|
excludeComponents?: string[];
|
8
|
+
componentGroups?: {
|
9
|
+
[key: string]: ComponentGroup;
|
10
|
+
};
|
11
|
+
}
|
12
|
+
export interface ComponentGroup {
|
13
|
+
components?: string[];
|
14
|
+
providers?: ComponentProvider[];
|
15
|
+
declarations?: ComponentProvider[];
|
16
|
+
}
|
17
|
+
export interface ComponentProvider {
|
18
|
+
import: string;
|
19
|
+
name: string;
|
8
20
|
}
|
9
21
|
export declare type ValueAccessorTypes = 'text' | 'radio' | 'select' | 'number' | 'boolean';
|
10
22
|
export interface ValueAccessorConfig {
|
package/dist/utils.js
CHANGED
@@ -5,7 +5,7 @@ const readFile = promisify(fs.readFile);
|
|
5
5
|
export const toLowerCase = (str) => str.toLowerCase();
|
6
6
|
export const dashToPascalCase = (str) => toLowerCase(str)
|
7
7
|
.split('-')
|
8
|
-
.map(
|
8
|
+
.map(segment => segment.charAt(0).toUpperCase() + segment.slice(1))
|
9
9
|
.join('');
|
10
10
|
export function sortBy(array, prop) {
|
11
11
|
return array.slice().sort((a, b) => {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@baloise/angular-output-target",
|
3
|
-
"version": "1.0
|
3
|
+
"version": "1.1.0",
|
4
4
|
"description": "Angular output target for @stencil/core components.",
|
5
5
|
"main": "dist/index.cjs.js",
|
6
6
|
"module": "dist/index.js",
|
@@ -61,5 +61,5 @@
|
|
61
61
|
],
|
62
62
|
"testURL": "http://localhost"
|
63
63
|
},
|
64
|
-
"gitHead": "
|
64
|
+
"gitHead": "6074bb9ab1b327fafca6ad13c5bc07366f7d27f2"
|
65
65
|
}
|
@@ -22,6 +22,6 @@ export class BooleanValueAccessor extends ValueAccessor {
|
|
22
22
|
super(el)
|
23
23
|
}
|
24
24
|
writeValue(value: any) {
|
25
|
-
this.el.nativeElement.
|
25
|
+
this.el.nativeElement.value = this.lastValue = value == null ? false : value
|
26
26
|
}
|
27
27
|
}
|