├── template ├── Miox@stable │ ├── CHANGELOG.md │ ├── README.md │ ├── src │ │ ├── webviews │ │ │ ├── index.scss │ │ │ └── index.js │ │ ├── index.scss │ │ └── router.js │ ├── .gitignore │ ├── deps.js │ ├── development.js │ └── production.js ├── Miox@plugin │ ├── src │ │ ├── test.js │ │ ├── index.js │ │ └── index.html │ ├── README.md │ ├── .babelrc │ ├── .gitignore │ ├── webpack.config.js │ ├── .gitattributes │ ├── package.json │ └── compile │ │ ├── development.js │ │ └── production.js └── miox@stable │ ├── .babelrc │ ├── webpack.config.js │ ├── package.json │ ├── src │ ├── index.js │ └── index.html │ └── .gitattributes ├── .gitignore ├── README.md ├── lib ├── util.js └── create.js ├── bin └── index.js ├── package.json └── npm-debug.log /template/Miox@stable/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /template/Miox@stable/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | .idea -------------------------------------------------------------------------------- /template/Miox@plugin/src/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; -------------------------------------------------------------------------------- /template/Miox@stable/src/webviews/index.scss: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /template/Miox@plugin/src/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | -------------------------------------------------------------------------------- /template/Miox@plugin/README.md: -------------------------------------------------------------------------------- 1 | # A New Project Plugin 2 | 3 | Everything is ready! -------------------------------------------------------------------------------- /template/Miox@stable/src/index.scss: -------------------------------------------------------------------------------- 1 | @import "scss/index"; 2 | @import "webviews/index"; -------------------------------------------------------------------------------- /template/Miox@plugin/.babelrc: -------------------------------------------------------------------------------- 1 | { "presets": ["es2015", "stage-0"], "plugins": ["add-module-exports"] } 2 | -------------------------------------------------------------------------------- /template/miox@stable/.babelrc: -------------------------------------------------------------------------------- 1 | { "presets": ["es2015", "stage-0"], "plugins": ["add-module-exports"] } 2 | -------------------------------------------------------------------------------- /template/Miox@plugin/.gitignore: -------------------------------------------------------------------------------- 1 | archive 2 | node_modules 3 | .idea 4 | bower_components 5 | explorations 6 | .DS_Store 7 | coverage 8 | perf 9 | *.map 10 | npm-debug.log -------------------------------------------------------------------------------- /template/Miox@stable/.gitignore: -------------------------------------------------------------------------------- 1 | archive 2 | node_modules 3 | .idea 4 | bower_components 5 | explorations 6 | .DS_Store 7 | coverage 8 | perf 9 | *.map 10 | npm-debug.log -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # miox-cli 2 | 3 | The [miox](https://github.com/cevio/matrix) framework cli 4 | 5 | ## Install 6 | 7 | ```bash 8 | $ npm install miox-cli -g 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```bash 14 | $ mi 15 | ``` 16 | 17 | ## License 18 | 19 | MIT -------------------------------------------------------------------------------- /template/Miox@stable/src/router.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by evio on 16/7/25. 3 | */ 4 | 'use strict'; 5 | 6 | import MioxRouter from 'miox-router'; 7 | import INDEX from './webviews/index'; 8 | const Router = new MioxRouter(); 9 | Router.patch('/', async ctx => await ctx.render(INDEX)); 10 | export default Router; 11 | -------------------------------------------------------------------------------- /lib/util.js: -------------------------------------------------------------------------------- 1 | exports.exit = function(err) { 2 | if (err) { 3 | console.error(err); 4 | return process.exit(1); 5 | } 6 | 7 | process.exit(0); 8 | }; 9 | 10 | exports.resolve = function(err, callback) { 11 | if (err) { 12 | return console.error(err); 13 | } 14 | 15 | callback(); 16 | }; -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var app = require('cmdu'); 4 | 5 | app.version = require('../package.json').version; 6 | 7 | app.action(function () { 8 | this.showHelp(); 9 | }); 10 | 11 | app 12 | .command('create') 13 | .alias('c') 14 | .describe('Create a new project with miox.') 15 | .use('../lib/create'); 16 | 17 | app.listen(); -------------------------------------------------------------------------------- /template/miox@stable/webpack.config.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Created by evio on 16/7/20. 4 | */ 5 | 'use strict'; 6 | const Production = require('./production'); 7 | const Development = require('./development'); 8 | let result; 9 | 10 | switch (process.env.NODE_ENV) { 11 | case "production": 12 | result = Production; 13 | break; 14 | case "development": 15 | result = Development; 16 | break; 17 | } 18 | 19 | module.exports = result; -------------------------------------------------------------------------------- /template/Miox@plugin/webpack.config.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Created by evio on 16/7/20. 4 | */ 5 | 'use strict'; 6 | const Production = require('./compile/production'); 7 | const Development = require('./compile/development'); 8 | let result; 9 | 10 | switch (process.env.NODE_ENV) { 11 | case "production": 12 | result = Production; 13 | break; 14 | case "development": 15 | result = Development; 16 | break; 17 | } 18 | 19 | module.exports = result; -------------------------------------------------------------------------------- /template/miox@stable/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "build/index.js", 6 | "scripts": { 7 | "dev": "NODE_ENV=development node_modules/.bin/webpack-dev-server --config ./webpack.config.js --host 0.0.0.0 --port 8080 --progress --colors --inline --hot --display-error-details --content-base src/", 8 | "git": "git add . && git commit -am 'update new code' && git pull && git push", 9 | "build": "rimraf ./build/ && NODE_ENV=production webpack --config ./webpack.config.js -p" 10 | }, 11 | "author": "沈赟杰", 12 | "license": "MIT" 13 | } 14 | -------------------------------------------------------------------------------- /template/miox@stable/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by evio on 16/7/25. 3 | */ 4 | 'use strict'; 5 | 6 | import 'normalize.css'; 7 | import './index.scss'; 8 | import { Bootstrap } from 'miox'; 9 | import MioxAnimate from 'miox-animate'; 10 | import MioxVueComponents from 'miox-vue-components'; 11 | import { Engine, plugin } from 'miox-vue-engine'; 12 | import Router from './router'; 13 | 14 | /** 15 | * 程序启动闭包 16 | */ 17 | Bootstrap(async app => { 18 | const engine = app.engine(Engine); 19 | plugin(MioxVueComponents); 20 | app.animate(MioxAnimate({ effect: 'slide' })); 21 | app.use(Router.routes()); 22 | }).catch(console.error); -------------------------------------------------------------------------------- /template/Miox@plugin/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Application Builder 14 | 15 | 16 | -------------------------------------------------------------------------------- /template/Miox@plugin/.gitattributes: -------------------------------------------------------------------------------- 1 | # Automatically normalize line endings for all text-based files 2 | # http://git-scm.com/docs/gitattributes#_end_of_line_conversion 3 | * text=auto 4 | # For the following file types, normalize line endings to LF on 5 | # checkin and prevent conversion to CRLF when they are checked out 6 | # (this is required in order to prevent newline related issues like, 7 | # for example, after the build script is run) 8 | .* text eol=lf 9 | *.css text eol=lf 10 | *.html text eol=lf 11 | *.js text eol=lf 12 | *.json text eol=lf 13 | *.md text eol=lf 14 | *.sh text eol=lf 15 | *.txt text eol=lf 16 | *.xml text eol=lf 17 | # Exclude the `.htaccess` file from GitHub's language statistics 18 | # https://github.com/github/linguist#using-gitattributes 19 | dist/.htaccess linguist-vendored 20 | -------------------------------------------------------------------------------- /template/miox@stable/.gitattributes: -------------------------------------------------------------------------------- 1 | # Automatically normalize line endings for all text-based files 2 | # http://git-scm.com/docs/gitattributes#_end_of_line_conversion 3 | * text=auto 4 | # For the following file types, normalize line endings to LF on 5 | # checkin and prevent conversion to CRLF when they are checked out 6 | # (this is required in order to prevent newline related issues like, 7 | # for example, after the build script is run) 8 | .* text eol=lf 9 | *.css text eol=lf 10 | *.html text eol=lf 11 | *.js text eol=lf 12 | *.json text eol=lf 13 | *.md text eol=lf 14 | *.sh text eol=lf 15 | *.txt text eol=lf 16 | *.xml text eol=lf 17 | # Exclude the `.htaccess` file from GitHub's language statistics 18 | # https://github.com/github/linguist#using-gitattributes 19 | dist/.htaccess linguist-vendored 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@u51/miox-cli", 3 | "description": "The miox framework cli", 4 | "version": "2.0.0", 5 | "author": { 6 | "name": "Spikef", 7 | "email": "Spikef@foxmail.com" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/Spikef/miox-cli.git" 12 | }, 13 | "keywords": [ 14 | "miox", 15 | "command", 16 | "cli" 17 | ], 18 | "files": [ 19 | "lib", 20 | "bin", 21 | "template" 22 | ], 23 | "bin": { 24 | "miox": "./bin/index.js" 25 | }, 26 | "dependencies": { 27 | "chalk": "^1.1.3", 28 | "cmdu": "^1.0.1", 29 | "fs-extra": "^0.30.0", 30 | "inquirer": "^1.0.3" 31 | }, 32 | "devDependencies": {}, 33 | "scripts": {}, 34 | "engine-strict": true, 35 | "engines": { 36 | "node": ">= 4.0" 37 | }, 38 | "license": "MIT" 39 | } 40 | -------------------------------------------------------------------------------- /template/Miox@stable/src/webviews/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by evio on 16/8/1. 3 | */ 4 | 'use strict'; 5 | 6 | import './index.scss'; 7 | 8 | import { Webview } from 'miox-vue-engine'; 9 | 10 | export default class IndexPage extends Webview { 11 | constructor(el){ 12 | super(el); 13 | } 14 | 15 | data(data){ 16 | data.title = 'Demo Page'; 17 | data.keyword = 'Hello World'; 18 | } 19 | 20 | template(){ 21 | return ` 22 | 23 | 24 | 25 | {{title}} 26 | 27 | 28 | 29 | {{keyword}} 30 | 31 | 32 | `; 33 | } 34 | } -------------------------------------------------------------------------------- /template/Miox@stable/deps.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by evio on 16/8/1. 3 | */ 4 | 'use strict'; 5 | 6 | var fs = require('fs-extra'); 7 | var path = require('path'); 8 | 9 | exports.devDependencies = ["autoprefixer", "babel-core", "babel-loader", "babel-plugin-add-module-exports", "babel-polyfill", "babel-preset-es2015", "babel-preset-stage-0", "css-loader", "extract-text-webpack-plugin", "file-loader", "html-webpack-plugin", "image-webpack-loader", "json-loader", "node-sass", "postcss-loader", "rimraf", "sass-loader", "style-loader", "url-loader", "webpack", "webpack-dev-server"]; 10 | exports.dependencies = ["miox@next", "miox-animate", "miox-router", "miox-vue-components", "miox-vue-engine", "normalize.css"]; 11 | exports.scss = function(where, fn){ 12 | var source = path.resolve(where, 'node_modules', 'miox', 'src', 'scss'); 13 | var target = path.resolve(where, 'src', 'scss'); 14 | fs.copy(source, target, function(err){ 15 | if (err) { throw err; } 16 | fn(); 17 | }); 18 | }; -------------------------------------------------------------------------------- /npm-debug.log: -------------------------------------------------------------------------------- 1 | 0 info it worked if it ends with ok 2 | 1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'git' ] 3 | 2 info using npm@3.10.6 4 | 3 info using node@v6.2.2 5 | 4 verbose stack Error: missing script: git 6 | 4 verbose stack at run (/usr/local/lib/node_modules/npm/lib/run-script.js:151:19) 7 | 4 verbose stack at /usr/local/lib/node_modules/npm/lib/run-script.js:61:5 8 | 4 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:356:5 9 | 4 verbose stack at handleExists (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:329:20) 10 | 4 verbose stack at FSReqWrap.cb [as oncomplete] (fs.js:251:19) 11 | 5 verbose cwd /EnvirsProject/miox-cli 12 | 6 error Darwin 15.6.0 13 | 7 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "git" 14 | 8 error node v6.2.2 15 | 9 error npm v3.10.6 16 | 10 error missing script: git 17 | 11 error If you need help, you may report this error at: 18 | 11 error 19 | 12 verbose exit [ 1, true ] 20 | -------------------------------------------------------------------------------- /template/Miox@plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "miox-router", 3 | "version": "0.0.3", 4 | "description": "miox router", 5 | "main": "src/index.js", 6 | "author": "沈赟杰", 7 | "license": "MIT", 8 | "scripts": { 9 | "dev": "NODE_ENV=development node_modules/.bin/webpack-dev-server --config webpack.config.js --host 0.0.0.0 --port 8090 --progress --colors --inline --hot --display-error-details --content-base src/", 10 | "build": "rimraf ./build/ && NODE_ENV=production webpack --config webpack.config.js -p" 11 | }, 12 | "devDependencies": { 13 | "autoprefixer": "^6.3.7", 14 | "babel-core": "^6.11.4", 15 | "babel-loader": "^6.2.4", 16 | "babel-plugin-add-module-exports": "^0.2.1", 17 | "babel-polyfill": "^6.9.1", 18 | "babel-preset-es2015": "^6.9.0", 19 | "babel-preset-stage-0": "^6.5.0", 20 | "css-loader": "^0.25.0", 21 | "extract-text-webpack-plugin": "^1.0.1", 22 | "file-loader": "^0.9.0", 23 | "html-webpack-plugin": "^2.22.0", 24 | "node-sass": "^3.8.0", 25 | "postcss-loader": "^0.9.1", 26 | "rimraf": "^2.5.4", 27 | "sass-loader": "^4.0.0", 28 | "style-loader": "^0.13.1", 29 | "webpack": "^1.13.1", 30 | "webpack-dev-server": "^1.14.1" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /template/Miox@plugin/compile/development.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by evio on 16/7/20. 3 | */ 4 | 'use strict'; 5 | 6 | const path = require('path'); 7 | const AutoPrefixer = require('autoprefixer'); 8 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 9 | const result = {}; 10 | 11 | /** 12 | * 配置启动文件地址 13 | * @type {*|Promise.<*>} 14 | */ 15 | result.entry = ['babel-polyfill', path.resolve(__dirname, '../src/test')]; 16 | 17 | /** 18 | * 配置输出文件地址和输出文件模式 19 | * @type {{path: (*|Promise.<*>), filename: string, libraryTarget: string}} 20 | */ 21 | result.output = { 22 | path: './build', 23 | filename: 'bundle.js', 24 | libraryTarget: 'var' 25 | }; 26 | 27 | result.module = {}; 28 | 29 | /** 30 | * 配置loaders 31 | * @type {*[]} 32 | */ 33 | result.module.loaders = [ 34 | { test: /\.js$/, loader: "babel" }, 35 | { test: /\.css$/, loader: "style!css!postcss" }, 36 | { test: /\.scss$/, loader: "style!css!postcss!sass" } 37 | ]; 38 | 39 | /** 40 | * autoprefix 41 | * @returns {*[]} 42 | */ 43 | result.postcss = () => { 44 | return [ AutoPrefixer({browsers: ['last 20 versions']}) ]; 45 | }; 46 | 47 | /** 48 | * 配置插件 49 | * @type {*[]} 50 | */ 51 | result.plugins = [ 52 | new HtmlWebpackPlugin({ 53 | template: path.resolve(__dirname, '../src/index.html'), 54 | filename: './index.html' 55 | }) 56 | ]; 57 | 58 | module.exports = result; -------------------------------------------------------------------------------- /template/Miox@plugin/compile/production.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by evio on 16/7/20. 3 | */ 4 | 'use strict'; 5 | const pkg = require('../package.json'); 6 | const globalName = pkg.project.name; 7 | const libraryName = pkg.project.library; 8 | const path = require('path'); 9 | const AutoPrefixer = require('autoprefixer'); 10 | const ExtractTextPlugin = require('extract-text-webpack-plugin'); 11 | const result = {}; 12 | result.plugins = []; 13 | 14 | result.plugins.push(new ExtractTextPlugin(globalName + '.css')); 15 | /** 16 | * 配置启动文件地址 17 | * @type {*|Promise.<*>} 18 | */ 19 | result.entry = ['babel-polyfill', path.resolve(__dirname, '../src/index')]; 20 | 21 | /** 22 | * 配置输出文件地址和输出文件模式 23 | * @type {{path: (*|Promise.<*>), filename: string, libraryTarget: string}} 24 | */ 25 | result.output = { 26 | path: './build', 27 | filename: globalName + '.umd.js', 28 | library: libraryName, 29 | libraryTarget: 'umd' 30 | }; 31 | 32 | result.module = {}; 33 | 34 | /** 35 | * 配置loaders 36 | * @type {*[]} 37 | */ 38 | result.module.loaders = [ 39 | { test: /\.js$/, loader: "babel" }, 40 | { test: /\.css$/, loader: ExtractTextPlugin.extract("style", "css!postcss") }, 41 | { test: /\.scss$/, loader: ExtractTextPlugin.extract("style", "css!postcss!sass") } 42 | ]; 43 | 44 | /** 45 | * autoprefix 46 | * @returns {*[]} 47 | */ 48 | result.postcss = () => { 49 | return [ AutoPrefixer({browsers: ['last 20 versions']}) ]; 50 | }; 51 | 52 | module.exports = result; -------------------------------------------------------------------------------- /template/Miox@stable/development.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by evio on 16/7/20. 3 | */ 4 | 'use strict'; 5 | 6 | const path = require('path'); 7 | const AutoPrefixer = require('autoprefixer'); 8 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 9 | const result = {}; 10 | const pkg = require('./package.json'); 11 | 12 | /** 13 | * 配置启动文件地址 14 | * @type {*|Promise.<*>} 15 | */ 16 | result.entry = path.resolve(__dirname, './src/index'); 17 | 18 | /** 19 | * 配置输出文件地址和输出文件模式 20 | * @type {{path: (*|Promise.<*>), filename: string, libraryTarget: string}} 21 | */ 22 | result.output = { 23 | path: path.resolve(__dirname, './build'), 24 | filename: pkg.name + '.js', 25 | libraryTarget: 'var' 26 | }; 27 | 28 | result.module = {}; 29 | 30 | /** 31 | * 配置loaders 32 | * @type {*[]} 33 | */ 34 | result.module.loaders = [ 35 | { test: /\.js$/, exclude: /node_modules/, loader: "babel" }, 36 | { test: /\.css$/, loader: "style!css!postcss" }, 37 | { test: /\.scss$/, loader: "style!css!postcss!sass" }, 38 | { test: /\.(png|gif)$/, loader: "url?limit=5000&name=img/[name]-[hash].[ext]!image-webpack" }, 39 | { test: /\.json$/, loader: "json" } 40 | ]; 41 | 42 | /** 43 | * autoprefix 44 | * @returns {*[]} 45 | */ 46 | result.postcss = () => { 47 | return [ AutoPrefixer({browsers: ['last 20 versions']}) ]; 48 | }; 49 | 50 | /** 51 | * 配置插件 52 | * @type {*[]} 53 | */ 54 | result.plugins = [ 55 | new HtmlWebpackPlugin({ 56 | template: path.resolve(__dirname, './src/index.html'), 57 | filename: './index.html' 58 | }) 59 | ]; 60 | 61 | result.imageWebpackLoader = { 62 | pngquant:{ 63 | quality: "65-90", 64 | speed: 4 65 | } 66 | }; 67 | 68 | module.exports = result; -------------------------------------------------------------------------------- /template/Miox@stable/production.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by evio on 16/7/20. 3 | */ 4 | 'use strict'; 5 | 6 | const path = require('path'); 7 | const AutoPrefixer = require('autoprefixer'); 8 | const ExtractTextPlugin = require('extract-text-webpack-plugin'); 9 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 10 | const result = {}; 11 | result.plugins = []; 12 | 13 | result.plugins.push(new ExtractTextPlugin('index.[contenthash:10].css')); 14 | /** 15 | * 配置启动文件地址 16 | * @type {*|Promise.<*>} 17 | */ 18 | result.entry = path.resolve(__dirname, './src/index'); 19 | 20 | /** 21 | * 配置输出文件地址和输出文件模式 22 | * @type {{path: (*|Promise.<*>), filename: string, libraryTarget: string}} 23 | */ 24 | result.output = { 25 | path: path.resolve(__dirname, 'build'), 26 | filename: 'index.[hash:10].js', 27 | libraryTarget: 'var' 28 | }; 29 | 30 | result.module = {}; 31 | 32 | /** 33 | * 配置loaders 34 | * @type {*[]} 35 | */ 36 | result.module.loaders = [ 37 | { test: /\.js$/, exclude: /node_modules/, loader: "babel" }, 38 | { test: /\.css$/, loader: ExtractTextPlugin.extract("style", "css!postcss") }, 39 | { test: /\.scss$/, loader: ExtractTextPlugin.extract("style", "css!postcss!sass") }, 40 | { test: /\.(png|gif)$/, loader: "url?limit=1&name=img/[name]-[hash].[ext]!image-webpack" }, 41 | { test: /\.json$/, loader: "json" } 42 | ]; 43 | 44 | /** 45 | * autoprefix 46 | * @returns {*[]} 47 | */ 48 | result.postcss = () => { 49 | return [ AutoPrefixer({browsers: ['last 20 versions']}) ]; 50 | }; 51 | 52 | result.plugins.push(new HtmlWebpackPlugin({ 53 | template: path.resolve(__dirname, './src/index.html'), 54 | filename: './index.html' 55 | })); 56 | 57 | result.imageWebpackLoader = { 58 | pngquant:{ 59 | quality: "65-90", 60 | speed: 4 61 | } 62 | }; 63 | 64 | module.exports = result; 65 | -------------------------------------------------------------------------------- /template/miox@stable/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 51信用卡 人品卡项目 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /lib/create.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | var fs = require('fs-extra'); 4 | var path = require('path'); 5 | var inquirer = require('inquirer'); 6 | var chalk = require('chalk'); 7 | var spawn = require('child_process').spawnSync; 8 | var util = require('./util'); 9 | 10 | var create = module.exports = function() { 11 | var questions = [ 12 | { 13 | type: 'input', 14 | name: 'name', 15 | message: 'Project name', 16 | validate: function (val) { 17 | return !val 18 | ? 'Project name cannot be empty' 19 | : (fs.existsSync('./' + val) ? 'Project already exist' : true); 20 | } 21 | }, 22 | { 23 | type: 'list', 24 | name: 'type', 25 | message: 'Which kind of project do you choose?', 26 | choices: [ 27 | "Miox@stable", 28 | "Miox@plugin" 29 | ] 30 | }, 31 | { 32 | type: 'list', 33 | name: 'usage', 34 | message: 'Which web library do you choose?', 35 | choices: [ 36 | "npm - https://npmjs.com", 37 | "nbm - http://web.51.nb" 38 | ] 39 | } 40 | ]; 41 | 42 | inquirer 43 | .prompt(questions) 44 | .then(function (answers) { 45 | create.makeProject(answers); 46 | }) 47 | }; 48 | 49 | create.makeProject = function(options) { 50 | var target = path.resolve(process.cwd(), options.name); 51 | var type = options.type; 52 | 53 | create 54 | .copyProject(target, type) 55 | .then(function() { 56 | return create.makePackage(target, options.name, type); 57 | }) 58 | .catch(function(err) { 59 | util.exit(err); 60 | }) 61 | .then(function() { 62 | return create.install(target, options.usage); 63 | }) 64 | .then(function () { 65 | console.log(''); 66 | console.log(chalk.green('Successfully create project %s', options.name)); 67 | console.log('Commands:'); 68 | console.log('------------------'); 69 | console.log('% cd '+ options.name); 70 | console.log('------------------'); 71 | console.log(' nbm run dev: 开启调试服务'); 72 | console.log(' nbm run git: 自动提交代码'); 73 | console.log(' nbm run build: 启动项目编译'); 74 | }); 75 | }; 76 | 77 | create.copyProject = function(target, type) { 78 | return new Promise(function(resolve, reject){ 79 | var source = path.resolve(__dirname, '../template', type); 80 | if ( !fs.existsSync(source) ){ 81 | return reject(new Error('can not find source dir')); 82 | } 83 | fs.copy(source, target, function(err){ 84 | if (err) { 85 | reject(err) 86 | } else { 87 | resolve(); 88 | } 89 | }); 90 | }); 91 | }; 92 | 93 | create.makePackage = function(target, name, type) { 94 | var packet = require('../template/' + type + '/package.json'); 95 | packet.name = name; 96 | packet.description = name; 97 | packet.project = { 98 | "name": name.replace(/\-/g, '.'), 99 | "library": change(name) 100 | }; 101 | 102 | return new Promise(function(resolve, reject){ 103 | fs.writeFile( 104 | path.resolve(target, 'package.json'), 105 | JSON.stringify(packet, null, 2), 106 | function(err) { 107 | if (err) { 108 | reject(err) 109 | } else { 110 | resolve(); 111 | } 112 | } 113 | ) 114 | }); 115 | }; 116 | 117 | create.install = function(target, usage) { 118 | return new Promise(function(resolve){ 119 | spawn(usage.split(' - ')[0], ['install'], { cwd: target, stdio: 'inherit'}); 120 | resolve(); 121 | }); 122 | }; 123 | 124 | function change(s1){ 125 | return s1.replace(/\-(\w)/g, function(all, letter){ 126 | return letter.toUpperCase(); 127 | }); 128 | } --------------------------------------------------------------------------------