1 | "use strict";
|
2 |
|
3 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
4 |
|
5 | function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
6 |
|
7 | const fs = require('fs-extra');
|
8 |
|
9 | const ejs = require('ejs');
|
10 |
|
11 | const fm = require('front-matter');
|
12 |
|
13 | const path = require('path');
|
14 |
|
15 | const _require = require('path'),
|
16 | resolve = _require.resolve;
|
17 |
|
18 | const walk = require('ignore-walk');
|
19 |
|
20 | const context = require('./context');
|
21 |
|
22 |
|
23 |
|
24 | const map = f => arr => arr.map(f);
|
25 |
|
26 | const filter = f => arr => arr.filter(f);
|
27 |
|
28 | const ignores = ['prompt.js', 'index.js', '.hygenignore', '.DS_Store', '.Spotlight-V100', '.Trashes', 'ehthumbs.db', 'Thumbs.db'];
|
29 |
|
30 | const renderTemplate = (tmpl, locals, config) => typeof tmpl === 'string' ? ejs.render(tmpl, context(locals, config)) : tmpl;
|
31 |
|
32 | function getFiles(_x) {
|
33 | return _getFiles.apply(this, arguments);
|
34 | }
|
35 |
|
36 | function _getFiles() {
|
37 | _getFiles = _asyncToGenerator(function* (dir) {
|
38 | const files = walk.sync({
|
39 | path: dir,
|
40 | ignoreFiles: ['.hygenignore']
|
41 | }).map(f => path.join(dir, f));
|
42 | return files;
|
43 | });
|
44 | return _getFiles.apply(this, arguments);
|
45 | }
|
46 |
|
47 | const render =
|
48 |
|
49 | function () {
|
50 | var _ref = _asyncToGenerator(function* (args, config) {
|
51 | return yield getFiles(args.actionfolder).then(things => things.sort((a, b) => a.localeCompare(b)))
|
52 | .then(filter(f => !ignores.find(ig => f.endsWith(ig))))
|
53 |
|
54 | .then(filter(file => args.subaction ? file.match(args.subaction) : true)).then(map(file => fs.readFile(file).then(text => ({
|
55 | file,
|
56 | text: text.toString()
|
57 | })))).then(_ => Promise.all(_)).then(map(({
|
58 | file,
|
59 | text
|
60 | }) => Object.assign({
|
61 | file
|
62 | }, fm(text)))).then(map(({
|
63 | file,
|
64 | attributes,
|
65 | body
|
66 | }) => ({
|
67 | file,
|
68 | attributes: Object.entries(attributes).reduce((obj, [key, value]) => (obj[key] = renderTemplate(value, args, config)) && obj, {}),
|
69 | body: renderTemplate(body, args, config)
|
70 | })));
|
71 | });
|
72 |
|
73 | return function render(_x2, _x3) {
|
74 | return _ref.apply(this, arguments);
|
75 | };
|
76 | }();
|
77 |
|
78 | module.exports = render; |
\ | No newline at end of file |