Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transformTagName compatibility #59

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: CI
on: push

jobs:
build-and-test-nix:
name: Build and Test
build-and-test-unix:
name: Build and Test Unix
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Test
run: npm test
plugin-build-and-test-windows:
name: Build and Test
name: Build and Test Windows
runs-on: windows-latest
timeout-minutes: 30
steps:
Expand Down
10 changes: 4 additions & 6 deletions packages/angular-output-target/__tests__/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ describe('normalizeOutputTarget', () => {
const results: OutputTargetAngular = normalizeOutputTarget(config, {
directivesProxyFile: '/component-library-angular/src/components.ts',
});

expect(results).toEqual({
directivesProxyFile: '/component-library-angular/src/components.ts',
excludeComponents: [],
valueAccessorConfig: [],
} as OutputTargetAngular);
expect(results.directivesProxyFile).toEqual('/component-library-angular/src/components.ts');
expect(results.excludeComponents).toEqual([]);
expect(results.valueAccessorConfigs).toEqual([]);
expect(typeof results.tagNameModifier).toBe('function');
});
});
2 changes: 1 addition & 1 deletion packages/angular-output-target/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/angular-output-target/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@stencil/angular-output-target",
"version": "0.0.3",
"version": "0.0.4",
"description": "This is an output plugin for stencil.",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/",
"resources/"
"resources/",
"angular-component-lib"
],
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import path from 'path';

import { dashToPascalCase, normalizePath } from './utils';
import { ComponentCompilerMeta } from '@stencil/core/internal';
import { TagNameModifier } from './types';

export const createComponentDefinition = (
componentCorePackage: string,
distTypesDir: string,
rootDir: string,
tagNameModifier: TagNameModifier,
) => (cmpMeta: ComponentCompilerMeta) => {
// Collect component meta
const inputs = [
Expand All @@ -21,7 +23,7 @@ export const createComponentDefinition = (

// Generate Angular @Directive
const directiveOpts = [
`selector: \'${cmpMeta.tagName}\'`,
`selector: \'${tagNameModifier(cmpMeta.tagName)}\'`,
`changeDetection: ChangeDetectionStrategy.OnPush`,
`template: '<ng-content></ng-content>'`,
];
Expand Down
13 changes: 10 additions & 3 deletions packages/angular-output-target/src/output-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import generateValueAccessors from './generate-value-accessors';

export async function angularDirectiveProxyOutput(
compilerCtx: CompilerCtx,
outputTarget: OutputTargetAngular,
outputTarget: Required<OutputTargetAngular>,
components: ComponentCompilerMeta[],
config: Config,
) {
Expand Down Expand Up @@ -63,7 +63,7 @@ async function copyResources(config: Config, outputTarget: OutputTargetAngular)
export function generateProxies(
components: ComponentCompilerMeta[],
pkgData: PackageJSON,
outputTarget: OutputTargetAngular,
outputTarget: Required<OutputTargetAngular>,
rootDir: string,
) {
const distTypesDir = path.dirname(pkgData.types);
Expand All @@ -83,7 +83,14 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
imports,
typeImports,
components
.map(createComponentDefinition(outputTarget.componentCorePackage!, distTypesDir, rootDir))
.map(
createComponentDefinition(
outputTarget.componentCorePackage!,
distTypesDir,
rootDir,
outputTarget.tagNameModifier,
),
)
.join('\n'),
];

Expand Down
13 changes: 11 additions & 2 deletions packages/angular-output-target/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ export const angularOutputTarget = (outputTarget: OutputTargetAngular): OutputTa
return normalizeOutputTarget(config, outputTarget);
},
async generator(config, compilerCtx, buildCtx) {
const normalizedOutputTarget = normalizeOutputTarget(config, outputTarget) as Required<
OutputTargetAngular
>;
const timespan = buildCtx.createTimeSpan(`generate angular proxies started`, true);

await angularDirectiveProxyOutput(compilerCtx, outputTarget, buildCtx.components, config);
await angularDirectiveProxyOutput(
compilerCtx,
normalizedOutputTarget,
buildCtx.components,
config,
);

timespan.finish(`generate angular proxies finished`);
},
Expand All @@ -23,7 +31,8 @@ export function normalizeOutputTarget(config: Config, outputTarget: any) {
const results: OutputTargetAngular = {
...outputTarget,
excludeComponents: outputTarget.excludeComponents || [],
valueAccessorConfig: outputTarget.valueAccessorConfig || [],
valueAccessorConfigs: outputTarget.valueAccessorConfigs || [],
tagNameModifier: outputTarget.tagNameModifier ?? ((tagName: string) => tagName),
};

if (config.rootDir == null) {
Expand Down
4 changes: 4 additions & 0 deletions packages/angular-output-target/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ export interface OutputTargetAngular {
directivesUtilsFile?: string;
valueAccessorConfigs?: ValueAccessorConfig[];
excludeComponents?: string[];
// @deprecated
tagNameModifier?: TagNameModifier;
}

export type ValueAccessorTypes = 'text' | 'radio' | 'select' | 'number' | 'boolean';

export type TagNameModifier = (tagName: string) => string;

export interface ValueAccessorConfig {
elementSelectors: string | string[];
event: string;
Expand Down
Loading