chore(core): nx reset command, updates to cli help output and docs

This commit is contained in:
James Henry 2021-10-13 16:51:28 +04:00 committed by Victor Savkin
parent 28f28af487
commit e7d49aa55d
16 changed files with 80 additions and 63 deletions

View File

@ -2,9 +2,7 @@
EXPERIMENTAL: Nx Daemon
The Daemon is not currently running you can start it manually by running the following command:
npx nx daemon:start
The Nx Daemon is a local server which runs in the background in order to intelligently cache information about the workspace's project graph.
## Usage

View File

@ -1,11 +1,11 @@
# clear-cache
# reset
Clears all the cached Nx artifacts and metadata about the workspace.
Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.
## Usage
```bash
nx clear-cache
nx reset
```
[Install `nx` globally]({{framework}}/getting-started/nx-setup#install-nx) to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpx nx`.

View File

@ -292,9 +292,9 @@
"file": "angular/cli/connect-to-nx-cloud"
},
{
"name": "clear-cache",
"id": "clear-cache",
"file": "angular/cli/clear-cache"
"name": "reset",
"id": "reset",
"file": "angular/cli/reset"
}
]
},
@ -1575,9 +1575,9 @@
"file": "react/cli/connect-to-nx-cloud"
},
{
"name": "clear-cache",
"id": "clear-cache",
"file": "react/cli/clear-cache"
"name": "reset",
"id": "reset",
"file": "react/cli/reset"
}
]
},
@ -2822,9 +2822,9 @@
"file": "node/cli/connect-to-nx-cloud"
},
{
"name": "clear-cache",
"id": "clear-cache",
"file": "node/cli/clear-cache"
"name": "reset",
"id": "reset",
"file": "node/cli/reset"
}
]
},

View File

@ -2,9 +2,7 @@
EXPERIMENTAL: Nx Daemon
The Daemon is not currently running you can start it manually by running the following command:
npx nx daemon:start
The Nx Daemon is a local server which runs in the background in order to intelligently cache information about the workspace's project graph.
## Usage

View File

@ -1,11 +1,11 @@
# clear-cache
# reset
Clears all the cached Nx artifacts and metadata about the workspace.
Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.
## Usage
```bash
nx clear-cache
nx reset
```
[Install `nx` globally]({{framework}}/getting-started/nx-setup#install-nx) to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpx nx`.

View File

@ -2,9 +2,7 @@
EXPERIMENTAL: Nx Daemon
The Daemon is not currently running you can start it manually by running the following command:
npx nx daemon:start
The Nx Daemon is a local server which runs in the background in order to intelligently cache information about the workspace's project graph.
## Usage

View File

@ -1,11 +1,11 @@
# clear-cache
# reset
Clears all the cached Nx artifacts and metadata about the workspace.
Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.
## Usage
```bash
nx clear-cache
nx reset
```
[Install `nx` globally]({{framework}}/getting-started/nx-setup#install-nx) to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpx nx`.

View File

@ -57,6 +57,7 @@ const invalidTargetNames = [
'workspace-schematic',
'connect-to-nx-cloud',
'clear-cache',
'reset',
'report',
'list',
];

View File

@ -1,29 +0,0 @@
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
import {
cacheDirectory,
readCacheDirectoryProperty,
} from '../utilities/cache-directory';
import { removeSync } from 'fs-extra';
import { output } from '../utilities/output';
export const clearCache = {
command: 'clear-cache',
describe:
'Clears all the cached Nx artifacts and metadata about the workspace.',
handler: clearCacheHandler,
};
async function clearCacheHandler() {
output.note({
title: 'Deleting the cache directory.',
bodyLines: [`This might take a few minutes.`],
});
const dir = cacheDirectory(
appRootPath,
readCacheDirectoryProperty(appRootPath)
);
removeSync(dir);
output.success({
title: 'Deleted the cache directory.',
});
}

View File

@ -11,10 +11,12 @@ import {
import { generateDaemonHelpOutput } from '../core/project-graph/daemon/client/generate-help-output';
import { nxVersion } from '../utils/versions';
import { examples } from './examples';
import { reset } from './reset';
const noop = (yargs: yargs.Argv): yargs.Argv => yargs;
const daemonHelpOutput = generateDaemonHelpOutput();
const isGenerateDocsProcess = process.env.NX_GENERATE_DOCS_PROCESS === 'true';
const daemonHelpOutput = generateDaemonHelpOutput(isGenerateDocsProcess);
// Ensure that the output takes up the available width of the terminal
yargs.wrap(yargs.terminalWidth());
@ -306,7 +308,7 @@ npx nx daemon:start
)
.command(require('./report').report)
.command(require('./list').list)
.command(require('./clear-cache').clearCache)
.command(reset)
.command(
'connect-to-nx-cloud',
chalk.bold(`Makes sure the workspace is connected to Nx Cloud`),

View File

@ -0,0 +1,33 @@
import { appRootPath } from '@nrwl/tao/src/utils/app-root';
import { remove } from 'fs-extra';
import type { CommandModule } from 'yargs';
import { stop as stopDaemon } from '../core/project-graph/daemon/client/client';
import {
cacheDirectory,
readCacheDirectoryProperty,
} from '../utilities/cache-directory';
import { output } from '../utilities/output';
export const reset: CommandModule = {
command: 'reset',
describe:
'Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.',
handler: resetHandler,
// Prior to v13 clear-cache was a top level nx command, so preserving as an alias
aliases: ['clear-cache'],
};
async function resetHandler() {
output.note({
title: 'Resetting the Nx workspace cache and stopping the Nx Daemon.',
bodyLines: [`This might take a few minutes.`],
});
const dir = cacheDirectory(
appRootPath,
readCacheDirectoryProperty(appRootPath)
);
await Promise.all([stopDaemon(), remove(dir)]);
output.success({
title: 'Successful reset the Nx workspace.',
});
}

View File

@ -23,6 +23,7 @@ export const supportedNxCommands: string[] = [
'run-many',
'connect-to-nx-cloud',
'clear-cache',
'reset',
'list',
'help',
'--help',

View File

@ -59,12 +59,12 @@ export function startInCurrentProcess(): void {
}
export function stop(): void {
logger.info(`NX Daemon Server - Stopping...`);
spawnSync(process.execPath, ['../server/stop.js'], {
cwd: __dirname,
stdio: 'inherit',
});
logger.info('NX Daemon Server - Stopped');
}
/**

View File

@ -2,7 +2,13 @@ import { spawnSync } from 'child_process';
import { getDaemonProcessId } from '../cache';
import { DAEMON_OUTPUT_LOG_FILE } from '../tmp-dir';
export function generateDaemonHelpOutput(): string {
export function generateDaemonHelpOutput(
isGenerateDocsProcess = false
): string {
if (isGenerateDocsProcess) {
return `The Nx Daemon is a local server which runs in the background in order to intelligently cache information about the workspace's project graph.`;
}
/**
* A workaround for cases such as yargs output where we need to synchronously
* get the value of this async operation.

View File

@ -274,7 +274,6 @@ export async function stopServer(): Promise<void> {
}
killSocketOrPath();
logger.info('NX Daemon Server - Stopped');
return resolve();
});
});

View File

@ -3,7 +3,6 @@ import { readFileSync } from 'fs';
import { removeSync } from 'fs-extra';
import { join } from 'path';
import { dedent } from 'tslint/lib/utils';
import { commandsObject } from '../../packages/workspace';
import { Framework, Frameworks } from './frameworks';
import {
formatDeprecated,
@ -37,8 +36,17 @@ interface ParsedCommand {
}
export async function generateCLIDocumentation() {
/**
* For certain commands, they will output dynamic data at runtime in a real workspace,
* so we leverage an envrionment variable to inform the logic of the context that we
* are just statically generating documentation for the current execution.
*/
process.env.NX_GENERATE_DOCS_PROCESS = 'true';
console.log(`\n${chalk.blue('i')} Generating Documentation for Nx Commands`);
const { commandsObject } = importFresh('../../packages/workspace');
await Promise.all(
Frameworks.map(async (framework: Framework) => {
const commandsOutputDirectory = join(
@ -187,5 +195,7 @@ nx ${command.name}
})
);
delete process.env.NX_GENERATE_DOCS_PROCESS;
console.log(`${chalk.green('✓')} Generated Documentation for Nx Commands`);
}