@stencil/angular-output-target 0.4.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/types.d.ts CHANGED
@@ -1,12 +1,25 @@
1
1
  export interface OutputTargetAngular {
2
- componentCorePackage?: string;
2
+ /**
3
+ * The package name of the component library.
4
+ * This is used to generate the import statements.
5
+ */
6
+ componentCorePackage: string;
7
+ /**
8
+ * The path to the proxy file that will be generated. This can be an absolute path
9
+ * or a relative path from the root directory of the Stencil library.
10
+ */
3
11
  directivesProxyFile: string;
4
12
  directivesArrayFile?: string;
5
- directivesUtilsFile?: string;
6
13
  valueAccessorConfigs?: ValueAccessorConfig[];
7
14
  excludeComponents?: string[];
8
15
  includeImportCustomElements?: boolean;
9
16
  customElementsDir?: string;
17
+ /**
18
+ * @experimental
19
+ *
20
+ * `true` to generate a single component Angular module for each component.
21
+ */
22
+ includeSingleComponentAngularModules?: boolean;
10
23
  }
11
24
  export declare type ValueAccessorTypes = 'text' | 'radio' | 'select' | 'number' | 'boolean';
12
25
  export interface ValueAccessorConfig {
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Config } from '@stencil/core/internal';
1
+ import { ComponentCompilerEvent, Config } from '@stencil/core/internal';
2
2
  import type { PackageJSON } from './types';
3
3
  export declare const toLowerCase: (str: string) => string;
4
4
  export declare const dashToPascalCase: (str: string) => string;
@@ -7,3 +7,29 @@ export declare function normalizePath(str: string): string;
7
7
  export declare function relativeImport(pathFrom: string, pathTo: string, ext?: string): string;
8
8
  export declare function isRelativePath(path: string): boolean | "";
9
9
  export declare function readPackageJson(config: Config, rootDir: string): Promise<PackageJSON>;
10
+ /**
11
+ * Formats an array of strings to a string of quoted, comma separated values.
12
+ * @param list The list of unformatted strings to format
13
+ * @returns The formatted array of strings. (e.g. ['foo', 'bar']) => `'foo', 'bar'`
14
+ */
15
+ export declare const formatToQuotedList: (list: readonly string[]) => string;
16
+ /**
17
+ * Creates an import statement for a list of named imports from a module.
18
+ * @param imports The list of named imports.
19
+ * @param module The module to import from.
20
+ *
21
+ * @returns The import statement as a string.
22
+ */
23
+ export declare const createImportStatement: (imports: string[], module: string) => string;
24
+ /**
25
+ * Creates the collection of import statements for a component based on the component's events type dependencies.
26
+ * @param componentTagName The tag name of the component (pascal case).
27
+ * @param events The events compiler metadata.
28
+ * @param options The options for generating the import statements (e.g. whether to import from the custom elements directory).
29
+ * @returns The import statements as an array of strings.
30
+ */
31
+ export declare const createComponentEventTypeImports: (componentTagName: string, events: readonly ComponentCompilerEvent[], options: {
32
+ componentCorePackage: string;
33
+ includeImportCustomElements?: boolean;
34
+ customElementsDir?: string;
35
+ }) => string;
package/dist/utils.js CHANGED
@@ -74,6 +74,51 @@ export async function readPackageJson(config, rootDir) {
74
74
  }
75
75
  return pkgData;
76
76
  }
77
+ /**
78
+ * Formats an array of strings to a string of quoted, comma separated values.
79
+ * @param list The list of unformatted strings to format
80
+ * @returns The formatted array of strings. (e.g. ['foo', 'bar']) => `'foo', 'bar'`
81
+ */
82
+ export const formatToQuotedList = (list) => list.map((item) => `'${item}'`).join(', ');
83
+ /**
84
+ * Creates an import statement for a list of named imports from a module.
85
+ * @param imports The list of named imports.
86
+ * @param module The module to import from.
87
+ *
88
+ * @returns The import statement as a string.
89
+ */
90
+ export const createImportStatement = (imports, module) => {
91
+ if (imports.length === 0) {
92
+ return '';
93
+ }
94
+ return `import { ${imports.join(', ')} } from '${module}';`;
95
+ };
96
+ /**
97
+ * Creates the collection of import statements for a component based on the component's events type dependencies.
98
+ * @param componentTagName The tag name of the component (pascal case).
99
+ * @param events The events compiler metadata.
100
+ * @param options The options for generating the import statements (e.g. whether to import from the custom elements directory).
101
+ * @returns The import statements as an array of strings.
102
+ */
103
+ export const createComponentEventTypeImports = (componentTagName, events, options) => {
104
+ const { componentCorePackage, includeImportCustomElements, customElementsDir } = options;
105
+ const imports = [];
106
+ const namedImports = new Set();
107
+ const importPathName = normalizePath(componentCorePackage) + (includeImportCustomElements ? `/${customElementsDir || 'components'}` : '');
108
+ events.forEach((event) => {
109
+ Object.entries(event.complexType.references).forEach(([typeName, refObject]) => {
110
+ if (refObject.location === 'local' || refObject.location === 'import') {
111
+ const newTypeName = `I${componentTagName}${typeName}`;
112
+ // Prevents duplicate imports for the same type.
113
+ if (!namedImports.has(newTypeName)) {
114
+ imports.push(`import type { ${typeName} as ${newTypeName} } from '${importPathName}';`);
115
+ namedImports.add(newTypeName);
116
+ }
117
+ }
118
+ });
119
+ });
120
+ return imports.join('\n');
121
+ };
77
122
  const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
78
123
  const NON_ASCII_REGEX = /[^\x00-\x80]+/;
79
124
  const SLASH_REGEX = /\\/g;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/angular-output-target",
3
- "version": "0.4.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",
@@ -14,11 +14,15 @@
14
14
  "access": "public"
15
15
  },
16
16
  "scripts": {
17
+ "prepublishOnly": "npm run build",
17
18
  "prebuild": "rimraf ./dist && npm run test",
18
19
  "build": "tsc && npm run rollup",
19
20
  "watch": "tsc --watch",
20
21
  "rollup": "rollup -c",
21
22
  "version": "npm run build",
23
+ "prettier": "npm run prettier.base -- --write",
24
+ "prettier.base": "prettier \"./({angular-component-lib,src,test,__tests__}/**/*.{ts,tsx,js,jsx})|*.{ts,tsx,js,jsx}\"",
25
+ "prettier.dry-run": "npm run prettier.base -- --list-different",
22
26
  "release": "np",
23
27
  "test": "jest --passWithNoTests",
24
28
  "test.watch": "jest --watch"
@@ -38,7 +42,7 @@
38
42
  "@angular/forms": "8.2.14"
39
43
  },
40
44
  "peerDependencies": {
41
- "@stencil/core": "^2.9.0"
45
+ "@stencil/core": "^2.9.0 || ^3.0.0"
42
46
  },
43
47
  "jest": {
44
48
  "transform": {