@stencil/angular-output-target 0.8.1-dev.11690825475.1243803f → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,7 +27,6 @@ export const config: Config = {
27
27
  outputTargets: [
28
28
  angularOutputTarget({
29
29
  componentCorePackage: 'component-library',
30
- outputType: 'component',
31
30
  directivesProxyFile: '../component-library-angular/src/directives/proxies.ts',
32
31
  directivesArrayFile: '../component-library-angular/src/directives/index.ts',
33
32
  }),
@@ -48,5 +47,5 @@ export const config: Config = {
48
47
  | `directivesArrayFile` | The output file of a constant of all the generated component wrapper classes. Used for easily declaring and exporting the generated components from an `NgModule`. This file path should point to a location within your Angular library/project. |
49
48
  | `valueAccessorConfigs` | The configuration object for how individual web components behave with Angular control value accessors. |
50
49
  | `excludeComponents` | An array of tag names to exclude from generating component wrappers for. This is helpful when have a custom framework implementation of a specific component or need to extend the base component wrapper behavior. |
51
- | `outputType` | Specifies the type of output to be generated. It can take one of the following values: <br />1. `component`: Generates all the component wrappers to be declared on an Angular module. This option is required for Stencil projects using the `dist` hydrated output.<br /> 2. `scam`: Generates a separate Angular module for each component.<br /> 3. `standalone`: Generates standalone component wrappers.<br /> Both `scam` and `standalone` options are compatible with the `dist-custom-elements` output. Developers **must** set a `customElementsDir` in the output target config when using either 'scam' or 'standalone'.<br />Note: Please choose the appropriate `outputType` based on your project's requirements and the desired output structure. |
52
- | `customElementsDir` | This is the directory where the custom elements are imported from when using the [Custom Elements Bundle](https://stenciljs.com/docs/custom-elements). Required to be set for `outputType: "scam"` or `outputType: "standalone"`. |
50
+ | `outputType` | Specifies the type of output to be generated. It can take one of the following values: <br />1. `component`: Generates all the component wrappers to be declared on an Angular module. This option is required for Stencil projects using the `dist` hydrated output.<br /> 2. `scam`: Generates a separate Angular module for each component.<br /> 3. `standalone`: Generates standalone component wrappers.<br /> Both `scam` and `standalone` options are compatible with the `dist-custom-elements` output. <br />Note: Please choose the appropriate `outputType` based on your project's requirements and the desired output structure. Defaults to `component`. |
51
+ | `customElementsDir` | This is the directory where the custom elements are imported from when using the [Custom Elements Bundle](https://stenciljs.com/docs/custom-elements). Defaults to the `components` directory. Only applies for `outputType: "scam"` or `outputType: "standalone"`. |
@@ -1,4 +1,5 @@
1
1
  import type { ComponentCompilerEvent } from '@stencil/core/internal';
2
+ import type { OutputType } from './types';
2
3
  /**
3
4
  * Creates an Angular component declaration from formatted Stencil compiler metadata.
4
5
  *
@@ -13,10 +14,11 @@ import type { ComponentCompilerEvent } from '@stencil/core/internal';
13
14
  export declare const createAngularComponentDefinition: (tagName: string, inputs: readonly string[], outputs: readonly string[], methods: readonly string[], includeImportCustomElements?: boolean, standalone?: boolean) => string;
14
15
  /**
15
16
  * Creates the component interface type definition.
17
+ * @param outputType The output type.
16
18
  * @param tagNameAsPascal The tag name as PascalCase.
17
19
  * @param events The events to generate the interface properties for.
18
20
  * @param componentCorePackage The component core package.
19
21
  * @param customElementsDir The custom elements directory.
20
22
  * @returns The component interface type definition as a string.
21
23
  */
22
- export declare const createComponentTypeDefinition: (tagNameAsPascal: string, events: readonly ComponentCompilerEvent[], componentCorePackage: string, customElementsDir?: string | undefined) => string;
24
+ export declare const createComponentTypeDefinition: (outputType: OutputType, tagNameAsPascal: string, events: readonly ComponentCompilerEvent[], componentCorePackage: string, customElementsDir?: string | undefined) => string;
@@ -103,17 +103,19 @@ const createDocComment = (doc) => {
103
103
  };
104
104
  /**
105
105
  * Creates the component interface type definition.
106
+ * @param outputType The output type.
106
107
  * @param tagNameAsPascal The tag name as PascalCase.
107
108
  * @param events The events to generate the interface properties for.
108
109
  * @param componentCorePackage The component core package.
109
110
  * @param customElementsDir The custom elements directory.
110
111
  * @returns The component interface type definition as a string.
111
112
  */
112
- export const createComponentTypeDefinition = (tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
113
+ export const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
113
114
  const publicEvents = events.filter((ev) => !ev.internal);
114
115
  const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
115
116
  componentCorePackage,
116
117
  customElementsDir,
118
+ outputType,
117
119
  });
118
120
  const eventTypes = publicEvents.map((event) => {
119
121
  const comment = createDocComment(event.docs);
package/dist/index.cjs.js CHANGED
@@ -9,6 +9,11 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
9
9
 
10
10
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
11
11
 
12
+ const OutputTypes = {
13
+ Component: 'component',
14
+ Scam: 'scam',
15
+ Standalone: 'standalone',
16
+ };
12
17
  const toLowerCase = (str) => str.toLowerCase();
13
18
  const dashToPascalCase = (str) => toLowerCase(str)
14
19
  .split('-')
@@ -100,6 +105,14 @@ const createImportStatement = (imports, module) => {
100
105
  }
101
106
  return `import { ${imports.join(', ')} } from '${module}';`;
102
107
  };
108
+ /**
109
+ * Checks if the outputType is for the custom elements build.
110
+ * @param outputType The output type.
111
+ * @returns `true` if the output type is for the custom elements build.
112
+ */
113
+ const isOutputTypeCustomElementsBuild = (outputType) => {
114
+ return outputType === OutputTypes.Standalone || outputType === OutputTypes.Scam;
115
+ };
103
116
  /**
104
117
  * Creates the collection of import statements for a component based on the component's events type dependencies.
105
118
  * @param componentTagName The tag name of the component (pascal case).
@@ -111,7 +124,7 @@ const createComponentEventTypeImports = (componentTagName, events, options) => {
111
124
  const { componentCorePackage, customElementsDir } = options;
112
125
  const imports = [];
113
126
  const namedImports = new Set();
114
- const isCustomElementsBuild = customElementsDir !== undefined;
127
+ const isCustomElementsBuild = isOutputTypeCustomElementsBuild(options.outputType);
115
128
  const importPathName = normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
116
129
  events.forEach((event) => {
117
130
  Object.entries(event.complexType.references).forEach(([typeName, refObject]) => {
@@ -235,17 +248,19 @@ const createDocComment = (doc) => {
235
248
  };
236
249
  /**
237
250
  * Creates the component interface type definition.
251
+ * @param outputType The output type.
238
252
  * @param tagNameAsPascal The tag name as PascalCase.
239
253
  * @param events The events to generate the interface properties for.
240
254
  * @param componentCorePackage The component core package.
241
255
  * @param customElementsDir The custom elements directory.
242
256
  * @returns The component interface type definition as a string.
243
257
  */
244
- const createComponentTypeDefinition = (tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
258
+ const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
245
259
  const publicEvents = events.filter((ev) => !ev.internal);
246
260
  const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
247
261
  componentCorePackage,
248
262
  customElementsDir,
263
+ outputType,
249
264
  });
250
265
  const eventTypes = publicEvents.map((event) => {
251
266
  const comment = createDocComment(event.docs);
@@ -393,11 +408,11 @@ async function copyResources$1(config, outputTarget) {
393
408
  function generateProxies(components, pkgData, outputTarget, rootDir) {
394
409
  const distTypesDir = path__default['default'].dirname(pkgData.types);
395
410
  const dtsFilePath = path__default['default'].join(rootDir, distTypesDir, GENERATED_DTS);
411
+ const { outputType } = outputTarget;
396
412
  const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
397
- const includeSingleComponentAngularModules = outputTarget.outputType === 'scam';
398
- const includeSingleComponentAngularComponents = outputTarget.outputType === 'standalone';
399
- const isCustomElementsBuild = outputTarget.customElementsDir !== undefined;
400
- const isStandaloneBuild = outputTarget.outputType === 'standalone';
413
+ const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
414
+ const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
415
+ const isStandaloneBuild = outputType === OutputTypes.Standalone;
401
416
  const includeOutputImports = components.some((component) => component.events.some((event) => !event.internal));
402
417
  /**
403
418
  * The collection of named imports from @angular/core.
@@ -439,9 +454,9 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
439
454
  let sourceImports = '';
440
455
  /**
441
456
  * Build an array of Custom Elements build imports and namespace them
442
- * so that they do not conflict with the React wrapper names. For example,
457
+ * so that they do not conflict with the Angular wrapper names. For example,
443
458
  * IonButton would be imported as IonButtonCmp so as to not conflict with the
444
- * IonButton React Component that takes in the Web Component as a parameter.
459
+ * IonButton Angular Component that takes in the Web Component as a parameter.
445
460
  */
446
461
  if (isCustomElementsBuild && outputTarget.componentCorePackage !== undefined) {
447
462
  const cmpImports = components.map((component) => {
@@ -450,16 +465,6 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
450
465
  });
451
466
  sourceImports = cmpImports.join('\n');
452
467
  }
453
- if (!isCustomElementsBuild) {
454
- if (includeSingleComponentAngularModules) {
455
- // Generating Angular modules is only supported in the dist-custom-elements build
456
- throw new Error('Generating single component Angular modules requires the "customElementsDir" option to be set.');
457
- }
458
- if (includeSingleComponentAngularComponents) {
459
- // Generates Angular standalone components is only supported in the dist-custom-elements build
460
- throw new Error('Generating standalone Angular components requires the "customElementsDir" option to be set.');
461
- }
462
- }
463
468
  const proxyFileOutput = [];
464
469
  const filterInternalProps = (prop) => !prop.internal;
465
470
  const mapPropName = (prop) => prop.name;
@@ -490,7 +495,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
490
495
  */
491
496
  const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, isCustomElementsBuild, isStandaloneBuild);
492
497
  const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
493
- const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
498
+ const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
494
499
  proxyFileOutput.push(componentDefinition, '\n');
495
500
  if (includeSingleComponentAngularModules) {
496
501
  proxyFileOutput.push(moduleDefinition, '\n');
@@ -503,20 +508,23 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
503
508
  const GENERATED_DTS = 'components.d.ts';
504
509
  const IMPORT_TYPES = 'Components';
505
510
 
506
- const angularOutputTarget = (outputTarget) => ({
507
- type: 'custom',
508
- name: 'angular-library',
509
- validate(config) {
510
- return normalizeOutputTarget(config, outputTarget);
511
- },
512
- async generator(config, compilerCtx, buildCtx) {
513
- const timespan = buildCtx.createTimeSpan(`generate angular proxies started`, true);
514
- await angularDirectiveProxyOutput(compilerCtx, outputTarget, buildCtx.components, config);
515
- timespan.finish(`generate angular proxies finished`);
516
- },
517
- });
511
+ const angularOutputTarget = (outputTarget) => {
512
+ let validatedOutputTarget;
513
+ return {
514
+ type: 'custom',
515
+ name: 'angular-library',
516
+ validate(config) {
517
+ validatedOutputTarget = normalizeOutputTarget(config, outputTarget);
518
+ },
519
+ async generator(config, compilerCtx, buildCtx) {
520
+ const timespan = buildCtx.createTimeSpan(`generate angular proxies started`, true);
521
+ await angularDirectiveProxyOutput(compilerCtx, validatedOutputTarget, buildCtx.components, config);
522
+ timespan.finish(`generate angular proxies finished`);
523
+ },
524
+ };
525
+ };
518
526
  function normalizeOutputTarget(config, outputTarget) {
519
- const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], valueAccessorConfigs: outputTarget.valueAccessorConfigs || [] });
527
+ const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], valueAccessorConfigs: outputTarget.valueAccessorConfigs || [], customElementsDir: outputTarget.customElementsDir || 'components', outputType: outputTarget.outputType || OutputTypes.Component });
520
528
  if (config.rootDir == null) {
521
529
  throw new Error('rootDir is not set and it should be set by stencil itself');
522
530
  }
@@ -532,8 +540,8 @@ function normalizeOutputTarget(config, outputTarget) {
532
540
  if (outputTarget.includeSingleComponentAngularModules !== undefined) {
533
541
  throw new Error("The 'includeSingleComponentAngularModules' option has been removed. Please use 'outputType' instead.");
534
542
  }
535
- if (outputTarget.outputType === 'scam') {
536
- console.warn('**Experimental**: outputType: "scam" is a developer preview feature and may change or be removed in the future.');
543
+ if (outputTarget.outputType === OutputTypes.Scam) {
544
+ console.warn(`**Experimental**: outputType: "${OutputTypes.Scam}" is a developer preview feature and may change or be removed in the future.`);
537
545
  }
538
546
  return results;
539
547
  }
package/dist/index.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import path from 'path';
2
2
  import { EOL } from 'os';
3
3
 
4
+ const OutputTypes = {
5
+ Component: 'component',
6
+ Scam: 'scam',
7
+ Standalone: 'standalone',
8
+ };
4
9
  const toLowerCase = (str) => str.toLowerCase();
5
10
  const dashToPascalCase = (str) => toLowerCase(str)
6
11
  .split('-')
@@ -92,6 +97,14 @@ const createImportStatement = (imports, module) => {
92
97
  }
93
98
  return `import { ${imports.join(', ')} } from '${module}';`;
94
99
  };
100
+ /**
101
+ * Checks if the outputType is for the custom elements build.
102
+ * @param outputType The output type.
103
+ * @returns `true` if the output type is for the custom elements build.
104
+ */
105
+ const isOutputTypeCustomElementsBuild = (outputType) => {
106
+ return outputType === OutputTypes.Standalone || outputType === OutputTypes.Scam;
107
+ };
95
108
  /**
96
109
  * Creates the collection of import statements for a component based on the component's events type dependencies.
97
110
  * @param componentTagName The tag name of the component (pascal case).
@@ -103,7 +116,7 @@ const createComponentEventTypeImports = (componentTagName, events, options) => {
103
116
  const { componentCorePackage, customElementsDir } = options;
104
117
  const imports = [];
105
118
  const namedImports = new Set();
106
- const isCustomElementsBuild = customElementsDir !== undefined;
119
+ const isCustomElementsBuild = isOutputTypeCustomElementsBuild(options.outputType);
107
120
  const importPathName = normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
108
121
  events.forEach((event) => {
109
122
  Object.entries(event.complexType.references).forEach(([typeName, refObject]) => {
@@ -227,17 +240,19 @@ const createDocComment = (doc) => {
227
240
  };
228
241
  /**
229
242
  * Creates the component interface type definition.
243
+ * @param outputType The output type.
230
244
  * @param tagNameAsPascal The tag name as PascalCase.
231
245
  * @param events The events to generate the interface properties for.
232
246
  * @param componentCorePackage The component core package.
233
247
  * @param customElementsDir The custom elements directory.
234
248
  * @returns The component interface type definition as a string.
235
249
  */
236
- const createComponentTypeDefinition = (tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
250
+ const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
237
251
  const publicEvents = events.filter((ev) => !ev.internal);
238
252
  const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
239
253
  componentCorePackage,
240
254
  customElementsDir,
255
+ outputType,
241
256
  });
242
257
  const eventTypes = publicEvents.map((event) => {
243
258
  const comment = createDocComment(event.docs);
@@ -385,11 +400,11 @@ async function copyResources$1(config, outputTarget) {
385
400
  function generateProxies(components, pkgData, outputTarget, rootDir) {
386
401
  const distTypesDir = path.dirname(pkgData.types);
387
402
  const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
403
+ const { outputType } = outputTarget;
388
404
  const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
389
- const includeSingleComponentAngularModules = outputTarget.outputType === 'scam';
390
- const includeSingleComponentAngularComponents = outputTarget.outputType === 'standalone';
391
- const isCustomElementsBuild = outputTarget.customElementsDir !== undefined;
392
- const isStandaloneBuild = outputTarget.outputType === 'standalone';
405
+ const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
406
+ const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
407
+ const isStandaloneBuild = outputType === OutputTypes.Standalone;
393
408
  const includeOutputImports = components.some((component) => component.events.some((event) => !event.internal));
394
409
  /**
395
410
  * The collection of named imports from @angular/core.
@@ -431,9 +446,9 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
431
446
  let sourceImports = '';
432
447
  /**
433
448
  * Build an array of Custom Elements build imports and namespace them
434
- * so that they do not conflict with the React wrapper names. For example,
449
+ * so that they do not conflict with the Angular wrapper names. For example,
435
450
  * IonButton would be imported as IonButtonCmp so as to not conflict with the
436
- * IonButton React Component that takes in the Web Component as a parameter.
451
+ * IonButton Angular Component that takes in the Web Component as a parameter.
437
452
  */
438
453
  if (isCustomElementsBuild && outputTarget.componentCorePackage !== undefined) {
439
454
  const cmpImports = components.map((component) => {
@@ -442,16 +457,6 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
442
457
  });
443
458
  sourceImports = cmpImports.join('\n');
444
459
  }
445
- if (!isCustomElementsBuild) {
446
- if (includeSingleComponentAngularModules) {
447
- // Generating Angular modules is only supported in the dist-custom-elements build
448
- throw new Error('Generating single component Angular modules requires the "customElementsDir" option to be set.');
449
- }
450
- if (includeSingleComponentAngularComponents) {
451
- // Generates Angular standalone components is only supported in the dist-custom-elements build
452
- throw new Error('Generating standalone Angular components requires the "customElementsDir" option to be set.');
453
- }
454
- }
455
460
  const proxyFileOutput = [];
456
461
  const filterInternalProps = (prop) => !prop.internal;
457
462
  const mapPropName = (prop) => prop.name;
@@ -482,7 +487,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
482
487
  */
483
488
  const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, isCustomElementsBuild, isStandaloneBuild);
484
489
  const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
485
- const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
490
+ const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
486
491
  proxyFileOutput.push(componentDefinition, '\n');
487
492
  if (includeSingleComponentAngularModules) {
488
493
  proxyFileOutput.push(moduleDefinition, '\n');
@@ -495,20 +500,23 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
495
500
  const GENERATED_DTS = 'components.d.ts';
496
501
  const IMPORT_TYPES = 'Components';
497
502
 
498
- const angularOutputTarget = (outputTarget) => ({
499
- type: 'custom',
500
- name: 'angular-library',
501
- validate(config) {
502
- return normalizeOutputTarget(config, outputTarget);
503
- },
504
- async generator(config, compilerCtx, buildCtx) {
505
- const timespan = buildCtx.createTimeSpan(`generate angular proxies started`, true);
506
- await angularDirectiveProxyOutput(compilerCtx, outputTarget, buildCtx.components, config);
507
- timespan.finish(`generate angular proxies finished`);
508
- },
509
- });
503
+ const angularOutputTarget = (outputTarget) => {
504
+ let validatedOutputTarget;
505
+ return {
506
+ type: 'custom',
507
+ name: 'angular-library',
508
+ validate(config) {
509
+ validatedOutputTarget = normalizeOutputTarget(config, outputTarget);
510
+ },
511
+ async generator(config, compilerCtx, buildCtx) {
512
+ const timespan = buildCtx.createTimeSpan(`generate angular proxies started`, true);
513
+ await angularDirectiveProxyOutput(compilerCtx, validatedOutputTarget, buildCtx.components, config);
514
+ timespan.finish(`generate angular proxies finished`);
515
+ },
516
+ };
517
+ };
510
518
  function normalizeOutputTarget(config, outputTarget) {
511
- const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], valueAccessorConfigs: outputTarget.valueAccessorConfigs || [] });
519
+ const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], valueAccessorConfigs: outputTarget.valueAccessorConfigs || [], customElementsDir: outputTarget.customElementsDir || 'components', outputType: outputTarget.outputType || OutputTypes.Component });
512
520
  if (config.rootDir == null) {
513
521
  throw new Error('rootDir is not set and it should be set by stencil itself');
514
522
  }
@@ -524,8 +532,8 @@ function normalizeOutputTarget(config, outputTarget) {
524
532
  if (outputTarget.includeSingleComponentAngularModules !== undefined) {
525
533
  throw new Error("The 'includeSingleComponentAngularModules' option has been removed. Please use 'outputType' instead.");
526
534
  }
527
- if (outputTarget.outputType === 'scam') {
528
- console.warn('**Experimental**: outputType: "scam" is a developer preview feature and may change or be removed in the future.');
535
+ if (outputTarget.outputType === OutputTypes.Scam) {
536
+ console.warn(`**Experimental**: outputType: "${OutputTypes.Scam}" is a developer preview feature and may change or be removed in the future.`);
529
537
  }
530
538
  return results;
531
539
  }
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCase, createImportStatement, } from './utils';
2
+ import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCase, createImportStatement, isOutputTypeCustomElementsBuild, OutputTypes, } from './utils';
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';
@@ -37,11 +37,11 @@ async function copyResources(config, outputTarget) {
37
37
  export function generateProxies(components, pkgData, outputTarget, rootDir) {
38
38
  const distTypesDir = path.dirname(pkgData.types);
39
39
  const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
40
+ const { outputType } = outputTarget;
40
41
  const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
41
- const includeSingleComponentAngularModules = outputTarget.outputType === 'scam';
42
- const includeSingleComponentAngularComponents = outputTarget.outputType === 'standalone';
43
- const isCustomElementsBuild = outputTarget.customElementsDir !== undefined;
44
- const isStandaloneBuild = outputTarget.outputType === 'standalone';
42
+ const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
43
+ const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
44
+ const isStandaloneBuild = outputType === OutputTypes.Standalone;
45
45
  const includeOutputImports = components.some((component) => component.events.some((event) => !event.internal));
46
46
  /**
47
47
  * The collection of named imports from @angular/core.
@@ -83,9 +83,9 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
83
83
  let sourceImports = '';
84
84
  /**
85
85
  * Build an array of Custom Elements build imports and namespace them
86
- * so that they do not conflict with the React wrapper names. For example,
86
+ * so that they do not conflict with the Angular wrapper names. For example,
87
87
  * IonButton would be imported as IonButtonCmp so as to not conflict with the
88
- * IonButton React Component that takes in the Web Component as a parameter.
88
+ * IonButton Angular Component that takes in the Web Component as a parameter.
89
89
  */
90
90
  if (isCustomElementsBuild && outputTarget.componentCorePackage !== undefined) {
91
91
  const cmpImports = components.map((component) => {
@@ -94,16 +94,6 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
94
94
  });
95
95
  sourceImports = cmpImports.join('\n');
96
96
  }
97
- if (!isCustomElementsBuild) {
98
- if (includeSingleComponentAngularModules) {
99
- // Generating Angular modules is only supported in the dist-custom-elements build
100
- throw new Error('Generating single component Angular modules requires the "customElementsDir" option to be set.');
101
- }
102
- if (includeSingleComponentAngularComponents) {
103
- // Generates Angular standalone components is only supported in the dist-custom-elements build
104
- throw new Error('Generating standalone Angular components requires the "customElementsDir" option to be set.');
105
- }
106
- }
107
97
  const proxyFileOutput = [];
108
98
  const filterInternalProps = (prop) => !prop.internal;
109
99
  const mapPropName = (prop) => prop.name;
@@ -134,7 +124,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n
134
124
  */
135
125
  const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, isCustomElementsBuild, isStandaloneBuild);
136
126
  const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
137
- const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
127
+ const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
138
128
  proxyFileOutput.push(componentDefinition, '\n');
139
129
  if (includeSingleComponentAngularModules) {
140
130
  proxyFileOutput.push(moduleDefinition, '\n');
package/dist/plugin.js CHANGED
@@ -1,20 +1,23 @@
1
- import { normalizePath } from './utils';
1
+ import { OutputTypes, normalizePath } from './utils';
2
2
  import { angularDirectiveProxyOutput } from './output-angular';
3
3
  import path from 'path';
4
- export const angularOutputTarget = (outputTarget) => ({
5
- type: 'custom',
6
- name: 'angular-library',
7
- validate(config) {
8
- return normalizeOutputTarget(config, outputTarget);
9
- },
10
- async generator(config, compilerCtx, buildCtx) {
11
- const timespan = buildCtx.createTimeSpan(`generate angular proxies started`, true);
12
- await angularDirectiveProxyOutput(compilerCtx, outputTarget, buildCtx.components, config);
13
- timespan.finish(`generate angular proxies finished`);
14
- },
15
- });
4
+ export const angularOutputTarget = (outputTarget) => {
5
+ let validatedOutputTarget;
6
+ return {
7
+ type: 'custom',
8
+ name: 'angular-library',
9
+ validate(config) {
10
+ validatedOutputTarget = normalizeOutputTarget(config, outputTarget);
11
+ },
12
+ async generator(config, compilerCtx, buildCtx) {
13
+ const timespan = buildCtx.createTimeSpan(`generate angular proxies started`, true);
14
+ await angularDirectiveProxyOutput(compilerCtx, validatedOutputTarget, buildCtx.components, config);
15
+ timespan.finish(`generate angular proxies finished`);
16
+ },
17
+ };
18
+ };
16
19
  export function normalizeOutputTarget(config, outputTarget) {
17
- const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], valueAccessorConfigs: outputTarget.valueAccessorConfigs || [] });
20
+ const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], valueAccessorConfigs: outputTarget.valueAccessorConfigs || [], customElementsDir: outputTarget.customElementsDir || 'components', outputType: outputTarget.outputType || OutputTypes.Component });
18
21
  if (config.rootDir == null) {
19
22
  throw new Error('rootDir is not set and it should be set by stencil itself');
20
23
  }
@@ -30,8 +33,8 @@ export function normalizeOutputTarget(config, outputTarget) {
30
33
  if (outputTarget.includeSingleComponentAngularModules !== undefined) {
31
34
  throw new Error("The 'includeSingleComponentAngularModules' option has been removed. Please use 'outputType' instead.");
32
35
  }
33
- if (outputTarget.outputType === 'scam') {
34
- console.warn('**Experimental**: outputType: "scam" is a developer preview feature and may change or be removed in the future.');
36
+ if (outputTarget.outputType === OutputTypes.Scam) {
37
+ console.warn(`**Experimental**: outputType: "${OutputTypes.Scam}" is a developer preview feature and may change or be removed in the future.`);
35
38
  }
36
39
  return results;
37
40
  }
package/dist/types.d.ts CHANGED
@@ -23,10 +23,10 @@ export interface OutputTargetAngular {
23
23
  /**
24
24
  * The type of output that should be generated.
25
25
  * - `component` - Generate many component wrappers tied to a single Angular module (lazy/hydrated approach).
26
- * - `scam` - @experimental Generate a Single Component Angular Module for each component.
26
+ * - `scam` - **Experimental** - Generate a Single Component Angular Module for each component.
27
27
  * - `standalone` - Generate a component with the `standalone` flag set to `true`.
28
28
  */
29
- outputType: OutputType;
29
+ outputType?: OutputType;
30
30
  }
31
31
  export declare type ValueAccessorTypes = 'text' | 'radio' | 'select' | 'number' | 'boolean';
32
32
  export interface ValueAccessorConfig {
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { ComponentCompilerEvent, Config } from '@stencil/core/internal';
2
- import type { PackageJSON } from './types';
2
+ import { OutputType, PackageJSON } from './types';
3
+ export declare const OutputTypes: {
4
+ [key: string]: OutputType;
5
+ };
3
6
  export declare const toLowerCase: (str: string) => string;
4
7
  export declare const dashToPascalCase: (str: string) => string;
5
8
  export declare function sortBy<T>(array: T[], prop: (item: T) => string): T[];
@@ -21,6 +24,12 @@ export declare const formatToQuotedList: (list: readonly string[]) => string;
21
24
  * @returns The import statement as a string.
22
25
  */
23
26
  export declare const createImportStatement: (imports: string[], module: string) => string;
27
+ /**
28
+ * Checks if the outputType is for the custom elements build.
29
+ * @param outputType The output type.
30
+ * @returns `true` if the output type is for the custom elements build.
31
+ */
32
+ export declare const isOutputTypeCustomElementsBuild: (outputType: OutputType) => boolean;
24
33
  /**
25
34
  * Creates the collection of import statements for a component based on the component's events type dependencies.
26
35
  * @param componentTagName The tag name of the component (pascal case).
@@ -31,4 +40,5 @@ export declare const createImportStatement: (imports: string[], module: string)
31
40
  export declare const createComponentEventTypeImports: (componentTagName: string, events: readonly ComponentCompilerEvent[], options: {
32
41
  componentCorePackage: string;
33
42
  customElementsDir?: string;
43
+ outputType: OutputType;
34
44
  }) => string;
package/dist/utils.js CHANGED
@@ -1,4 +1,9 @@
1
1
  import path from 'path';
2
+ export const OutputTypes = {
3
+ Component: 'component',
4
+ Scam: 'scam',
5
+ Standalone: 'standalone',
6
+ };
2
7
  export const toLowerCase = (str) => str.toLowerCase();
3
8
  export const dashToPascalCase = (str) => toLowerCase(str)
4
9
  .split('-')
@@ -93,6 +98,14 @@ export const createImportStatement = (imports, module) => {
93
98
  }
94
99
  return `import { ${imports.join(', ')} } from '${module}';`;
95
100
  };
101
+ /**
102
+ * Checks if the outputType is for the custom elements build.
103
+ * @param outputType The output type.
104
+ * @returns `true` if the output type is for the custom elements build.
105
+ */
106
+ export const isOutputTypeCustomElementsBuild = (outputType) => {
107
+ return outputType === OutputTypes.Standalone || outputType === OutputTypes.Scam;
108
+ };
96
109
  /**
97
110
  * Creates the collection of import statements for a component based on the component's events type dependencies.
98
111
  * @param componentTagName The tag name of the component (pascal case).
@@ -104,7 +117,7 @@ export const createComponentEventTypeImports = (componentTagName, events, option
104
117
  const { componentCorePackage, customElementsDir } = options;
105
118
  const imports = [];
106
119
  const namedImports = new Set();
107
- const isCustomElementsBuild = customElementsDir !== undefined;
120
+ const isCustomElementsBuild = isOutputTypeCustomElementsBuild(options.outputType);
108
121
  const importPathName = normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
109
122
  events.forEach((event) => {
110
123
  Object.entries(event.complexType.references).forEach(([typeName, refObject]) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/angular-output-target",
3
- "version": "0.8.1-dev.11690825475.1243803f",
3
+ "version": "0.8.1",
4
4
  "description": "Angular output target for @stencil/core components.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -58,7 +58,7 @@
58
58
  ],
59
59
  "testURL": "http://localhost"
60
60
  },
61
- "gitHead": "243803f02d0675190181da7ed8ad6ff432c3ee1d",
61
+ "gitHead": "a3588e905186a0e86e7f88418fd5b2f9531b55e0",
62
62
  "volta": {
63
63
  "extends": "../../package.json"
64
64
  }