Skip to content

Commit

Permalink
fix mcr lib path
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 22, 2024
1 parent d9ff5de commit ae4af9d
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions lib/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const path = require('path');
const { deflateSync } = require('lz-utils');
const Util = require('./utils/util.js');
const MCR = 'monocart-coverage-reports';

const Assets = {

Expand Down Expand Up @@ -37,13 +38,27 @@ const Assets = {
return cwd;
},

resolveMcrLib: () => {
const mp = require.resolve(MCR);
if (fs.existsSync(mp)) {
return path.dirname(mp);
}
},

resolvePackage: (p) => {
const pkgPath = path.resolve(__dirname, './packages', p);
if (fs.existsSync(pkgPath)) {
return pkgPath;
}

if (!fs.existsSync(pkgPath)) {
Util.logError(`Not found package: ${pkgPath}`);
// look from node_modules after bundled
const libPath = Assets.resolveMcrLib();
if (libPath) {
return path.resolve(libPath, './packages', p);
}

Util.logError(`Not found package: ${pkgPath}`);

return pkgPath;
},

Expand All @@ -53,15 +68,27 @@ const Assets = {
return Assets.templateCache;
}

const templatePath = path.resolve(__dirname, './default/template.html');
const p = './default/template.html';
let templatePath = path.resolve(__dirname, p);

if (!fs.existsSync(templatePath)) {
// look from node_modules after bundled
const libPath = Assets.resolveMcrLib();
if (libPath) {
templatePath = path.resolve(libPath, p);
}

}

const template = Util.readFileSync(templatePath);
if (template) {
Assets.templateCache = template;
} else {
Util.logError(`Not found template: ${templatePath}`);
return template;
}

return template;
Util.logError(`Not found template: ${templatePath}`);

return 'Not found template';
},

saveHtmlReport: async (options) => {
Expand Down

0 comments on commit ae4af9d

Please sign in to comment.