@stencil/angular-output-target 0.5.0 → 0.6.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/dist/generate-angular-modules.d.ts +6 -0
- package/dist/generate-angular-modules.js +17 -0
- package/dist/index.cjs.js +37 -1
- package/dist/index.js +37 -1
- package/dist/output-angular.js +18 -1
- package/dist/plugin.js +3 -0
- package/dist/types.d.ts +6 -0
- package/package.json +2 -2
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an Angular module declaration for a component wrapper.
|
|
3
|
+
* @param componentTagName The tag name of the Stencil component.
|
|
4
|
+
* @returns The Angular module declaration as a string.
|
|
5
|
+
*/
|
|
6
|
+
export declare const generateAngularModuleForComponent: (componentTagName: string) => string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { dashToPascalCase } from './utils';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an Angular module declaration for a component wrapper.
|
|
4
|
+
* @param componentTagName The tag name of the Stencil component.
|
|
5
|
+
* @returns The Angular module declaration as a string.
|
|
6
|
+
*/
|
|
7
|
+
export const generateAngularModuleForComponent = (componentTagName) => {
|
|
8
|
+
const tagNameAsPascal = dashToPascalCase(componentTagName);
|
|
9
|
+
const componentClassName = `${tagNameAsPascal}`;
|
|
10
|
+
const moduleClassName = `${tagNameAsPascal}Module`;
|
|
11
|
+
const moduleDefinition = `@NgModule({
|
|
12
|
+
declarations: [${componentClassName}],
|
|
13
|
+
exports: [${componentClassName}]
|
|
14
|
+
})
|
|
15
|
+
export class ${moduleClassName} { }`;
|
|
16
|
+
return moduleDefinition;
|
|
17
|
+
};
|
package/dist/index.cjs.js
CHANGED
|
@@ -339,6 +339,23 @@ const VALUE_ACCESSOR_EVENT = `<VALUE_ACCESSOR_EVENT>`;
|
|
|
339
339
|
const VALUE_ACCESSOR_TARGETATTR = '<VALUE_ACCESSOR_TARGETATTR>';
|
|
340
340
|
const VALUE_ACCESSOR_EVENTTARGETS = ` '(<VALUE_ACCESSOR_EVENT>)': 'handleChangeEvent($event.target.<VALUE_ACCESSOR_TARGETATTR>)'`;
|
|
341
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Creates an Angular module declaration for a component wrapper.
|
|
344
|
+
* @param componentTagName The tag name of the Stencil component.
|
|
345
|
+
* @returns The Angular module declaration as a string.
|
|
346
|
+
*/
|
|
347
|
+
const generateAngularModuleForComponent = (componentTagName) => {
|
|
348
|
+
const tagNameAsPascal = dashToPascalCase(componentTagName);
|
|
349
|
+
const componentClassName = `${tagNameAsPascal}`;
|
|
350
|
+
const moduleClassName = `${tagNameAsPascal}Module`;
|
|
351
|
+
const moduleDefinition = `@NgModule({
|
|
352
|
+
declarations: [${componentClassName}],
|
|
353
|
+
exports: [${componentClassName}]
|
|
354
|
+
})
|
|
355
|
+
export class ${moduleClassName} { }`;
|
|
356
|
+
return moduleDefinition;
|
|
357
|
+
};
|
|
358
|
+
|
|
342
359
|
async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
|
343
360
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
|
344
361
|
const rootDir = config.rootDir;
|
|
@@ -370,9 +387,11 @@ async function copyResources$1(config, outputTarget) {
|
|
|
370
387
|
], srcDirectory);
|
|
371
388
|
}
|
|
372
389
|
function generateProxies(components, pkgData, outputTarget, rootDir) {
|
|
390
|
+
var _a;
|
|
373
391
|
const distTypesDir = path__default['default'].dirname(pkgData.types);
|
|
374
392
|
const dtsFilePath = path__default['default'].join(rootDir, distTypesDir, GENERATED_DTS);
|
|
375
393
|
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
394
|
+
const includeSingleComponentAngularModules = (_a = outputTarget.includeSingleComponentAngularModules) !== null && _a !== void 0 ? _a : false;
|
|
376
395
|
/**
|
|
377
396
|
* The collection of named imports from @angular/core.
|
|
378
397
|
*/
|
|
@@ -388,6 +407,9 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
|
|
|
388
407
|
* The collection of named imports from the angular-component-lib/utils.
|
|
389
408
|
*/
|
|
390
409
|
const componentLibImports = ['ProxyCmp', 'proxyOutputs'];
|
|
410
|
+
if (includeSingleComponentAngularModules) {
|
|
411
|
+
angularCoreImports.push('NgModule');
|
|
412
|
+
}
|
|
391
413
|
const imports = `/* tslint:disable */
|
|
392
414
|
/* auto-generated angular directive proxies */
|
|
393
415
|
${createImportStatement(angularCoreImports, '@angular/core')}
|
|
@@ -423,6 +445,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
|
|
|
423
445
|
});
|
|
424
446
|
sourceImports = cmpImports.join('\n');
|
|
425
447
|
}
|
|
448
|
+
if (includeSingleComponentAngularModules) {
|
|
449
|
+
// Generating Angular modules is only supported in the dist-custom-elements build
|
|
450
|
+
if (!outputTarget.includeImportCustomElements) {
|
|
451
|
+
throw new Error('Generating single component Angular modules requires the "includeImportCustomElements" option to be set to true.');
|
|
452
|
+
}
|
|
453
|
+
}
|
|
426
454
|
const proxyFileOutput = [];
|
|
427
455
|
const filterInternalProps = (prop) => !prop.internal;
|
|
428
456
|
const mapPropName = (prop) => prop.name;
|
|
@@ -448,11 +476,16 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
|
|
|
448
476
|
/**
|
|
449
477
|
* For each component, we need to generate:
|
|
450
478
|
* 1. The @Component decorated class
|
|
451
|
-
* 2.
|
|
479
|
+
* 2. Optionally the @NgModule decorated class (if includeSingleComponentAngularModules is true)
|
|
480
|
+
* 3. The component interface (using declaration merging for types).
|
|
452
481
|
*/
|
|
453
482
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, includeImportCustomElements);
|
|
483
|
+
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
454
484
|
const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, includeImportCustomElements, customElementsDir);
|
|
455
485
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
486
|
+
if (includeSingleComponentAngularModules) {
|
|
487
|
+
proxyFileOutput.push(moduleDefinition, '\n');
|
|
488
|
+
}
|
|
456
489
|
proxyFileOutput.push(componentTypeDefinition, '\n');
|
|
457
490
|
}
|
|
458
491
|
const final = [imports, typeImports, sourceImports, ...proxyFileOutput];
|
|
@@ -487,6 +520,9 @@ function normalizeOutputTarget(config, outputTarget) {
|
|
|
487
520
|
if (outputTarget.directivesArrayFile && !path__default['default'].isAbsolute(outputTarget.directivesArrayFile)) {
|
|
488
521
|
results.directivesArrayFile = normalizePath(path__default['default'].join(config.rootDir, outputTarget.directivesArrayFile));
|
|
489
522
|
}
|
|
523
|
+
if (outputTarget.includeSingleComponentAngularModules !== undefined) {
|
|
524
|
+
console.warn('**Experimental**: includeSingleComponentAngularModules is a developer preview feature and may change or be removed in the future.');
|
|
525
|
+
}
|
|
490
526
|
return results;
|
|
491
527
|
}
|
|
492
528
|
|
package/dist/index.js
CHANGED
|
@@ -331,6 +331,23 @@ const VALUE_ACCESSOR_EVENT = `<VALUE_ACCESSOR_EVENT>`;
|
|
|
331
331
|
const VALUE_ACCESSOR_TARGETATTR = '<VALUE_ACCESSOR_TARGETATTR>';
|
|
332
332
|
const VALUE_ACCESSOR_EVENTTARGETS = ` '(<VALUE_ACCESSOR_EVENT>)': 'handleChangeEvent($event.target.<VALUE_ACCESSOR_TARGETATTR>)'`;
|
|
333
333
|
|
|
334
|
+
/**
|
|
335
|
+
* Creates an Angular module declaration for a component wrapper.
|
|
336
|
+
* @param componentTagName The tag name of the Stencil component.
|
|
337
|
+
* @returns The Angular module declaration as a string.
|
|
338
|
+
*/
|
|
339
|
+
const generateAngularModuleForComponent = (componentTagName) => {
|
|
340
|
+
const tagNameAsPascal = dashToPascalCase(componentTagName);
|
|
341
|
+
const componentClassName = `${tagNameAsPascal}`;
|
|
342
|
+
const moduleClassName = `${tagNameAsPascal}Module`;
|
|
343
|
+
const moduleDefinition = `@NgModule({
|
|
344
|
+
declarations: [${componentClassName}],
|
|
345
|
+
exports: [${componentClassName}]
|
|
346
|
+
})
|
|
347
|
+
export class ${moduleClassName} { }`;
|
|
348
|
+
return moduleDefinition;
|
|
349
|
+
};
|
|
350
|
+
|
|
334
351
|
async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
|
335
352
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
|
336
353
|
const rootDir = config.rootDir;
|
|
@@ -362,9 +379,11 @@ async function copyResources$1(config, outputTarget) {
|
|
|
362
379
|
], srcDirectory);
|
|
363
380
|
}
|
|
364
381
|
function generateProxies(components, pkgData, outputTarget, rootDir) {
|
|
382
|
+
var _a;
|
|
365
383
|
const distTypesDir = path.dirname(pkgData.types);
|
|
366
384
|
const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
|
|
367
385
|
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
386
|
+
const includeSingleComponentAngularModules = (_a = outputTarget.includeSingleComponentAngularModules) !== null && _a !== void 0 ? _a : false;
|
|
368
387
|
/**
|
|
369
388
|
* The collection of named imports from @angular/core.
|
|
370
389
|
*/
|
|
@@ -380,6 +399,9 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
|
|
|
380
399
|
* The collection of named imports from the angular-component-lib/utils.
|
|
381
400
|
*/
|
|
382
401
|
const componentLibImports = ['ProxyCmp', 'proxyOutputs'];
|
|
402
|
+
if (includeSingleComponentAngularModules) {
|
|
403
|
+
angularCoreImports.push('NgModule');
|
|
404
|
+
}
|
|
383
405
|
const imports = `/* tslint:disable */
|
|
384
406
|
/* auto-generated angular directive proxies */
|
|
385
407
|
${createImportStatement(angularCoreImports, '@angular/core')}
|
|
@@ -415,6 +437,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
|
|
|
415
437
|
});
|
|
416
438
|
sourceImports = cmpImports.join('\n');
|
|
417
439
|
}
|
|
440
|
+
if (includeSingleComponentAngularModules) {
|
|
441
|
+
// Generating Angular modules is only supported in the dist-custom-elements build
|
|
442
|
+
if (!outputTarget.includeImportCustomElements) {
|
|
443
|
+
throw new Error('Generating single component Angular modules requires the "includeImportCustomElements" option to be set to true.');
|
|
444
|
+
}
|
|
445
|
+
}
|
|
418
446
|
const proxyFileOutput = [];
|
|
419
447
|
const filterInternalProps = (prop) => !prop.internal;
|
|
420
448
|
const mapPropName = (prop) => prop.name;
|
|
@@ -440,11 +468,16 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
|
|
|
440
468
|
/**
|
|
441
469
|
* For each component, we need to generate:
|
|
442
470
|
* 1. The @Component decorated class
|
|
443
|
-
* 2.
|
|
471
|
+
* 2. Optionally the @NgModule decorated class (if includeSingleComponentAngularModules is true)
|
|
472
|
+
* 3. The component interface (using declaration merging for types).
|
|
444
473
|
*/
|
|
445
474
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, includeImportCustomElements);
|
|
475
|
+
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
446
476
|
const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, includeImportCustomElements, customElementsDir);
|
|
447
477
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
478
|
+
if (includeSingleComponentAngularModules) {
|
|
479
|
+
proxyFileOutput.push(moduleDefinition, '\n');
|
|
480
|
+
}
|
|
448
481
|
proxyFileOutput.push(componentTypeDefinition, '\n');
|
|
449
482
|
}
|
|
450
483
|
const final = [imports, typeImports, sourceImports, ...proxyFileOutput];
|
|
@@ -479,6 +512,9 @@ function normalizeOutputTarget(config, outputTarget) {
|
|
|
479
512
|
if (outputTarget.directivesArrayFile && !path.isAbsolute(outputTarget.directivesArrayFile)) {
|
|
480
513
|
results.directivesArrayFile = normalizePath(path.join(config.rootDir, outputTarget.directivesArrayFile));
|
|
481
514
|
}
|
|
515
|
+
if (outputTarget.includeSingleComponentAngularModules !== undefined) {
|
|
516
|
+
console.warn('**Experimental**: includeSingleComponentAngularModules is a developer preview feature and may change or be removed in the future.');
|
|
517
|
+
}
|
|
482
518
|
return results;
|
|
483
519
|
}
|
|
484
520
|
|
package/dist/output-angular.js
CHANGED
|
@@ -3,6 +3,7 @@ import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCas
|
|
|
3
3
|
import { createAngularComponentDefinition, createComponentTypeDefinition } from './generate-angular-component';
|
|
4
4
|
import { generateAngularDirectivesFile } from './generate-angular-directives-file';
|
|
5
5
|
import generateValueAccessors from './generate-value-accessors';
|
|
6
|
+
import { generateAngularModuleForComponent } from './generate-angular-modules';
|
|
6
7
|
export async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
|
7
8
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
|
8
9
|
const rootDir = config.rootDir;
|
|
@@ -34,9 +35,11 @@ async function copyResources(config, outputTarget) {
|
|
|
34
35
|
], srcDirectory);
|
|
35
36
|
}
|
|
36
37
|
export function generateProxies(components, pkgData, outputTarget, rootDir) {
|
|
38
|
+
var _a;
|
|
37
39
|
const distTypesDir = path.dirname(pkgData.types);
|
|
38
40
|
const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
|
|
39
41
|
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
42
|
+
const includeSingleComponentAngularModules = (_a = outputTarget.includeSingleComponentAngularModules) !== null && _a !== void 0 ? _a : false;
|
|
40
43
|
/**
|
|
41
44
|
* The collection of named imports from @angular/core.
|
|
42
45
|
*/
|
|
@@ -52,6 +55,9 @@ export function generateProxies(components, pkgData, outputTarget, rootDir) {
|
|
|
52
55
|
* The collection of named imports from the angular-component-lib/utils.
|
|
53
56
|
*/
|
|
54
57
|
const componentLibImports = ['ProxyCmp', 'proxyOutputs'];
|
|
58
|
+
if (includeSingleComponentAngularModules) {
|
|
59
|
+
angularCoreImports.push('NgModule');
|
|
60
|
+
}
|
|
55
61
|
const imports = `/* tslint:disable */
|
|
56
62
|
/* auto-generated angular directive proxies */
|
|
57
63
|
${createImportStatement(angularCoreImports, '@angular/core')}
|
|
@@ -87,6 +93,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
|
|
|
87
93
|
});
|
|
88
94
|
sourceImports = cmpImports.join('\n');
|
|
89
95
|
}
|
|
96
|
+
if (includeSingleComponentAngularModules) {
|
|
97
|
+
// Generating Angular modules is only supported in the dist-custom-elements build
|
|
98
|
+
if (!outputTarget.includeImportCustomElements) {
|
|
99
|
+
throw new Error('Generating single component Angular modules requires the "includeImportCustomElements" option to be set to true.');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
90
102
|
const proxyFileOutput = [];
|
|
91
103
|
const filterInternalProps = (prop) => !prop.internal;
|
|
92
104
|
const mapPropName = (prop) => prop.name;
|
|
@@ -112,11 +124,16 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
|
|
|
112
124
|
/**
|
|
113
125
|
* For each component, we need to generate:
|
|
114
126
|
* 1. The @Component decorated class
|
|
115
|
-
* 2.
|
|
127
|
+
* 2. Optionally the @NgModule decorated class (if includeSingleComponentAngularModules is true)
|
|
128
|
+
* 3. The component interface (using declaration merging for types).
|
|
116
129
|
*/
|
|
117
130
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, includeImportCustomElements);
|
|
131
|
+
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
118
132
|
const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, includeImportCustomElements, customElementsDir);
|
|
119
133
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
134
|
+
if (includeSingleComponentAngularModules) {
|
|
135
|
+
proxyFileOutput.push(moduleDefinition, '\n');
|
|
136
|
+
}
|
|
120
137
|
proxyFileOutput.push(componentTypeDefinition, '\n');
|
|
121
138
|
}
|
|
122
139
|
const final = [imports, typeImports, sourceImports, ...proxyFileOutput];
|
package/dist/plugin.js
CHANGED
|
@@ -27,5 +27,8 @@ export function normalizeOutputTarget(config, outputTarget) {
|
|
|
27
27
|
if (outputTarget.directivesArrayFile && !path.isAbsolute(outputTarget.directivesArrayFile)) {
|
|
28
28
|
results.directivesArrayFile = normalizePath(path.join(config.rootDir, outputTarget.directivesArrayFile));
|
|
29
29
|
}
|
|
30
|
+
if (outputTarget.includeSingleComponentAngularModules !== undefined) {
|
|
31
|
+
console.warn('**Experimental**: includeSingleComponentAngularModules is a developer preview feature and may change or be removed in the future.');
|
|
32
|
+
}
|
|
30
33
|
return results;
|
|
31
34
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -14,6 +14,12 @@ export interface OutputTargetAngular {
|
|
|
14
14
|
excludeComponents?: string[];
|
|
15
15
|
includeImportCustomElements?: boolean;
|
|
16
16
|
customElementsDir?: string;
|
|
17
|
+
/**
|
|
18
|
+
* @experimental
|
|
19
|
+
*
|
|
20
|
+
* `true` to generate a single component Angular module for each component.
|
|
21
|
+
*/
|
|
22
|
+
includeSingleComponentAngularModules?: boolean;
|
|
17
23
|
}
|
|
18
24
|
export declare type ValueAccessorTypes = 'text' | 'radio' | 'select' | 'number' | 'boolean';
|
|
19
25
|
export interface ValueAccessorConfig {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/angular-output-target",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Angular output target for @stencil/core components.",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@angular/forms": "8.2.14"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@stencil/core": "^2.9.0 || ^3.0.0
|
|
45
|
+
"@stencil/core": "^2.9.0 || ^3.0.0"
|
|
46
46
|
},
|
|
47
47
|
"jest": {
|
|
48
48
|
"transform": {
|