Skip to content

Commit

Permalink
feat(misc): optionally update package.json scripts in init generators (
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez authored Jan 22, 2024
1 parent c1238aa commit e475835
Show file tree
Hide file tree
Showing 69 changed files with 865 additions and 44 deletions.
6 changes: 6 additions & 0 deletions docs/generated/cli/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Type: `string`

The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) to install and initialize. If the version is not specified it will install the same version as the `nx` package for Nx core plugins or the latest version for other packages

### updatePackageScripts

Type: `boolean`

Update `package.json` scripts with inferred targets. Defaults to `true` when `NX_PCV3=true` and the package is a core Nx plugin

### verbose

Type: `boolean`
Expand Down
1 change: 0 additions & 1 deletion docs/generated/packages/angular/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"default": false
}
},
"additionalProperties": false,
"presets": []
},
"description": "Initializes the `@nrwl/angular` plugin.",
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/cypress/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"presets": []
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/detox/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/eslint/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/expo/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/jest/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
1 change: 0 additions & 1 deletion docs/generated/packages/nest/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"default": false
}
},
"additionalProperties": false,
"required": [],
"presets": []
},
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/next/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/nuxt/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/nx/documents/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Type: `string`

The package name and optional version (e.g. `@nx/react` or `@nx/react@latest`) to install and initialize. If the version is not specified it will install the same version as the `nx` package for Nx core plugins or the latest version for other packages

### updatePackageScripts

Type: `boolean`

Update `package.json` scripts with inferred targets. Defaults to `true` when `NX_PCV3=true` and the package is a core Nx plugin

### verbose

Type: `boolean`
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/playwright/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/react-native/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/remix/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/storybook/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"presets": []
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/vite/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"presets": []
Expand Down
6 changes: 6 additions & 0 deletions docs/generated/packages/webpack/generators/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": [],
Expand Down
3 changes: 1 addition & 2 deletions packages/angular/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@
"description": "Keep existing dependencies versions",
"default": false
}
},
"additionalProperties": false
}
}
6 changes: 6 additions & 0 deletions packages/cypress/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
Tree,
updateNxJson,
} from '@nx/devkit';
import { updatePackageScripts } from '@nx/devkit/src/utils/update-package-scripts';
import { createNodes } from '../../plugins/plugin';
import { cypressVersion, nxVersion } from '../../utils/versions';
import { Schema } from './schema';
import { CypressPluginOptions } from '../../plugins/plugin';
Expand Down Expand Up @@ -108,6 +110,10 @@ export async function cypressInitGenerator(tree: Tree, options: Schema) {
installTask = updateDependencies(tree, options);
}

if (options.updatePackageScripts) {
await updatePackageScripts(tree, createNodes);
}

if (!options.skipFormat) {
await formatFiles(tree);
}
Expand Down
1 change: 1 addition & 0 deletions packages/cypress/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface Schema {
skipFormat?: boolean;
skipPackageJson?: boolean;
keepExistingVersions?: boolean;
updatePackageScripts?: boolean;
}
6 changes: 6 additions & 0 deletions packages/cypress/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ describe('Add Linting', () => {
});
});

it('should update configuration when eslint is passed', () => {
addLinting(tree, {
it('should update configuration when eslint is passed', async () => {
await addLinting(tree, {
e2eName: 'my-app-e2e',
e2eProjectName: 'my-app-e2e',
e2eProjectRoot: 'apps/my-app-e2e',
Expand All @@ -45,7 +45,7 @@ describe('Add Linting', () => {
});

it('should not add lint target when "none" is passed', async () => {
addLinting(tree, {
await addLinting(tree, {
e2eName: 'my-app-e2e',
e2eProjectName: 'my-app-e2e',
e2eProjectRoot: 'apps/my-app-e2e',
Expand Down
7 changes: 6 additions & 1 deletion packages/detox/src/generators/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
Tree,
updateNxJson,
} from '@nx/devkit';
import { DetoxPluginOptions } from '../../plugins/plugin';
import { updatePackageScripts } from '@nx/devkit/src/utils/update-package-scripts';
import { createNodes, DetoxPluginOptions } from '../../plugins/plugin';
import { detoxVersion, nxVersion } from '../../utils/versions';
import { Schema } from './schema';

Expand All @@ -24,6 +25,10 @@ export async function detoxInitGenerator(host: Tree, schema: Schema) {
addPlugin(host);
}

if (schema.updatePackageScripts) {
await updatePackageScripts(host, createNodes);
}

if (!schema.skipFormat) {
await formatFiles(host);
}
Expand Down
1 change: 1 addition & 0 deletions packages/detox/src/generators/init/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface Schema {
skipFormat?: boolean;
skipPackageJson?: boolean; //default is false
keepExistingVersions?: boolean; //default is false
updatePackageScripts?: boolean;
}
6 changes: 6 additions & 0 deletions packages/detox/src/generators/init/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": false
},
"updatePackageScripts": {
"type": "boolean",
"x-priority": "internal",
"description": "Update `package.json` scripts with inferred targets",
"default": false
}
},
"required": []
Expand Down
3 changes: 2 additions & 1 deletion packages/devkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"ignore": "^5.0.4",
"tmp": "~0.2.1",
"tslib": "^2.3.0",
"semver": "7.5.3"
"semver": "7.5.3",
"yargs-parser": "21.1.1"
},
"peerDependencies": {
"nx": ">= 16 <= 18"
Expand Down
Loading

1 comment on commit e475835

@vercel
Copy link

@vercel vercel bot commented on e475835 Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.