├── .babelrc ├── .gitignore ├── README-zh.md ├── README.md ├── bin └── init.js ├── package.json └── task └── generator.js /.babelrc: -------------------------------------------------------------------------------- 1 | { "presets": ["es2015"] } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by IDE 2 | .idea/ 3 | .idea/* 4 | *.iml 5 | .DS_Store 6 | 7 | # Node 8 | logs 9 | *.log 10 | npm-debug.log* 11 | node_modules 12 | dist 13 | *log 14 | .npm 15 | 16 | # Runtime data 17 | pids 18 | *.pid 19 | *.seed -------------------------------------------------------------------------------- /README-zh.md: -------------------------------------------------------------------------------- 1 | # weex-starter-cli 2 | 3 | > # weex-starter-cli 是一个可以快速构建weex项目的脚手架工具 4 | 5 | ## 安装脚手架 6 | 7 | ```bash 8 | npm install weex-starter-cli -g 9 | ``` 10 | 11 | ## 快速开始 12 | 13 | ```bash 14 | // 创建项目目录 15 | mkdir helloweex 16 | 17 | // 切换至项目目录 18 | cd helloweex 19 | 20 | // 脚手架构建项目 21 | weex-starter-cli 22 | 23 | //运行iOS项目 24 | 25 | // 需要运行 bundle exec pod install 安装pod文件 26 | // 打开项目,command+R运行项目 27 | ``` 28 | 29 | ## 目录结构 30 | 31 | * `src/*`: 所有vue相关的源码 32 | * `src/init.js`: weex入口文件 33 | * `build/*`: 构建脚本 34 | * `dist/*`: 编译后文件目录 35 | * `iOS/*`: weex for iOS代码 36 | * `mock/*`: mock数据以及express服务器目录 37 | * `static/*`: 静态页面目录 38 | * `index.html`: 渲染模版页面 39 | * `.babelrc`: babel配置文件 40 | * `.eslintrc`: eslint配置文件 41 | * `config`: 环境相关配置文件 42 | 43 | ## npm脚本 44 | 45 | ```bash 46 | # 运行开发环境 47 | npm run dev 48 | 49 | # 编译开发环境 50 | npm run build:dev 51 | 52 | # 编译qa环境 53 | npm run build:qa 54 | 55 | # 环境生产 56 | npm run build:prod 57 | 58 | # 运行api服务器 59 | npm run serve 60 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # weex-starter-cli 2 | 3 | > # weex-starter-cli 4 | 5 | ## Install Cli 6 | 7 | ```bash 8 | npm install weex-starter-cli -g 9 | ``` 10 | 11 | ## getting start 12 | 13 | 1.create directory 14 | 15 | ```bash 16 | mkdir helloweex 17 | ``` 18 | 19 | 2.checkout directory 20 | 21 | ```bash 22 | cd helloweex 23 | ``` 24 | 25 | 3.init project 26 | 27 | ```bash 28 | weex-starter-cli 29 | ``` 30 | 31 | 4.init iOS 32 | 33 | ```bash 34 | need bundle exec pod install // pod install 35 | open project and run by Xcode // open project run project 36 | ``` 37 | 38 | 39 | ## file structure 40 | 41 | * `src/*`: all Vue's source code 42 | * `app.js`: entrance of the Weex page 43 | * `build/*`: some build scripts 44 | * `dist/*`: where places generated code 45 | * `assets/*`: some assets for Web preview 46 | * `index.html`: a page with Web preview and qrcode of Weex js bundle 47 | * `weex.html`: Web render 48 | * `.babelrc`: babel config (preset-2015 by default) 49 | * `.eslintrc`: eslint config (standard by default) 50 | 51 | ## npm scripts 52 | 53 | ```bash 54 | # build in dev-server and run project 55 | npm run dev 56 | 57 | # build the js bundles for dev 58 | npm run build:dev 59 | 60 | # build the js bundles for qa 61 | npm run build:qa 62 | 63 | # build the js bundles for prod 64 | npm run build:prod 65 | 66 | # run api-server 67 | npm run serve 68 | ``` 69 | -------------------------------------------------------------------------------- /bin/init.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // generator an template 4 | const yargs = require('yargs'); 5 | const argv = yargs.argv; 6 | 7 | const generator = require('../task/generator'); 8 | 9 | generator.generate(argv._[0]); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "weex-starter-cli", 3 | "version": "0.0.2", 4 | "description": "Auto generate project template", 5 | "main": "index.js", 6 | "bin": { 7 | "weex-starter-cli": "./bin/init.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/Roxyhuang/weex-starter-cli.git" 12 | }, 13 | "keywords": [ 14 | "cli" 15 | ], 16 | "author": "neo_huang", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/Roxyhuang/weex-starter-cli/issues" 20 | }, 21 | "homepage": "https://github.com/Roxyhuang/weex-starter-cli#readme", 22 | "dependencies": { 23 | "chalk": "^1.1.3", 24 | "fs-extra": "^3.0.1", 25 | "nodegit": "^0.18.3", 26 | "prompt": "^1.0.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /task/generator.js: -------------------------------------------------------------------------------- 1 | const prompt = require('prompt'); 2 | const fs = require('fs-extra'); 3 | const path = require('path'); 4 | const chalk = require('chalk'); 5 | const nodegit = require('nodegit'); 6 | 7 | exports.generate = function (name) { 8 | if(typeof(name) == 'undefined') { 9 | const dirname = path.resolve('.').split(path.sep).pop(); 10 | getName(dirname, chalk.green('Generate project in current directory?(Y/n)'),(err,result) => { 11 | if(result.name.toLowerCase() === 'n') { 12 | return; 13 | } 14 | const dirpath = process.cwd(); 15 | let projectName = result.name.toLocaleLowerCase() === 'y' ? dirname : result.name; 16 | var url = "https://github.com/Roxyhuang/weex-starter-kit.git", 17 | local = dirpath, 18 | cloneOpts = {}; 19 | console.log("Cloning into 'weex-starter-kit'..."); 20 | nodegit.Clone(url, local, cloneOpts).then(function (repo) { 21 | // copy(projectName,dirpath); 22 | replace(projectName,dirpath); 23 | console.log("Cloned " + path.basename(url) + " to " + repo.workdir()); 24 | }).catch(function (err) { 25 | console.log(err); 26 | }); 27 | }) 28 | 29 | } else { 30 | getName(name, chalk.green('Init your Project'), (err, result) => { 31 | if (err) { 32 | return; 33 | } 34 | let projectName = result.name; 35 | const dirpath = path.join(process.cwd(),projectName); 36 | createProject(projectName,dirpath); 37 | }) 38 | } 39 | 40 | 41 | } 42 | 43 | function getName(name, message = "Project Name", done) { 44 | const schema = { 45 | properties: { 46 | name: { 47 | message: message, 48 | default: name 49 | } 50 | } 51 | }; 52 | prompt.start() 53 | prompt.get(schema, done) 54 | } 55 | 56 | 57 | 58 | // init a project 59 | function createProject(name, dirpath) { 60 | fs.mkdir(dirpath, 484, function (err) { 61 | if (err) { 62 | if (err.code == 'EEXIST') { 63 | return console.log(chalk.red( 'the folder "' + name + '" exists! Please rename your project.')); 64 | } else { 65 | console.error(err) 66 | } 67 | } else { 68 | var url = "https://github.com/Roxyhuang/weex-starter-kit.git", 69 | local = dirpath, 70 | cloneOpts = {}; 71 | 72 | nodegit.Clone(url, local, cloneOpts).then(function (repo) { 73 | // copy(name,dirpath); 74 | replace(name,dirpath); 75 | console.log("Cloned " + path.basename(url) + " to " + repo.workdir()); 76 | }).catch(function (err) { 77 | console.log(err); 78 | }); 79 | } 80 | }); 81 | } 82 | 83 | 84 | function copy(name,dirpath) { 85 | const files = [] 86 | const src = path.join(__dirname, '..', 'template') 87 | walk(src, files); 88 | files.forEach(file => { 89 | const relative = path.relative(src, file) 90 | const finalPath = path.join(dirpath, relative).replace(/\.npmignore$/, '.gitignore') 91 | if (!fs.existsSync(finalPath)) { 92 | console.log(chalk.grey(`file: ${finalPath} created.`)); 93 | 94 | fs.copySync(file, finalPath) 95 | } 96 | else { 97 | console.log(`file: ${finalPath} already existed.`) 98 | } 99 | }) 100 | } 101 | 102 | function replace(name,dirpath) { 103 | const files = ['package.json', 'README.md'] 104 | files.forEach(file => { 105 | let filePath = path.join(dirpath, file); 106 | var content = fs.readFileSync(filePath , { 107 | encoding: 'utf-8' 108 | }) 109 | content = content.replace(/{{\s*(.+)\s*}}/ig, function (defaultName) { 110 | return name || defaultName 111 | }) 112 | fs.writeFileSync(filePath, content) 113 | }) 114 | } 115 | /** 116 | * ref: http://stackoverflow.com/a/16684530 117 | */ 118 | function walk(dir, files) { 119 | const list = fs.readdirSync(dir) 120 | list.forEach(function (file) { 121 | file = path.join(dir, file) 122 | const stat = fs.statSync(file) 123 | if (stat && stat.isDirectory()) { 124 | walk(file, files) 125 | } 126 | else { 127 | files.push(file) 128 | } 129 | }) 130 | } --------------------------------------------------------------------------------