Skip to content

Commit

Permalink
fix(core): nextjs-standalone generates package scripts consistent wit…
Browse files Browse the repository at this point in the history
…h create-next-app
  • Loading branch information
jaysoo committed Feb 29, 2024
1 parent 7879b3f commit 217b7cc
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,62 @@ It will show tasks that you can run with Nx.
"
`;

exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for angular-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;

exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for nextjs-standalone preset 1`] = `
{
"build": "nx build",
"dev": "nx dev",
"start": "nx start",
"test": "nx test",
}
`;

exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for node-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;

exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for nuxt-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;

exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for react-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;

exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for ts-standalone preset 1`] = `
{
"build": "nx build",
"test": "nx test",
}
`;

exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for vue-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;

exports[`@nx/workspace:generateWorkspaceFiles should recommend vscode extensions (angular) 1`] = `
[
"nrwl.angular-console",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,25 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
const pnpm = tree.read('/proj/pnpm-workspace.yaml').toString();
expect(pnpm).toContain('packages/*');
});

it.each([
Preset.ReactStandalone,
Preset.VueStandalone,
Preset.NuxtStandalone,
Preset.AngularStandalone,
Preset.NodeStandalone,
Preset.NextJsStandalone,
Preset.TsStandalone,
])('should create package scripts for %s preset', async (preset) => {
await generateWorkspaceFiles(tree, {
name: 'proj',
directory: 'proj',
preset,
defaultBase: 'main',
appName: 'demo',
isCustomPreset: false,
});

expect(readJson(tree, 'proj/package.json').scripts).toMatchSnapshot();
});
});
15 changes: 13 additions & 2 deletions packages/workspace/src/generators/new/generate-workspace-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function setPresetProperty(tree: Tree, options: NormalizedSchema) {
return json;
});
}

function createNxJson(
tree: Tree,
{ directory, defaultBase, preset }: NormalizedSchema
Expand Down Expand Up @@ -163,8 +164,7 @@ function addNpmScripts(tree: Tree, options: NormalizedSchema) {
options.preset === Preset.ReactStandalone ||
options.preset === Preset.VueStandalone ||
options.preset === Preset.NuxtStandalone ||
options.preset === Preset.NodeStandalone ||
options.preset === Preset.NextJsStandalone
options.preset === Preset.NodeStandalone
) {
updateJson(tree, join(options.directory, 'package.json'), (json) => {
Object.assign(json.scripts, {
Expand All @@ -175,6 +175,17 @@ function addNpmScripts(tree: Tree, options: NormalizedSchema) {
return json;
});
}
if (options.preset === Preset.NextJsStandalone) {
updateJson(tree, join(options.directory, 'package.json'), (json) => {
Object.assign(json.scripts, {
dev: 'nx dev',
build: 'nx build',
start: 'nx start',
test: 'nx test',
});
return json;
});
}
if (options.preset === Preset.TsStandalone) {
updateJson(tree, join(options.directory, 'package.json'), (json) => {
Object.assign(json.scripts, {
Expand Down

0 comments on commit 217b7cc

Please sign in to comment.