Repository: incubator-weex Updated Branches: refs/heads/master 1f1dc67d6 -> af6531238
* [jsfm] refactor the build script and entry files of js framework Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b4194ac4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b4194ac4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b4194ac4 Branch: refs/heads/master Commit: b4194ac4e3b6e264b3cdf42c64d7b41bd11098a8 Parents: 7d1096a Author: Hanks <[email protected]> Authored: Thu Feb 1 20:06:10 2018 +0800 Committer: Hanks <[email protected]> Committed: Thu Feb 1 20:06:10 2018 +0800 ---------------------------------------------------------------------- build/build.js | 6 ++-- build/config.js | 37 ++++++++++++++++--------- package.json | 8 ++++-- runtime/api/init.js | 11 ++++++++ runtime/entries/env.js | 27 ++++++++++++++++++ runtime/entries/index.js | 2 ++ runtime/entries/legacy.js | 23 +++++++++++++++ runtime/entries/setup.js | 3 -- runtime/frameworks/legacy/app/ctrl/init.js | 5 +--- runtime/frameworks/legacy/app/ctrl/misc.js | 6 ++-- runtime/shared/index.js | 20 +++++++------ 11 files changed, 110 insertions(+), 38 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/build/build.js ---------------------------------------------------------------------- diff --git a/build/build.js b/build/build.js index d845816..2eff062 100644 --- a/build/build.js +++ b/build/build.js @@ -71,11 +71,13 @@ async function runRollup (config) { async function build (name) { let pkgName = 'weex-js-framework' switch (name) { + case 'jsfm': case 'native': pkgName = 'weex-js-framework'; break + case 'env': pkgName = 'weex-env'; 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 'legacy': pkgName = 'weex-legacy'; break case 'vanilla': pkgName = 'weex-vanilla-framework'; break } @@ -99,5 +101,5 @@ async function build (name) { function report (filePath) { const size = (fs.statSync(filePath).size / 1024).toFixed(2) + 'KB' const file = path.relative(process.cwd(), filePath) - console.log(` => write ${file} (${size})`) + console.log(` => ${file} (${size})`) } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/build/config.js ---------------------------------------------------------------------- diff --git a/build/config.js b/build/config.js index 6c3873b..a1acb76 100644 --- a/build/config.js +++ b/build/config.js @@ -30,9 +30,8 @@ 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; var process = {env:{}}; var setTimeout = global.setTimeout;\n` +const frameworkBanner = `var global=this; var process={env:{}}; ` + + `var setTimeout=global.setTimeout;\n` const configs = { 'weex-js-framework': { @@ -46,6 +45,15 @@ const configs = { + frameworkBanner } }, + 'weex-env': { + input: absolute('runtime/entries/env.js'), + output: { + name: 'WeexEnvironmentAPIs', + file: absolute('pre-build/weex-env'), + banner: `/* Prepare Weex Environment APIs ${subversion.framework}, Build ${now()}. */\n\n` + + `var global = this; var process = {env:{}};` + } + }, 'weex-vue': { input: absolute('runtime/entries/vue.js'), output: { @@ -76,12 +84,14 @@ const configs = { banner: `/* Weex JS Runtime ${subversion.framework}, Build ${now()}. */\n\n` } }, - 'weex-legacy-framework': { - input: absolute('runtime/frameworks/legacy/index.js'), + 'weex-legacy': { + input: absolute('runtime/entries/legacy.js'), output: { - name: 'WeexLegacyFramework', - file: absolute('packages/weex-legacy-framework/index'), - banner: `/* Weex Legacy Framework ${subversion.framework}, Build ${now()}. */\n` + name: 'WeexLegacy', + file: absolute('pre-build/weex-legacy'), + banner: `(this.nativeLog || function(s) {console.log(s)})` + + `('Weex Legacy Framework ${subversion.framework}, Build ${now()}.');\n` + + frameworkBanner } }, 'weex-vanilla-framework': { @@ -107,33 +117,34 @@ function getConfig (name, minify, es6) { name: output.name, file: output.file + suffix, format: output.format || 'umd', - banner: output.banner + banner: output.banner, + sourcemap: true }, plugins: opt.plugins.concat([ nodeResolve({ jsnext: true, main: true }), json(), replace({ - '__WEEX_VERSION__': JSON.stringify(subversion.framework), + '__WEEX_VERSION__': JSON.stringify(packageJSON.version), + '__WEEX_JS_FRAMEWORK_VERSION__': JSON.stringify(subversion.framework), 'process.env.NODE_ENV': JSON.stringify(minify ? 'production' : 'development'), 'process.env.VUE_ENV': JSON.stringify('WEEX'), + 'process.env.WEEX_FREEZE': JSON.stringify(!!process.env.WEEX_FREEZE), 'process.env.SUPPORT_ES2015': !!es6, 'process.env.NODE_DEBUG': false }), - commonjs() + commonjs({ ignoreGlobal: true }) ]) } if (!es6) { config.plugins.push(buble()) } if (minify) { - config.output.sourcemap = true config.plugins.push(es6 ? uglify({ safari10: true, toplevel: true }, uglifyES.minify) : uglify() ) } else { - config.output.sourcemap = 'inline' config.plugins.unshift(eslint({ exclude: ['**/*.json', '**/*.css'] })) } return config http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 44e4c20..616afb2 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,8 @@ "node": ">=8" }, "scripts": { + "build:jsfm": "node build/build.js jsfm", + "build:env": "WEEX_FREEZE=true node build/build.js env", "build:native": "node build/build.js native", "build:vue": "node build/build.js vue", "build:rax": "node build/build.js rax", @@ -50,15 +52,15 @@ "build:ci:web": "webpack --watch --config build/webpack.ci.web.config.js", "build:ci:native": "webpack --watch --config build/webpack.ci.config.js", "build:ci": "npm run build:ci:native && npm run build:ci:web", - "build": "npm run build:native && npm run build:examples && npm run build:test", - "dev:native": "node build/build.js native --watch", + "build": "npm run build:env && npm run build:jsfm && npm run build:vue && npm run build:rax", + "dev:jsfm": "node build/build.js jsfm --watch", "dev:runtime": "node build/build.js runtime --watch", "dev:legacy": "node build/build.js legacy --watch", "dev:vanilla": "node build/build.js vanilla --watch", "dev:examples": "webpack --watch --config build/webpack.examples.config.js", "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", + "lint": "eslint runtime", "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", http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/runtime/api/init.js ---------------------------------------------------------------------- diff --git a/runtime/api/init.js b/runtime/api/init.js index 8c6bd0a..41bdd0f 100644 --- a/runtime/api/init.js +++ b/runtime/api/init.js @@ -52,6 +52,14 @@ function getBundleType (code) { return 'Weex' } +/** + * Get js framework version at runtime. + */ +function getJSFMVersion () { + // It will be converted into a version string at build time + return __WEEX_JS_FRAMEWORK_VERSION__ // eslint-disable-line +} + function createServices (id, env, config) { // Init JavaScript services for this instance. const serviceMap = Object.create(null) @@ -108,6 +116,8 @@ function createInstanceContext (id, options = {}, data) { const runtimeContext = Object.create(null) Object.assign(runtimeContext, services, { weex, + getJSFMVersion, + __WEEX_CALL_JAVASCRIPT__: receiveTasks, services // Temporary compatible with some legacy APIs in Rax }) Object.freeze(runtimeContext) @@ -216,6 +226,7 @@ const methods = { createInstance, createInstanceContext, getRoot, + getJSFMVersion, getDocument: getDoc, registerService: register, unregisterService: unregister, http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/runtime/entries/env.js ---------------------------------------------------------------------- diff --git a/runtime/entries/env.js b/runtime/entries/env.js new file mode 100644 index 0000000..38c4947 --- /dev/null +++ b/runtime/entries/env.js @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { setNativeConsole, freezePrototype } from '../shared' +export * from '../shared' + +setNativeConsole() + +if (process.env.WEEX_FREEZE) { + freezePrototype() +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/runtime/entries/index.js ---------------------------------------------------------------------- diff --git a/runtime/entries/index.js b/runtime/entries/index.js index 9d590b6..4b5d13b 100644 --- a/runtime/entries/index.js +++ b/runtime/entries/index.js @@ -17,7 +17,9 @@ * under the License. */ +import { freezePrototype } from './env' import setup from './setup' import frameworks from '../frameworks' setup(frameworks) +freezePrototype() http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/runtime/entries/legacy.js ---------------------------------------------------------------------- diff --git a/runtime/entries/legacy.js b/runtime/entries/legacy.js new file mode 100644 index 0000000..ab82f1e --- /dev/null +++ b/runtime/entries/legacy.js @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import setup from './setup' +import * as Weex from '../frameworks/legacy/index' + +setup({ Weex }) http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/runtime/entries/setup.js ---------------------------------------------------------------------- diff --git a/runtime/entries/setup.js b/runtime/entries/setup.js index 7c59712..ed979e2 100644 --- a/runtime/entries/setup.js +++ b/runtime/entries/setup.js @@ -18,7 +18,6 @@ */ import { subversion } from '../../package.json' -import * as shared from '../shared' import runtime from '../api' import services from '../services' @@ -36,8 +35,6 @@ export default function (frameworks) { runtime.service.register(serviceName, services[serviceName]) } - shared.freezePrototype() - shared.setNativeConsole() runtime.freezePrototype() // register framework meta info http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/runtime/frameworks/legacy/app/ctrl/init.js ---------------------------------------------------------------------- diff --git a/runtime/frameworks/legacy/app/ctrl/init.js b/runtime/frameworks/legacy/app/ctrl/init.js index 401d614..f0a7f10 100644 --- a/runtime/frameworks/legacy/app/ctrl/init.js +++ b/runtime/frameworks/legacy/app/ctrl/init.js @@ -198,10 +198,7 @@ function callFunctionNative (globalObjects, body) { try { const weex = globalObjects.weex || {} const config = weex.config || {} - fn = compileAndRunBundle(script, - config.bundleUrl, - config.bundleDigest, - config.codeCachePath) + fn = compileAndRunBundle(script, config.bundleUrl, config.bundleDigest, config.codeCachePath) if (fn && typeof fn === 'function') { fn(...globalValues) isNativeCompileOk = true http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/runtime/frameworks/legacy/app/ctrl/misc.js ---------------------------------------------------------------------- diff --git a/runtime/frameworks/legacy/app/ctrl/misc.js b/runtime/frameworks/legacy/app/ctrl/misc.js index 13ab09e..4259690 100644 --- a/runtime/frameworks/legacy/app/ctrl/misc.js +++ b/runtime/frameworks/legacy/app/ctrl/misc.js @@ -35,8 +35,7 @@ import { extend, typof } from '../../util/index' * @param {any} data */ export function refresh (app, data) { - console.debug(`[JS Framework] Refresh with`, data, - `in instance[${app.id}]`) + console.debug(`[JS Framework] Refresh with`, data, `in instance[${app.id}]`) const vm = app.vm if (vm && data) { if (typeof vm.refreshData === 'function') { @@ -162,8 +161,7 @@ export function fireEvent (app, ref, type, e, domChanges) { * @param {boolean} ifKeepAlive */ export function callback (app, callbackId, data, ifKeepAlive) { - console.debug(`[JS Framework] Invoke a callback(${callbackId}) with`, data, - `in instance(${app.id})`) + console.debug(`[JS Framework] Invoke a callback(${callbackId}) with`, data, `in instance(${app.id})`) const result = app.doc.taskCenter.callback(callbackId, data, ifKeepAlive) updateActions(app) app.doc.taskCenter.send('dom', { action: 'updateFinish' }, []) http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b4194ac4/runtime/shared/index.js ---------------------------------------------------------------------- diff --git a/runtime/shared/index.js b/runtime/shared/index.js index a478b86..19ca3cd 100644 --- a/runtime/shared/index.js +++ b/runtime/shared/index.js @@ -17,16 +17,18 @@ * under the License. */ -import './polyfill/arrayFrom' -import './polyfill/objectAssign' -import './polyfill/objectSetPrototypeOf' +if (!process.env.SUPPORT_ES2015) { + require('./polyfill/arrayFrom') + require('./polyfill/objectAssign') + require('./polyfill/objectSetPrototypeOf') -// import promise hack and polyfills -import './polyfill/promise' -import 'core-js/modules/es6.object.to-string' -import 'core-js/modules/es6.string.iterator' -import 'core-js/modules/web.dom.iterable' -import 'core-js/modules/es6.promise' + // import promise hack and polyfills + require('./polyfill/promise') + require('core-js/modules/es6.object.to-string') + require('core-js/modules/es6.string.iterator') + require('core-js/modules/web.dom.iterable') + require('core-js/modules/es6.promise') +} export * from './env/console' export * from './env/setTimeout'
