Skip to content

Commit

Permalink
feat(vue): update vue app and lib generators to support TS solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Dec 11, 2024
1 parent 726c07d commit 0d868d2
Show file tree
Hide file tree
Showing 31 changed files with 962 additions and 108 deletions.
17 changes: 10 additions & 7 deletions docs/generated/packages/nuxt/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,27 @@
"pattern": "^[a-zA-Z][^:]*$",
"x-priority": "important"
},
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint"],
"default": "eslint"
},
"skipFormat": {
"description": "Skip formatting files.",
"type": "boolean",
"default": false,
"x-priority": "internal"
},
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint", "none"],
"default": "none",
"x-prompt": "Which linter would you like to use?",
"x-priority": "important"
},
"unitTestRunner": {
"type": "string",
"enum": ["vitest", "none"],
"description": "Test runner to use for unit tests.",
"x-prompt": "Which unit test runner would you like to use?",
"default": "none"
"default": "none",
"x-priority": "important"
},
"e2eTestRunner": {
"type": "string",
Expand Down
17 changes: 10 additions & 7 deletions docs/generated/packages/vue/generators/application.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@
]
}
},
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint", "none"],
"default": "eslint"
},
"routing": {
"type": "boolean",
"description": "Generate application with routes.",
Expand All @@ -72,12 +66,21 @@
"default": false,
"x-priority": "internal"
},
"linter": {
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint", "none"],
"default": "none",
"x-prompt": "Which linter would you like to use?",
"x-priority": "important"
},
"unitTestRunner": {
"type": "string",
"enum": ["vitest", "none"],
"description": "Test runner to use for unit tests.",
"x-prompt": "Which unit test runner would you like to use?",
"default": "vitest"
"default": "none",
"x-priority": "important"
},
"inSourceTests": {
"type": "boolean",
Expand Down
8 changes: 6 additions & 2 deletions docs/generated/packages/vue/generators/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@
"description": "The tool to use for running lint checks.",
"type": "string",
"enum": ["eslint", "none"],
"default": "eslint"
"default": "none",
"x-prompt": "Which linter would you like to use?",
"x-priority": "important"
},
"unitTestRunner": {
"type": "string",
"enum": ["vitest", "none"],
"description": "Test runner to use for unit tests.",
"x-prompt": "What unit test runner should be used?"
"x-prompt": "What unit test runner should be used?",
"default": "none",
"x-priority": "important"
},
"inSourceTests": {
"type": "boolean",
Expand Down
33 changes: 27 additions & 6 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ import { printSocialInformation } from '../src/utils/social-information';

interface BaseArguments extends CreateWorkspaceOptions {
preset: Preset;
linter?: 'none' | 'eslint';
formatter?: 'none' | 'prettier';
workspaces?: boolean;
}

interface NoneArguments extends BaseArguments {
stack: 'none';
workspaceType?: 'package-based' | 'integrated' | 'standalone';
js?: boolean;
appName?: string | undefined;
formatter?: 'none' | 'prettier';
}

interface ReactArguments extends BaseArguments {
Expand All @@ -52,9 +54,6 @@ interface ReactArguments extends BaseArguments {
nextAppDir: boolean;
nextSrcDir: boolean;
e2eTestRunner: 'none' | 'cypress' | 'playwright';
linter?: 'none' | 'eslint';
formatter?: 'none' | 'prettier';
workspaces?: boolean;
}

interface AngularArguments extends BaseArguments {
Expand Down Expand Up @@ -730,6 +729,10 @@ async function determineVueOptions(
let style: undefined | string = undefined;
let appName: string;
let e2eTestRunner: undefined | 'none' | 'cypress' | 'playwright' = undefined;
let linter: undefined | 'none' | 'eslint';
let formatter: undefined | 'none' | 'prettier';

const workspaces = parsedArgs.workspaces ?? false;

if (parsedArgs.preset && parsedArgs.preset !== Preset.Vue) {
preset = parsedArgs.preset;
Expand All @@ -741,7 +744,9 @@ async function determineVueOptions(
} else {
const framework = await determineVueFramework(parsedArgs);

const workspaceType = await determineStandaloneOrMonorepo();
const workspaceType = workspaces
? 'monorepo'
: await determineStandaloneOrMonorepo();
if (workspaceType === 'standalone') {
appName = parsedArgs.appName ?? parsedArgs.name;
} else {
Expand Down Expand Up @@ -798,7 +803,23 @@ async function determineVueOptions(
style = reply.style;
}

return { preset, style, appName, e2eTestRunner };
if (workspaces) {
linter = await determineLinterOptions(parsedArgs);
formatter = await determineFormatterOptions(parsedArgs);
} else {
linter = 'eslint';
formatter = 'prettier';
}

return {
preset,
style,
appName,
e2eTestRunner,
linter,
formatter,
workspaces,
};
}

async function determineAngularOptions(
Expand Down
181 changes: 180 additions & 1 deletion packages/nuxt/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readJson, readProjectConfiguration } from '@nx/devkit';
import {
Tree,
readJson,
readProjectConfiguration,
updateJson,
writeJson,
} from '@nx/devkit';
import { applicationGenerator } from './application';

describe('app', () => {
Expand Down Expand Up @@ -194,4 +200,177 @@ describe('app', () => {
});
}
);

describe('TS solution setup', () => {
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
updateJson(tree, 'package.json', (json) => {
json.workspaces = ['packages/*', 'apps/*'];
return json;
});
writeJson(tree, 'tsconfig.base.json', {
compilerOptions: {
composite: true,
declaration: true,
},
});
writeJson(tree, 'tsconfig.json', {
extends: './tsconfig.base.json',
files: [],
references: [],
});
});

it('should add project references when using TS solution', async () => {
await applicationGenerator(tree, {
directory: 'myapp',
e2eTestRunner: 'playwright',
unitTestRunner: 'vitest',
linter: 'eslint',
});

expect(tree.read('myapp/vite.config.ts', 'utf-8')).toMatchInlineSnapshot(
`null`
);
expect(readJson(tree, 'tsconfig.json').references).toMatchInlineSnapshot(`
[
{
"path": "./myapp-e2e",
},
{
"path": "./myapp",
},
]
`);
expect(readJson(tree, 'myapp/tsconfig.json')).toMatchInlineSnapshot(`
{
"compilerOptions": {},
"extends": "../tsconfig.base.json",
"files": [],
"include": [
".nuxt/nuxt.d.ts",
],
"references": [
{
"path": "./tsconfig.app.json",
},
{
"path": "./tsconfig.spec.json",
},
],
}
`);
expect(readJson(tree, 'myapp/tsconfig.app.json')).toMatchInlineSnapshot(`
{
"compilerOptions": {
"composite": true,
"jsx": "preserve",
"jsxImportSource": "vue",
"module": "esnext",
"moduleResolution": "bundler",
"outDir": "out-tsc/myapp",
"resolveJsonModule": true,
"rootDir": "src",
},
"exclude": [
"dist",
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"eslint.config.js",
"eslint.config.cjs",
"eslint.config.mjs",
],
"extends": "../tsconfig.base.json",
"include": [
".nuxt/nuxt.d.ts",
"src/**/*",
],
}
`);
expect(readJson(tree, 'myapp/tsconfig.spec.json')).toMatchInlineSnapshot(`
{
"compilerOptions": {
"composite": true,
"jsx": "preserve",
"jsxImportSource": "vue",
"module": "esnext",
"moduleResolution": "bundler",
"outDir": "./out-tsc/vitest",
"resolveJsonModule": true,
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest",
],
},
"extends": "../tsconfig.base.json",
"include": [
".nuxt/nuxt.d.ts",
"vite.config.ts",
"vite.config.mts",
"vitest.config.ts",
"vitest.config.mts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts",
],
"references": [
{
"path": "./tsconfig.app.json",
},
],
}
`);
expect(readJson(tree, 'myapp-e2e/tsconfig.json')).toMatchInlineSnapshot(`
{
"compilerOptions": {
"allowJs": true,
"outDir": "dist",
"sourceMap": false,
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo",
},
"exclude": [
"dist",
"eslint.config.js",
"eslint.config.mjs",
"eslint.config.cjs",
],
"extends": "../tsconfig.base.json",
"include": [
"**/*.ts",
"**/*.js",
"playwright.config.ts",
"src/**/*.spec.ts",
"src/**/*.spec.js",
"src/**/*.test.ts",
"src/**/*.test.js",
"src/**/*.d.ts",
],
"references": [
{
"path": "../myapp",
},
],
}
`);
});
});
});
Loading

0 comments on commit 0d868d2

Please sign in to comment.