forked from FontoXML/fontoxpath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
106 lines (100 loc) · 2.75 KB
/
build.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
const peg = require('pegjs');
const fs = require('fs');
const Compiler = new require('google-closure-compiler').compiler;
const UglifyJS = require('uglify-js');
const path = require('path');
const skipParserBuild = process.env.npm_config_skip_parser;
const skipClosureBuild = process.env.npm_config_skip_closure;
function doPegJsBuild () {
return new Promise((resolve, reject) => fs.readFile('./src/parsing/xpath.pegjs', 'utf8', (err, file) => err ? reject(err) : resolve(file)))
.then(pegJsString => peg.generate(pegJsString, {
cache: true,
output: 'source',
format: 'globals',
exportVar: 'xPathParser'
}))
.then(parserString => UglifyJS.minify(parserString).code)
.then(parserString => `export default () => ${JSON.stringify(parserString)};`)
.then(parserString => new Promise((resolve, reject) => fs.writeFile('./src/parsing/xPathParser.raw.js', parserString, (err) => err ? reject(err) : resolve())))
.then(() => console.info('Parser generator done'));
}
function doSelectorsBuild () {
return new Promise((resolve, reject) => {
new Compiler({
assume_function_wrapper: true,
new_type_inf: true,
debug: false,
language_in: 'ES6',
language_out: 'ES5_strict',
create_source_map: './dist/fontoxpath.js.map',
jscomp_error: [
'accessControls',
'checkDebuggerStatement',
'checkRegExp',
'checkTypes',
'checkVars',
'const',
'constantProperty',
'deprecated',
'deprecatedAnnotations',
'duplicate',
'missingProperties',
'missingReturn',
'newCheckTypes',
'typeInvalidation',
'undefinedVars',
'uselessCode'
],
warning_level: 'VERBOSE',
compilation_level: 'ADVANCED',
externs: [
path.resolve('./externs/IDomFacade.js'),
path.resolve('./externs/INodesFactory.js')
],
module_resolution: 'NODE',
dependency_mode: 'STRICT',
output_wrapper: `
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define([], factory);
} else if (typeof exports === 'object') {
// Node, CommonJS-like
module.exports = factory();
} else {
// Browser globals (root is window)
root.fontoxpath = factory();
}
})(this, function () {
var window = {};
%output%
return window;
});
//# sourceMappingURL=./fontoxpath.js.map`,
js_output_file: './dist/fontoxpath.js',
entry_point: './src/index.js',
js: './src/**.js'
})
.run((exitCode, stdOut, stdErr) => {
if (exitCode !== 0) {
reject(stdErr);
return;
}
resolve(stdOut + stdErr);
});
})
.then((stdOut) => {
console.info(stdOut);
});
}
var chain = Promise.resolve();
if (!skipParserBuild) {
chain = chain.then(doPegJsBuild);
}
if (!skipClosureBuild) {
chain = chain.then(doSelectorsBuild);
}
chain.catch((err) => {
console.error(err);
process.exit(1);
});