Merge pull request #825 from ing-bank/fix/providenceDashboard

Fix/providence dashboard
This commit is contained in:
Thijs Louisse 2020-07-22 10:55:58 +02:00 committed by GitHub
commit 4cf829a874
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 21 deletions

View file

@ -304,14 +304,17 @@ class PBoard extends DecorateMixin(LitElement) {
const refSearch = `_${ref.replace('#', '_')}_`; const refSearch = `_${ref.replace('#', '_')}_`;
activeRepos.forEach(dep => { activeRepos.forEach(dep => {
const depSearch = `_${dep.replace('#', '_')}_`; const depSearch = `_${dep.replace('#', '_')}_`;
const found = this.__resultFiles[activeAnalyzer].find( const found = this.__resultFiles[activeAnalyzer].find(({ fileName }) => {
({ fileName }) => fileName.includes(refSearch) && fileName.includes(depSearch), return (
); fileName.includes(encodeURIComponent(refSearch)) &&
fileName.includes(encodeURIComponent(depSearch))
);
});
if (found) { if (found) {
jsonResultsActiveFilter.push(found.content); jsonResultsActiveFilter.push(found.content);
} else { } else {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.warn(`No result output json for ${refSearch} and ${depSearch}`); console.info(`No result output json for ${refSearch} and ${depSearch}`);
} }
}); });
}); });

View file

@ -6,6 +6,7 @@ const { LogService } = require('../../src/program/services/LogService.js');
// eslint-disable-next-line import/no-dynamic-require // eslint-disable-next-line import/no-dynamic-require
const providenceConf = require(`${pathLib.join(process.cwd(), 'providence.conf.js')}`); const providenceConf = require(`${pathLib.join(process.cwd(), 'providence.conf.js')}`);
let outputFilePaths; let outputFilePaths;
try { try {
outputFilePaths = fs.readdirSync(ReportService.outputPath); outputFilePaths = fs.readdirSync(ReportService.outputPath);
@ -38,23 +39,42 @@ outputFilePaths.forEach(fileName => {
} }
}); });
function getPackageJson(projectPath) {
let pkgJson;
try {
const file = pathLib.resolve(projectPath, 'package.json');
pkgJson = JSON.parse(fs.readFileSync(file, 'utf8'));
} catch (_) {
// eslint-disable-next-line no-empty
}
return pkgJson;
}
function transformToProjectNames(collections) { function transformToProjectNames(collections) {
const res = {}; const res = {};
// eslint-disable-next-line array-callback-return // eslint-disable-next-line array-callback-return
Object.entries(collections).map(([key, val]) => { Object.entries(collections).map(([key, val]) => {
res[key] = val.map(c => pathLib.basename(c)); res[key] = val.map(c => {
const pkg = getPackageJson(c);
return pkg && pkg.name;
});
}); });
return res; return res;
} }
const pathFromServerRootToHere = `/${pathLib.relative(process.cwd(), __dirname)}`; const pathFromServerRootToHere = `/${pathLib.relative(process.cwd(), __dirname)}`;
// Needed for dev purposes (we call it from ./packages/providence-analytics/ instead of ./)
// Allows es-dev-server to find the right moduleDirs
const fromPackageRoot = process.argv.includes('--serve-from-package-root');
const moduleRoot = fromPackageRoot ? pathLib.resolve(process.cwd(), '../../') : process.cwd();
const config = createConfig({ const config = createConfig({
port: 8080, port: 8080,
// appIndex: './dashboard/index.html', appIndex: pathLib.resolve(__dirname, 'index.html'),
// rootDir: process.cwd(), rootDir: moduleRoot,
nodeResolve: true, nodeResolve: true,
// moduleDirs: pathLib.resolve(process.cwd(), 'node_modules'), moduleDirs: pathLib.resolve(moduleRoot, 'node_modules'),
watch: false, watch: false,
open: true, open: true,
middlewares: [ middlewares: [

View file

@ -19,7 +19,8 @@
"src" "src"
], ],
"scripts": { "scripts": {
"dashboard": "node ./dashboard/src/server.js", "dashboard": "node ./dashboard/src/server.js --serve-from-package-root",
"match-lion-imports": "npm run providence analyze match-imports --search-target-collection @lion-targets --reference-collection @lion-references",
"providence": "node --max-old-space-size=8192 ./src/cli/index.js", "providence": "node --max-old-space-size=8192 ./src/cli/index.js",
"test:node": "mocha './test-node/**/*.test.js'", "test:node": "mocha './test-node/**/*.test.js'",
"test:node:e2e": "mocha './test-node/program/**/*.e2e.js' --timeout 60000", "test:node:e2e": "mocha './test-node/program/**/*.e2e.js' --timeout 60000",

View file

@ -1,13 +1,41 @@
const pathLib = require('path');
const fs = require('fs');
// This file is read by dashboard and cli and needs to be present under process.cwd() // This file is read by dashboard and cli and needs to be present under process.cwd()
// It mainly serves as an example and it allows to run the dashboard locally // It mainly serves as an example and it allows to run the dashboard locally
// from within this repo. // from within this repo.
/**
* @returns {string[]}
*/
function getAllLionScopedPackagePaths() {
const rootPath = pathLib.resolve(__dirname, '../../packages');
const filesAndDirs = fs.readdirSync(rootPath);
const packages = filesAndDirs.filter(f => {
const filePath = pathLib.join(rootPath, f);
if (fs.lstatSync(filePath).isDirectory()) {
let pkgJson;
try {
pkgJson = JSON.parse(fs.readFileSync(pathLib.resolve(filePath, './package.json')));
// eslint-disable-next-line no-empty
} catch (_) {
return false;
}
return pkgJson.name && pkgJson.name.startsWith('@lion/');
}
return false;
});
return packages.map(p => pathLib.join(rootPath, p));
}
const lionScopedPackagePaths = getAllLionScopedPackagePaths();
const providenceConfig = { const providenceConfig = {
metaConfig: { metaConfig: {
categoryConfig: [ categoryConfig: [
{ {
// This is the name found in package.json // This is the name found in package.json
project: 'lion-based-ui', project: '@lion/overlays',
majorVersion: 1, majorVersion: 1,
// These conditions will be run on overy filePath // These conditions will be run on overy filePath
categories: { categories: {
@ -25,20 +53,16 @@ const providenceConfig = {
], ],
}, },
// By predefening groups, we can do a query for programs/collections... // By predefening groups, we can do a query for programs/collections...
// Select via " providence analyze -t 'exampleCollection' " // Select via " providence analyze --search-target-collection 'exampleCollection' "
searchTargetCollections: { searchTargetCollections: {
exampleCollection: [ '@lion-targets': lionScopedPackagePaths,
'./providence-input-data/search-targets/example-project-a',
'./providence-input-data/search-targets/example-project-b',
],
// ... // ...
}, },
referenceCollections: { referenceCollections: {
// Our products // Usually the references are different from the targets.
'lion-based-ui': [ // In this demo file, we test @lion usage amongst itself
'./providence-input-data/references/lion-based-ui', // Select via " providence analyze --reference-collection 'exampleCollection' "
'./providence-input-data/references/lion-based-ui-labs', '@lion-references': lionScopedPackagePaths,
],
}, },
}; };

View file

@ -39,6 +39,7 @@ 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 */

View file

@ -337,7 +337,7 @@ class InputDataService {
try { try {
// eslint-disable-next-line import/no-dynamic-require, global-require // eslint-disable-next-line import/no-dynamic-require, global-require
return require(`${process.cwd()}/providence.conf.js`); return require(`${process.cwd()}/providence.conf.js`);
} catch (_) { } catch (e) {
return null; return null;
} }
} }