* feat(core): consolidate settings between workspace.json + nx.json workspace.json (and linked project.json files) now contain all project specific settings. nx.json now contains all settings that affect the whole workspace. * chore(core): fix angular unit tests w/ new config * chore(core): fix failing tests * chore(core): fix formatting * chore(core): fix more tests * chore(core): normalize-nx-json feedback * chore(core): Fix more unit tests * chore(core): fix remaining tests in workspace * chore(linter): fix remaining linter tests * chore(core): fix remaining spec + build issues * chore(core): formatting fixes * feat(core): migration script to move config options to new locations * chore(core): fix e2e tests * chore(core): run format * chore(react-native): fix failing tests Signed-off-by: AgentEnder <craigorycoppola@gmail.com> * feat(core): move properties to new location during format step Signed-off-by: AgentEnder <craigorycoppola@gmail.com> * feat(core): initial pass on ngcli-adapter for property consolidation Signed-off-by: AgentEnder <craigorycoppola@gmail.com> * chore(misc): fix tests Signed-off-by: AgentEnder <craigorycoppola@gmail.com> * docs(core): update docs with changes * chore(misc): fix tests * chore(core): code review changes updateWorkspaceJson -> updateWorkspace, no longer uses updater function Signed-off-by: AgentEnder <craigorycoppola@gmail.com> * chore(core): fix bug in ngcli impl * fix(core): fix bug in ngcli-adapter Signed-off-by: AgentEnder <craigorycoppola@gmail.com> * fix(core): fix ngcli-adapter Signed-off-by: AgentEnder <craigorycoppola@gmail.com> * chore(core): fix workspace e2e * chore(core): fix nx-plugin e2e * fix(core): move defaultProject to nx.json * chore(core): fix broken workspace test * chore(core): formatting * chore(core): fix workspace format * chore(core): add nxJson to ExecutorContext Signed-off-by: AgentEnder <craigorycoppola@gmail.com> * chore(core): remove all references ot `NxProjectConfiguration` from our code * chore(core): Review Changes * fix(core): update new config locations v13 migration
158 lines
3.6 KiB
TypeScript
158 lines
3.6 KiB
TypeScript
import yargsParser = require('yargs-parser');
|
|
import * as fs from 'fs';
|
|
|
|
function calculateDefaultProjectName(
|
|
cwd: string,
|
|
root: string,
|
|
workspaceConfiguration: any,
|
|
nxJson
|
|
) {
|
|
let relativeCwd = cwd.replace(/\\/g, '/').split(root.replace(/\\/g, '/'))[1];
|
|
if (relativeCwd) {
|
|
relativeCwd = relativeCwd.startsWith('/')
|
|
? relativeCwd.substring(1)
|
|
: relativeCwd;
|
|
const matchingProject = Object.keys(workspaceConfiguration.projects).find(
|
|
(p) => {
|
|
const projectRoot = workspaceConfiguration.projects[p].root;
|
|
return (
|
|
relativeCwd == projectRoot ||
|
|
relativeCwd.startsWith(`${projectRoot}/`)
|
|
);
|
|
}
|
|
);
|
|
if (matchingProject) return matchingProject;
|
|
}
|
|
return (
|
|
nxJson.cli?.defaultProjectName ||
|
|
nxJson.defaultProject ||
|
|
workspaceConfiguration.defaultProject
|
|
);
|
|
}
|
|
|
|
const invalidTargetNames = [
|
|
'g',
|
|
'generate',
|
|
'update',
|
|
'migrate',
|
|
'add',
|
|
'affected',
|
|
'run-many',
|
|
'affected:apps',
|
|
'affected:libs',
|
|
'affected:build',
|
|
'affected:test',
|
|
'affected:e2e',
|
|
'affected:dep-graph',
|
|
'affected:lint',
|
|
'print-affected',
|
|
'daemon',
|
|
'daemon:start',
|
|
'daemon:stop',
|
|
'format:check',
|
|
'format',
|
|
'format:write',
|
|
'workspace-lint',
|
|
'workspace-generator',
|
|
'workspace-schematic',
|
|
'connect-to-nx-cloud',
|
|
'clear-cache',
|
|
'report',
|
|
'list',
|
|
];
|
|
|
|
export function parseRunOneOptions(
|
|
root: string,
|
|
workspaceJsonConfiguration: any,
|
|
nxJson: any,
|
|
args: string[]
|
|
): false | { project; target; configuration; parsedArgs } {
|
|
const defaultProjectName = calculateDefaultProjectName(
|
|
process.cwd(),
|
|
root,
|
|
workspaceJsonConfiguration,
|
|
nxJson
|
|
);
|
|
|
|
const parsedArgs = yargsParser(args, {
|
|
boolean: ['prod', 'help'],
|
|
string: ['configuration', 'project'],
|
|
alias: {
|
|
c: 'configuration',
|
|
},
|
|
configuration: {
|
|
'strip-dashed': true,
|
|
},
|
|
});
|
|
|
|
if (parsedArgs['help']) {
|
|
return false;
|
|
}
|
|
|
|
let project;
|
|
let target;
|
|
let configuration;
|
|
|
|
if (parsedArgs._[0] === 'run') {
|
|
[project, target, configuration] = (parsedArgs._[1] as any).split(':');
|
|
parsedArgs._ = parsedArgs._.slice(2);
|
|
} else {
|
|
target = parsedArgs._[0];
|
|
project = parsedArgs._[1];
|
|
parsedArgs._ = parsedArgs._.slice(2);
|
|
}
|
|
|
|
const projectIsNotSetExplicitly = !project;
|
|
if (!project && defaultProjectName) {
|
|
project = defaultProjectName;
|
|
}
|
|
|
|
if (parsedArgs.project) {
|
|
project = parsedArgs.project;
|
|
}
|
|
// we need both to be able to run a target, no tasks runner
|
|
if (!project || !target) {
|
|
return false;
|
|
}
|
|
|
|
// we need both to be able to run a target, no tasks runner
|
|
const p =
|
|
workspaceJsonConfiguration.projects &&
|
|
workspaceJsonConfiguration.projects[project];
|
|
if (!p) return false;
|
|
|
|
let targets;
|
|
if (typeof p === 'string') {
|
|
targets = JSON.parse(
|
|
fs.readFileSync(`${p}/project.json`).toString()
|
|
).targets;
|
|
} else {
|
|
targets = p.architect ?? p.targets;
|
|
}
|
|
|
|
// for backwards compat we require targets to be set when use defaultProjectName
|
|
if ((!targets || !targets[target]) && projectIsNotSetExplicitly) return false;
|
|
if (invalidTargetNames.indexOf(target) > -1) return false;
|
|
|
|
if (parsedArgs.configuration) {
|
|
configuration = parsedArgs.configuration;
|
|
} else if (parsedArgs.prod) {
|
|
configuration = 'production';
|
|
} else if (
|
|
!configuration &&
|
|
targets &&
|
|
targets[target] &&
|
|
targets[target].defaultConfiguration
|
|
) {
|
|
configuration = targets[target].defaultConfiguration;
|
|
}
|
|
|
|
const res = { project, target, configuration, parsedArgs };
|
|
delete parsedArgs['c'];
|
|
delete parsedArgs['configuration'];
|
|
delete parsedArgs['prod'];
|
|
delete parsedArgs['project'];
|
|
|
|
return res;
|
|
}
|