Skip to content

Commit

Permalink
feat(nuxt): added nuxt to create-nx-workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Nov 6, 2023
1 parent 33ca596 commit 951852f
Show file tree
Hide file tree
Showing 21 changed files with 340 additions and 28,050 deletions.
2 changes: 1 addition & 1 deletion e2e/nuxt/src/nuxt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Nuxt Plugin', () => {

it('should build storybook for app', () => {
runCLI(
`generate @nx/vue:storybook-configuration ${app} --generateStories --no-interactive`
`generate @nx/nuxt:storybook-configuration ${app} --generateStories --no-interactive`
);
runCLI(`run ${app}:build-storybook --verbose`);
checkFilesExist(`dist/storybook/${app}/index.html`);
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
"@ngrx/router-store": "~16.0.0",
"@ngrx/store": "~16.0.0",
"@nguniversal/builders": "~16.2.0",
"@nuxt/kit": "^3.7.4",
"@nuxt/schema": "^3.7.4",
"@nx/angular": "17.0.0-rc.2",
"@nx/cypress": "17.0.0-rc.2",
"@nx/devkit": "17.0.0-rc.2",
Expand Down Expand Up @@ -158,7 +156,6 @@
"cytoscape-popper": "^2.0.0",
"cz-git": "^1.4.0",
"czg": "^1.4.0",
"defu": "^6.1.2",
"detect-port": "^1.5.1",
"dotenv": "~16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down
88 changes: 85 additions & 3 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ interface VueArguments extends BaseArguments {
stack: 'vue';
workspaceType: 'standalone' | 'integrated';
appName: string;
// framework: 'none' | 'nuxt';
style: string;
e2eTestRunner: 'none' | 'cypress' | 'playwright';
}

interface NuxtArguments extends BaseArguments {
stack: 'nuxt';
workspaceType: 'standalone' | 'integrated';
appName: string;
style: string;
e2eTestRunner: 'none' | 'cypress' | 'playwright';
}
Expand All @@ -88,6 +95,7 @@ type Arguments =
| ReactArguments
| AngularArguments
| VueArguments
| NuxtArguments
| NodeArguments
| UnknownStackArguments;

Expand All @@ -112,6 +120,8 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
describe: chalk.dim`Customizes the initial content of your workspace. Default presets include: [${Object.values(
Preset
)
// TODO(katerina): Remove this option when @nx/nuxt is released.
.filter((p) => p !== Preset.NuxtStandalone && p !== Preset.Nuxt)
.map((p) => `"${p}"`)
.join(
', '
Expand Down Expand Up @@ -357,7 +367,7 @@ async function determineFolder(

async function determineStack(
parsedArgs: yargs.Arguments<Arguments>
): Promise<'none' | 'react' | 'angular' | 'vue' | 'node' | 'unknown'> {
): Promise<'none' | 'react' | 'angular' | 'vue' | 'node' | 'nuxt' | 'unknown'> {
if (parsedArgs.preset) {
switch (parsedArgs.preset) {
case Preset.Angular:
Expand All @@ -373,6 +383,9 @@ async function determineStack(
case Preset.VueStandalone:
case Preset.VueMonorepo:
return 'vue';
case Preset.NuxtStandalone:
case Preset.Nuxt:
return 'nuxt';
case Preset.Nest:
case Preset.NodeStandalone:
case Preset.Express:
Expand Down Expand Up @@ -437,6 +450,8 @@ async function determinePresetOptions(
return determineAngularOptions(parsedArgs);
case 'vue':
return determineVueOptions(parsedArgs);
case 'nuxt':
return determineNuxtOptions(parsedArgs);
case 'node':
return determineNodeOptions(parsedArgs);
default:
Expand Down Expand Up @@ -670,6 +685,69 @@ async function determineVueOptions(
return { preset, style, appName, e2eTestRunner };
}

async function determineNuxtOptions(
parsedArgs: yargs.Arguments<NuxtArguments>
): Promise<Partial<Arguments>> {
let preset: Preset;
let style: undefined | string = undefined;
let appName: string;
let e2eTestRunner: undefined | 'none' | 'cypress' | 'playwright' = undefined;

if (parsedArgs.preset) {
preset = parsedArgs.preset;
} else {
const workspaceType = await determineStandaloneOrMonorepo();

if (workspaceType === 'standalone') {
preset = Preset.NuxtStandalone;
} else {
preset = Preset.Nuxt;
}
}

if (preset === Preset.NuxtStandalone) {
appName = parsedArgs.appName ?? parsedArgs.name;
} else {
appName = await determineAppName(parsedArgs);
}

e2eTestRunner = await determineE2eTestRunner(parsedArgs);

if (parsedArgs.style) {
style = parsedArgs.style;
} else {
const reply = await enquirer.prompt<{ style: string }>([
{
name: 'style',
message: `Default stylesheet format`,
initial: 'css' as any,
type: 'autocomplete',
choices: [
{
name: 'css',
message: 'CSS',
},
{
name: 'scss',
message: 'SASS(.scss) [ http://sass-lang.com ]',
},
{
name: 'less',
message: 'LESS [ http://lesscss.org ]',
},
{
name: 'none',
message: 'None',
},
],
},
]);
style = reply.style;
}

return { preset, style, appName, e2eTestRunner };
}

async function determineAngularOptions(
parsedArgs: yargs.Arguments<AngularArguments>
): Promise<Partial<Arguments>> {
Expand Down Expand Up @@ -929,7 +1007,11 @@ async function determineStandaloneOrMonorepo(): Promise<

async function determineAppName(
parsedArgs: yargs.Arguments<
ReactArguments | AngularArguments | NodeArguments | VueArguments
| ReactArguments
| AngularArguments
| NodeArguments
| VueArguments
| NuxtArguments
>
): Promise<string> {
if (parsedArgs.appName) return parsedArgs.appName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const presetOptions: { name: Preset; message: string }[] = [
name: Preset.VueMonorepo,
message: 'vue [a monorepo with a single Vue application]',
},
{
name: Preset.Nuxt,
message: 'nuxt [a monorepo with a single Nuxt application]',
},
{
name: Preset.NextJs,
message: 'next.js [a monorepo with a single Next.js application]',
Expand Down
2 changes: 2 additions & 0 deletions packages/create-nx-workspace/src/utils/preset/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export enum Preset {
ReactStandalone = 'react-standalone',
VueMonorepo = 'vue-monorepo',
VueStandalone = 'vue-standalone',
Nuxt = 'nuxt',
NuxtStandalone = 'nuxt-standalone',
NextJs = 'next',
NextJsStandalone = 'nextjs-standalone',
ReactNative = 'react-native',
Expand Down
7 changes: 6 additions & 1 deletion packages/nuxt/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": ["nx", "typescript"]
"ignoredDependencies": [
"nx",
"typescript",
"@nx/cypress",
"@nx/playwright"
]
}
]
}
Expand Down
1 change: 0 additions & 1 deletion packages/nuxt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from './src/utils/versions';
export { applicationGenerator } from './src/generators/application/application';
export { type InitSchema } from './src/generators/init/schema';
export { nuxtInitGenerator } from './src/generators/init/init';
export * from './plugins/with-nuxt';
8 changes: 1 addition & 7 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@
"migrations": "./migrations.json"
},
"dependencies": {
"defu": "^6.1.2",
"fs-extra": "^11.1.0",
"tslib": "^2.3.0",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@nx/eslint": "file:../eslint",
"@nx/vue": "file:../vue",
"@nx/cypress": "file:../cypress",
"@nx/playwright": "file:../playwright",
"@nuxt/kit": "^3.7.4",
"@nuxt/schema": "^3.7.4"
"@nx/vue": "file:../vue"
},
"publishConfig": {
"access": "public"
Expand Down
49 changes: 0 additions & 49 deletions packages/nuxt/plugins/with-nuxt.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ exports[`app generated files content - as-provided should configure eslint corre
`;

exports[`app generated files content - as-provided should configure nuxt correctly 1`] = `
"import { NxNuxtModule } from '@nx/nuxt';
"import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: [NxNuxtModule],
srcDir: 'src',
devtools: { enabled: true },
css: ['~/assets/css/styles.css'],
vite: {
plugins: [nxViteTsPaths()],
},
});
"
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { NxNuxtModule } from '@nx/nuxt';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: [NxNuxtModule],
srcDir: 'src',
devtools: { enabled: true },
css: ['~/assets/css/styles.css'],
vite: {
plugins: [
nxViteTsPaths()
],
}
});
Loading

0 comments on commit 951852f

Please sign in to comment.