Skip to content

Commit

Permalink
chore(core): lazy load commands
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry authored and vsavkin committed Oct 15, 2021
1 parent a4e0d72 commit 4ff498f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
17 changes: 17 additions & 0 deletions packages/workspace/src/command-line/daemon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { logger } from '@nrwl/devkit';
import type { Arguments } from 'yargs';
import { DAEMON_OUTPUT_LOG_FILE } from '../core/project-graph/daemon/tmp-dir';

export async function daemonHandler(args: Arguments) {
const { startInBackground, startInCurrentProcess } = await import(
'../core/project-graph/daemon/client/client'
);
if (!args.background) {
return startInCurrentProcess();
}
logger.info(`NX Daemon Server - Starting in a background process...`);
const pid = await startInBackground();
logger.log(
` Logs from the Daemon process (ID: ${pid}) can be found here: ${DAEMON_OUTPUT_LOG_FILE}\n`
);
}
28 changes: 10 additions & 18 deletions packages/workspace/src/command-line/nx-commands.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { getPackageManagerCommand, logger, writeJsonFile } from '@nrwl/devkit';
import { getPackageManagerCommand, writeJsonFile } from '@nrwl/devkit';
import * as chalk from 'chalk';
import { execSync } from 'child_process';
import * as path from 'path';
import * as yargs from 'yargs';
import {
startInBackground,
startInCurrentProcess,
} from '../core/project-graph/daemon/client/client';
import { generateDaemonHelpOutput } from '../core/project-graph/daemon/client/generate-help-output';
import { DAEMON_OUTPUT_LOG_FILE } from '../core/project-graph/daemon/tmp-dir';
import { nxVersion } from '../utils/versions';
import { examples } from './examples';
import { reset } from './reset';

const noop = (yargs: yargs.Argv): yargs.Argv => yargs;

Expand Down Expand Up @@ -207,16 +201,7 @@ The Daemon is not currently running you can start it manually by running the fol
npx nx daemon
`.trimRight()),
(yargs) => linkToNxDevAndExamples(withDaemonStartOptions(yargs), 'daemon'),
async (args) => {
if (!args.background) {
return startInCurrentProcess();
}
logger.info(`NX Daemon Server - Starting in a background process...`);
const pid = await startInBackground();
logger.log(
` Logs from the Daemon process (ID: ${pid}) can be found here: ${DAEMON_OUTPUT_LOG_FILE}\n`
);
}
async (args) => (await import('./daemon')).daemonHandler(args)
)

.command(
Expand Down Expand Up @@ -298,7 +283,14 @@ npx nx daemon
)
.command(require('./report').report)
.command(require('./list').list)
.command(reset)
.command({
command: 'reset',
describe:
'Clears all the cached Nx artifacts and metadata about the workspace and shuts down the Nx Daemon.',
// Prior to v13 clear-cache was a top level nx command, so preserving as an alias
aliases: ['clear-cache'],
handler: async () => (await import('./reset')).resetHandler(),
})
.command(
'connect-to-nx-cloud',
chalk.bold(`Makes sure the workspace is connected to Nx Cloud`),
Expand Down
12 changes: 1 addition & 11 deletions packages/workspace/src/command-line/reset.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
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() {
export async function resetHandler() {
output.note({
title: 'Resetting the Nx workspace cache and stopping the Nx Daemon.',
bodyLines: [`This might take a few minutes.`],
Expand Down

0 comments on commit 4ff498f

Please sign in to comment.