@stencil/angular-output-target 0.6.1-dev.11655483906.1e51ded4 → 0.6.1-dev.11662151255.17ea4066

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/index.js CHANGED
@@ -74,132 +74,184 @@ async function readPackageJson(config, rootDir) {
74
74
  return pkgData;
75
75
  }
76
76
  /**
77
- * Returns the formatted custom event interface name for the component.
78
- * With a tag of "my-cmp", it will return "MyCmpCustomEvent".
77
+ * Formats an array of strings to a string of quoted, comma separated values.
78
+ * @param list The list of unformatted strings to format
79
+ * @returns The formatted array of strings. (e.g. ['foo', 'bar']) => `'foo', 'bar'`
80
+ */
81
+ const formatToQuotedList = (list) => list.map((item) => `'${item}'`).join(', ');
82
+ /**
83
+ * Creates an import statement for a list of named imports from a module.
84
+ * @param imports The list of named imports.
85
+ * @param module The module to import from.
79
86
  *
80
- * @param componentTagName The tag selector of the component (i.e. my-cmp)
81
- * @returns The formatted custom event interface name.
87
+ * @returns The import statement as a string.
82
88
  */
83
- function formatCustomEventInterfaceName(componentTagName) {
84
- return `${dashToPascalCase(componentTagName)}CustomEvent`;
85
- }
86
- const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
87
- const NON_ASCII_REGEX = /[^\x00-\x80]+/;
88
- const SLASH_REGEX = /\\/g;
89
-
90
- const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir, includeImportCustomElements = false, customElementsDir = 'components') => (cmpMeta) => {
91
- // Collect component meta
92
- const inputs = [
93
- ...cmpMeta.properties.filter((prop) => !prop.internal).map((prop) => prop.name),
94
- ...cmpMeta.virtualProperties.map((prop) => prop.name),
95
- ].sort();
96
- const outputs = cmpMeta.events.filter((ev) => !ev.internal).map((prop) => prop);
97
- const methods = cmpMeta.methods.filter((method) => !method.internal).map((prop) => prop.name);
98
- // Process meta
99
- const hasOutputs = outputs.length > 0;
100
- // Generate Angular @Directive
101
- const directiveOpts = [
102
- `selector: \'${cmpMeta.tagName}\'`,
103
- `changeDetection: ChangeDetectionStrategy.OnPush`,
104
- `template: '<ng-content></ng-content>'`,
105
- ];
106
- if (inputs.length > 0) {
107
- directiveOpts.push(`inputs: ['${inputs.join(`', '`)}']`);
89
+ const createImportStatement = (imports, module) => {
90
+ if (imports.length === 0) {
91
+ return '';
108
92
  }
109
- const tagNameAsPascal = dashToPascalCase(cmpMeta.tagName);
110
- const outputsInterface = new Set();
111
- const outputReferenceRemap = {};
112
- outputs.forEach((output) => {
113
- Object.entries(output.complexType.references).forEach(([reference, refObject]) => {
114
- // Add import line for each local/import reference, and add new mapping name.
115
- // `outputReferenceRemap` should be updated only if the import interface is set in outputsInterface,
116
- // this will prevent global types to be remapped.
117
- const remappedReference = `I${cmpMeta.componentClassName}${reference}`;
93
+ return `import { ${imports.join(', ')} } from '${module}';`;
94
+ };
95
+ /**
96
+ * Creates the collection of import statements for a component based on the component's events type dependencies.
97
+ * @param componentTagName The tag name of the component (pascal case).
98
+ * @param events The events compiler metadata.
99
+ * @param options The options for generating the import statements (e.g. whether to import from the custom elements directory).
100
+ * @returns The import statements as an array of strings.
101
+ */
102
+ const createComponentEventTypeImports = (componentTagName, events, options) => {
103
+ const { componentCorePackage, includeImportCustomElements, customElementsDir } = options;
104
+ const imports = [];
105
+ const namedImports = new Set();
106
+ const importPathName = normalizePath(componentCorePackage) + (includeImportCustomElements ? `/${customElementsDir || 'components'}` : '');
107
+ events.forEach((event) => {
108
+ Object.entries(event.complexType.references).forEach(([typeName, refObject]) => {
118
109
  if (refObject.location === 'local' || refObject.location === 'import') {
119
- outputReferenceRemap[reference] = remappedReference;
120
- let importLocation = componentCorePackage;
121
- if (componentCorePackage !== undefined) {
122
- const dirPath = includeImportCustomElements ? `/${customElementsDir || 'components'}` : '';
123
- importLocation = `${normalizePath(componentCorePackage)}${dirPath}`;
110
+ const newTypeName = `I${componentTagName}${typeName}`;
111
+ // Prevents duplicate imports for the same type.
112
+ if (!namedImports.has(newTypeName)) {
113
+ imports.push(`import type { ${typeName} as ${newTypeName} } from '${importPathName}';`);
114
+ namedImports.add(newTypeName);
124
115
  }
125
- outputsInterface.add(`import type { ${reference} as ${remappedReference} } from '${importLocation}';`);
126
116
  }
127
117
  });
128
118
  });
129
- const componentEvents = [
130
- '' // Empty first line
131
- ];
132
- // Generate outputs
133
- outputs.forEach((output, index) => {
134
- componentEvents.push(` /**
135
- * ${output.docs.text} ${output.docs.tags.map((tag) => `@${tag.name} ${tag.text}`)}
136
- */`);
137
- /**
138
- * The original attribute contains the original type defined by the devs.
139
- * This regexp normalizes the reference, by removing linebreaks,
140
- * replacing consecutive spaces with a single space, and adding a single space after commas.
141
- **/
142
- const outputTypeRemapped = Object.entries(outputReferenceRemap).reduce((type, [src, dst]) => {
143
- return type
144
- .replace(new RegExp(`^${src}$`, 'g'), `${dst}`)
145
- .replace(new RegExp(`([^\\w])${src}([^\\w])`, 'g'), (v, p1, p2) => [p1, dst, p2].join(''));
146
- }, output.complexType.original
147
- .replace(/\n/g, ' ')
148
- .replace(/\s{2,}/g, ' ')
149
- .replace(/,\s*/g, ', '));
150
- /**
151
- * Starting in Stencil 2.16.0, the compiler will generate a CustomEvent interface
152
- * for each component with custom events.
153
- *
154
- * The name of this custom event is "ComponentTagNameCustomEvent".
155
- */
156
- componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
157
- if (index === outputs.length - 1) {
158
- // Empty line to push end `}` to new line
159
- componentEvents.push('\n');
160
- }
161
- });
162
- const lines = [
163
- '',
164
- `${[...outputsInterface].join('\n')}
165
- export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {${componentEvents.length > 1 ? componentEvents.join('\n') : ''}}
119
+ return imports.join('\n');
120
+ };
121
+ const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
122
+ const NON_ASCII_REGEX = /[^\x00-\x80]+/;
123
+ const SLASH_REGEX = /\\/g;
166
124
 
167
- ${getProxyCmp(cmpMeta.tagName, includeImportCustomElements, inputs, methods)}
125
+ /**
126
+ * Creates an Angular component declaration from formatted Stencil compiler metadata.
127
+ *
128
+ * @param tagName The tag name of the component.
129
+ * @param inputs The inputs of the Stencil component (e.g. ['myInput']).
130
+ * @param outputs The outputs/events of the Stencil component. (e.g. ['myOutput']).
131
+ * @param methods The methods of the Stencil component. (e.g. ['myMethod']).
132
+ * @param includeImportCustomElements Whether to define the component as a custom element.
133
+ * @returns The component declaration as a string.
134
+ */
135
+ const createAngularComponentDefinition = (tagName, inputs, outputs, methods, includeImportCustomElements = false) => {
136
+ const tagNameAsPascal = dashToPascalCase(tagName);
137
+ const hasInputs = inputs.length > 0;
138
+ const hasOutputs = outputs.length > 0;
139
+ const hasMethods = methods.length > 0;
140
+ // Formats the input strings into comma separated, single quoted values.
141
+ const formattedInputs = formatToQuotedList(inputs);
142
+ // Formats the output strings into comma separated, single quoted values.
143
+ const formattedOutputs = formatToQuotedList(outputs);
144
+ // Formats the method strings into comma separated, single quoted values.
145
+ const formattedMethods = formatToQuotedList(methods);
146
+ const proxyCmpOptions = [];
147
+ if (includeImportCustomElements) {
148
+ const defineCustomElementFn = `define${tagNameAsPascal}`;
149
+ proxyCmpOptions.push(`\n defineCustomElementFn: ${defineCustomElementFn}`);
150
+ }
151
+ if (hasInputs) {
152
+ proxyCmpOptions.push(`\n inputs: [${formattedInputs}]`);
153
+ }
154
+ if (hasMethods) {
155
+ proxyCmpOptions.push(`\n methods: [${formattedMethods}]`);
156
+ }
157
+ /**
158
+ * Notes on the generated output:
159
+ * - We disable @angular-eslint/no-inputs-metadata-property, so that
160
+ * Angular does not complain about the inputs property. The output target
161
+ * uses the inputs property to define the inputs of the component instead of
162
+ * having to use the @Input decorator (and manually define the type and default value).
163
+ */
164
+ const output = `@ProxyCmp({${proxyCmpOptions.join(',')}\n})
168
165
  @Component({
169
- ${directiveOpts.join(',\n ')}
166
+ selector: '${tagName}',
167
+ template: '<ng-content></ng-content>',
168
+ changeDetection: ChangeDetectionStrategy.OnPush,
169
+ // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
170
+ inputs: [${formattedInputs}],
170
171
  })
171
- export class ${tagNameAsPascal} {`,
172
- ];
173
- lines.push(' protected el: HTMLElement;');
174
- lines.push(` constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
172
+ export class ${tagNameAsPascal} {
173
+ protected el: HTMLElement;
174
+ constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {
175
175
  c.detach();
176
- this.el = r.nativeElement;`);
177
- if (hasOutputs) {
178
- lines.push(` proxyOutputs(this, this.el, ['${outputs.map((output) => output.name).join(`', '`)}']);`);
176
+ this.el = r.nativeElement;${hasOutputs
177
+ ? `
178
+ proxyOutputs(this, this.el, [${formattedOutputs}]);`
179
+ : ''}
180
+ }
181
+ }`;
182
+ return output;
183
+ };
184
+ /**
185
+ * Sanitizes and formats the component event type.
186
+ * @param componentClassName The class name of the component (e.g. 'MyComponent')
187
+ * @param event The Stencil component event.
188
+ * @returns The sanitized event type as a string.
189
+ */
190
+ const formatOutputType = (componentClassName, event) => {
191
+ /**
192
+ * The original attribute contains the original type defined by the devs.
193
+ * This regexp normalizes the reference, by removing linebreaks,
194
+ * replacing consecutive spaces with a single space, and adding a single space after commas.
195
+ */
196
+ return Object.entries(event.complexType.references)
197
+ .filter(([_, refObject]) => refObject.location === 'local' || refObject.location === 'import')
198
+ .reduce((type, [src, dst]) => {
199
+ const renamedType = `I${componentClassName}${type}`;
200
+ return renamedType
201
+ .replace(new RegExp(`^${src}$`, 'g'), `${dst}`)
202
+ .replace(new RegExp(`([^\\w])${src}([^\\w])`, 'g'), (v, p1, p2) => [p1, dst, p2].join(''));
203
+ }, event.complexType.original
204
+ .replace(/\n/g, ' ')
205
+ .replace(/\s{2,}/g, ' ')
206
+ .replace(/,\s*/g, ', '));
207
+ };
208
+ /**
209
+ * Creates a formatted comment block based on the JS doc comment.
210
+ * @param doc The compiler jsdoc.
211
+ * @returns The formatted comment block as a string.
212
+ */
213
+ const createDocComment = (doc) => {
214
+ if (doc.text.trim().length === 0 && doc.tags.length === 0) {
215
+ return '';
179
216
  }
180
- lines.push(` }`);
181
- lines.push(`}`);
182
- return lines.join('\n');
217
+ return `/**
218
+ * ${doc.text}${doc.tags.length > 0 ? ' ' : ''}${doc.tags.map((tag) => `@${tag.name} ${tag.text}`)}
219
+ */`;
220
+ };
221
+ /**
222
+ * Creates the component interface type definition.
223
+ * @param tagNameAsPascal The tag name as PascalCase.
224
+ * @param events The events to generate the interface properties for.
225
+ * @param componentCorePackage The component core package.
226
+ * @param includeImportCustomElements Whether to include the import for the custom element definition.
227
+ * @param customElementsDir The custom elements directory.
228
+ * @returns The component interface type definition as a string.
229
+ */
230
+ const createComponentTypeDefinition = (tagNameAsPascal, events, componentCorePackage, includeImportCustomElements = false, customElementsDir) => {
231
+ const typeDefinition = `${createComponentEventTypeImports(tagNameAsPascal, events, {
232
+ componentCorePackage,
233
+ includeImportCustomElements,
234
+ customElementsDir,
235
+ })}
236
+
237
+ export interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {
238
+ ${events
239
+ .map((event) => {
240
+ const comment = createDocComment(event.docs);
241
+ return `${comment.length > 0 ? ` ${comment}` : ''}
242
+ ${event.name}: EventEmitter<CustomEvent<${formatOutputType(tagNameAsPascal, event)}>>;`;
243
+ })
244
+ .join('\n')}
245
+ }`;
246
+ return typeDefinition;
183
247
  };
184
- function getProxyCmp(tagName, includeCustomElement, inputs, methods) {
185
- const hasInputs = inputs.length > 0;
186
- const hasMethods = methods.length > 0;
187
- const proxMeta = [
188
- `defineCustomElementFn: ${includeCustomElement ? 'define' + dashToPascalCase(tagName) : 'undefined'}`
189
- ];
190
- if (hasInputs)
191
- proxMeta.push(`inputs: ['${inputs.join(`', '`)}']`);
192
- if (hasMethods)
193
- proxMeta.push(`methods: ['${methods.join(`', '`)}']`);
194
- return `@ProxyCmp({\n ${proxMeta.join(',\n ')}\n})`;
195
- }
196
248
 
197
249
  function generateAngularDirectivesFile(compilerCtx, components, outputTarget) {
198
250
  // Only create the file if it is defined in the stencil configuration
199
251
  if (!outputTarget.directivesArrayFile) {
200
252
  return Promise.resolve();
201
253
  }
202
- const proxyPath = relativeImport(outputTarget.directivesArrayFile, outputTarget.directivesProxyFile, '.ts');
254
+ const proxyPath = relativeImport(outputTarget.directivesArrayFile, outputTarget.proxyDeclarationFile, '.ts');
203
255
  const directives = components
204
256
  .map((cmpMeta) => dashToPascalCase(cmpMeta.tagName))
205
257
  .map((className) => `d.${className}`)
@@ -215,15 +267,12 @@ export const DIRECTIVES = [
215
267
  }
216
268
 
217
269
  async function generateValueAccessors(compilerCtx, components, outputTarget, config) {
218
- if (!Array.isArray(outputTarget.valueAccessorConfigs) ||
219
- outputTarget.valueAccessorConfigs.length === 0) {
270
+ if (!Array.isArray(outputTarget.valueAccessorConfigs) || outputTarget.valueAccessorConfigs.length === 0) {
220
271
  return;
221
272
  }
222
- const targetDir = path.dirname(outputTarget.directivesProxyFile);
273
+ const targetDir = path.dirname(outputTarget.proxyDeclarationFile);
223
274
  const normalizedValueAccessors = outputTarget.valueAccessorConfigs.reduce((allAccessors, va) => {
224
- const elementSelectors = Array.isArray(va.elementSelectors)
225
- ? va.elementSelectors
226
- : [va.elementSelectors];
275
+ const elementSelectors = Array.isArray(va.elementSelectors) ? va.elementSelectors : [va.elementSelectors];
227
276
  const type = va.type;
228
277
  let allElementSelectors = [];
229
278
  let allEventTargets = [];
@@ -272,13 +321,30 @@ const VALUE_ACCESSOR_EVENT = `<VALUE_ACCESSOR_EVENT>`;
272
321
  const VALUE_ACCESSOR_TARGETATTR = '<VALUE_ACCESSOR_TARGETATTR>';
273
322
  const VALUE_ACCESSOR_EVENTTARGETS = ` '(<VALUE_ACCESSOR_EVENT>)': 'handleChangeEvent($event.target.<VALUE_ACCESSOR_TARGETATTR>)'`;
274
323
 
324
+ /**
325
+ * Creates an Angular module declaration for a component wrapper.
326
+ * @param componentTagName The tag name of the Stencil component.
327
+ * @returns The Angular module declaration as a string.
328
+ */
329
+ const generateAngularModuleForComponent = (componentTagName) => {
330
+ const tagNameAsPascal = dashToPascalCase(componentTagName);
331
+ const componentClassName = `${tagNameAsPascal}`;
332
+ const moduleClassName = `${tagNameAsPascal}Module`;
333
+ const moduleDefinition = `@NgModule({
334
+ declarations: [${componentClassName}],
335
+ exports: [${componentClassName}]
336
+ })
337
+ export class ${moduleClassName} { }`;
338
+ return moduleDefinition;
339
+ };
340
+
275
341
  async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
276
342
  const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
277
343
  const rootDir = config.rootDir;
278
344
  const pkgData = await readPackageJson(config, rootDir);
279
345
  const finalText = generateProxies(filteredComponents, pkgData, outputTarget, config.rootDir);
280
346
  await Promise.all([
281
- compilerCtx.fs.writeFile(outputTarget.directivesProxyFile, finalText),
347
+ compilerCtx.fs.writeFile(outputTarget.proxyDeclarationFile, finalText),
282
348
  copyResources$1(config, outputTarget),
283
349
  generateAngularDirectivesFile(compilerCtx, filteredComponents, outputTarget),
284
350
  generateValueAccessors(compilerCtx, filteredComponents, outputTarget, config),
@@ -292,7 +358,7 @@ async function copyResources$1(config, outputTarget) {
292
358
  throw new Error('stencil is not properly initialized at this step. Notify the developer');
293
359
  }
294
360
  const srcDirectory = path.join(__dirname, '..', 'angular-component-lib');
295
- const destDirectory = path.join(path.dirname(outputTarget.directivesProxyFile), 'angular-component-lib');
361
+ const destDirectory = path.join(path.dirname(outputTarget.proxyDeclarationFile), 'angular-component-lib');
296
362
  return config.sys.copy([
297
363
  {
298
364
  src: srcDirectory,
@@ -303,14 +369,34 @@ async function copyResources$1(config, outputTarget) {
303
369
  ], srcDirectory);
304
370
  }
305
371
  function generateProxies(components, pkgData, outputTarget, rootDir) {
372
+ var _a;
306
373
  const distTypesDir = path.dirname(pkgData.types);
307
374
  const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
308
- const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
375
+ const componentsTypeFile = relativeImport(outputTarget.proxyDeclarationFile, dtsFilePath, '.d.ts');
376
+ const createSingleComponentAngularModules = (_a = outputTarget.createSingleComponentAngularModules) !== null && _a !== void 0 ? _a : false;
377
+ /**
378
+ * The collection of named imports from @angular/core.
379
+ */
380
+ const angularCoreImports = [
381
+ 'ChangeDetectionStrategy',
382
+ 'ChangeDetectorRef',
383
+ 'Component',
384
+ 'ElementRef',
385
+ 'EventEmitter',
386
+ 'NgZone',
387
+ ];
388
+ /**
389
+ * The collection of named imports from the angular-component-lib/utils.
390
+ */
391
+ const componentLibImports = ['ProxyCmp', 'proxyOutputs'];
392
+ if (createSingleComponentAngularModules) {
393
+ angularCoreImports.push('NgModule');
394
+ }
309
395
  const imports = `/* tslint:disable */
310
396
  /* auto-generated angular directive proxies */
311
- import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
312
- import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
313
- const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
397
+ ${createImportStatement(angularCoreImports, '@angular/core')}
398
+
399
+ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}\n`;
314
400
  /**
315
401
  * Generate JSX import type from correct location.
316
402
  * When using custom elements build, we need to import from
@@ -318,21 +404,15 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
318
404
  * otherwise we risk bundlers pulling in lazy loaded imports.
319
405
  */
320
406
  const generateTypeImports = () => {
407
+ let importLocation = outputTarget.componentCorePackage
408
+ ? normalizePath(outputTarget.componentCorePackage)
409
+ : normalizePath(componentsTypeFile);
410
+ importLocation += outputTarget.includeImportCustomElements
411
+ ? `/${outputTarget.customElementsDir || 'components'}`
412
+ : '';
321
413
  return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
322
414
  };
323
- /**
324
- * Components that have custom events have uniquely generated interfaces as of
325
- * Stencil 2.16.0. We import these interfaces so they can be used in the generate
326
- * functions for the @Output() events.
327
- */
328
- const customEventInterfaces = components.filter(c => c.events.filter(e => !e.internal).length > 0).map(c => {
329
- return formatCustomEventInterfaceName(c.tagName);
330
- });
331
- const customEventImports = `import type { ${customEventInterfaces.join(', ')} } from '${importLocation}';\n`;
332
- const typeImports = [
333
- generateTypeImports(),
334
- customEventImports,
335
- ];
415
+ const typeImports = generateTypeImports();
336
416
  let sourceImports = '';
337
417
  /**
338
418
  * Build an array of Custom Elements build imports and namespace them
@@ -341,31 +421,54 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
341
421
  * IonButton React Component that takes in the Web Component as a parameter.
342
422
  */
343
423
  if (outputTarget.includeImportCustomElements && outputTarget.componentCorePackage !== undefined) {
344
- const cmpImports = components.map(component => {
424
+ const cmpImports = components.map((component) => {
345
425
  const pascalImport = dashToPascalCase(component.tagName);
346
- return `import { defineCustomElement as define${pascalImport} } from '${normalizePath(outputTarget.componentCorePackage)}/${outputTarget.customElementsDir ||
347
- 'components'}/${component.tagName}.js';`;
426
+ return `import { defineCustomElement as define${pascalImport} } from '${normalizePath(outputTarget.componentCorePackage)}/${outputTarget.customElementsDir || 'components'}/${component.tagName}.js';`;
348
427
  });
349
428
  sourceImports = cmpImports.join('\n');
350
429
  }
351
- const final = [
352
- imports,
353
- typeImports.join('\n'),
354
- sourceImports,
355
- components
356
- .map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
357
- .join('\n'),
358
- ];
430
+ if (createSingleComponentAngularModules) {
431
+ // Generating Angular modules is only supported in the dist-custom-elements build
432
+ if (!outputTarget.includeImportCustomElements) {
433
+ throw new Error('Generating single component Angular modules requires the "includeImportCustomElements" option to be set to true.');
434
+ }
435
+ }
436
+ const proxyFileOutput = [];
437
+ const filterInternalProps = (prop) => !prop.internal;
438
+ const mapPropName = (prop) => prop.name;
439
+ const { includeImportCustomElements, componentCorePackage, customElementsDir } = outputTarget;
440
+ for (let cmpMeta of components) {
441
+ const tagNameAsPascal = dashToPascalCase(cmpMeta.tagName);
442
+ const inputs = [];
443
+ if (cmpMeta.properties) {
444
+ inputs.push(...cmpMeta.properties.filter(filterInternalProps).map(mapPropName));
445
+ }
446
+ if (cmpMeta.virtualProperties) {
447
+ inputs.push(...cmpMeta.virtualProperties.map(mapPropName));
448
+ }
449
+ inputs.sort();
450
+ const outputs = [];
451
+ if (cmpMeta.events) {
452
+ outputs.push(...cmpMeta.events.filter(filterInternalProps).map(mapPropName));
453
+ }
454
+ const methods = [];
455
+ if (cmpMeta.methods) {
456
+ methods.push(...cmpMeta.methods.filter(filterInternalProps).map(mapPropName));
457
+ }
458
+ /**
459
+ * For each component, we need to generate:
460
+ * 1. The @Component decorated class
461
+ * 2. Optionally the @NgModule decorated class (if createSingleComponentAngularModules is true)
462
+ * 3. The component interface (using declaration merging for types).
463
+ */
464
+ const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, inputs, outputs, methods, includeImportCustomElements);
465
+ const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
466
+ const componentTypeDefinition = createComponentTypeDefinition(tagNameAsPascal, cmpMeta.events, componentCorePackage, includeImportCustomElements, customElementsDir);
467
+ proxyFileOutput.push(componentDefinition, '\n', createSingleComponentAngularModules ? moduleDefinition : '', '\n', componentTypeDefinition, '\n');
468
+ }
469
+ const final = [imports, typeImports, sourceImports, ...proxyFileOutput];
359
470
  return final.join('\n') + '\n';
360
471
  }
361
- /**
362
- * Returns the path to import the file from.
363
- */
364
- const getImportPackageName = (outputTarget, componentsTypeFile) => {
365
- let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
366
- importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
367
- return importLocation;
368
- };
369
472
  const GENERATED_DTS = 'components.d.ts';
370
473
  const IMPORT_TYPES = 'Components';
371
474
 
@@ -382,15 +485,18 @@ const angularOutputTarget = (outputTarget) => ({
382
485
  },
383
486
  });
384
487
  function normalizeOutputTarget(config, outputTarget) {
385
- const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], valueAccessorConfig: outputTarget.valueAccessorConfig || [] });
488
+ const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], valueAccessorConfigs: outputTarget.valueAccessorConfigs || [] });
386
489
  if (config.rootDir == null) {
387
490
  throw new Error('rootDir is not set and it should be set by stencil itself');
388
491
  }
389
- if (outputTarget.directivesProxyFile == null) {
390
- throw new Error('directivesProxyFile is required');
492
+ if (outputTarget.directivesProxyFile !== undefined) {
493
+ throw new Error('directivesProxyFile has been removed. Use proxyDeclarationFile instead.');
494
+ }
495
+ if (outputTarget.proxyDeclarationFile == null) {
496
+ throw new Error('proxyDeclarationFile is required. Please set it in the Stencil config.');
391
497
  }
392
- if (outputTarget.directivesProxyFile && !path.isAbsolute(outputTarget.directivesProxyFile)) {
393
- results.directivesProxyFile = normalizePath(path.join(config.rootDir, outputTarget.directivesProxyFile));
498
+ if (outputTarget.proxyDeclarationFile && !path.isAbsolute(outputTarget.proxyDeclarationFile)) {
499
+ results.proxyDeclarationFile = normalizePath(path.join(config.rootDir, outputTarget.proxyDeclarationFile));
394
500
  }
395
501
  if (outputTarget.directivesArrayFile && !path.isAbsolute(outputTarget.directivesArrayFile)) {
396
502
  results.directivesArrayFile = normalizePath(path.join(config.rootDir, outputTarget.directivesArrayFile));