fix(providence-analytics): allow dashboard to run within package

This commit is contained in:
Thijs Louisse 2020-07-21 23:35:55 +02:00
parent 8396888699
commit 12b6608516
2 changed files with 25 additions and 5 deletions

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,7 @@
"src" "src"
], ],
"scripts": { "scripts": {
"dashboard": "node ./dashboard/src/server.js", "dashboard": "node ./dashboard/src/server.js --serve-from-package-root",
"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",