-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt): component and page generators
- Loading branch information
Showing
28 changed files
with
769 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 3 additions & 11 deletions
14
packages/nuxt/src/generators/application/files/nuxt.config.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
import { nxTsPaths } from '@nx/nuxt'; | ||
import { NxNuxtModule } from '@nx/nuxt'; | ||
|
||
// https://nuxt.com/docs/api/configuration/nuxt-config | ||
export default defineNuxtConfig({ | ||
/** | ||
* Nuxt recommends setting custom alias from a tsconfig here, | ||
* instead of in tsconfig since it will override the auto generated tsconfig. | ||
* all aliases added here will be added to the auto generated tsconfig. | ||
* Other projects generated with Nx will be added to the root level tsconfig.base.json | ||
* which might want to be used in this project. | ||
* | ||
* https://nuxt.com/docs/guide/directory-structure/tsconfig | ||
**/ | ||
alias: nxTsPaths(), | ||
modules: [NxNuxtModule], | ||
srcDir: 'src', | ||
devtools: { enabled: true }, | ||
css: ['~/assets/css/styles.css'], | ||
}); |
10 changes: 0 additions & 10 deletions
10
packages/nuxt/src/generators/application/files/pages/index.vue__tmpl__
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/nuxt/src/generators/application/files/src/pages/index.vue__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<template> | ||
<NxWelcome title="<%= title %>" /> | ||
</template> | ||
|
||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; | ||
import { Tree } from '@nx/devkit'; | ||
import { applicationGenerator } from '../application/application'; | ||
import { componentGenerator } from './component'; | ||
|
||
describe('app', () => { | ||
let tree: Tree; | ||
const name = 'my-app'; | ||
|
||
describe('generated files content - as-provided', () => { | ||
beforeAll(async () => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
await applicationGenerator(tree, { | ||
name, | ||
projectNameAndRootFormat: 'as-provided', | ||
}); | ||
}); | ||
it('should create a new vue component in the correct location', async () => { | ||
await componentGenerator(tree, { | ||
name: 'hello', | ||
project: name, | ||
}); | ||
|
||
expect(tree.exists('my-app/src/components/hello/hello.vue')).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { formatFiles, runTasksInSerial, Tree } from '@nx/devkit'; | ||
import { componentGenerator as vueComponentGenerator } from '@nx/vue'; | ||
import { Schema } from './schema'; | ||
|
||
/* | ||
* This generator is basically the Vue one, but for Nuxt we | ||
* are just adjusting some options | ||
*/ | ||
export async function componentGenerator(host: Tree, options: Schema) { | ||
const componentGenerator = await vueComponentGenerator(host, { | ||
...options, | ||
routing: false, | ||
skipFormat: true, | ||
}); | ||
|
||
if (!options.skipFormat) { | ||
await formatFiles(host); | ||
} | ||
|
||
return runTasksInSerial(componentGenerator); | ||
} | ||
|
||
export default componentGenerator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export interface Schema { | ||
project: string; | ||
name: string; | ||
skipTests?: boolean; | ||
flat?: boolean; | ||
pascalCaseFiles?: boolean; | ||
pascalCaseDirectory?: boolean; | ||
fileName?: string; | ||
inSourceTests?: boolean; | ||
skipFormat?: boolean; | ||
directory?: string; | ||
unitTestRunner?: 'jest' | 'vitest' | 'none'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"$id": "NxNuxtComponent", | ||
"title": "Create a Nuxt Component", | ||
"description": "Create a Nuxt Component for Nx.", | ||
"type": "object", | ||
"examples": [ | ||
{ | ||
"command": "nx g component my-component --project=myapp", | ||
"description": "Generate a component in the `myapp` application" | ||
}, | ||
{ | ||
"command": "nx g component my-component --project=myapp --classComponent", | ||
"description": "Generate a class component in the `myapp` application" | ||
} | ||
], | ||
"properties": { | ||
"project": { | ||
"type": "string", | ||
"description": "The name of the project.", | ||
"alias": "p", | ||
"$default": { | ||
"$source": "projectName" | ||
}, | ||
"x-prompt": "What is the name of the project for this component?", | ||
"x-priority": "important" | ||
}, | ||
"name": { | ||
"type": "string", | ||
"description": "The name of the component.", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
}, | ||
"x-prompt": "What name would you like to use for the component?", | ||
"x-priority": "important" | ||
}, | ||
"skipTests": { | ||
"type": "boolean", | ||
"description": "When true, does not create `spec.ts` test files for the new component.", | ||
"default": false, | ||
"x-priority": "internal" | ||
}, | ||
"flat": { | ||
"type": "boolean", | ||
"description": "Create component at the source root rather than its own directory.", | ||
"default": false | ||
}, | ||
"directory": { | ||
"type": "string", | ||
"description": "Create the component under this directory (can be nested).", | ||
"alias": "dir", | ||
"x-priority": "important" | ||
}, | ||
"pascalCaseFiles": { | ||
"type": "boolean", | ||
"description": "Use pascal case component file name (e.g. `App.vue`).", | ||
"alias": "P", | ||
"default": false | ||
}, | ||
"pascalCaseDirectory": { | ||
"type": "boolean", | ||
"description": "Use pascal case directory name (e.g. `App/App.vue`).", | ||
"alias": "R", | ||
"default": false | ||
}, | ||
"fileName": { | ||
"type": "string", | ||
"description": "Create a component with this file name." | ||
}, | ||
"inSourceTests": { | ||
"type": "boolean", | ||
"default": false, | ||
"description": "When using Vitest, separate spec files will not be generated and instead will be included within the source files. Read more on the Vitest docs site: https://vitest.dev/guide/in-source.html" | ||
}, | ||
"skipFormat": { | ||
"description": "Skip formatting files.", | ||
"type": "boolean", | ||
"default": false, | ||
"x-priority": "internal" | ||
}, | ||
"unitTestRunner": { | ||
"type": "string", | ||
"enum": ["vitest", "jest", "none"], | ||
"description": "Test runner to use for unit tests.", | ||
"x-prompt": "What unit test runner should be used?" | ||
} | ||
}, | ||
"required": ["name", "project"] | ||
} |
Oops, something went wrong.