From 9cd607e822b600ca25a1c713bfca2d62aad2efbd Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 17 Jul 2019 15:03:31 +0800 Subject: [PATCH] project config --- .gitignore | 1 - js-framework/.gitignore | 4 +- js-framework/index.runtime.ts | 1 + js-framework/index.ts | 3 + js-framework/package-lock.json | 121 +++++++++++++++++- js-framework/package.json | 11 +- js-framework/rollup.config.js | 32 +++++ .../src/runtime}/sandbox.ts | 24 +++- js-framework/src/util/uniqueId.ts | 4 +- js-framework/tsconfig.json | 4 +- js-runtime/.gitignore | 1 - js-runtime/package.json | 23 ---- js-runtime/tsconfig.json | 62 --------- 13 files changed, 188 insertions(+), 103 deletions(-) create mode 100644 js-framework/index.runtime.ts create mode 100644 js-framework/rollup.config.js rename {js-runtime/src => js-framework/src/runtime}/sandbox.ts (83%) delete mode 100644 js-runtime/.gitignore delete mode 100644 js-runtime/package.json delete mode 100644 js-runtime/tsconfig.json diff --git a/.gitignore b/.gitignore index 98cff0bf..39b6783c 100644 --- a/.gitignore +++ b/.gitignore @@ -63,4 +63,3 @@ fastlane/Preview.html fastlane/screenshots fastlane/test_output fastlane/readme.md -js-framework-dst \ No newline at end of file diff --git a/js-framework/.gitignore b/js-framework/.gitignore index 40b878db..692a327e 100644 --- a/js-framework/.gitignore +++ b/js-framework/.gitignore @@ -1 +1,3 @@ -node_modules/ \ No newline at end of file +node_modules/ +build/ +bundle/ \ No newline at end of file diff --git a/js-framework/index.runtime.ts b/js-framework/index.runtime.ts new file mode 100644 index 00000000..b87b097c --- /dev/null +++ b/js-framework/index.runtime.ts @@ -0,0 +1 @@ +export * from './src/runtime/sandbox' \ No newline at end of file diff --git a/js-framework/index.ts b/js-framework/index.ts index a2073e17..de1f9627 100644 --- a/js-framework/index.ts +++ b/js-framework/index.ts @@ -15,3 +15,6 @@ console.log(v.toModel()) const layout = new VLayout layout.space = 10 console.log(layout.toModel()) +export * from "./src/ui/view" +export * from "./src/ui/page" +export * from "./src/util/color" diff --git a/js-framework/package-lock.json b/js-framework/package-lock.json index e46d5280..408c6add 100644 --- a/js-framework/package-lock.json +++ b/js-framework/package-lock.json @@ -1,13 +1,132 @@ { - "name": "hego-jsframework", + "name": "hego-js-framework", "version": "0.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" + }, + "@types/node": { + "version": "12.6.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.6.6.tgz", + "integrity": "sha512-SMgj3x28MkJyHdWaMv/g/ca3LYDi5gR7O8mX0VKazvFOnmlDXctSEdd/8jfSqozjKFK1R9If1QZWkafX7yQTpA==" + }, + "@types/resolve": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", + "integrity": "sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==", + "requires": { + "@types/node": "*" + } + }, + "acorn": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.2.0.tgz", + "integrity": "sha512-8oe72N3WPMjA+2zVG71Ia0nXZ8DpQH+QyyHO+p06jT8eg8FGG3FbcUIi8KziHlAfheJQZeoqbvq1mQSQHXKYLw==" + }, + "builtin-modules": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz", + "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==" + }, + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==" + }, + "is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=" + }, + "is-reference": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.3.tgz", + "integrity": "sha512-W1iHHv/oyBb2pPxkBxtaewxa1BC58Pn5J0hogyCdefwUIvb6R+TGbAcIa4qPNYLqLhb3EnOgUf2MQkkF76BcKw==", + "requires": { + "@types/estree": "0.0.39" + } + }, + "magic-string": { + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.3.tgz", + "integrity": "sha512-6QK0OpF/phMz0Q2AxILkX2mFhi7m+WMwTRg0LQKq/WBB0cDP4rYH3Wp4/d3OTXlrPLVJT/RFqj8tFeAR4nk8AA==", + "requires": { + "sourcemap-codec": "^1.4.4" + } + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" + }, "reflect-metadata": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + }, + "resolve": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", + "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==", + "requires": { + "path-parse": "^1.0.6" + } + }, + "rollup": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.17.0.tgz", + "integrity": "sha512-k/j1m0NIsI4SYgCJR4MWPstGJOWfJyd6gycKoMhyoKPVXxm+L49XtbUwZyFsrSU2YXsOkM4u1ll9CS/ZgJBUpw==", + "requires": { + "@types/estree": "0.0.39", + "@types/node": "^12.6.2", + "acorn": "^6.2.0" + } + }, + "rollup-plugin-commonjs": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.0.1.tgz", + "integrity": "sha512-x0PcCVdEc4J8igv1qe2vttz8JKAKcTs3wfIA3L8xEty3VzxgORLrzZrNWaVMc+pBC4U3aDOb9BnWLAQ8J11vkA==", + "requires": { + "estree-walker": "^0.6.1", + "is-reference": "^1.1.2", + "magic-string": "^0.25.2", + "resolve": "^1.11.0", + "rollup-pluginutils": "^2.8.1" + } + }, + "rollup-plugin-node-resolve": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz", + "integrity": "sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw==", + "requires": { + "@types/resolve": "0.0.8", + "builtin-modules": "^3.1.0", + "is-module": "^1.0.0", + "resolve": "^1.11.1", + "rollup-pluginutils": "^2.8.1" + } + }, + "rollup-pluginutils": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.1.tgz", + "integrity": "sha512-J5oAoysWar6GuZo0s+3bZ6sVZAC0pfqKz68De7ZgDi5z63jOVZn1uJL/+z1jeKHNbGII8kAyHF5q8LnxSX5lQg==", + "requires": { + "estree-walker": "^0.6.1" + } + }, + "sourcemap-codec": { + "version": "1.4.6", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.6.tgz", + "integrity": "sha512-1ZooVLYFxC448piVLBbtOxFcXwnymH9oUF8nRd3CuYDVvkRBxRl6pB4Mtas5a4drtL+E8LDgFkQNcgIw6tc8Hg==" + }, + "tslib": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", + "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==" } } } diff --git a/js-framework/package.json b/js-framework/package.json index 08448252..4373b72a 100644 --- a/js-framework/package.json +++ b/js-framework/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "tsc -p .&& node ./build/index.js" + "dev": "tsc -p .&& node ./build/index.js", + "build": "tsc -p . && rollup -c " }, "repository": { "type": "https", @@ -18,6 +19,10 @@ }, "homepage": "https://github.com/penfeizhou/hego#readme", "dependencies": { - "reflect-metadata": "^0.1.13" + "reflect-metadata": "^0.1.13", + "rollup": "^1.17.0", + "rollup-plugin-commonjs": "^10.0.1", + "rollup-plugin-node-resolve": "^5.2.0", + "tslib": "^1.10.0" } -} \ No newline at end of file +} diff --git a/js-framework/rollup.config.js b/js-framework/rollup.config.js new file mode 100644 index 00000000..4ac67243 --- /dev/null +++ b/js-framework/rollup.config.js @@ -0,0 +1,32 @@ +const path = require('path') +const fs = require('fs') +import resolve from 'rollup-plugin-node-resolve' +import commonjs from 'rollup-plugin-commonjs' + +export default [ + { + input: "build/index.runtime.js", + output: { + name: "hego", + format: "iife", + file: "bundle/sandbox.js", + }, + sourceMap: true, + plugins: [ + resolve({ jsnext: true, main: true }), + // commonjs() + ] + }, + { + input: "build/index.js", + output: { + format: "cjs", + file: "bundle/bundle.js", + }, + sourceMap: true, + plugins: [ + resolve({ jsnext: true, main: true }), + commonjs() + ] + }, +] \ No newline at end of file diff --git a/js-runtime/src/sandbox.ts b/js-framework/src/runtime/sandbox.ts similarity index 83% rename from js-runtime/src/sandbox.ts rename to js-framework/src/runtime/sandbox.ts index 4247a4da..c4ab6f35 100644 --- a/js-runtime/src/sandbox.ts +++ b/js-framework/src/runtime/sandbox.ts @@ -1,3 +1,5 @@ +import { uniqueId } from "../util/uniqueId"; + /** * ``` TypeScript * // load script in global scope @@ -25,11 +27,6 @@ declare function nativeRequire(moduleName: string): boolean declare function nativeBridge(contextId: string, namespace: string, method: string, args?: any, callbackId?: string): boolean -let __uniqueId__: number = 0 - -function uniqueId(prefix: string) { - return `__${prefix}_${__uniqueId__++}__`; -} export function log(message: any) { console.log(message) @@ -132,7 +129,20 @@ export function jsRegisterModule(name: string, moduleObject: any) { gModules.set(name, moduleObject) } -export function jsCall() { - +export function jsCallContextMethod(contextId: string, methodName: string, args?: any) { + const context = gContexts.get(contextId) + if (context === undefined) { + loge(`Cannot find context for context id:${contextId}`) + return + } + if (Reflect.has(context, methodName)) { + const argumentsList: any = [] + for (let i = 2; i < arguments.length; i++) { + argumentsList.push(arguments[i]) + } + return Reflect.apply(Reflect.get(context, methodName), context, argumentsList) + } else { + loge(`Cannot find method for context id:${contextId},method name is:${methodName}`) + } } diff --git a/js-framework/src/util/uniqueId.ts b/js-framework/src/util/uniqueId.ts index 36fb3fb9..372510f9 100644 --- a/js-framework/src/util/uniqueId.ts +++ b/js-framework/src/util/uniqueId.ts @@ -1,5 +1,5 @@ let __uniqueId__: number = 0 -export function uniqueId() { - return `__unique_${__uniqueId__++}__`; +export function uniqueId(prefix: string) { + return `__${prefix}_${__uniqueId__++}__`; } \ No newline at end of file diff --git a/js-framework/tsconfig.json b/js-framework/tsconfig.json index c3efcf59..d511f6a0 100644 --- a/js-framework/tsconfig.json +++ b/js-framework/tsconfig.json @@ -4,7 +4,7 @@ /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ "target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ @@ -37,7 +37,7 @@ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ diff --git a/js-runtime/.gitignore b/js-runtime/.gitignore deleted file mode 100644 index 40b878db..00000000 --- a/js-runtime/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ \ No newline at end of file diff --git a/js-runtime/package.json b/js-runtime/package.json deleted file mode 100644 index 0bf30ce3..00000000 --- a/js-runtime/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "hego-js-runtime", - "version": "0.1.0", - "description": "The JS Runtime of Hego", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "dev": "tsc -p .&& node ./build/index.js" - }, - "repository": { - "type": "https", - "url": "https://github.com/penfeizhou/hego.git" - }, - "author": "pengfeizhou", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/penfeizhou/hego/issues" - }, - "homepage": "https://github.com/penfeizhou/hego#readme", - "dependencies": { - "reflect-metadata": "^0.1.13" - } -} \ No newline at end of file diff --git a/js-runtime/tsconfig.json b/js-runtime/tsconfig.json deleted file mode 100644 index c3efcf59..00000000 --- a/js-runtime/tsconfig.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "compilerOptions": { - "experimentalDecorators": true, - /* Basic Options */ - // "incremental": true, /* Enable incremental compilation */ - "target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - // "lib": [], /* Specify library files to be included in the compilation. */ - // "allowJs": true, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ - // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - // "sourceMap": true, /* Generates corresponding '.map' file. */ - // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "build/", /* Redirect output structure to the directory. */ - // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "composite": true, /* Enable project compilation */ - // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - /* Module Resolution Options */ - // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */ - }, - "include": [ - "**/*.ts", - ] -} \ No newline at end of file