Skip to content

Commit

Permalink
fix: use fallback absolute path when relative path method is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
matmar10 committed Aug 30, 2021
1 parent 1c3a31e commit 3feb70f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
16 changes: 12 additions & 4 deletions examples/multiple-dirs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ var path = require('path');

var livingcss = require('../../index');

livingcss('css/buttons.css', 'styleguide');
livingcss(path.join(__dirname, 'css/buttons.css'), 'styleguide');
livingcss(path.join(__dirname, 'css/buttons.css'), path.join(__dirname, 'styleguide'));
livingcss('css/buttons.css', path.join(__dirname, 'styleguide'));
(async function() {
try {
// all these methods should work:
await livingcss('css/buttons.css', 'styleguide');
// await livingcss(path.join(__dirname, 'css/buttons.css'), 'styleguide');
// await livingcss(path.join(__dirname, 'css/buttons.css'), path.join(__dirname, 'styleguide'));
// await livingcss('css/buttons.css', path.join(__dirname, 'styleguide'));
} catch (err) {
console.error(err);
console.error(err.stack);
}
})();
25 changes: 21 additions & 4 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,30 @@ function generate(dest, template, context, options) {
}

return preprocess
.then(function() {
.then(async function() {
// inline all stylesheets for polymer shared styles to work
// @see https://www.polymer-project.org/1.0/docs/devguide/styling#style-modules
return utils.readFiles(context.stylesheets, function(data, file) {

const parsedStylesheetFile = function(data, file) {
context.parsedStylesheets = context.parsedStylesheets || [];
context.parsedStylesheets.push(utils.fixSVGIssue(data));
});
};

let fileList;
try {
fileList = await utils.readFiles(context.stylesheets, parsedStylesheetFile);
} catch (err) {
if ('ENOENT' !== err.code) {
throw err;
}
const destDir = path.dirname(dest);
const stylesheets = context.stylesheets.map((file) => {
return path.resolve(destDir, file);
});
fileList = await utils.readFiles(stylesheets, parsedStylesheetFile);
}

return fileList;
})
.then(function success() {
var html = Handlebars.compile(template)(context);
Expand Down Expand Up @@ -94,4 +111,4 @@ function generate(dest, template, context, options) {
});
}

module.exports = generate;
module.exports = generate;

0 comments on commit 3feb70f

Please sign in to comment.