Skip to content

Commit

Permalink
Merge pull request #1691 from micalevisk/feat/add-options-on-start
Browse files Browse the repository at this point in the history
feat: add options `entryFile` and `sourceRoot` to `start` command
  • Loading branch information
kamilmysliwiec committed Jun 23, 2022
2 parents 2188581 + f82725b commit 7c3b563
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
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

0 comments on commit 7c3b563

Please sign in to comment.