forked from jimmywarting/FormData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
43 lines (36 loc) · 1.06 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
const https = require('https')
const fs = require('fs')
const { URLSearchParams } = require('url')
// This is an async file read
const code = fs.readFileSync('./FormData.js', 'utf8').toString()
// Build the post string from an object
const postData = new URLSearchParams({
compilation_level: 'ADVANCED_OPTIMIZATIONS',
output_format: 'text',
output_info: 'compiled_code',
warning_level: 'QUIET',
output_wrapper: ';(function(){%output%})();',
js_code: code
}).toString()
// An object of options to indicate where to post to
const options = {
host: 'closure-compiler.appspot.com',
path: '/compile',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
}
// Set up the request
const req = https.request(options, res => {
res.setEncoding('utf8')
if (res.statusCode !== 200) {
console.log('FATAL An error occurred trying to use closure compiler')
process.exit(-2)
}
res.pipe(fs.createWriteStream('formdata.min.js'))
})
// post the data
req.write(postData)
req.end()