Skip to content

Commit

Permalink
fix(core): migrate to yargs 17.x
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Mar 29, 2022
1 parent bab515e commit 69c6d9b
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 200 deletions.
4 changes: 0 additions & 4 deletions docs/generated/cli/affected-apps.md
Expand Up @@ -69,8 +69,6 @@ Show help

### ~~only-failed~~

Default: `false`

**Deprecated:** The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.

Isolate projects which previously failed
Expand All @@ -85,8 +83,6 @@ This is the name of the tasks runner configured in nx.json

### skip-nx-cache

Default: `false`

Rerun the tasks even when the results are available in the cache

### uncommitted
Expand Down
6 changes: 0 additions & 6 deletions docs/generated/cli/affected-graph.md
Expand Up @@ -103,8 +103,6 @@ Bind the project graph server to a specific ip address.

### ~~only-failed~~

Default: `false`

**Deprecated:** The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.

Isolate projects which previously failed
Expand All @@ -125,8 +123,6 @@ This is the name of the tasks runner configured in nx.json

### skip-nx-cache

Default: `false`

Rerun the tasks even when the results are available in the cache

### uncommitted
Expand All @@ -147,6 +143,4 @@ Show version number

### watch

Default: `false`

Watch for changes to project graph and update in-browser
4 changes: 0 additions & 4 deletions docs/generated/cli/affected-libs.md
Expand Up @@ -69,8 +69,6 @@ Show help

### ~~only-failed~~

Default: `false`

**Deprecated:** The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.

Isolate projects which previously failed
Expand All @@ -85,8 +83,6 @@ This is the name of the tasks runner configured in nx.json

### skip-nx-cache

Default: `false`

Rerun the tasks even when the results are available in the cache

### uncommitted
Expand Down
4 changes: 0 additions & 4 deletions docs/generated/cli/affected.md
Expand Up @@ -87,8 +87,6 @@ Show help

### ~~only-failed~~

Default: `false`

**Deprecated:** The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.

Isolate projects which previously failed
Expand All @@ -103,8 +101,6 @@ This is the name of the tasks runner configured in nx.json

### skip-nx-cache

Default: `false`

Rerun the tasks even when the results are available in the cache

### target
Expand Down
4 changes: 0 additions & 4 deletions docs/generated/cli/format-check.md
Expand Up @@ -53,8 +53,6 @@ Format only libraries and applications files.

### ~~only-failed~~

Default: `false`

**Deprecated:** The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.

Isolate projects which previously failed
Expand All @@ -69,8 +67,6 @@ This is the name of the tasks runner configured in nx.json

### skip-nx-cache

Default: `false`

Rerun the tasks even when the results are available in the cache

### uncommitted
Expand Down
4 changes: 0 additions & 4 deletions docs/generated/cli/format-write.md
Expand Up @@ -53,8 +53,6 @@ Format only libraries and applications files.

### ~~only-failed~~

Default: `false`

**Deprecated:** The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.

Isolate projects which previously failed
Expand All @@ -69,8 +67,6 @@ This is the name of the tasks runner configured in nx.json

### skip-nx-cache

Default: `false`

Rerun the tasks even when the results are available in the cache

### uncommitted
Expand Down
2 changes: 0 additions & 2 deletions docs/generated/cli/graph.md
Expand Up @@ -107,6 +107,4 @@ Show version number

### watch

Default: `false`

Watch for changes to project graph and update in-browser
4 changes: 0 additions & 4 deletions docs/generated/cli/print-affected.md
Expand Up @@ -81,8 +81,6 @@ Show help

### ~~only-failed~~

Default: `false`

**Deprecated:** The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.

Isolate projects which previously failed
Expand All @@ -97,8 +95,6 @@ Select the subset of the returned json document (e.g., --selected=projects)

### skip-nx-cache

Default: `false`

Rerun the tasks even when the results are available in the cache

### uncommitted
Expand Down
6 changes: 0 additions & 6 deletions docs/generated/cli/run-many.md
Expand Up @@ -57,8 +57,6 @@ Show help

### ~~only-failed~~

Default: `false`

**Deprecated:** The command to rerun failed projects will appear if projects fail. This now does nothing and will be removed in v15.

Only run the target on projects which previously failed
Expand All @@ -77,8 +75,6 @@ Override the tasks runner in `nx.json`

### skip-nx-cache

Default: `false`

Rerun the tasks even when the results are available in the cache

### target
Expand All @@ -95,8 +91,6 @@ Show version number

### ~~with-deps~~

Default: `false`

**Deprecated:** Configure target dependencies instead. It will be removed in v14.

Include dependencies of specified projects when computing what to run
18 changes: 9 additions & 9 deletions packages/create-nx-workspace/bin/create-nx-workspace.ts
Expand Up @@ -122,17 +122,15 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
'strip-dashed': true,
'dot-notation': false,
})
.strict()
.command(
// this is the default and only command
'$0 [name] [options]',
'Create a new Nx workspace',
(yargs) =>
yargs
.positional('name', {
.option('name', {
describe: `Workspace name (e.g. org name)`,
type: 'string',
demandOption: true,
})
.option('preset', {
describe: `Customizes the initial content of your workspace. To build your own see https://nx.dev/nx-plugin/overview#preset`,
Expand Down Expand Up @@ -179,7 +177,7 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
describe: `Default base to use for new projects`,
type: 'string',
}),
async (argv) => {
async (argv: yargs.ArgumentsCamelCase<Arguments>) => {
await main(argv).catch((error) => {
const { version } = require('../package.json');
output.error({
Expand All @@ -192,7 +190,7 @@ export const commandsObject: yargs.Argv<Arguments> = yargs
)
.help('help')
.updateLocale(yargsDecorator)
.version(nxVersion);
.version(nxVersion) as yargs.Argv<Arguments>;

async function main(parsedArgs: yargs.Arguments<Arguments>) {
const {
Expand Down Expand Up @@ -242,7 +240,9 @@ async function main(parsedArgs: yargs.Arguments<Arguments>) {
}
}

async function getConfiguration(argv: yargs.Arguments<Arguments>) {
async function getConfiguration(
argv: yargs.Arguments<Arguments>
): Promise<void> {
try {
let style, appName;

Expand All @@ -260,7 +260,7 @@ async function getConfiguration(argv: yargs.Arguments<Arguments>) {
const defaultBase = await determineDefaultBase(argv);
const nxCloud = await determineNxCloud(argv);

return {
Object.assign(argv, {
name,
preset,
appName,
Expand All @@ -269,7 +269,7 @@ async function getConfiguration(argv: yargs.Arguments<Arguments>) {
nxCloud,
packageManager,
defaultBase,
};
});
} catch (e) {
console.error(e);
process.exit(1);
Expand Down Expand Up @@ -751,7 +751,7 @@ function execAndWait(command: string, cwd: string) {
});
}

async function determineNxCloud(parsedArgs: any) {
async function determineNxCloud(parsedArgs: yargs.Arguments<Arguments>) {
if (parsedArgs.nxCloud === undefined) {
return enquirer
.prompt([
Expand Down
4 changes: 2 additions & 2 deletions packages/create-nx-workspace/bin/decorator.ts
@@ -1,6 +1,6 @@
import * as chalk from 'chalk';

export const yargsDecorator = {
'Options:': `${chalk.green('Options')}:`,
'Positionals:': `${chalk.green('Positionals')}:`,
'Options:': `${chalk.bold('Options')}:`,
'Positionals:': `${chalk.bold('Positionals')}:`,
};
12 changes: 11 additions & 1 deletion packages/create-nx-workspace/bin/package-manager.ts
@@ -1,4 +1,6 @@
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { join } from 'path';

/*
* Because we don't want to depend on @nrwl/workspace (to speed up the workspace creation)
Expand All @@ -9,6 +11,14 @@ export const packageManagerList = ['npm', 'yarn', 'pnpm'] as const;

export type PackageManager = typeof packageManagerList[number];

export function detectPackageManager(dir: string = ''): PackageManager {
return existsSync(join(dir, 'yarn.lock'))
? 'yarn'
: existsSync(join(dir, 'pnpm-lock.yaml'))
? 'pnpm'
: 'npm';
}

/**
* Returns commands for the package manager used in the workspace.
* By default, the package manager is derived based on the lock file,
Expand All @@ -22,7 +32,7 @@ export type PackageManager = typeof packageManagerList[number];
*
*/
export function getPackageManagerCommand(
packageManager: PackageManager = 'npm'
packageManager: PackageManager = detectPackageManager()
): {
install: string;
add: string;
Expand Down
14 changes: 12 additions & 2 deletions scripts/documentation/documentation.ts
@@ -1,5 +1,7 @@
import * as chalk from 'chalk';
import { execSync } from 'child_process';
import { removeSync } from 'fs-extra';
import { join } from 'path';
import { generateCLIDocumentation } from './generate-cli-data';
import { generateCNWocumentation } from './generate-cnw-documentation';
import { generateDevkitDocumentation } from './generate-devkit-documentation';
Expand All @@ -10,8 +12,16 @@ async function generate() {
console.log(`${chalk.blue('i')} Generating Documentation`);
generatePackageSchemas();
generateDevkitDocumentation();
await generateCNWocumentation();
await generateCLIDocumentation();

const commandsOutputDirectory = join(
__dirname,
'../../docs/',
'generated',
'cli'
);
removeSync(commandsOutputDirectory);
await generateCNWocumentation(commandsOutputDirectory);
await generateCLIDocumentation(commandsOutputDirectory);

console.log(`\n${chalk.green('✓')} Generated Documentation\n`);
} catch (e) {
Expand Down

0 comments on commit 69c6d9b

Please sign in to comment.