config js project
This commit is contained in:
parent
d6b9bb60c3
commit
1e6fa459c3
3
demo/.gitignore
vendored
Normal file
3
demo/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
build/
|
||||
bundle/
|
4
demo/index.ts
Normal file
4
demo/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export default [
|
||||
'src/Counter',
|
||||
'src/Snake',
|
||||
]
|
2056
demo/package-lock.json
generated
Normal file
2056
demo/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
demo/package.json
Normal file
22
demo/package.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "demo",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "tsc -p .&& rollup -c",
|
||||
"dev": "tsc -w -p . & rollup -c -w",
|
||||
"clean": "rm -rf build && rm -rf bundle"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"doric": "file:../js-framework",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rollup": "^1.17.0",
|
||||
"rollup-plugin-commonjs": "^10.0.1",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-watch": "^4.3.1",
|
||||
"tslib": "^1.10.0",
|
||||
"typescript": "^3.5.3"
|
||||
}
|
||||
}
|
18
demo/rollup.config.js
Normal file
18
demo/rollup.config.js
Normal file
@ -0,0 +1,18 @@
|
||||
import resolve from 'rollup-plugin-node-resolve'
|
||||
import commonjs from 'rollup-plugin-commonjs'
|
||||
import bundles from './build/index'
|
||||
|
||||
export default bundles.map(bundle => {
|
||||
return {
|
||||
input: `build/${bundle}.js`,
|
||||
output: {
|
||||
format: "cjs",
|
||||
file: `bundle/${bundle}.js`,
|
||||
},
|
||||
plugins: [
|
||||
resolve({ jsnext: true, main: true }),
|
||||
commonjs()
|
||||
],
|
||||
external: ['reflect-metadata', 'doric'],
|
||||
}
|
||||
})
|
112
demo/src/Counter.ts
Normal file
112
demo/src/Counter.ts
Normal file
@ -0,0 +1,112 @@
|
||||
import { Image, ViewHolder, VMPanel, ViewModel, Gravity, NativeCall, Text, Color, VLayout, log, logw, loge, Group, } from "doric"
|
||||
|
||||
|
||||
interface CountModel {
|
||||
count: number
|
||||
}
|
||||
|
||||
class CounterView extends ViewHolder {
|
||||
number = new Text
|
||||
counter = new Text
|
||||
build(root: Group) {
|
||||
const vlayout = new VLayout
|
||||
vlayout.width = 200
|
||||
vlayout.height = 200
|
||||
vlayout.gravity = new Gravity().center()
|
||||
this.number.textSize = 40
|
||||
this.number.layoutConfig = {
|
||||
alignment: new Gravity().center()
|
||||
}
|
||||
this.counter = new Text
|
||||
this.counter.text = "点击计数"
|
||||
this.counter.border = {
|
||||
width: 1,
|
||||
color: Color.parse('#000000'),
|
||||
}
|
||||
this.counter.textSize = 20
|
||||
this.counter.corners = 5
|
||||
vlayout.space = 20
|
||||
vlayout.layoutConfig = {
|
||||
alignment: new Gravity().center()
|
||||
}
|
||||
vlayout.border = {
|
||||
width: 1,
|
||||
color: Color.parse("#000000"),
|
||||
}
|
||||
this.counter.shadow = {
|
||||
color: Color.parse("#00ff00"),
|
||||
opacity: 0.5,
|
||||
radius: 20,
|
||||
offsetX: 10,
|
||||
offsetY: 10,
|
||||
}
|
||||
vlayout.shadow = {
|
||||
color: Color.parse("#ffff00"),
|
||||
opacity: 0.5,
|
||||
radius: 20,
|
||||
offsetX: 10,
|
||||
offsetY: 10,
|
||||
}
|
||||
vlayout.corners = 20
|
||||
vlayout.addChild(this.number)
|
||||
vlayout.addChild(this.counter)
|
||||
// root.bgColor = Color.parse('#00ff00')
|
||||
vlayout.bgColor = Color.parse('#ff00ff')
|
||||
root.addChild(vlayout)
|
||||
const iv = new Image
|
||||
// iv.width = iv.height = 100
|
||||
iv.imageUrl = "https://misc.aotu.io/ONE-SUNDAY/SteamEngine.png"
|
||||
//iv.bgColor = Color.parse('#00ff00')
|
||||
root.addChild(iv)
|
||||
}
|
||||
|
||||
setNumber(n: number) {
|
||||
this.number.text = n.toString()
|
||||
}
|
||||
|
||||
setCounter(v: Function) {
|
||||
this.counter.onClick = v
|
||||
}
|
||||
}
|
||||
|
||||
class CounterVM extends ViewModel<CountModel, CounterView> {
|
||||
|
||||
binding(v: CounterView, model: CountModel): void {
|
||||
v.setNumber(model.count)
|
||||
v.setCounter(() => {
|
||||
this.getModel().count++
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@Entry
|
||||
class MyPage extends VMPanel<CountModel, CounterView>{
|
||||
|
||||
getVMClass() {
|
||||
return CounterVM
|
||||
}
|
||||
|
||||
getModel() {
|
||||
return {
|
||||
count: 0,
|
||||
add: function () {
|
||||
this.count++
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
getViewHolder() {
|
||||
return new CounterView
|
||||
}
|
||||
|
||||
|
||||
@NativeCall
|
||||
log() {
|
||||
log("Hello.HEGO")
|
||||
logw("Hello.HEGO")
|
||||
loge("Hello.HEGO")
|
||||
context.modal.toast('This is a toast.').then((r) => {
|
||||
loge(r)
|
||||
})
|
||||
}
|
||||
}
|
@ -1,114 +1,5 @@
|
||||
import { HLayout, Image, ViewHolder, VMPanel, View, ViewModel, WRAP_CONTENT, Gravity, Mutable, NativeCall, Text, Color, VLayout, Panel, log, logw, loge, Group, Stack, } from "./index"
|
||||
import { loge, log, ViewHolder, Stack, ViewModel, Gravity, Text, Color, HLayout, VLayout, Group, VMPanel } from "doric";
|
||||
|
||||
|
||||
interface CountModel {
|
||||
count: number
|
||||
}
|
||||
|
||||
class CounterView extends ViewHolder {
|
||||
number = new Text
|
||||
counter = new Text
|
||||
build(root: Group) {
|
||||
const vlayout = new VLayout
|
||||
vlayout.width = 200
|
||||
vlayout.height = 200
|
||||
vlayout.gravity = new Gravity().center()
|
||||
this.number.textSize = 40
|
||||
this.number.layoutConfig = {
|
||||
alignment: new Gravity().center()
|
||||
}
|
||||
this.counter = new Text
|
||||
this.counter.text = "点击计数"
|
||||
this.counter.border = {
|
||||
width: 1,
|
||||
color: Color.parse('#000000'),
|
||||
}
|
||||
this.counter.textSize = 20
|
||||
this.counter.corners = 5
|
||||
vlayout.space = 20
|
||||
vlayout.layoutConfig = {
|
||||
alignment: new Gravity().center()
|
||||
}
|
||||
vlayout.border = {
|
||||
width: 1,
|
||||
color: Color.parse("#000000"),
|
||||
}
|
||||
this.counter.shadow = {
|
||||
color: Color.parse("#00ff00"),
|
||||
opacity: 0.5,
|
||||
radius: 20,
|
||||
offsetX: 10,
|
||||
offsetY: 10,
|
||||
}
|
||||
vlayout.shadow = {
|
||||
color: Color.parse("#ffff00"),
|
||||
opacity: 0.5,
|
||||
radius: 20,
|
||||
offsetX: 10,
|
||||
offsetY: 10,
|
||||
}
|
||||
vlayout.corners = 20
|
||||
vlayout.addChild(this.number)
|
||||
vlayout.addChild(this.counter)
|
||||
// root.bgColor = Color.parse('#00ff00')
|
||||
vlayout.bgColor = Color.parse('#ff00ff')
|
||||
root.addChild(vlayout)
|
||||
const iv = new Image
|
||||
// iv.width = iv.height = 100
|
||||
iv.imageUrl = "https://misc.aotu.io/ONE-SUNDAY/SteamEngine.png"
|
||||
//iv.bgColor = Color.parse('#00ff00')
|
||||
root.addChild(iv)
|
||||
}
|
||||
|
||||
setNumber(n: number) {
|
||||
this.number.text = n.toString()
|
||||
}
|
||||
|
||||
setCounter(v: Function) {
|
||||
this.counter.onClick = v
|
||||
}
|
||||
}
|
||||
|
||||
class CounterVM extends ViewModel<CountModel, CounterView> {
|
||||
|
||||
binding(v: CounterView, model: CountModel): void {
|
||||
v.setNumber(model.count)
|
||||
v.setCounter(() => {
|
||||
this.getModel().count++
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class MyPage extends VMPanel<CountModel, CounterView>{
|
||||
|
||||
getVMClass() {
|
||||
return CounterVM
|
||||
}
|
||||
|
||||
getModel() {
|
||||
return {
|
||||
count: 0,
|
||||
add: function () {
|
||||
this.count++
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
getViewHolder() {
|
||||
return new CounterView
|
||||
}
|
||||
|
||||
|
||||
@NativeCall
|
||||
log() {
|
||||
log("Hello.HEGO")
|
||||
logw("Hello.HEGO")
|
||||
loge("Hello.HEGO")
|
||||
context.modal.toast('This is a toast.').then((r) => {
|
||||
loge(r)
|
||||
})
|
||||
}
|
||||
}
|
||||
type SnakeNode = {
|
||||
x: number
|
||||
y: number
|
62
demo/tsconfig.json
Normal file
62
demo/tsconfig.json
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"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": "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. */
|
||||
// "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",
|
||||
]
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var program = require('commander');
|
||||
|
||||
|
||||
var program = require('commander');
|
||||
|
||||
program
|
||||
@ -10,6 +7,7 @@ program
|
||||
.option('-n, --native', 'Native')
|
||||
.action(function (name, cmd) {
|
||||
console.log('create ' + name + (cmd.native ? ' native' : 'js'))
|
||||
require('./scripts/init')(name)
|
||||
})
|
||||
program
|
||||
.command('dev')
|
||||
|
35
doric-cli/scripts/init.js
Normal file
35
doric-cli/scripts/init.js
Normal file
@ -0,0 +1,35 @@
|
||||
var fs = require('fs');
|
||||
|
||||
module.exports = function (name) {
|
||||
if (fs.existsSync(name)) {
|
||||
console.warn(`Dir:${process.cwd()}/${name} already exists`)
|
||||
return;
|
||||
}
|
||||
fs.mkdir(name, function (err) {
|
||||
if (err) {
|
||||
return console.error(err);
|
||||
}
|
||||
console.log(`create dir ${name} success`);
|
||||
fs.writeFileSync(`${name}/package.json`, `{
|
||||
"name": "${name}",
|
||||
"version": "0.1.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "tsc -p .&& rollup -c",
|
||||
"dev": "tsc -w -p . & rollup -c -w",
|
||||
"clean": "rm -rf build && rm -rf demo && rm -rf bundle"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rollup": "^1.17.0",
|
||||
"rollup-plugin-commonjs": "^10.0.1",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-watch": "^4.3.1",
|
||||
"tslib": "^1.10.0",
|
||||
"typescript": "^3.5.3"
|
||||
}
|
||||
}`)
|
||||
})
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "doric-js-framework",
|
||||
"name": "doric",
|
||||
"version": "0.1.0",
|
||||
"description": "The JS Framework of Doric",
|
||||
"main": "index.js",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "tsc -p .&& rollup -c",
|
||||
"dev": "tsc -w -p . & rollup -c -w",
|
||||
"clean": "rm -rf build && rm -rf demo && rm -rf bundle"
|
||||
"clean": "rm -rf build && rm -rf bundle"
|
||||
},
|
||||
"repository": {
|
||||
"type": "https",
|
||||
@ -22,7 +22,6 @@
|
||||
"dependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rollup": "^1.17.0",
|
||||
"rollup-plugin-commonjs": "^10.0.1",
|
||||
"rollup-plugin-node-resolve": "^5.2.0",
|
||||
"rollup-watch": "^4.3.1",
|
||||
"tslib": "^1.10.0",
|
||||
|
@ -1,7 +1,6 @@
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
import resolve from 'rollup-plugin-node-resolve'
|
||||
import commonjs from 'rollup-plugin-commonjs'
|
||||
|
||||
export default [
|
||||
{
|
||||
@ -11,7 +10,6 @@ export default [
|
||||
format: "iife",
|
||||
file: "bundle/doric-sandbox.js",
|
||||
},
|
||||
sourceMap: true,
|
||||
plugins: [
|
||||
resolve({ jsnext: true, main: true }),
|
||||
]
|
||||
@ -22,23 +20,9 @@ export default [
|
||||
format: "cjs",
|
||||
file: "bundle/doric-lib.js",
|
||||
},
|
||||
sourceMap: true,
|
||||
plugins: [
|
||||
resolve({ jsnext: true, main: true }),
|
||||
],
|
||||
external: ['reflect-metadata']
|
||||
},
|
||||
{
|
||||
input: "build/demo.js",
|
||||
output: {
|
||||
format: "cjs",
|
||||
file: "demo/demo.js",
|
||||
},
|
||||
sourceMap: true,
|
||||
plugins: [
|
||||
resolve({ jsnext: true, main: true }),
|
||||
commonjs()
|
||||
],
|
||||
external: ['./index'],
|
||||
},
|
||||
]
|
Reference in New Issue
Block a user