Skip to content

Commit

Permalink
feat(nuxt): updates to file sctructure
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Oct 10, 2023
1 parent 2f444d2 commit b8e2722
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/nuxt/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const route = useRoute();
<NuxtLink to="/about">About</NuxtLink>
</nav>
</header>
<router-view></router-view>
<nuxt-page></nuxt-page>
</main>
</template>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<NxWelcome title="<%= title %>" />
</template>



2 changes: 1 addition & 1 deletion packages/nuxt/src/generators/component/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
4 changes: 2 additions & 2 deletions packages/nuxt/src/generators/page/page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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();
});
});
});
4 changes: 2 additions & 2 deletions packages/nuxt/src/generators/page/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
2 changes: 0 additions & 2 deletions packages/nuxt/src/generators/page/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export interface Schema {
project: string;
name: string;
pascalCaseFiles?: boolean;
pascalCaseDirectory?: boolean;
directory?: string;
fileName?: string;
skipFormat?: boolean;
Expand Down
10 changes: 0 additions & 10 deletions packages/nuxt/src/generators/page/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
24 changes: 3 additions & 21 deletions packages/nuxt/src/utils/lint.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
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,
},
};

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,
};
};
2 changes: 1 addition & 1 deletion packages/nuxt/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit b8e2722

Please sign in to comment.