feat(providence-analytics): allow target dependencies via cli
This commit is contained in:
parent
13e82cd316
commit
45372291b9
2 changed files with 50 additions and 32 deletions
|
|
@ -60,7 +60,7 @@ function pathsArrayFromCs(t, cwd = process.cwd()) {
|
||||||
* @param {object} eCfg external configuration. Usually providence.conf.js
|
* @param {object} eCfg external configuration. Usually providence.conf.js
|
||||||
* @returns {string[]}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
function pathsArrayFromCollectionName(name, colType = 'search-target', eCfg) {
|
function pathsArrayFromCollectionName(name, colType = 'search-target', eCfg, cwd) {
|
||||||
let collection;
|
let collection;
|
||||||
if (colType === 'search-target') {
|
if (colType === 'search-target') {
|
||||||
collection = eCfg.searchTargetCollections;
|
collection = eCfg.searchTargetCollections;
|
||||||
|
|
@ -68,7 +68,7 @@ function pathsArrayFromCollectionName(name, colType = 'search-target', eCfg) {
|
||||||
collection = eCfg.referenceCollections;
|
collection = eCfg.referenceCollections;
|
||||||
}
|
}
|
||||||
if (collection && collection[name]) {
|
if (collection && collection[name]) {
|
||||||
return pathsArrayFromCs(collection[name].join(','));
|
return pathsArrayFromCs(collection[name].join(','), cwd);
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
@ -107,10 +107,14 @@ function targetDefault() {
|
||||||
/**
|
/**
|
||||||
* @desc Returns all sub projects matching condition supplied in matchFn
|
* @desc Returns all sub projects matching condition supplied in matchFn
|
||||||
* @param {string[]} searchTargetPaths all search-target project paths
|
* @param {string[]} searchTargetPaths all search-target project paths
|
||||||
* @param {function} matchFn filters out packages we're interested in
|
* @param {string} matchPattern base for RegExp
|
||||||
* @param {string[]} modes
|
* @param {string[]} modes
|
||||||
*/
|
*/
|
||||||
async function appendProjectDependencyPaths(rootPaths, matchFn, modes = ['npm', 'bower']) {
|
async function appendProjectDependencyPaths(rootPaths, matchPattern, modes = ['npm', 'bower']) {
|
||||||
|
let matchFn;
|
||||||
|
if (matchPattern) {
|
||||||
|
matchFn = (_, d) => new RegExp(matchPattern).test(d);
|
||||||
|
}
|
||||||
const depProjectPaths = [];
|
const depProjectPaths = [];
|
||||||
await aForEach(rootPaths, async targetPath => {
|
await aForEach(rootPaths, async targetPath => {
|
||||||
await aForEach(modes, async mode => {
|
await aForEach(modes, async mode => {
|
||||||
|
|
|
||||||
|
|
@ -8,22 +8,18 @@ const providenceModule = require('../program/providence.js');
|
||||||
const { LogService } = require('../program/services/LogService.js');
|
const { LogService } = require('../program/services/LogService.js');
|
||||||
const { QueryService } = require('../program/services/QueryService.js');
|
const { QueryService } = require('../program/services/QueryService.js');
|
||||||
const { InputDataService } = require('../program/services/InputDataService.js');
|
const { InputDataService } = require('../program/services/InputDataService.js');
|
||||||
const { promptAnalyzerMenu, promptAnalyzerConfigMenu } = require('./prompt-analyzer-menu.js');
|
const promptModule = require('./prompt-analyzer-menu.js');
|
||||||
const {
|
const cliHelpers = require('./cli-helpers.js');
|
||||||
extensionsFromCs,
|
|
||||||
setQueryMethod,
|
|
||||||
targetDefault,
|
|
||||||
appendProjectDependencyPaths,
|
|
||||||
installDeps,
|
|
||||||
pathsArrayFromCollectionName,
|
|
||||||
pathsArrayFromCs,
|
|
||||||
} = require('./cli-helpers.js');
|
|
||||||
const extendDocsModule = require('./generate-extend-docs-data.js');
|
const extendDocsModule = require('./generate-extend-docs-data.js');
|
||||||
|
|
||||||
|
const { extensionsFromCs, setQueryMethod, targetDefault, installDeps } = cliHelpers;
|
||||||
|
|
||||||
const { version } = require('../../package.json');
|
const { version } = require('../../package.json');
|
||||||
|
|
||||||
async function cli({ cwd, addProjectDependencyPaths } = {}) {
|
async function cli({ cwd } = {}) {
|
||||||
let resolveCli;
|
let resolveCli;
|
||||||
let rejectCli;
|
let rejectCli;
|
||||||
|
|
||||||
const cliPromise = new Promise((resolve, reject) => {
|
const cliPromise = new Promise((resolve, reject) => {
|
||||||
resolveCli = resolve;
|
resolveCli = resolve;
|
||||||
rejectCli = reject;
|
rejectCli = reject;
|
||||||
|
|
@ -39,7 +35,6 @@ async function cli({ cwd, addProjectDependencyPaths } = {}) {
|
||||||
let regexSearchOptions;
|
let regexSearchOptions;
|
||||||
|
|
||||||
const externalConfig = InputDataService.getExternalConfig();
|
const externalConfig = InputDataService.getExternalConfig();
|
||||||
console.log('externalConfig', externalConfig);
|
|
||||||
|
|
||||||
async function getQueryInputData(
|
async function getQueryInputData(
|
||||||
/* eslint-disable no-shadow */
|
/* eslint-disable no-shadow */
|
||||||
|
|
@ -48,7 +43,6 @@ async function cli({ cwd, addProjectDependencyPaths } = {}) {
|
||||||
featureOptions,
|
featureOptions,
|
||||||
analyzerOptions,
|
analyzerOptions,
|
||||||
/* eslint-enable no-shadow */
|
/* eslint-enable no-shadow */
|
||||||
showAnalyzerConfigMenu,
|
|
||||||
) {
|
) {
|
||||||
let queryConfig = null;
|
let queryConfig = null;
|
||||||
let queryMethod = null;
|
let queryMethod = null;
|
||||||
|
|
@ -64,11 +58,14 @@ async function cli({ cwd, addProjectDependencyPaths } = {}) {
|
||||||
} else if (searchMode === 'analyzer-query') {
|
} else if (searchMode === 'analyzer-query') {
|
||||||
let { name, config } = analyzerOptions;
|
let { name, config } = analyzerOptions;
|
||||||
if (!name) {
|
if (!name) {
|
||||||
const answers = await promptAnalyzerMenu();
|
const answers = await promptModule.promptAnalyzerMenu();
|
||||||
name = answers.analyzerName;
|
name = answers.analyzerName;
|
||||||
}
|
}
|
||||||
if (showAnalyzerConfigMenu && !config) {
|
if (!config) {
|
||||||
const answers = await promptAnalyzerConfigMenu(name, analyzerOptions.promptOptionalConfig);
|
const answers = await promptModule.promptAnalyzerConfigMenu(
|
||||||
|
name,
|
||||||
|
analyzerOptions.promptOptionalConfig,
|
||||||
|
);
|
||||||
config = answers.analyzerConfig;
|
config = answers.analyzerConfig;
|
||||||
}
|
}
|
||||||
// Will get metaConfig from ./providence.conf.js
|
// Will get metaConfig from ./providence.conf.js
|
||||||
|
|
@ -97,11 +94,18 @@ async function cli({ cwd, addProjectDependencyPaths } = {}) {
|
||||||
referencePaths = commander.referenceCollection || commander.referencePaths;
|
referencePaths = commander.referenceCollection || commander.referencePaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
let extendedSearchTargets;
|
/**
|
||||||
if (addProjectDependencyPaths) {
|
* May or may not include dependencies of search target
|
||||||
extendedSearchTargets = await appendProjectDependencyPaths(searchTargetPaths);
|
* @type {string[]}
|
||||||
|
*/
|
||||||
|
let totalSearchTargets;
|
||||||
|
if (commander.includeTargetDeps) {
|
||||||
|
totalSearchTargets = await cliHelpers.appendProjectDependencyPaths(
|
||||||
|
searchTargetPaths,
|
||||||
|
commander.targetDepsFilter,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
extendedSearchTargets = searchTargetPaths;
|
totalSearchTargets = searchTargetPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: filter out:
|
// TODO: filter out:
|
||||||
|
|
@ -120,7 +124,7 @@ async function cli({ cwd, addProjectDependencyPaths } = {}) {
|
||||||
},
|
},
|
||||||
debugEnabled: commander.debug,
|
debugEnabled: commander.debug,
|
||||||
queryMethod,
|
queryMethod,
|
||||||
targetProjectPaths: extendedSearchTargets,
|
targetProjectPaths: totalSearchTargets,
|
||||||
referenceProjectPaths: referencePaths,
|
referenceProjectPaths: referencePaths,
|
||||||
targetProjectRootPaths: searchTargetPaths,
|
targetProjectRootPaths: searchTargetPaths,
|
||||||
writeLogFile: commander.writeLogFile,
|
writeLogFile: commander.writeLogFile,
|
||||||
|
|
@ -157,7 +161,7 @@ async function cli({ cwd, addProjectDependencyPaths } = {}) {
|
||||||
'-t, --search-target-paths [targets]',
|
'-t, --search-target-paths [targets]',
|
||||||
`path(s) to project(s) on which analysis/querying should take place. Requires
|
`path(s) to project(s) on which analysis/querying should take place. Requires
|
||||||
a list of comma seperated values relative to project root`,
|
a list of comma seperated values relative to project root`,
|
||||||
v => pathsArrayFromCs(v, cwd),
|
v => cliHelpers.pathsArrayFromCs(v, cwd),
|
||||||
targetDefault(),
|
targetDefault(),
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
|
|
@ -165,31 +169,41 @@ async function cli({ cwd, addProjectDependencyPaths } = {}) {
|
||||||
`path(s) to project(s) which serve as a reference (applicable for certain analyzers like
|
`path(s) to project(s) which serve as a reference (applicable for certain analyzers like
|
||||||
'match-imports'). Requires a list of comma seperated values relative to
|
'match-imports'). Requires a list of comma seperated values relative to
|
||||||
project root (like 'node_modules/lion-based-ui, node_modules/lion-based-ui-labs').`,
|
project root (like 'node_modules/lion-based-ui, node_modules/lion-based-ui-labs').`,
|
||||||
v => pathsArrayFromCs(v, cwd),
|
v => cliHelpers.pathsArrayFromCs(v, cwd),
|
||||||
InputDataService.referenceProjectPaths,
|
InputDataService.referenceProjectPaths,
|
||||||
)
|
)
|
||||||
.option('-w, --whitelist [whitelist]', `whitelisted paths, like './src, ./packages/*'`, v =>
|
.option('-w, --whitelist [whitelist]', `whitelisted paths, like './src, ./packages/*'`, v =>
|
||||||
pathsArrayFromCs(v, cwd),
|
cliHelpers.pathsArrayFromCs(v, cwd),
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'--whitelist-reference [whitelist-reference]',
|
'--whitelist-reference [whitelist-reference]',
|
||||||
`whitelisted paths for reference, like './src, ./packages/*'`,
|
`whitelisted paths for reference, like './src, ./packages/*'`,
|
||||||
v => pathsArrayFromCs(v, cwd),
|
v => cliHelpers.pathsArrayFromCs(v, cwd),
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'--search-target-collection [collection-name]',
|
'--search-target-collection [collection-name]',
|
||||||
`path(s) to project(s) which serve as a reference (applicable for certain analyzers like
|
`path(s) to project(s) which serve as a reference (applicable for certain analyzers like
|
||||||
'match-imports'). Should be a collection defined in providence.conf.js as paths relative to
|
'match-imports'). Should be a collection defined in providence.conf.js as paths relative to
|
||||||
project root.`,
|
project root.`,
|
||||||
v => pathsArrayFromCollectionName(v, 'search-target', externalConfig),
|
v => cliHelpers.pathsArrayFromCollectionName(v, 'search-target', externalConfig),
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'--reference-collection [collection-name]',
|
'--reference-collection [collection-name]',
|
||||||
`path(s) to project(s) on which analysis/querying should take place. Should be a collection
|
`path(s) to project(s) on which analysis/querying should take place. Should be a collection
|
||||||
defined in providence.conf.js as paths relative to project root.`,
|
defined in providence.conf.js as paths relative to project root.`,
|
||||||
v => pathsArrayFromCollectionName(v, 'reference', externalConfig),
|
v => cliHelpers.pathsArrayFromCollectionName(v, 'reference', externalConfig),
|
||||||
)
|
)
|
||||||
.option('--write-log-file', `Writes all logs to 'providence.log' file`);
|
.option('--write-log-file', `Writes all logs to 'providence.log' file`)
|
||||||
|
.option(
|
||||||
|
'--include-target-deps',
|
||||||
|
`For all search targets, will include all its dependencies
|
||||||
|
(node_modules and bower_components). When --target-deps-filter is applied, a subset
|
||||||
|
will be applied that matches the filter condition`,
|
||||||
|
)
|
||||||
|
.option(
|
||||||
|
'--target-deps-filter [target-deps-filter]',
|
||||||
|
`Regex condition to be applied to dependencies of search targets.`,
|
||||||
|
);
|
||||||
|
|
||||||
commander
|
commander
|
||||||
.command('search <regex>')
|
.command('search <regex>')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue