Skip to content

Commit

Permalink
feat: exec in configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ydhn committed Apr 12, 2023
1 parent e50c7b8 commit 177d945
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
53 changes: 25 additions & 28 deletions actions/start.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export class StartAction extends BuildAction {
options,
);

const binaryToRunOption = options.find(
(option) => option.name === 'exec',
);
const debugModeOption = options.find((option) => option.name === 'debug');
const watchModeOption = options.find((option) => option.name === 'watch');
const isWatchEnabled = !!(watchModeOption && watchModeOption.value);
Expand All @@ -43,34 +40,34 @@ export class StartAction extends BuildAction {
watchAssetsModeOption && watchAssetsModeOption.value
);
const debugFlag = debugModeOption && debugModeOption.value;
const binaryToRun =
binaryToRunOption && (binaryToRunOption.value as string | undefined);
const binaryToRun = getValueOrDefault(
configuration,
'exec',
appName,
'exec',
options,
defaultConfiguration.exec,
);

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 entryFile = getValueOrDefault(
configuration,
'entryFile',
appName,
'entryFile',
options,
defaultConfiguration.entryFile,
);
const sourceRoot = getValueOrDefault(
configuration,
'sourceRoot',
appName,
'sourceRoot',
options,
defaultConfiguration.sourceRoot,
);
const onSuccess = this.createOnSuccessHook(
entryFile,
sourceRoot,
Expand Down Expand Up @@ -101,7 +98,7 @@ export class StartAction extends BuildAction {
sourceRoot: string,
debugFlag: boolean | string | undefined,
outDirName: string,
binaryToRun = 'node',
binaryToRun: string,
) {
let childProcessRef: any;
process.on(
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/helpers/get-value-or-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function getValueOrDefault<T = any>(
configuration: Required<Configuration>,
propertyPath: string,
appName: string,
key?: 'path' | 'webpack' | 'webpackPath',
key?: 'path' | 'webpack' | 'webpackPath' | 'entryFile' | 'sourceRoot' | 'exec',
options: Input[] = [],
defaultValue?: T,
): T {
Expand Down
2 changes: 2 additions & 0 deletions lib/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ProjectConfiguration {
type?: string;
root?: string;
entryFile?: string;
exec?: string;
sourceRoot?: string;
compilerOptions?: CompilerOptions;
}
Expand All @@ -49,6 +50,7 @@ export interface Configuration {
collection?: string;
sourceRoot?: string;
entryFile?: string;
exec?: string;
monorepo?: boolean;
compilerOptions?: CompilerOptions;
generateOptions?: GenerateOptions;
Expand Down
1 change: 1 addition & 0 deletions lib/configuration/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const defaultConfiguration: Required<Configuration> = {
sourceRoot: 'src',
collection: '@nestjs/schematics',
entryFile: 'main',
exec: 'node',
projects: {},
monorepo: false,
compilerOptions: {
Expand Down
9 changes: 9 additions & 0 deletions test/lib/compiler/helpers/get-value-or-default.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('Get Value or Default', () => {
monorepo: true,
sourceRoot: '',
entryFile: '',
exec: '',
projects: {},
language: '',
collection: '',
Expand All @@ -20,6 +21,7 @@ describe('Get Value or Default', () => {
monorepo: false,
sourceRoot: '',
entryFile: '',
exec: '',
projects: {},
language: '',
collection: '',
Expand All @@ -38,6 +40,7 @@ describe('Get Value or Default', () => {
monorepo: true,
sourceRoot: '',
entryFile: '',
exec: '',
projects: {
'test-project': {
compilerOptions: {
Expand All @@ -61,6 +64,7 @@ describe('Get Value or Default', () => {
monorepo: true,
sourceRoot: '',
entryFile: '',
exec: '',
projects: {
'test-project': {
compilerOptions: {
Expand All @@ -84,6 +88,7 @@ describe('Get Value or Default', () => {
monorepo: true,
sourceRoot: '',
entryFile: '',
exec: '',
projects: {
'test-project': {
compilerOptions: {},
Expand All @@ -107,6 +112,7 @@ describe('Get Value or Default', () => {
monorepo: true,
sourceRoot: '',
entryFile: '',
exec: '',
projects: {
'test-project': {
compilerOptions: {},
Expand All @@ -130,6 +136,7 @@ describe('Get Value or Default', () => {
monorepo: true,
sourceRoot: '',
entryFile: '',
exec: '',
projects: {
'test-project': {
compilerOptions: {},
Expand All @@ -153,6 +160,7 @@ describe('Get Value or Default', () => {
monorepo: true,
sourceRoot: '',
entryFile: '',
exec: '',
projects: {
'test-project': {
compilerOptions: {},
Expand All @@ -176,6 +184,7 @@ describe('Get Value or Default', () => {
monorepo: true,
sourceRoot: '',
entryFile: '',
exec: '',
projects: {
'test.project.v1.api': {
sourceRoot: 'apps/test.project.v1.api/src',
Expand Down
2 changes: 2 additions & 0 deletions test/lib/configuration/nest-configuration.loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('Nest Configuration Loader', () => {
collection: '@nestjs/schematics',
sourceRoot: 'src',
entryFile: 'main',
exec: 'node',
monorepo: false,
projects: {},
compilerOptions: {
Expand All @@ -66,6 +67,7 @@ describe('Nest Configuration Loader', () => {
collection: '@nestjs/schematics',
sourceRoot: 'src',
entryFile: 'secondary',
exec: 'node',
monorepo: false,
projects: {},
compilerOptions: {
Expand Down

0 comments on commit 177d945

Please sign in to comment.