Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add options entryFile and sourceRoot to start command #1691

Merged
merged 1 commit into from Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 30 additions & 9 deletions actions/start.action.ts
Expand Up @@ -6,8 +6,10 @@ import * as killProcess from 'tree-kill';
import { treeKillSync as killProcessSync } from '../lib/utils/tree-kill';
import { Input } from '../commands';
import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default';
import { Configuration } from '../lib/configuration';
import { defaultOutDir } from '../lib/configuration/defaults';
import {
defaultConfiguration,
defaultOutDir,
} from '../lib/configuration/defaults';
import { ERROR_PREFIX } from '../lib/ui';
import { BuildAction } from './build.action';

Expand Down Expand Up @@ -47,9 +49,31 @@ export class StartAction extends BuildAction {
const { options: tsOptions } =
this.tsConfigProvider.getByConfigFilename(pathToTsconfig);
const outDir = tsOptions.outDir || defaultOutDir;
const entryFile =
(options.find((option) => option.name === 'entryFile')
?.value as string) ||
getValueOrDefault(
configuration,
'entryFile',
appName,
undefined,
undefined,
defaultConfiguration.entryFile,
);
const sourceRoot =
(options.find((option) => option.name === 'sourceRoot')
?.value as string) ||
getValueOrDefault(
configuration,
'sourceRoot',
appName,
undefined,
undefined,
defaultConfiguration.sourceRoot,
);
const onSuccess = this.createOnSuccessHook(
configuration,
appName,
entryFile,
sourceRoot,
debugFlag,
outDir,
binaryToRun,
Expand All @@ -73,15 +97,12 @@ export class StartAction extends BuildAction {
}

public createOnSuccessHook(
configuration: Required<Configuration>,
appName: string,
entryFile: string,
sourceRoot: string,
debugFlag: boolean | string | undefined,
outDirName: string,
binaryToRun = 'node',
) {
const sourceRoot = getValueOrDefault(configuration, 'sourceRoot', appName);
const entryFile = getValueOrDefault(configuration, 'entryFile', appName);

let childProcessRef: any;
process.on(
'exit',
Expand Down
16 changes: 16 additions & 0 deletions commands/start.command.ts
Expand Up @@ -17,6 +17,14 @@ export class StartCommand extends AbstractCommand {
.option('--webpack', 'Use webpack for compilation.')
.option('--webpackPath [path]', 'Path to webpack configuration.')
.option('--tsc', 'Use tsc for compilation.')
.option(
'--sourceRoot [sourceRoot]',
'Points at the root of the source code for the single project in standard mode structures, or the default project in monorepo mode structures.',
)
.option(
'--entryFile [entryFile]',
"Path to the entry file where this command will work with. Defaults to the one defined at your Nest's CLI config file.",
)
.option('-e, --exec [binary]', 'Binary to run (default: "node").')
.option(
'--preserveWatchOutput',
Expand Down Expand Up @@ -48,6 +56,14 @@ export class StartCommand extends AbstractCommand {
name: 'exec',
value: command.exec,
});
options.push({
name: 'sourceRoot',
value: command.sourceRoot,
});
options.push({
name: 'entryFile',
value: command.entryFile,
});
options.push({
name: 'preserveWatchOutput',
value:
Expand Down