Skip to content

Commit

Permalink
refactor resolveTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 22, 2024
1 parent 77dba6e commit d9ff5de
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
47 changes: 27 additions & 20 deletions lib/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { deflateSync } = require('lz-utils');
const Util = require('./utils/util.js');

const Assets = {

resolveNodeModule: (id) => {

// for deno npm module
Expand Down Expand Up @@ -31,13 +32,36 @@ const Assets = {
return dep;
}

Util.logError(`Not found module: ${p}`);
Util.logError(`Not found module: ${cwd}`);

return cwd;
},

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

if (!fs.existsSync(pkgPath)) {
Util.logError(`Not found package: ${pkgPath}`);
}

return pkgPath;
},

resolveTemplate: () => {

if (Assets.templateCache) {
return Assets.templateCache;
}

const templatePath = path.resolve(__dirname, './default/template.html');
const template = Util.readFileSync(templatePath);
if (template) {
Assets.templateCache = template;
} else {
Util.logError(`Not found template: ${templatePath}`);
}

return template;
},

saveHtmlReport: async (options) => {
Expand Down Expand Up @@ -107,7 +131,7 @@ const Assets = {
}

// html
const template = Assets.getTemplate();
const template = Assets.resolveTemplate();
const html = Util.replace(template, {
title: reportData.title,
content: htmlStr
Expand All @@ -116,23 +140,6 @@ const Assets = {
await Util.writeFile(htmlPath, html);

return reportPath;
},

getTemplate: function() {

if (Assets.templateCache) {
return Assets.templateCache;
}

const templatePath = path.resolve(__dirname, './default/template.html');
const template = Util.readFileSync(templatePath);
if (template) {
Assets.templateCache = template;
} else {
Util.logError(`not found template: ${templatePath}`);
}

return template;
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/test-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const generate = async () => {
console.log('generate istanbul coverage reports ...');

const coverageResults = await MCR(coverageOptions).generate();
console.log('istanbul coverageResults', Object.keys(coverageResults));
// console.log('istanbul coverageResults', Object.keys(coverageResults));
console.log('istanbul coverage reportPath', EC.magenta(coverageResults.reportPath));
};

Expand Down
2 changes: 1 addition & 1 deletion test/test-v8-and-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const generate = async () => {
console.log('generate v8-and-istanbul coverage reports ...');
// to istanbul
const coverageResults = await MCR(multipleReportsOptions).generate();
console.log('v8-to-istanbul coverageResults', Object.keys(coverageResults));
// console.log('v8-to-istanbul coverageResults', Object.keys(coverageResults));
console.log('reportPath', EC.magenta(coverageResults.reportPath));
};

Expand Down
2 changes: 1 addition & 1 deletion test/test-v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const generate = async () => {
console.log('generate v8 coverage reports ...');

const coverageResults = await MCR(coverageOptions).generate();
console.log('v8 coverageResults', Object.keys(coverageResults));
// console.log('v8 coverageResults', Object.keys(coverageResults));
console.log('v8 coverage reportPath', EC.magenta(coverageResults.reportPath));
};

Expand Down

0 comments on commit d9ff5de

Please sign in to comment.