Skip to content

Commit

Permalink
fix(web): add option to override outputPath for file-server (nrwl#12941)
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens authored and FrozenPandaz committed Nov 2, 2022
1 parent 5df5339 commit 4a088fa
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
4 changes: 4 additions & 0 deletions docs/generated/packages/web.json
Expand Up @@ -999,6 +999,10 @@
"type": "boolean",
"description": "Redirect 404 errors to index.html (useful for SPA's)",
"default": false
},
"staticFilePath": {
"type": "string",
"description": "Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath"
}
},
"additionalProperties": false,
Expand Down
49 changes: 28 additions & 21 deletions packages/nx/src/command-line/nx-commands.ts
Expand Up @@ -403,8 +403,17 @@ function withPlainOption(yargs: yargs.Argv): yargs.Argv {
});
}

function withExcludeOption(yargs: yargs.Argv): yargs.Argv {
return yargs.option('exclude', {
describe: 'Exclude certain projects from being processed',
type: 'array',
coerce: parseCSV,
default: [],
});
}

function withRunOptions(yargs: yargs.Argv): yargs.Argv {
return yargs
return withExcludeOption(yargs)
.option('parallel', {
describe: 'Max number of parallel processes [default is 3]',
type: 'string',
Expand Down Expand Up @@ -449,11 +458,19 @@ function withRunOptions(yargs: yargs.Argv): yargs.Argv {
'Rerun the tasks even when the results are available in the cache',
type: 'boolean',
default: false,
})
.options('cloud', {
type: 'boolean',
hidden: true,
})
.options('dte', {
type: 'boolean',
hidden: true,
});
}

function withAffectedOptions(yargs: yargs.Argv): yargs.Argv {
return yargs
return withExcludeOption(yargs)
.parserConfiguration({
'strip-dashed': true,
'unknown-options-as-args': true,
Expand Down Expand Up @@ -501,12 +518,6 @@ function withAffectedOptions(yargs: yargs.Argv): yargs.Argv {
)
.group(['files', 'uncommitted', 'untracked'], 'or using:')
.implies('head', 'base')
.option('exclude', {
describe: 'Exclude certain projects from being processed',
type: 'array',
coerce: parseCSV,
default: [],
})
.conflicts({
files: ['uncommitted', 'untracked', 'base', 'head', 'all'],
untracked: ['uncommitted', 'files', 'base', 'head', 'all'],
Expand Down Expand Up @@ -547,12 +558,6 @@ function withRunManyOptions(yargs: yargs.Argv): yargs.Argv {
describe: '[deprecated] Run the target on all projects in the workspace',
type: 'boolean',
default: true,
})
.option('exclude', {
describe: 'Exclude certain projects from being processed',
type: 'array',
coerce: parseCSV,
default: [],
});
}

Expand Down Expand Up @@ -685,13 +690,15 @@ function withRunOneOptions(yargs: yargs.Argv) {
);

const res = withRunOptions(
withOutputStyleOption(yargs, [
'dynamic',
'static',
'stream',
'stream-without-prefixes',
'compact',
])
withTargetOption(
withOutputStyleOption(yargs, [
'dynamic',
'static',
'stream',
'stream-without-prefixes',
'compact',
])
)
)
.parserConfiguration({
'strip-dashed': true,
Expand Down
16 changes: 9 additions & 7 deletions packages/web/src/executors/file-server/file-server.impl.ts
Expand Up @@ -3,6 +3,8 @@ import * as chalk from 'chalk';
import {
ExecutorContext,
joinPathFragments,
parseTargetString,
readTargetOptions,
workspaceLayout,
} from '@nrwl/devkit';
import ignore from 'ignore';
Expand Down Expand Up @@ -57,14 +59,14 @@ function getBuildTargetCommand(options: Schema) {
}

function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) {
if (options.staticFilePath) {
return options.staticFilePath;
}

let buildOptions;
try {
const [project, target, config] = options.buildTarget.split(':');

const buildTarget = context.workspace.projects[project].targets[target];
buildOptions = config
? { ...buildTarget.options, ...buildTarget.configurations[config] }
: buildTarget.options;
const target = parseTargetString(options.buildTarget);
buildOptions = readTargetOptions(target, context);
} catch (e) {
throw new Error(`Invalid buildTarget: ${options.buildTarget}`);
}
Expand All @@ -73,7 +75,7 @@ function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) {
const outputPath = buildOptions.outputPath;
if (!outputPath) {
throw new Error(
`Invalid buildTarget: ${options.buildTarget}. The target must contain outputPath property.`
`Unable to get the outputPath from buildTarget ${options.buildTarget}. Make sure ${options.buildTarget} has an outputPath property or manually provide an staticFilePath property`
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/web/src/executors/file-server/schema.d.ts
Expand Up @@ -12,4 +12,5 @@ export interface Schema {
proxyOptions?: object;
watch?: boolean;
spa: boolean;
staticFilePath?: string;
}
4 changes: 4 additions & 0 deletions packages/web/src/executors/file-server/schema.json
Expand Up @@ -67,6 +67,10 @@
"type": "boolean",
"description": "Redirect 404 errors to index.html (useful for SPA's)",
"default": false
},
"staticFilePath": {
"type": "string",
"description": "Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath"
}
},
"additionalProperties": false,
Expand Down

0 comments on commit 4a088fa

Please sign in to comment.