forked from gnab/remark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.js
95 lines (77 loc) · 2.24 KB
/
make.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require('shelljs/make');
require('shelljs/global');
// Targets
target.all = function () {
target.lint();
target.test();
target.bundle();
target.minify();
};
target.resources = function () {
console.log('Compiling resources...');
compileResources('src/remark/resources.js');
};
target.lint = function () {
console.log('Linting...');
run('jshint src', {silent: true});
};
target.test = function () {
console.log('Running tests...');
run('mocha --recursive test');
};
target.bundle = function () {
console.log('Bundling...');
run('browserify src/remark.js', {silent: true}).output.to('remark.js');
};
target.minify = function () {
console.log('Minifying...');
run('uglifyjs remark.js', {silent: true}).output.to('remark.min.js');
};
// Helper functions
var path = require('path')
, config = require('./package.json').config
, ignoredStyles = ['brown_paper', 'school_book', 'pojoaque']
;
function compileResources (target) {
var highlightjs = 'vendor/highlight.js/src/'
, resources = {
DOCUMENT_STYLES: JSON.stringify(
less('src/remark.less'))
, OVERLAY_TEMPLATE: JSON.stringify(
cat('src/overlay.html.template'))
, HIGHLIGHTER_STYLES: JSON.stringify(
ls(highlightjs + 'styles/*.css').reduce(mapStyle, {}))
, HIGHLIGHTER_ENGINE:
cat(highlightjs + 'highlight.js')
, HIGHLIGHTER_LANGUAGES:
config.highlighter.languages.map(function (language) {
return '{name:"' + language + '",create:' +
cat(highlightjs + 'languages/' + language + '.js') + '}';
}).join(',')
};
cat('src/resources.js.template')
.replace(/%(\w+)%/g, function (match, key) {
return resources[key];
})
.to(target);
}
function mapStyle (map, file) {
var key = path.basename(file, path.extname(file));
if (ignoredStyles.indexOf(key) === -1) {
map[key] = less(file);
}
return map;
}
function less (file) {
return run('lessc -x ' + file, {silent: true}).output.replace(/\n/g, '');
}
function run (command, options) {
var result = exec('node_modules/.bin/' + command, options);
if (result.code !== 0) {
if (!options || options.silent) {
console.error(result.output);
}
exit(1);
}
return result;
}