UNPKG

2.14 kBJavaScriptView Raw
1var _ = require("lodash");
2var async = require("async");
3var path = require("path");
4var frontLoader = require("./loaders/front-loader");
5var matter = require("gray-matter");
6
7/**
8 * Generate a TaskNme based on condensation configuration
9 * @this Condensation
10 * @param {Object} options - All options
11 * @param {string} [options.separator=":"] - The separator to use when joining the parts of the name
12 * @returns {genTaskNameFunc~taskNameFunc} - Function that generates task names
13 */
14exports.genTaskNameFunc = function genTaskNameFunc(options) {
15 options = _.merge({
16 separator: ':'
17 },options);
18
19
20 /**
21 * Make a task name
22 * @param {...string} str - Parts of the task name that will be joined together
23 * @returns {string} - The full task name
24 */
25 var taskNameFunc = function taskNameFunc() {
26 var validParts = _.dropWhile(_.flatten([this.prefix,arguments]),function(item) {
27 return !item;
28 });
29 return validParts.join(this.separator);
30 };
31
32 return taskNameFunc.bind(options);
33};
34
35/**
36 * Generates a distribution path
37 * @this Condensation
38 * @param {Object} options - All options
39 * @param {string} [options.root="dist"] - The root distribution name
40 * @param {string} [options.s3prefix=""] - Prefix to add to all s3 paths
41 * @param {string} options.id - The unique ID for this distribution
42 * @returns {String} - The distribution path
43 */
44exports.genDistPath = function genDistPath(options) {
45 var opts = _.merge({
46 root: 'dist',
47 s3prefix: '',
48 id: null
49 },options);
50
51 return(
52 path.join.apply(
53 null,
54 _.flatten([
55 opts.root,
56 opts.id,
57 opts.s3prefix
58 ])
59 )
60 );
61
62};
63
64/**
65 *
66 */
67exports.processFrontMatter = function processFrontMatter(file, templateData, cb) {
68 var self = this;
69
70 var m = matter(file.contents.toString());
71
72 async.mapValues(
73 (m.data.frontload || {}),
74 function(value, key, cb) {
75 var moduleConfig = _.merge({},value);
76 moduleConfig._file = file;
77 frontLoader.call(self, moduleConfig, templateData, cb);
78 },
79 function(err, result) {
80 _.merge(m.data, result);
81 cb(err, m);
82 }
83 );
84
85};