add doric-cli init content

This commit is contained in:
pengfei.zhou 2019-08-13 14:31:12 +08:00
parent a3a6d4111f
commit 76fe0f9044
9 changed files with 190 additions and 35 deletions

View File

@ -25,6 +25,7 @@ android {
afterEvaluate { afterEvaluate {
buildJSBundle.exec() buildJSBundle.exec()
buildDemo.exec()
buildDebugger.exec() buildDebugger.exec()
} }
@ -33,6 +34,11 @@ task buildJSBundle(type: Exec) {
commandLine 'npm', 'run', 'build' commandLine 'npm', 'run', 'build'
} }
task buildDemo(type: Exec) {
workingDir project.rootDir.getParent() + "/demo"
commandLine 'npm', 'run', 'build'
}
task buildDebugger(type: Exec) { task buildDebugger(type: Exec) {
workingDir project.rootDir.getParent() + "/debugger" workingDir project.rootDir.getParent() + "/debugger"
commandLine 'npm', 'run', 'build' commandLine 'npm', 'run', 'build'

67
doric-cli/contents/$.ts Normal file
View File

@ -0,0 +1,67 @@
import { ViewHolder, VMPanel, ViewModel, Gravity, Text, VLayout, 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 = "Click to count"
this.counter.textSize = 20
vlayout.space = 20
vlayout.layoutConfig = {
alignment: new Gravity().center()
}
vlayout.addChild(this.number)
vlayout.addChild(this.counter)
root.addChild(vlayout)
}
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 __$__ extends VMPanel<CountModel, CounterView>{
getVMClass() {
return CounterVM
}
getModel() {
return {
count: 0
}
}
getViewHolder() {
return new CounterView
}
}

View File

@ -0,0 +1,3 @@
node_modules/
build/
bundle/

View File

@ -0,0 +1,22 @@
{
"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 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"
}
}

View 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'],
}
})

View File

@ -0,0 +1,61 @@
{
"compilerOptions": {
/* 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",
]
}

View File

@ -1,4 +1,5 @@
var fs = require('fs'); var fs = require('fs');
require('shelljs/global')
module.exports = function (name) { module.exports = function (name) {
if (fs.existsSync(name)) { if (fs.existsSync(name)) {
@ -10,26 +11,15 @@ module.exports = function (name) {
return console.error(err); return console.error(err);
} }
console.log(`create dir ${name} success`); console.log(`create dir ${name} success`);
fs.writeFileSync(`${name}/package.json`, `{ fs.writeFileSync(`${name}/package.json`, fs.readFileSync(`${__dirname}/../contents/_package.json`).toString().replace(/__\$__/g, name))
"name": "${name}", fs.writeFileSync(`${name}/tsconfig.json`, fs.readFileSync(`${__dirname}/../contents/_tsconfig.json`))
"version": "0.1.0", fs.writeFileSync(`${name}/rollup.config.js`, fs.readFileSync(`${__dirname}/../contents/_rollup.config.js`))
"main": "index.js", fs.writeFileSync(`${name}/.gitignore`, fs.readFileSync(`${__dirname}/../contents/_gitignore`))
"scripts": { fs.mkdirSync(`${name}/src`)
"test": "echo \"Error: no test specified\" && exit 1", fs.writeFileSync(`${name}/src/${name}.ts`, fs.readFileSync(`${__dirname}/../contents/$.ts`).toString().replace(/__\$__/g, name))
"build": "tsc -p .&& rollup -c", fs.writeFileSync(`${name}/index.ts`, `export default ['src/${name}']`)
"dev": "tsc -w -p . & rollup -c -w", exec(`cd ${name} && npm install && npm run build`, () => {
"clean": "rm -rf build && rm -rf demo && rm -rf bundle" console.log(`Create Doric Project ${name} Success`)
}, })
"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"
}
}`)
}) })
} }

View File

@ -419,7 +419,7 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\nexport NVM_DIR=\"$HOME/.nvm\"\n[ -s \"$NVM_DIR/nvm.sh\" ] && \\. \"$NVM_DIR/nvm.sh\" # This loads nvm\n[ -s \"$NVM_DIR/bash_completion\" ] && \\. \"$NVM_DIR/bash_completion\" # This loads nvm bash_completion\n\ncd ../../js-framework && npm run build\n"; shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\nexport NVM_DIR=\"$HOME/.nvm\"\n[ -s \"$NVM_DIR/nvm.sh\" ] && \\. \"$NVM_DIR/nvm.sh\" # This loads nvm\n[ -s \"$NVM_DIR/bash_completion\" ] && \\. \"$NVM_DIR/bash_completion\" # This loads nvm bash_completion\n\ncd ../../js-framework && npm run build\ncd ../demo && npm run build\n";
}; };
/* End PBXShellScriptBuildPhase section */ /* End PBXShellScriptBuildPhase section */

View File

@ -21,16 +21,7 @@ @implementation ViewController
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
UILabel *label = [[UILabel alloc] init];
label.text = @"Hello,Doric";
[label sizeToFit];
label.centerX = self.view.width/2;
label.centerY = self.view.height/2;
[self.view addSubview:label];
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(test:)];
[label addGestureRecognizer:recognizer];
label.userInteractionEnabled = YES;
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"Snake" ofType:@"js"]; NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"Snake" ofType:@"js"];
NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; NSString *jsContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"Snake"]; self.doricContext = [[DoricContext alloc] initWithScript:jsContent source:@"Snake"];
@ -39,8 +30,5 @@ - (void)viewDidLoad {
@"height":[NSNumber numberWithFloat:self.view.height]},nil]; @"height":[NSNumber numberWithFloat:self.view.height]},nil];
} }
- (void)test:(UIView *)view {
NSLog(@"test");
[self.doricContext callEntity:@"log",nil];
}
@end @end