From b8e2722a469d904d06bfbeff6b169517c6228c6d Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Tue, 10 Oct 2023 12:57:23 +0300 Subject: [PATCH] feat(nuxt): updates to file sctructure --- .../__snapshots__/application.spec.ts.snap | 34 ++++++++++++------ .../application/application.spec.ts | 4 +++ .../src/generators/application/application.ts | 2 +- .../application/files/nuxt.config.ts__tmpl__ | 1 + .../application/files/pages/index.vue__tmpl__ | 10 ------ .../files/{ => src}/app.vue__tmpl__ | 2 +- .../{ => src}/assets/css/styles.css__tmpl__ | 0 .../components/NxWelcome.vue__tmpl__ | 0 .../files/{ => src}/pages/About.vue__tmpl__ | 0 .../files/src/pages/index.vue__tmpl__ | 6 ++++ .../files/{ => src}/public/__dot__gitkeep | 0 .../{ => src}/public/favicon.ico__tmpl__ | Bin .../{ => src}/server/api/greet.ts__tmpl__ | 0 .../{ => src}/server/tsconfig.json__tmpl__ | 0 .../generators/component/component.spec.ts | 2 +- .../nuxt/src/generators/page/page.spec.ts | 4 +-- packages/nuxt/src/generators/page/page.ts | 4 +-- packages/nuxt/src/generators/page/schema.d.ts | 2 -- packages/nuxt/src/generators/page/schema.json | 10 ------ packages/nuxt/src/utils/lint.ts | 24 ++----------- packages/nuxt/src/utils/versions.ts | 2 +- 21 files changed, 46 insertions(+), 61 deletions(-) delete mode 100644 packages/nuxt/src/generators/application/files/pages/index.vue__tmpl__ rename packages/nuxt/src/generators/application/files/{ => src}/app.vue__tmpl__ (95%) rename packages/nuxt/src/generators/application/files/{ => src}/assets/css/styles.css__tmpl__ (100%) rename packages/nuxt/src/generators/application/files/{ => src}/components/NxWelcome.vue__tmpl__ (100%) rename packages/nuxt/src/generators/application/files/{ => src}/pages/About.vue__tmpl__ (100%) create mode 100644 packages/nuxt/src/generators/application/files/src/pages/index.vue__tmpl__ rename packages/nuxt/src/generators/application/files/{ => src}/public/__dot__gitkeep (100%) rename packages/nuxt/src/generators/application/files/{ => src}/public/favicon.ico__tmpl__ (100%) rename packages/nuxt/src/generators/application/files/{ => src}/server/api/greet.ts__tmpl__ (100%) rename packages/nuxt/src/generators/application/files/{ => src}/server/tsconfig.json__tmpl__ (100%) diff --git a/packages/nuxt/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/nuxt/src/generators/application/__snapshots__/application.spec.ts.snap index 8f3a7dbe55cf61..bc122fd1d548fa 100644 --- a/packages/nuxt/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/nuxt/src/generators/application/__snapshots__/application.spec.ts.snap @@ -10,12 +10,26 @@ exports[`app generated files content - as-provided should add nuxt entries in .g .cache" `; +exports[`app generated files content - as-provided should configure eslint correctly 1`] = ` +"{ + "extends": ["@nuxt/eslint-config", "../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx", "*.vue"], + "rules": {} + } + ] +} +" +`; + exports[`app generated files content - as-provided should configure tsconfig and project.json correctly 1`] = ` "{ "name": "my-app", "$schema": "../node_modules/nx/schemas/project-schema.json", "projectType": "application", - "sourceRoot": "my-app", + "sourceRoot": "my-app/src", "targets": { "serve": { "executor": "nx:run-commands", @@ -86,16 +100,16 @@ exports[`app generated files content - as-provided should create all new files i ".prettierignore", "my-app/project.json", "my-app/.npmrc", - "my-app/app.vue", - "my-app/assets/css/styles.css", - "my-app/components/NxWelcome.vue", "my-app/nuxt.config.ts", - "my-app/pages/About.vue", - "my-app/pages/index.vue", - "my-app/public/.gitkeep", - "my-app/public/favicon.ico", - "my-app/server/api/greet.ts", - "my-app/server/tsconfig.json", + "my-app/src/app.vue", + "my-app/src/assets/css/styles.css", + "my-app/src/components/NxWelcome.vue", + "my-app/src/pages/about.vue", + "my-app/src/pages/index.vue", + "my-app/src/public/.gitkeep", + "my-app/src/public/favicon.ico", + "my-app/src/server/api/greet.ts", + "my-app/src/server/tsconfig.json", "my-app/tsconfig.json", ".gitignore", ".eslintrc.json", diff --git a/packages/nuxt/src/generators/application/application.spec.ts b/packages/nuxt/src/generators/application/application.spec.ts index 069342413e33d4..534c7f71821864 100644 --- a/packages/nuxt/src/generators/application/application.spec.ts +++ b/packages/nuxt/src/generators/application/application.spec.ts @@ -23,6 +23,10 @@ describe('app', () => { expect(tree.read('.gitignore', 'utf-8')).toMatchSnapshot(); }); + it('should configure eslint correctly', () => { + expect(tree.read('my-app/.eslintrc.json', 'utf-8')).toMatchSnapshot(); + }); + it('should configure tsconfig and project.json correctly', () => { expect(tree.read('my-app/project.json', 'utf-8')).toMatchSnapshot(); expect(tree.read('my-app/tsconfig.json', 'utf-8')).toMatchSnapshot(); diff --git a/packages/nuxt/src/generators/application/application.ts b/packages/nuxt/src/generators/application/application.ts index 725b991469e977..383386ddb3cf53 100644 --- a/packages/nuxt/src/generators/application/application.ts +++ b/packages/nuxt/src/generators/application/application.ts @@ -37,7 +37,7 @@ export async function applicationGenerator(tree: Tree, schema: Schema) { addProjectConfiguration(tree, options.name, { root: options.appProjectRoot, projectType: 'application', - sourceRoot: `${options.appProjectRoot}`, + sourceRoot: `${options.appProjectRoot}/src`, targets: {}, }); diff --git a/packages/nuxt/src/generators/application/files/nuxt.config.ts__tmpl__ b/packages/nuxt/src/generators/application/files/nuxt.config.ts__tmpl__ index 47a11e8f9dd419..d9400616092940 100644 --- a/packages/nuxt/src/generators/application/files/nuxt.config.ts__tmpl__ +++ b/packages/nuxt/src/generators/application/files/nuxt.config.ts__tmpl__ @@ -12,6 +12,7 @@ export default defineNuxtConfig({ * https://nuxt.com/docs/guide/directory-structure/tsconfig **/ alias: nxTsPaths(), + srcDir: 'src', devtools: { enabled: true }, css: ['~/assets/css/styles.css'], }); diff --git a/packages/nuxt/src/generators/application/files/pages/index.vue__tmpl__ b/packages/nuxt/src/generators/application/files/pages/index.vue__tmpl__ deleted file mode 100644 index 8b2372472de761..00000000000000 --- a/packages/nuxt/src/generators/application/files/pages/index.vue__tmpl__ +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/packages/nuxt/src/generators/application/files/app.vue__tmpl__ b/packages/nuxt/src/generators/application/files/src/app.vue__tmpl__ similarity index 95% rename from packages/nuxt/src/generators/application/files/app.vue__tmpl__ rename to packages/nuxt/src/generators/application/files/src/app.vue__tmpl__ index eb4e205fc24a64..b1d63eea6e5594 100644 --- a/packages/nuxt/src/generators/application/files/app.vue__tmpl__ +++ b/packages/nuxt/src/generators/application/files/src/app.vue__tmpl__ @@ -10,7 +10,7 @@ const route = useRoute(); About - + diff --git a/packages/nuxt/src/generators/application/files/assets/css/styles.css__tmpl__ b/packages/nuxt/src/generators/application/files/src/assets/css/styles.css__tmpl__ similarity index 100% rename from packages/nuxt/src/generators/application/files/assets/css/styles.css__tmpl__ rename to packages/nuxt/src/generators/application/files/src/assets/css/styles.css__tmpl__ diff --git a/packages/nuxt/src/generators/application/files/components/NxWelcome.vue__tmpl__ b/packages/nuxt/src/generators/application/files/src/components/NxWelcome.vue__tmpl__ similarity index 100% rename from packages/nuxt/src/generators/application/files/components/NxWelcome.vue__tmpl__ rename to packages/nuxt/src/generators/application/files/src/components/NxWelcome.vue__tmpl__ diff --git a/packages/nuxt/src/generators/application/files/pages/About.vue__tmpl__ b/packages/nuxt/src/generators/application/files/src/pages/About.vue__tmpl__ similarity index 100% rename from packages/nuxt/src/generators/application/files/pages/About.vue__tmpl__ rename to packages/nuxt/src/generators/application/files/src/pages/About.vue__tmpl__ diff --git a/packages/nuxt/src/generators/application/files/src/pages/index.vue__tmpl__ b/packages/nuxt/src/generators/application/files/src/pages/index.vue__tmpl__ new file mode 100644 index 00000000000000..0e99129293e931 --- /dev/null +++ b/packages/nuxt/src/generators/application/files/src/pages/index.vue__tmpl__ @@ -0,0 +1,6 @@ + + + + diff --git a/packages/nuxt/src/generators/application/files/public/__dot__gitkeep b/packages/nuxt/src/generators/application/files/src/public/__dot__gitkeep similarity index 100% rename from packages/nuxt/src/generators/application/files/public/__dot__gitkeep rename to packages/nuxt/src/generators/application/files/src/public/__dot__gitkeep diff --git a/packages/nuxt/src/generators/application/files/public/favicon.ico__tmpl__ b/packages/nuxt/src/generators/application/files/src/public/favicon.ico__tmpl__ similarity index 100% rename from packages/nuxt/src/generators/application/files/public/favicon.ico__tmpl__ rename to packages/nuxt/src/generators/application/files/src/public/favicon.ico__tmpl__ diff --git a/packages/nuxt/src/generators/application/files/server/api/greet.ts__tmpl__ b/packages/nuxt/src/generators/application/files/src/server/api/greet.ts__tmpl__ similarity index 100% rename from packages/nuxt/src/generators/application/files/server/api/greet.ts__tmpl__ rename to packages/nuxt/src/generators/application/files/src/server/api/greet.ts__tmpl__ diff --git a/packages/nuxt/src/generators/application/files/server/tsconfig.json__tmpl__ b/packages/nuxt/src/generators/application/files/src/server/tsconfig.json__tmpl__ similarity index 100% rename from packages/nuxt/src/generators/application/files/server/tsconfig.json__tmpl__ rename to packages/nuxt/src/generators/application/files/src/server/tsconfig.json__tmpl__ diff --git a/packages/nuxt/src/generators/component/component.spec.ts b/packages/nuxt/src/generators/component/component.spec.ts index 323dd9e6aa9474..d0dadc66cb230c 100644 --- a/packages/nuxt/src/generators/component/component.spec.ts +++ b/packages/nuxt/src/generators/component/component.spec.ts @@ -21,7 +21,7 @@ describe('app', () => { project: name, }); - expect(tree.exists('my-app/components/hello/hello.vue')).toBeTruthy(); + expect(tree.exists('my-app/src/components/hello/hello.vue')).toBeTruthy(); }); }); }); diff --git a/packages/nuxt/src/generators/page/page.spec.ts b/packages/nuxt/src/generators/page/page.spec.ts index da2606bc339fa7..b51c9d7fdecc4a 100644 --- a/packages/nuxt/src/generators/page/page.spec.ts +++ b/packages/nuxt/src/generators/page/page.spec.ts @@ -42,7 +42,7 @@ describe('app', () => { project: name, }); - expect(tree.exists('my-app/pages/About.vue')).toBeTruthy(); + expect(tree.exists('my-app/src/pages/about.vue')).toBeTruthy(); }); it('should create a new page in the correct location for nested directory', async () => { @@ -51,7 +51,7 @@ describe('app', () => { project: name, }); - expect(tree.exists('my-app/pages/About.vue')).toBeTruthy(); + expect(tree.exists('my-app/src/pages/about.vue')).toBeTruthy(); }); }); }); diff --git a/packages/nuxt/src/generators/page/page.ts b/packages/nuxt/src/generators/page/page.ts index 1c5e495ae26f03..aa16daab5b1d42 100644 --- a/packages/nuxt/src/generators/page/page.ts +++ b/packages/nuxt/src/generators/page/page.ts @@ -13,8 +13,8 @@ export async function pageGenerator(host: Tree, options: Schema) { directory: getDirectory(options.directory), skipTests: true, flat: true, - pascalCaseFiles: options.pascalCaseFiles ?? true, - pascalCaseDirectory: options.pascalCaseDirectory ?? true, + pascalCaseFiles: false, // it's good to keep route names lowercase + pascalCaseDirectory: false, skipFormat: true, }); diff --git a/packages/nuxt/src/generators/page/schema.d.ts b/packages/nuxt/src/generators/page/schema.d.ts index 228d53dc340aea..c3c8815adcc69a 100644 --- a/packages/nuxt/src/generators/page/schema.d.ts +++ b/packages/nuxt/src/generators/page/schema.d.ts @@ -1,8 +1,6 @@ export interface Schema { project: string; name: string; - pascalCaseFiles?: boolean; - pascalCaseDirectory?: boolean; directory?: string; fileName?: string; skipFormat?: boolean; diff --git a/packages/nuxt/src/generators/page/schema.json b/packages/nuxt/src/generators/page/schema.json index e8b058951c9389..481722b5fc6c2a 100644 --- a/packages/nuxt/src/generators/page/schema.json +++ b/packages/nuxt/src/generators/page/schema.json @@ -37,16 +37,6 @@ "description": "Create the page under this directory - all nested directories will be created under the pages directory.", "alias": "dir" }, - "pascalCaseFiles": { - "type": "boolean", - "description": "Use pascal case component file name (e.g. `App.vue`).", - "alias": "P" - }, - "pascalCaseDirectory": { - "type": "boolean", - "description": "Use pascal case directory name (e.g. `App/App.vue`).", - "alias": "R" - }, "fileName": { "type": "string", "description": "Create a component with this file name." diff --git a/packages/nuxt/src/utils/lint.ts b/packages/nuxt/src/utils/lint.ts index 2082b1dcffaff7..1b1176bcd0350b 100644 --- a/packages/nuxt/src/utils/lint.ts +++ b/packages/nuxt/src/utils/lint.ts @@ -1,17 +1,9 @@ -import { - eslintPluginVueVersion, - vueEslintConfigPrettierVersion, - vueEslintConfigTypescriptVersion, -} from '@nx/vue'; -import { nuxtEslintConfigTypescriptVersion } from './versions'; +import { nuxtEslintConfigVersion } from './versions'; export const extraEslintDependencies = { dependencies: {}, devDependencies: { - '@nuxtjs/eslint-config-typescript': nuxtEslintConfigTypescriptVersion, - 'eslint-plugin-vue': eslintPluginVueVersion, - '@vue/eslint-config-prettier': vueEslintConfigPrettierVersion, - '@vue/eslint-config-typescript': vueEslintConfigTypescriptVersion, + '@nuxt/eslint-config': nuxtEslintConfigVersion, }, }; @@ -19,18 +11,8 @@ export const extendNuxtEslintJson = (json: any) => { const { extends: pluginExtends, ...config } = json; return { - extends: [ - 'eslint:recommended', - '@nuxtjs/eslint-config-typescript', - 'plugin:vue/vue3-essential', - '@vue/eslint-config-typescript', - '@vue/eslint-config-prettier/skip-formatting', - ...(pluginExtends || []), - ], + extends: ['@nuxt/eslint-config', ...(pluginExtends || [])], ignorePatterns: ['.nuxt', 'node_modules', '.output'], - rules: { - 'vue/multi-word-component-names': 'off', - }, ...config, }; }; diff --git a/packages/nuxt/src/utils/versions.ts b/packages/nuxt/src/utils/versions.ts index 37abc8e70edae3..da902409905805 100644 --- a/packages/nuxt/src/utils/versions.ts +++ b/packages/nuxt/src/utils/versions.ts @@ -6,4 +6,4 @@ export const nuxtVersion = '^3.7.4'; export const h3Version = '^1.8.2'; // linting deps -export const nuxtEslintConfigTypescriptVersion = '12.1.0'; +export const nuxtEslintConfigVersion = '0.2.0';