Skip to content

Commit

Permalink
fix(core): adjust logic to use environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 14, 2023
1 parent bcf8876 commit 1d55bb0
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 37 deletions.
6 changes: 0 additions & 6 deletions docs/generated/cli/create-nx-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ Type: `string`

Customizes the initial content of your workspace. Default presets include: ["apps", "empty", "core", "npm", "ts", "web-components", "angular-monorepo", "angular-standalone", "react-monorepo", "react-standalone", "react-native", "expo", "next", "nest", "express", "react", "angular", "node-standalone"]. To build your own see https://nx.dev/packages/nx-plugin#preset

### presetVersion

Type: `string`

Version of the custom preset to be used.

### routing

Type: `boolean`
Expand Down
6 changes: 0 additions & 6 deletions docs/generated/packages/nx/documents/create-nx-workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ Type: `string`

Customizes the initial content of your workspace. Default presets include: ["apps", "empty", "core", "npm", "ts", "web-components", "angular-monorepo", "angular-standalone", "react-monorepo", "react-standalone", "react-native", "expo", "next", "nest", "express", "react", "angular", "node-standalone"]. To build your own see https://nx.dev/packages/nx-plugin#preset

### presetVersion

Type: `string`

Version of the custom preset to be used.

### routing

Type: `boolean`
Expand Down
4 changes: 0 additions & 4 deletions docs/generated/packages/workspace/generators/new.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
"description": "What to create in the new workspace.",
"type": "string"
},
"presetVersion": {
"description": "Version of the custom preset to be used.",
"oneOf": [{ "type": "string" }, { "type": "number" }]
},
"appName": { "type": "string", "description": "Application name." },
"nxCloud": {
"description": "Connect the workspace to the free tier of the distributed cache provided by Nx Cloud.",
Expand Down
5 changes: 0 additions & 5 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {

interface Arguments extends CreateWorkspaceOptions {
preset: string;
presetVersion: string;
appName: string;
style: string;
framework: Framework;
Expand Down Expand Up @@ -68,10 +67,6 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
)}]. To build your own see https://nx.dev/packages/nx-plugin#preset`,
type: 'string',
})
.option('presetVersion', {
describe: chalk.dim`Version of the custom preset to be used.`,
type: 'string',
})
.option('appName', {
describe: chalk.dim`The name of the application when a preset with pregenerated app is selected`,
type: 'string',
Expand Down
4 changes: 3 additions & 1 deletion packages/workspace/src/generators/new/generate-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ function getPresetDependencies({
return {
dev: {},
dependencies: {
[preset]: getNpmPackageVersion(preset, presetVersion),
[preset]:
process.env['NX_E2E_PRESET_VERSION'] ??
getNpmPackageVersion(preset, presetVersion),
},
};
}
Expand Down
23 changes: 12 additions & 11 deletions packages/workspace/src/generators/new/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ interface Schema {
style?: string;
nxCloud?: boolean;
preset: string;
presetVersion?: string | number; // number is needed so that generator doesn't fail on numeric-like strings (e.g. "14")
defaultBase: string;
framework?: string;
docker?: boolean;
Expand Down Expand Up @@ -97,22 +96,24 @@ function parsePresetName(input: string): { package: string; version?: string } {
// If the preset already contains a version in the name
// -- [email protected]
// -- @scope/package@version
const SCOPED_PACKAGE = /^(@[^\/]+\/[^@\/]+)(?:@([^\/]+))?$/;
const NON_SCOPED_PACKAGE = /^([^@\/]+)(?:@([^\/]+))?$/;
const match = input.match(SCOPED_PACKAGE) || input.match(NON_SCOPED_PACKAGE);
if (!match?.[0]) {
throw new Error(`Invalid package name: ${input}`);
const atIndex = input.indexOf('@', 1); // Skip the beginning @ because it denotes a scoped package.

if (atIndex > 0) {
return {
package: input.slice(0, atIndex),
version: input.slice(atIndex + 1),
};
} else {
if (!input) {
throw new Error(`Invalid package name: ${input}`);
}
return { package: input };
}
return {
package: match[1],
version: match[2],
};
}

function normalizeOptions(options: Schema): NormalizedSchema {
const normalized: Partial<NormalizedSchema> = {
...options,
presetVersion: options.presetVersion?.toString(),
};

normalized.name = names(options.name).fileName;
Expand Down
4 changes: 0 additions & 4 deletions packages/workspace/src/generators/new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
"description": "What to create in the new workspace.",
"type": "string"
},
"presetVersion": {
"description": "Version of the custom preset to be used.",
"oneOf": [{ "type": "string" }, { "type": "number" }]
},
"appName": {
"type": "string",
"description": "Application name."
Expand Down

0 comments on commit 1d55bb0

Please sign in to comment.