|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const zlib = require('zlib')
|
|
|
|
const rollup = require('rollup')
|
|
|
|
const uglify = require('uglify-js')
|
|
|
|
|
|
|
|
if (!fs.existsSync('dist')) {
|
|
|
|
fs.mkdirSync('dist')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update main file
|
|
|
|
const version = process.env.VERSION || require('../package.json').version
|
|
|
|
const main = fs
|
|
|
|
.readFileSync('src/core/index.js', 'utf-8')
|
|
|
|
.replace(/Vue\.version = '[^']+'/, "Vue.version = '" + version + "'")
|
|
|
|
fs.writeFileSync('src/core/index.js', main)
|
|
|
|
|
|
|
|
// update weex subversion
|
|
|
|
const weexVersion = process.env.WEEX_VERSION || require('../packages/weex-vue-framework/package.json').version
|
|
|
|
const weexMain = fs
|
|
|
|
.readFileSync('src/entries/weex-framework.js', 'utf-8')
|
|
|
|
.replace(/Vue\.version = '[^']+'/, "Vue.version = '" + weexVersion + "'")
|
|
|
|
fs.writeFileSync('src/entries/weex-framework.js', weexMain)
|
|
|
|
|
|
|
|
let builds = require('./config').getAllBuilds()
|
|
|
|
|
|
|
|
// filter builds via command line arg
|
|
|
|
if (process.argv[2]) {
|
|
|
|
const filters = process.argv[2].split(',')
|
|
|
|
builds = builds.filter(b => {
|
|
|
|
return filters.some(f => b.dest.indexOf(f) > -1)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
// filter out weex builds by default
|
|
|
|
builds = builds.filter(b => {
|
|
|
|
return b.dest.indexOf('weex') === -1
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
build(builds)
|
|
|
|
|
|
|
|
function build (builds) {
|
|
|
|
let built = 0
|
|
|
|
const total = builds.length
|
|
|
|
const next = () => {
|
|
|
|
buildEntry(builds[built]).then(() => {
|
|
|
|
built++
|
|
|
|
if (built < total) {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
}).catch(logError)
|
|
|
|
}
|
|
|
|
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildEntry (config) {
|
|
|
|
const isProd = /min\.js$/.test(config.dest)
|
|
|
|
return rollup.rollup(config).then(bundle => {
|
|
|
|
const code = bundle.generate(config).code
|
|
|
|
if (isProd) {
|
|
|
|
var minified = (config.banner ? config.banner + '\n' : '') + uglify.minify(code, {
|
|
|
|
fromString: true,
|
|
|
|
output: {
|
|
|
|
screw_ie8: true,
|
|
|
|
ascii_only: true
|
|
|
|
},
|
|
|
|
compress: {
|
|
|
|
pure_funcs: ['makeMap']
|
|
|
|
}
|
|
|
|
}).code
|
|
|
|
return write(config.dest, minified, true)
|
|
|
|
} else {
|
|
|
|
return write(config.dest, code)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function write (dest, code, zip) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
function report (extra) {
|
|
|
|
console.log(blue(path.relative(process.cwd(), dest)) + ' ' + getSize(code) + (extra || ''))
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
|
|
|
|
fs.writeFile(dest, code, err => {
|
|
|
|
if (err) return reject(err)
|
|
|
|
if (zip) {
|
|
|
|
zlib.gzip(code, (err, zipped) => {
|
|
|
|
if (err) return reject(err)
|
|
|
|
report(' (gzipped: ' + getSize(zipped) + ')')
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
report()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSize (code) {
|
|
|
|
return (code.length / 1024).toFixed(2) + 'kb'
|
|
|
|
}
|
|
|
|
|
|
|
|
function logError (e) {
|
|
|
|
console.log(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
function blue (str) {
|
|
|
|
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
|
|
|
|
}
|