@stencil/angular-output-target 0.5.0 → 0.5.1-dev.11685564559.1b0b6e89

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.
@@ -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,24 +387,30 @@ 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;
395
+ const includeOutputImports = components.some((component) => component.events.some((event) => !event.internal));
376
396
  /**
377
397
  * The collection of named imports from @angular/core.
378
398
  */
379
- const angularCoreImports = [
380
- 'ChangeDetectionStrategy',
381
- 'ChangeDetectorRef',
382
- 'Component',
383
- 'ElementRef',
384
- 'EventEmitter',
385
- 'NgZone',
386
- ];
399
+ const angularCoreImports = ['ChangeDetectionStrategy', 'ChangeDetectorRef', 'Component', 'ElementRef'];
400
+ if (includeOutputImports) {
401
+ angularCoreImports.push('EventEmitter');
402
+ }
403
+ angularCoreImports.push('NgZone');
387
404
  /**
388
405
  * The collection of named imports from the angular-component-lib/utils.
389
406
  */
390
- const componentLibImports = ['ProxyCmp', 'proxyOutputs'];
407
+ const componentLibImports = ['ProxyCmp'];
408
+ if (includeOutputImports) {
409
+ componentLibImports.push('proxyOutputs');
410
+ }
411
+ if (includeSingleComponentAngularModules) {
412
+ angularCoreImports.push('NgModule');
413
+ }
391
414
  const imports = `/* tslint:disable */
392
415
  /* auto-generated angular directive proxies */
393
416
  ${createImportStatement(angularCoreImports, '@angular/core')}
@@ -423,6 +446,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
423
446
  });
424
447
  sourceImports = cmpImports.join('\n');
425
448
  }
449
+ if (includeSingleComponentAngularModules) {
450
+ // Generating Angular modules is only supported in the dist-custom-elements build
451
+ if (!outputTarget.includeImportCustomElements) {
452
+ throw new Error('Generating single component Angular modules requires the "includeImportCustomElements" option to be set to true.');
453
+ }
454
+ }
426
455
  const proxyFileOutput = [];
427
456
  const filterInternalProps = (prop) => !prop.internal;
428
457
  const mapPropName = (prop) => prop.name;
@@ -448,11 +477,16 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
448
477
  /**
449
478
  * For each component, we need to generate:
450
479
  * 1. The @Component decorated class
451
- * 2. The component interface (using declaration merging for types).
480
+ * 2. Optionally the @NgModule decorated class (if includeSingleComponentAngularModules is true)
481
+ * 3. The component interface (using declaration merging for types).
452
482
  */
453
483
  const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, includeImportCustomElements);
484
+ const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
454
485
  const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, includeImportCustomElements, customElementsDir);
455
486
  proxyFileOutput.push(componentDefinition, '\n');
487
+ if (includeSingleComponentAngularModules) {
488
+ proxyFileOutput.push(moduleDefinition, '\n');
489
+ }
456
490
  proxyFileOutput.push(componentTypeDefinition, '\n');
457
491
  }
458
492
  const final = [imports, typeImports, sourceImports, ...proxyFileOutput];
@@ -487,6 +521,9 @@ function normalizeOutputTarget(config, outputTarget) {
487
521
  if (outputTarget.directivesArrayFile && !path__default['default'].isAbsolute(outputTarget.directivesArrayFile)) {
488
522
  results.directivesArrayFile = normalizePath(path__default['default'].join(config.rootDir, outputTarget.directivesArrayFile));
489
523
  }
524
+ if (outputTarget.includeSingleComponentAngularModules !== undefined) {
525
+ console.warn('**Experimental**: includeSingleComponentAngularModules is a developer preview feature and may change or be removed in the future.');
526
+ }
490
527
  return results;
491
528
  }
492
529
 
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,24 +379,30 @@ 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;
387
+ const includeOutputImports = components.some((component) => component.events.some((event) => !event.internal));
368
388
  /**
369
389
  * The collection of named imports from @angular/core.
370
390
  */
371
- const angularCoreImports = [
372
- 'ChangeDetectionStrategy',
373
- 'ChangeDetectorRef',
374
- 'Component',
375
- 'ElementRef',
376
- 'EventEmitter',
377
- 'NgZone',
378
- ];
391
+ const angularCoreImports = ['ChangeDetectionStrategy', 'ChangeDetectorRef', 'Component', 'ElementRef'];
392
+ if (includeOutputImports) {
393
+ angularCoreImports.push('EventEmitter');
394
+ }
395
+ angularCoreImports.push('NgZone');
379
396
  /**
380
397
  * The collection of named imports from the angular-component-lib/utils.
381
398
  */
382
- const componentLibImports = ['ProxyCmp', 'proxyOutputs'];
399
+ const componentLibImports = ['ProxyCmp'];
400
+ if (includeOutputImports) {
401
+ componentLibImports.push('proxyOutputs');
402
+ }
403
+ if (includeSingleComponentAngularModules) {
404
+ angularCoreImports.push('NgModule');
405
+ }
383
406
  const imports = `/* tslint:disable */
384
407
  /* auto-generated angular directive proxies */
385
408
  ${createImportStatement(angularCoreImports, '@angular/core')}
@@ -415,6 +438,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
415
438
  });
416
439
  sourceImports = cmpImports.join('\n');
417
440
  }
441
+ if (includeSingleComponentAngularModules) {
442
+ // Generating Angular modules is only supported in the dist-custom-elements build
443
+ if (!outputTarget.includeImportCustomElements) {
444
+ throw new Error('Generating single component Angular modules requires the "includeImportCustomElements" option to be set to true.');
445
+ }
446
+ }
418
447
  const proxyFileOutput = [];
419
448
  const filterInternalProps = (prop) => !prop.internal;
420
449
  const mapPropName = (prop) => prop.name;
@@ -440,11 +469,16 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
440
469
  /**
441
470
  * For each component, we need to generate:
442
471
  * 1. The @Component decorated class
443
- * 2. The component interface (using declaration merging for types).
472
+ * 2. Optionally the @NgModule decorated class (if includeSingleComponentAngularModules is true)
473
+ * 3. The component interface (using declaration merging for types).
444
474
  */
445
475
  const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, includeImportCustomElements);
476
+ const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
446
477
  const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, includeImportCustomElements, customElementsDir);
447
478
  proxyFileOutput.push(componentDefinition, '\n');
479
+ if (includeSingleComponentAngularModules) {
480
+ proxyFileOutput.push(moduleDefinition, '\n');
481
+ }
448
482
  proxyFileOutput.push(componentTypeDefinition, '\n');
449
483
  }
450
484
  const final = [imports, typeImports, sourceImports, ...proxyFileOutput];
@@ -479,6 +513,9 @@ function normalizeOutputTarget(config, outputTarget) {
479
513
  if (outputTarget.directivesArrayFile && !path.isAbsolute(outputTarget.directivesArrayFile)) {
480
514
  results.directivesArrayFile = normalizePath(path.join(config.rootDir, outputTarget.directivesArrayFile));
481
515
  }
516
+ if (outputTarget.includeSingleComponentAngularModules !== undefined) {
517
+ console.warn('**Experimental**: includeSingleComponentAngularModules is a developer preview feature and may change or be removed in the future.');
518
+ }
482
519
  return results;
483
520
  }
484
521
 
@@ -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,24 +35,30 @@ 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;
43
+ const includeOutputImports = components.some((component) => component.events.some((event) => !event.internal));
40
44
  /**
41
45
  * The collection of named imports from @angular/core.
42
46
  */
43
- const angularCoreImports = [
44
- 'ChangeDetectionStrategy',
45
- 'ChangeDetectorRef',
46
- 'Component',
47
- 'ElementRef',
48
- 'EventEmitter',
49
- 'NgZone',
50
- ];
47
+ const angularCoreImports = ['ChangeDetectionStrategy', 'ChangeDetectorRef', 'Component', 'ElementRef'];
48
+ if (includeOutputImports) {
49
+ angularCoreImports.push('EventEmitter');
50
+ }
51
+ angularCoreImports.push('NgZone');
51
52
  /**
52
53
  * The collection of named imports from the angular-component-lib/utils.
53
54
  */
54
- const componentLibImports = ['ProxyCmp', 'proxyOutputs'];
55
+ const componentLibImports = ['ProxyCmp'];
56
+ if (includeOutputImports) {
57
+ componentLibImports.push('proxyOutputs');
58
+ }
59
+ if (includeSingleComponentAngularModules) {
60
+ angularCoreImports.push('NgModule');
61
+ }
55
62
  const imports = `/* tslint:disable */
56
63
  /* auto-generated angular directive proxies */
57
64
  ${createImportStatement(angularCoreImports, '@angular/core')}
@@ -87,6 +94,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
87
94
  });
88
95
  sourceImports = cmpImports.join('\n');
89
96
  }
97
+ if (includeSingleComponentAngularModules) {
98
+ // Generating Angular modules is only supported in the dist-custom-elements build
99
+ if (!outputTarget.includeImportCustomElements) {
100
+ throw new Error('Generating single component Angular modules requires the "includeImportCustomElements" option to be set to true.');
101
+ }
102
+ }
90
103
  const proxyFileOutput = [];
91
104
  const filterInternalProps = (prop) => !prop.internal;
92
105
  const mapPropName = (prop) => prop.name;
@@ -112,11 +125,16 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
112
125
  /**
113
126
  * For each component, we need to generate:
114
127
  * 1. The @Component decorated class
115
- * 2. The component interface (using declaration merging for types).
128
+ * 2. Optionally the @NgModule decorated class (if includeSingleComponentAngularModules is true)
129
+ * 3. The component interface (using declaration merging for types).
116
130
  */
117
131
  const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, includeImportCustomElements);
132
+ const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
118
133
  const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, includeImportCustomElements, customElementsDir);
119
134
  proxyFileOutput.push(componentDefinition, '\n');
135
+ if (includeSingleComponentAngularModules) {
136
+ proxyFileOutput.push(moduleDefinition, '\n');
137
+ }
120
138
  proxyFileOutput.push(componentTypeDefinition, '\n');
121
139
  }
122
140
  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.5.0",
3
+ "version": "0.5.1-dev.11685564559.1b0b6e89",
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-beta.0"
45
+ "@stencil/core": "^2.9.0 || ^3.0.0"
46
46
  },
47
47
  "jest": {
48
48
  "transform": {
@@ -58,5 +58,8 @@
58
58
  ],
59
59
  "testURL": "http://localhost"
60
60
  },
61
- "gitHead": "a3588e905186a0e86e7f88418fd5b2f9531b55e0"
61
+ "gitHead": "b0b6e898b94958cabecfa212c9a58c9e9ac4411e",
62
+ "volta": {
63
+ "extends": "../../package.json"
64
+ }
62
65
  }