Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [build] update build scripts of js framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanks10100 committed Dec 29, 2017
1 parent 51dd277 commit d0dd5a0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 117 deletions.
83 changes: 17 additions & 66 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
"use strict"

const fs = require('fs')
const path = require('path')
const gzip = require('zlib').createGzip()
const pkg = require('../package.json')
const rollup = require('rollup')
const watch = require('rollup-watch')
const webpack = require('webpack')

const getConfig = require('./config')

// create dist folder
if (!fs.existsSync('dist')) {
fs.mkdirSync('dist')
}

let isWatch = false
if (process.argv[3]) {
isWatch = process.argv[3] === '--watch' || process.argv[3] === '-w'
Expand All @@ -46,41 +36,19 @@ else {
console.log('\nPlease specify the package you want to build. [native, runtime, browser, vue]')
}

function extend(to, ...froms) {
froms.forEach(function (from) {
for (const key in from) {
if (from.hasOwnProperty(key)) {
to[key] = from[key]
}
}
})
return to
}

function runRollupOnWatch(config) {
function runRollupOnWatch (config) {
const watcher = watch(rollup, config)
watcher.on('event', event => {
switch ( event.code ) {
case 'STARTING':
console.log('checking rollup-watch version...')
break

case 'BUILD_START':
console.log('bundling...')
break

case 'BUILD_END':
switch (event.code) {
case 'STARTING': console.log('checking rollup-watch version...'); break
case 'BUILD_START': console.log('bundling...'); break
case 'BUILD_END': {
console.log('bundled in ' + path.relative(process.cwd(), config.dest)
+ ' (' + event.duration + 'ms)')
console.log('Watching for changes...' )
break

case 'ERROR':
console.error('ERROR: ', event.error)
break

default:
console.error('unknown event', event)
console.log('Watching for changes...')
} break
case 'ERROR': console.error('ERROR: ', event.error); break
default: console.error('unknown event', event)
}
})
}
Expand All @@ -99,10 +67,12 @@ function runRollup (config) {
function build (name) {
let pkgName = 'weex-js-framework'
switch (name) {
case 'native': pkgName = 'weex-js-framework'; break;
case 'runtime': pkgName = 'weex-js-runtime'; break;
case 'legacy': pkgName = 'weex-legacy-framework'; break;
case 'vanilla': pkgName = 'weex-vanilla-framework'; break;
case 'native': pkgName = 'weex-js-framework'; break
case 'vue': pkgName = 'weex-vue'; break
case 'rax': pkgName = 'weex-rax'; break
case 'runtime': pkgName = 'weex-js-runtime'; break
case 'legacy': pkgName = 'weex-legacy-framework'; break
case 'vanilla': pkgName = 'weex-vanilla-framework'; break
}

const config = getConfig(pkgName)
Expand All @@ -112,34 +82,15 @@ function build (name) {
return runRollupOnWatch(config)
}
else {
console.log(`\n => start to build ${name} (${pkgName})\n`)
console.log(`\n => start to build ${pkgName}\n`)
return new Promise((resolve, reject) => {
return runRollup(config).then(() => {
let p = Promise.resolve()
return p.then(function () {
return runRollup(minifyConfig).then(() => {
zip(minifyConfig.dest, resolve)
})
})
return runRollup(minifyConfig)
})
})
}
}

function zip (filePath, callback) {
const read = fs.createReadStream(filePath)
const write = fs.createWriteStream(filePath + '.gz')
read.pipe(gzip).pipe(write).on('close', () => {
report(filePath + '.gz')
callback && callback()
})
}

function now () {
const time = Date.now() - (new Date()).getTimezoneOffset() * 60000
return (new Date(time)).toISOString().replace('T', ' ').substring(0, 16)
}

function report (filePath) {
const size = (fs.statSync(filePath).size / 1024).toFixed(2) + 'KB'
const file = path.relative(process.cwd(), filePath)
Expand Down
80 changes: 38 additions & 42 deletions build/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -17,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

const path = require('path')
const json = require('rollup-plugin-json')
const eslint = require('rollup-plugin-eslint')
Expand All @@ -25,78 +25,73 @@ const nodeResolve = require('rollup-plugin-node-resolve')
const uglify = require('rollup-plugin-uglify')
const commonjs = require('rollup-plugin-commonjs')
const buble = require('rollup-plugin-buble')
const subversion = require('../package.json').subversion
const packageJSON = require('../package.json')
const deps = packageJSON.dependencies
const subversion = packageJSON.subversion

const frameworkBanner = `;(this.getJSFMVersion = function()`
+ `{return "${subversion.framework}"});\n`
+ `var global = this, process = { env: {} };var setTimeout = global.setTimeout;\n`
+ `var global = this; var setTimeout = global.setTimeout;\n`

const configs = {
'weex-js-framework': {
moduleName: 'Weex',
entry: absolute('html5/render/native/index.js'),
dest: absolute('packages/weex-js-framework/index.js'),
entry: absolute('runtime/entries/index.js'),
dest: absolute('pre-build/weex-js-framework.js'),
banner: `(this.nativeLog || function(s) {console.log(s)})`
+ `('START JS FRAMEWORK ${subversion.framework}, Build ${now()}.');\n`
+ frameworkBanner,
format: 'umd',
plugins: [
nodeResolve({
jsnext: true,
main: true
}),
]
+ `('START JS FRAMEWORK ${subversion.framework}, Build ${now()}. `
+ `(Vue: ${deps['weex-vue-framework']}, Rax: ${deps['weex-rax-framework']})');\n`
+ frameworkBanner
},
'weex-vue': {
moduleName: 'Weex',
entry: absolute('runtime/entries/vue.js'),
dest: absolute('pre-build/weex-vue.js'),
banner: `/* Weex JS Framework ${subversion.framework} `
+ `(Vue: ${deps['weex-vue-framework']}), Build ${now()}. */\n\n`
+ frameworkBanner
},
'weex-rax': {
moduleName: 'Weex',
entry: absolute('runtime/entries/rax.js'),
dest: absolute('pre-build/weex-rax.js'),
banner: `/* Weex JS Framework ${subversion.framework} `
+ `(Rax: ${deps['weex-rax-framework']}), Build ${now()}. */\n\n`
+ frameworkBanner
},
'weex-js-runtime': {
moduleName: 'WeexRuntime',
entry: absolute('html5/runtime/index.js'),
entry: absolute('runtime/api/index.js'),
dest: absolute('packages/weex-js-runtime/index.js'),
banner: `/* WEEX JS RUNTIME ${subversion.framework}, Build ${now()}. */\n\n`,
format: 'umd',
plugins: [
nodeResolve({
jsnext: true,
main: true
}),
]
banner: `/* Weex JS Runtime ${subversion.framework}, Build ${now()}. */\n\n`
},
'weex-legacy-framework': {
moduleName: 'WeexLegacyFramework',
entry: absolute('html5/frameworks/legacy/index.js'),
entry: absolute('runtime/frameworks/legacy/index.js'),
dest: absolute('packages/weex-legacy-framework/index.js'),
banner: `/* Weex Legacy Framework ${subversion.framework}, Build ${now()}. */\n`,
format: 'umd',
plugins: [
nodeResolve({
jsnext: true,
main: true
}),
]
banner: `/* Weex Legacy Framework ${subversion.framework}, Build ${now()}. */\n`
},
'weex-vanilla-framework': {
moduleName: 'WeexVanillaFramework',
entry: absolute('html5/frameworks/vanilla/index.js'),
entry: absolute('runtime/frameworks/vanilla/index.js'),
dest: absolute('packages/weex-vanilla-framework/index.js'),
banner: `/* Weex Vanilla Framework ${subversion.framework}, Build ${now()}. */\n`,
format: 'umd',
plugins: [
nodeResolve({
jsnext: true,
main: true
}),
]
banner: `/* Weex Vanilla Framework ${subversion.framework}, Build ${now()}. */\n`
}
}

function getConfig (name, minify) {
const opt = configs[name]
if (!opt.plugins) {
opt.plugins = []
}
const config = {
moduleName: opt.moduleName,
entry: opt.entry,
dest: minify ? opt.dest && opt.dest.replace(/\.js$/, '.min.js') : opt.dest,
format: opt.format,
format: opt.format || 'umd',
banner: opt.banner,
plugins: opt.plugins.concat([
nodeResolve({ jsnext: true, main: true }),
json(),
replace({
'process.env.VIEWPORT_WIDTH': 750,
Expand All @@ -110,6 +105,7 @@ function getConfig (name, minify) {
}

if (minify) {
config.sourceMap = true
config.plugins.push(uglify())
}
else {
Expand Down
14 changes: 7 additions & 7 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ if (unFlowedFiles.length > 0) {
// Error or Warn when delete public interface
var isNotDanger = false;
console.log('pr.title:'+danger.github.pr.title)
if(!isNotDanger && danger.github.pr.title
if(!isNotDanger && danger.github.pr.title
&& danger.github.pr.title.match(/@notdanger/i)){
isNotDanger = true;
}
console.log('pr.body:'+danger.github.pr.body)
if(!isNotDanger && danger.github.pr.body
if(!isNotDanger && danger.github.pr.body
&& danger.github.pr.body.match(/@notdanger/i)){
isNotDanger = true;
}
Expand Down Expand Up @@ -146,10 +146,10 @@ const getFileType = file => {
} else if (file.match(/android\/sdk\/src\/main\/java\/.+\.java/)) {
return type_android_sdk;
} else if (
file.match(/html5\/(shared|frameworks|render|runtime|services)\/.+\.js/)
file.match(/runtime\/.+\.js/)
) {
return type_jsfm;
} else if (file.match(/html5\/test\/.+\.js/)) {
} else if (file.match(/test\/js-framework\/.+\.js/)) {
return type_jsfm_test;
} else if (file.match(/doc\/\.+\.md/)) {
return type_doc;
Expand Down Expand Up @@ -250,7 +250,7 @@ const ignoreCopyrightVerifyPath = [
'test',
'packages',
'pre-build',
'html5/test/case',
'test/js\-framework/case',
'android/playground/app/src/main/assets',
'android/sdk/assets',
'ios/playground/bundlejs',
Expand All @@ -275,7 +275,7 @@ filesToVerifySrcHeader.forEach(filepath => {
}

// check cn for source code
var reg = /[\u4e00-\u9FA5]+/;
var reg = /[\u4e00-\u9FA5]+/;
var res = reg.test(content);
if(res){
console.error("Code file "+ filepath +" has cn source code.");
Expand Down Expand Up @@ -356,7 +356,7 @@ function getContent(url) {
console.log('response:', response.statusCode)
if (response.statusCode < 200 || response.statusCode > 299) {
if (response.statusCode === 404 || response.statusCode === 502) {
// ignore this, probably a renamed file,or .so that can't blame
// ignore this, probably a renamed file,or .so that can't blame
return resolve('')
}
reject(new Error('Failed to load page, status code: ' + response.statusCode + ', '
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"scripts": {
"postinstall": "bash ./scripts/install-hooks.sh",
"build:native": "node build/build.js native",
"build:vue": "node build/build.js vue",
"build:rax": "node build/build.js rax",
"build:runtime": "node build/build.js runtime",
"build:legacy": "node build/build.js legacy",
"build:vanilla": "node build/build.js vanilla",
Expand All @@ -58,8 +60,8 @@
"dev:examples:web": "webpack --watch --config build/webpack.examples.web.config.js",
"dev:test": "webpack --watch --config build/webpack.test.config.js",
"lint": "eslint html5",
"test:case": "mocha --require reify html5/test/case/tester.js",
"test:unit": "mocha --require reify html5/test/unit/**/*",
"test:case": "mocha --require reify test/js-framework/case/tester.js",
"test:unit": "mocha --require reify test/js-framework/unit/**/*",
"test": "npm run lint && npm run test:unit && npm run test:case",
"test:cover-html": "babel-istanbul cover --report html node_modules/mocha/bin/_mocha -- --require reify --reporter dot html5/test/unit/ && open coverage/index.html",
"test:cover": "babel-istanbul cover --report text node_modules/mocha/bin/_mocha -- --require reify --reporter dot html5/test/unit/",
Expand Down

0 comments on commit d0dd5a0

Please sign in to comment.