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

Feature/ticket 1159 nxext stencil vue integration #1160

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: '🐞 Bug Report'
about: Create a report to help us improve
title: 'Stencil | Svelte | Sveltekit | Solid | Vite | Vitest | React | Angular: <your title>'
title: 'Stencil | Svelte | Sveltekit | Solid | Vite | Vitest | Vue | React | Angular: <your title>'
labels: bug
assignees: ''
---
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/documentation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: '📄 Documentation'
about: Suggest an idea for the docs
title: 'Stencil | Svelte | Sveltekit | Solid | Vite | Vitest | React | Angular: <your title>'
title: 'Stencil | Svelte | Sveltekit | Solid | Vite | Vitest | Vue | React | Angular: <your title>'
labels: documentation
assignees: ''
---
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: "\U0001F680 Feature Request"
about: Suggest an idea for this project
title: 'Stencil | Svelte | Sveltekit | Solid | Vite | Vitest | React | Angular: <your title>'
title: 'Stencil | Svelte | Sveltekit | Solid | Vite | Vitest | Vue | React | Angular: <your title>'
labels: feature request
assignees: ''
---
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/guides.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: '⚙️ Guides'
about: Suggest an idea for the guides
title: 'Stencil | Svelte | Sveltekit | Solid | Vite | Vitest | React | Angular: <your title>'
title: 'Stencil | Svelte | Sveltekit | Solid | Vite | Vitest | Vue | React | Angular: <your title>'
labels: guides
assignees: ''
---
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/stencil/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Type: `boolean`

## @nxext/stencil:add-outputtarget

Add react/angular libraries for the component library
Add react/angular/vue libraries for the component library

### Usage

Expand Down Expand Up @@ -314,7 +314,7 @@ nx g add-outputtarget ... --dry-run

Type: `string`

Possible values: `angular`, `react`, `svelte`
Possible values: `angular`, `react`, `svelte`, `vue`

Select what kind of library you want to generate.

Expand Down
15 changes: 15 additions & 0 deletions e2e/stencil-e2e/tests/library.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ describe('library e2e', () => {
).not.toThrow();
});

it(`should generate vue lib`, async () => {
const plugin = uniq('lib');
await runNxCommandAsync(
`generate @nxext/stencil:lib ${plugin} --style='css' --buildable --e2eTestRunner='none' --junitTestRunner='none'`
);
await runNxCommandAsync(
`generate @nxext/stencil:add-outputtarget ${plugin} --outputType=vue`
);
await runNxCommandAsync(`build ${plugin}`);

expect(() =>
checkFilesExist(`libs/${plugin}-vue/src/index.ts`)
).not.toThrow();
});

it(`should generate angular lib`, async () => {
const plugin = uniq('lib');
await runNxCommandAsync(
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@nx/playwright": "20.0.0",
"@nx/plugin": "20.0.0",
"@nx/react": "20.0.0",
"@nx/vue": "20.0.0",
"@nx/storybook": "20.0.0",
"@nx/vite": "20.0.0",
"@nx/web": "20.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/stencil/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ nx storybook my-lib

_The Storybook startup needs an successful `nx build` cause of the generated loaders to work_

## React and Angular
## React, Angular and Vue

You're able to generate angular/react libraries for yout stencil libraries using stencils outputtargets:
You're able to generate angular/react/vue libraries for yout stencil libraries using stencils outputtargets:

```
nx g @nxext/stencil:add-outputtarget my-lib
```

With the `--outputType='react'` or `--outputType='angular'` you can define the kind of library.
With the `--outputType='react'` or `--outputType='angular'` or `--outputType='vue'` you can define the kind of library.
2 changes: 1 addition & 1 deletion packages/stencil/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"add-outputtarget": {
"factory": "./src/generators/add-outputtarget/add-outputtarget",
"schema": "./src/generators/add-outputtarget/schema.json",
"description": "Add react/angular libraries for the component library"
"description": "Add react/angular/vue libraries for the component library"
},
"add-outputtarget/add-angular": {
"factory": "./src/generators/add-outputtarget/add-angular/generator",
Expand Down
6 changes: 5 additions & 1 deletion packages/stencil/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"nx": "^20.0.0",
"fs-extra": "^10.1.0",
"@nx/angular": "^20.0.0",
"@nx/react": "^20.0.0"
"@nx/react": "^20.0.0",
"@nx/vue": "^20.0.0"
},
"peerDependencies": {},
"peerDependenciesMeta": {
Expand All @@ -55,6 +56,9 @@
"@nx/react": {
"optional": true
},
"@nx/vue": {
"optional": true
},
"@nx/angular": {
"optional": true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { createTestUILib } from '../../utils/testing';
import { uniq } from '@nx/plugin/testing';
import { Tree } from '@nx/devkit';
import { outputtargetGenerator } from './add-outputtarget';
import { AddOutputtargetSchematicSchema } from './schema';

xdescribe('add-outputtarget vue', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be skipped.

let tree: Tree;
const projectName = uniq('testprojekt');
const projectAppDirectory = `apps/${projectName}`;
const projectLibDirectory = `libs/${projectName}`;
const options = {
projectName: projectName,
publishable: false,
skipFormat: false,
};

beforeEach(async () => {
tree = await createTestUILib(projectLibDirectory);
});

describe('using vue', () => {
const vueOptions: AddOutputtargetSchematicSchema = {
...options,
unitTestRunner: 'none',
outputType: 'vue',
};

it('should not generate default vue library', async () => {
await outputtargetGenerator(tree, vueOptions);

expect(
tree.exists(`libs/${projectName}-vue/src/lib/${projectName}-vue.tsx`)
).toBeFalsy();
expect(
tree.exists(
`libs/${projectName}-vue/src/lib/${projectName}-vue.spec.tsx`
)
).toBeFalsy();
expect(
tree.exists(`libs/${projectName}-vue/src/lib/${projectName}-vue.css`)
).toBeFalsy();

const indexFile: Buffer = tree.read(
`libs/${projectName}-vue/src/index.ts`
);
expect(indexFile.toString()).toMatch(
`export * from './generated/components';`
);
});

it('should add vueOutputTarget', async () => {
await outputtargetGenerator(tree, vueOptions);

expect(
tree
.read(`libs/${projectName}/stencil.config.ts`)
.includes(
`import { vueOutputTarget } from '@stencil/vue-output-target';`
)
).toBeTruthy();

expect(
tree
.read(`libs/${projectName}/stencil.config.ts`)
.includes(`vueOutputTarget({`)
).toBeTruthy();
});

it('should be able to generate a publishable lib', async () => {
await outputtargetGenerator(tree, {
...vueOptions,
publishable: true,
importPath: '@proj/mylib',
});

expect(tree.exists(`libs/${projectName}/package.json`)).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { isBuildableStencilProject } from '../../utils/utillities';
import { AddOutputtargetSchematicSchema } from './schema';
import { addAngularGenerator } from './add-angular/generator';
import { addReactGenerator } from './add-react/generator';
import addVueGenerator from './add-vue/generator';
import { assertNotUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';

export async function outputtargetGenerator(
Expand All @@ -30,6 +31,10 @@ export async function outputtargetGenerator(
tasks.push(await addReactGenerator(host, options));
}

if (options.outputType === 'vue') {
tasks.push(await addVueGenerator(host, options));
}

if (!options.skipFormat) {
await formatFiles(host);
}
Expand Down
123 changes: 123 additions & 0 deletions packages/stencil/src/generators/add-outputtarget/add-vue/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import {
addDependenciesToPackageJson,
applyChangesToString,
ensurePackage,
getWorkspaceLayout,
NX_VERSION,
readProjectConfiguration,
runTasksInSerial,
Tree,
} from '@nx/devkit';
import { initGenerator as jsInitGenerator } from '@nx/js';
import { AddOutputtargetSchematicSchema } from '../schema';
import { Linter } from '@nx/eslint';
import { STENCIL_OUTPUTTARGET_VERSION } from '../../../utils/versions';
import * as ts from 'typescript';
import { getDistDir, getRelativePath } from '../../../utils/fileutils';
import { addImport } from '@nxext/common';
import { addOutputTarget } from '../../../stencil-core-utils';
import { calculateStencilSourceOptions } from '../lib/calculate-stencil-source-options';

async function prepareVueLibrary(
host: Tree,
options: AddOutputtargetSchematicSchema
) {
const { libsDir } = getWorkspaceLayout(host);
const vueProjectName = `${options.projectName}-vue`;
const vueProjectDir = `libs/${vueProjectName}`;

const jsInitTask = await jsInitGenerator(host, {
...options,
tsConfigName: 'tsconfig.base.json',
skipFormat: true,
});

ensurePackage('@nx/vue', NX_VERSION);
const { libraryGenerator } = await import('@nx/vue');
const libraryTarget = await libraryGenerator(host, {
directory: vueProjectDir,
publishable: options.publishable,
bundler: options.publishable ? 'vite' : 'none',
importPath: options.importPath,
component: false,
skipTsConfig: false,
skipFormat: true,
unitTestRunner: 'vitest',
linter: Linter.EsLint,
});

await addDependenciesToPackageJson(
host,
{},
{
'@stencil/vue-output-target': STENCIL_OUTPUTTARGET_VERSION['vue'],
}
);

host.write(
`${libsDir}/${vueProjectName}/src/index.ts`,
`export * from './generated/components';`
);

return runTasksInSerial(jsInitTask, libraryTarget);
}

function addVueOutputtarget(
tree: Tree,
projectName: string,
stencilProjectConfig,
stencilConfigPath: string,
stencilConfigSource: ts.SourceFile,
packageName: string
) {
const vueProjectConfig = readProjectConfiguration(tree, `${projectName}-vue`);
const realtivePath = getRelativePath(
getDistDir(stencilProjectConfig.root),
vueProjectConfig.root
);

const changes = applyChangesToString(stencilConfigSource.text, [
...addImport(
stencilConfigSource,
`import { vueOutputTarget } from '@stencil/vue-output-target';`
),
...addOutputTarget(
stencilConfigSource,
`
vueOutputTarget({
componentCorePackage: '${packageName}',
proxiesFile: '${realtivePath}/src/generated/components.ts',
includeDefineCustomElements: true,
})
`
),
]);
tree.write(stencilConfigPath, changes);
}

export async function addVueGenerator(
host: Tree,
options: AddOutputtargetSchematicSchema
) {
const libraryTarget = await prepareVueLibrary(host, options);

const {
stencilProjectConfig,
stencilConfigPath,
stencilConfigSource,
packageName,
} = calculateStencilSourceOptions(host, options.projectName);

addVueOutputtarget(
host,
options.projectName,
stencilProjectConfig,
stencilConfigPath,
stencilConfigSource,
packageName
);

return libraryTarget;
}

export default addVueGenerator;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OutputTargetType } from './lib/add-outputtarget-to-config';

export type OutputTargetType = 'angular' | 'react' | 'vue' | 'svelte';
export type OutputTargetType = 'angular' | 'react' | 'svelte' | 'vue';

export interface AddOutputtargetSchematicSchema {
projectName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"outputType": {
"type": "string",
"enum": ["angular", "react", "svelte"],
"enum": ["angular", "react", "svelte", "vue"],
"description": "Select what kind of library you want to generate.",
"x-prompt": "Which framework do you use?"
},
Expand Down
1 change: 1 addition & 0 deletions packages/stencil/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const ESLINT_PLUGIN_VERSIONS = {
export const STENCIL_OUTPUTTARGET_VERSION = {
react: '^0.5.3',
angular: '^0.8.3',
vue: '^0.9.0',
};

export const STENCIL_STYLE_PLUGIN_VERSION = {
Expand Down
Loading
Loading