Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Feb 25, 2019
1 parent e84d750 commit 32d5a79
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const fm = require('front-matter');

const path = require('path');

const context = require('./context'); // for some reason lodash/fp takes 90ms to load.
const context = require('./context');

const _require = require('path'),
resolve = _require.resolve; // for some reason lodash/fp takes 90ms to load.
// inline what we use here with the regular lodash.


Expand All @@ -26,19 +29,37 @@ const ignores = ['prompt.js', 'index.js'];

const renderTemplate = (tmpl, locals, config) => L.isString(tmpl) ? ejs.render(tmpl, context(locals, config)) : tmpl;

function getFiles(_x) {
return _getFiles.apply(this, arguments);
}

function _getFiles() {
_getFiles = _asyncToGenerator(function* (dir) {
const subdirs = yield fs.readdir(dir);
const files = yield Promise.all(subdirs.map(
/*#__PURE__*/
function () {
var _ref2 = _asyncToGenerator(function* (subdir) {
const res = resolve(dir, subdir);
return (yield fs.stat(res)).isDirectory() ? getFiles(res) : res;
});

return function (_x4) {
return _ref2.apply(this, arguments);
};
}()));
return Array.prototype.concat(...files);
});
return _getFiles.apply(this, arguments);
}

const render =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (args, config) {
return yield fs.readdir(args.actionfolder).then(things => things.sort((a, b) => a.localeCompare(b))).then(map(_ => path.join(args.actionfolder, _))).then(filter(f => !L.find(ignores, ig => L.endsWith(f, ig)))).then(map(file => fs.lstat(file).then(stat => ({
file,
stat
})))).then(_ => Promise.all(_)).then(filter(({
file,
stat
}) => stat.isFile() && (args.subaction ? file.match(args.subaction) : true))).then(map(({
file
}) => file)).then(map(file => fs.readFile(file).then(text => ({
return yield getFiles(args.actionfolder).then(things => things.sort((a, b) => a.localeCompare(b))) // TODO: add a test to verify this sort
.then(filter(f => !L.find(ignores, ig => L.endsWith(f, ig)))) // TODO: add a test for ignoring prompt.js and index.js
.then(filter(file => args.subaction ? file.match(args.subaction) : true)).then(map(file => fs.readFile(file).then(text => ({
file,
text: text.toString()
})))).then(_ => Promise.all(_)).then(map(({
Expand All @@ -57,7 +78,7 @@ function () {
})));
});

return function render(_x, _x2) {
return function render(_x2, _x3) {
return _ref.apply(this, arguments);
};
}();
Expand Down

0 comments on commit 32d5a79

Please sign in to comment.