-
Notifications
You must be signed in to change notification settings - Fork 87
/
build.js
34 lines (32 loc) · 1.01 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
const path = require('path')
const fs = require('fs')
const pkg = require('./package.json')
const UglifyJS = require('uglify-js')
const uglify = code => {
const result = UglifyJS.minify(code)
if (result.error) {
throw result.error
}
return result.code
}
const getDestPath = basename => {
return path.resolve(__dirname, 'dist', basename)
}
const bigBanner = `/*
* ${pkg.name} v${pkg.version}
* ${pkg.description}
* ${pkg.repository.url.substring(4)}
* by ${pkg.author.name} (${pkg.author.url})
*/
`
const smallBanner = `/* ${pkg.name} v${pkg.version} | ${pkg.description} | ${pkg.repository.url.substring(4)} | by ${pkg.author.name} (${pkg.author.url}) */
`
const srcPath = path.resolve(__dirname, 'index.js')
const srcCode = fs.readFileSync(srcPath, 'utf8')
const destPath = getDestPath('binking.js')
const destPathMin = getDestPath('binking.min.js')
fs.writeFileSync(destPath, bigBanner + srcCode)
fs.writeFileSync(destPathMin, smallBanner + uglify(srcCode))
console.info(`Builded
${destPath}
${destPathMin}`)