forked from highlightjs/highlight.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.js
141 lines (118 loc) · 4.4 KB
/
node.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'use strict';
let _ = require('lodash');
let bluebird = require('bluebird');
let path = require('path');
let packageJSON = require('../package');
let registry = require('./tasks');
let utility = require('./utility');
let directory, filterCB,
languages = utility.glob(path.join('src', 'languages', '*.js')),
header = utility.regex.header;
function templateAllFunc(blobs) {
const names = _.map(blobs, blob => path.basename(blob.name, '.js'));
return bluebird.resolve({ names: names });
}
function buildLanguages() {
let input = languages,
output = path.join(directory.build, 'lib', 'languages'),
replaceArgs = utility.replace(header, ''),
template = 'module.exports = <%= content %>;';
return {
logStart: { task: ['log', 'Building language files.'] },
read: { requires: 'logStart', task: ['glob', input] },
filter: { requires: 'read', task: ['filter', filterCB] },
replace: { requires: 'filter', task: ['replace', replaceArgs] },
template: { requires: 'replace', task: ['template', template] },
writeLog: {
requires: 'template',
task: ['log', 'Writing language files.']
},
write: { requires: 'writeLog', task: ['dest', output] }
};
}
function buildCore() {
const input = path.join(directory.root, 'src', 'highlight.js'),
output = path.join(directory.build, 'lib');
return {
startLog: { task: ['log', 'Building core file.'] },
read: { requires: 'startLog', task: ['read', input] },
writeLog: { requires: 'read', task: ['log', 'Writing core file.'] },
write: { requires: 'writeLog', task: ['dest', output] }
};
}
function buildIndex() {
let input = languages,
output = path.join(directory.build, 'lib', 'index.js'),
templateArgs = {
template: [ 'var hljs = require(\'./highlight\');\n'
, '<% _.each(names, function(name) { %>' +
'hljs.registerLanguage(\'<%= name %>\', ' +
'require(\'./languages/<%= name %>\'));'
, '<% }); %>'
, 'module.exports = hljs;'
].join('\n'),
callback: templateAllFunc
};
return {
startLog: { task: ['log', 'Building index file.'] },
read: { requires: 'startLog', task: ['glob', input] },
filter: { requires: 'read', task: ['filter', filterCB] },
reorder: { requires: 'filter', task: 'reorderDeps' },
template: { requires: 'reorder', task: ['templateAll', templateArgs] },
writeLog: { requires: 'template', task: ['log', 'Writing index file.'] },
write: { requires: 'writeLog', task: ['write', output] }
};
}
function copyMetaFiles() {
let docs = path.join('docs', '*.rst'),
glob = `{README.md,LICENSE,${docs}}`,
input = utility.glob(path.join(directory.root, glob)),
output = { dir: directory.build, base: '.' };
return {
startLog: { task: ['log', 'Copying meta files.'] },
read: { requires: 'startLog', task: ['glob', input] },
writeLog: { requires: 'read', task: ['log', 'Writing meta files.'] },
write: { requires: 'writeLog', task: ['dest', output] }
};
}
function buildStyles() {
let input = path.join(directory.root, 'src', 'styles', '*'),
output = path.join(directory.build, 'styles'),
options = { encoding: 'binary', dir: output };
return {
startLog: { task: ['log', 'Building style files.'] },
read: {
requires: 'startLog',
task: ['glob', utility.glob(input, 'binary')]
},
writeLog: { requires: 'read', task: ['log', 'Writing style files.'] },
write: { requires: 'writeLog', task: ['dest', options] }
};
}
function buildPackageFile() {
const input = path.join(directory.root, 'AUTHORS.en.txt'),
output = path.join(directory.build, 'package.json');
return {
startLog: { task: ['log', 'Building package.json file.'] },
read: { requires: 'startLog', task: ['read', input] },
build: { requires: 'read', task: ['buildPackage', packageJSON] },
writeLog: {
requires: 'build',
task: ['log', 'Writing package.json file.']
},
write: { requires: 'writeLog', task: ['write', output] }
};
}
module.exports = function(commander, dir) {
directory = dir;
filterCB = utility.buildFilterCallback(commander.args);
let tasks = [
buildLanguages(),
buildCore(),
buildIndex(),
buildStyles(),
copyMetaFiles(),
buildPackageFile()
];
return utility.toQueue(tasks, registry);
};