├── .gitignore ├── LICENSE ├── README.md ├── bin ├── dingtalk ├── dingtalk-create ├── dingtalk-init ├── dingtalk-list └── dingtalk-search ├── docs └── README.md ├── index.js ├── package.json └── src ├── check-version.js ├── create-generate.js ├── env.js ├── local-path.js ├── logger.js ├── npm-install.js └── template.vue /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | .vscode 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## weex-dingtalk-cli 2 | 3 | > A simple CLI for scaffolding Dingtalk Weex Microapp projects. 4 | 5 | ## Install 6 | 7 | ```bash 8 | $ npm install -g weex-dingtalk-cli 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```bash 14 | $ dingtalk 15 | ``` 16 | 17 | ```bash 18 | $ dingtalk init 19 | ``` 20 | 21 | ```bash 22 | $ dingtalk init simple icepy 23 | ``` 24 | 25 | ```bash 26 | $ dingtalk init simple icepy --offline 27 | ``` 28 | 29 | ```bash 30 | $ dingtalk list 31 | ``` 32 | 33 | ```bash 34 | $ dingtalk search 35 | ``` 36 | 37 | ... ^_^ 🔥 Thanks for use. -------------------------------------------------------------------------------- /bin/dingtalk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const program = require('commander'); 4 | const package = require('../package.json'); 5 | 6 | program 7 | .version(package.version) 8 | .usage(' [options]') 9 | .command('init','generate a new project from a template') 10 | .command('list', 'list available official templates') 11 | .command('search', 'search the specified dingtalk for modules') 12 | .parse(process.argv) 13 | -------------------------------------------------------------------------------- /bin/dingtalk-create: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const path = require('path'); 4 | const chalk = require('chalk'); 5 | const commander = require('commander'); 6 | 7 | commander 8 | .usage(' [file-name]') 9 | 10 | process.on('exit', function () { 11 | console.log() 12 | }); 13 | 14 | commander.on('--help',function(){ 15 | console.log(' Examples:'); 16 | console.log(); 17 | console.log(chalk.gray(' # create a new vue file with an official template')); 18 | console.log(' $ dingtalk create vue src/v'); 19 | console.log(); 20 | }); 21 | 22 | function help(){ 23 | commander.parse(process.argv); 24 | if (commander.args.length < 1){ 25 | return commander.help(); 26 | } 27 | } 28 | 29 | help(); 30 | 31 | let template = commander.args[0]; 32 | let name = commander.args[1]; 33 | let to = path.resolve(name || '.'); 34 | console.log(template); 35 | console.log(name); 36 | 37 | /** 38 | * some template 39 | * 40 | * vue vue code 41 | */ 42 | 43 | -------------------------------------------------------------------------------- /bin/dingtalk-init: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const path = require('path'); 4 | const exists = require('fs').existsSync; 5 | const download = require('download-git-repo'); 6 | const chalk = require('chalk'); 7 | const commander = require('commander'); 8 | const inquirer = require('inquirer'); 9 | const ora = require('ora'); 10 | const home = require('user-home'); 11 | const rm = require('rimraf'); 12 | const co = require('co'); 13 | const checkVersion = require('../src/check-version.js'); 14 | const localPath = require('../src/local-path'); 15 | const createGenerateProject = require('../src/create-generate.js'); 16 | const logger = require('../src/logger.js'); 17 | const install = require('../src/npm-install.js'); 18 | 19 | const success = logger.success; 20 | const fail = logger.fail; 21 | const isLocalPath = localPath.isLocalPath 22 | const getTemplatePath = localPath.getTemplatePath 23 | 24 | commander 25 | .usage(' [project-name]') 26 | .option('--offline','use cached template') 27 | 28 | process.on('exit', function () { 29 | console.log() 30 | }); 31 | 32 | commander.on('--help',function(){ 33 | console.log(' Template:'); 34 | console.log(); 35 | console.log(chalk.green(' # simple, webpack-simple, webpack')); 36 | console.log(); 37 | console.log(' Examples:'); 38 | console.log(); 39 | console.log(chalk.gray(' # create a new project with an official template')); 40 | console.log(' $ dingtalk init webpack my-project'); 41 | console.log(); 42 | }); 43 | 44 | function help(){ 45 | commander.parse(process.argv); 46 | if (commander.args.length < 1){ 47 | return commander.help(); 48 | } 49 | } 50 | 51 | help(); 52 | 53 | /* 54 | * template type 55 | * 56 | * "simple" simple weex project 57 | * 58 | * "webpack-simple" No integrated vuex vue-router, only integrated Dingtalk SDK. 59 | * 60 | * "webpack" integrated Dingtalk SDK,journey,vue-router and vuex,support web. 61 | */ 62 | 63 | let template = commander.args[0]; 64 | let name = commander.args[1]; 65 | let to = path.resolve(name || '.'); 66 | let tmp = path.join(home, '.dingtalk-templates', template.replace(/\//g, '-')); 67 | let clone = commander.clone || false; 68 | let project_name = (!name || name === '.') ? path.relative('../', process.cwd()) : name; 69 | 70 | if (commander.offline) { 71 | console.log(`> Use cached template at ` + chalk.yellow(tmp)); 72 | template = tmp 73 | } 74 | 75 | function run(){ 76 | if (isLocalPath(template)){ 77 | const templatePath = getTemplatePath(template); 78 | console.log(chalk.yellow('the future support : use cached template')) 79 | if (exists(templatePath)){ 80 | collectMetaData(function(meta){ 81 | createGenerateProject(project_name,templatePath,to,meta,function(err){ 82 | if (err){ 83 | fail(err); 84 | return; 85 | } 86 | console.log(); 87 | success('Generated .' + project_name); 88 | console.log(); 89 | install(to); 90 | }); 91 | }); 92 | } else { 93 | fail('Local template "'+ templatePath +'" not found.'); 94 | } 95 | } else { 96 | success('await.... check cli version') 97 | checkVersion(function(){ 98 | // 只能使用官方模板 99 | const officialTemplate = 'dingtalk-templates/' + template; 100 | downloadGenerate(officialTemplate); 101 | }); 102 | } 103 | } 104 | 105 | function downloadGenerate(Template){ 106 | if (exists(tmp)){ 107 | // remove local template 108 | rm(tmp,function(err){ 109 | if (err){ 110 | fail('Failed to rm -rf localhost repo ' + Template + ': ' + JSON.stringify(err)); 111 | return; 112 | } 113 | downloadHandler(Template); 114 | }); 115 | } else { 116 | downloadHandler(Template); 117 | } 118 | } 119 | 120 | function downloadHandler(Template){ 121 | let spinner = ora('downloading template '); 122 | spinner.start(); 123 | download(Template, tmp, {clone: clone}, function(err){ 124 | spinner.stop(); 125 | if (err){ 126 | fail('Failed to download repo ' + Template + ': ' + err.message); 127 | return; 128 | } 129 | collectMetaData(function(meta){ 130 | createGenerateProject(project_name,tmp,to,meta,function(err){ 131 | if (err){ 132 | fail(err); 133 | return; 134 | } 135 | console.log(); 136 | success('Generated .' + project_name); 137 | console.log(); 138 | install(to); 139 | }); 140 | }); 141 | }); 142 | } 143 | 144 | function collectMetaData(cb){ 145 | co(function *(){ 146 | const poName = yield new Promise(function(resolve,reject){ 147 | inquirer.prompt({ 148 | type: 'input', 149 | message: 'enter your project name, the default name is "'+ project_name +'":', 150 | name: 'name' 151 | }).then(function (answers) { 152 | resolve(answers.name || project_name); 153 | }); 154 | }); 155 | const author = yield new Promise(function(resolve,reject){ 156 | inquirer.prompt({ 157 | type: 'input', 158 | message: 'enter author, the default author is "icepy":', 159 | name: 'author' 160 | }).then(function (answers) { 161 | resolve(answers.author || 'icepy'); 162 | }); 163 | }); 164 | const description = yield new Promise(function(resolve,reject){ 165 | inquirer.prompt({ 166 | type: 'input', 167 | message: 'enter description, the default description is "A Weex and Vue.js projec":', 168 | name: 'description' 169 | }).then(function (answers) { 170 | resolve(answers.description || 'A Weex and Vue.js projec'); 171 | }); 172 | }); 173 | typeof cb === 'function' && cb({ 174 | name: poName, 175 | author: author, 176 | description: description 177 | }); 178 | }).catch(function(err){ 179 | fail(JSON.stringify(err)); 180 | }); 181 | } 182 | 183 | if (exists(to)){ 184 | // 如果需要生成的项目已经存在 185 | // inquirer.prompt([{ 186 | // type: 'confirm', 187 | // message: 'ignore', 188 | // name: 'ok' 189 | // }]).then(function(answers){ 190 | // if (answers.ok){ 191 | // // 暂不处理 192 | // } 193 | // }); 194 | console.log(chalk.red('don\'t deal with. you must remove your current create project: ' + to)); 195 | } else { 196 | run(); 197 | } 198 | 199 | -------------------------------------------------------------------------------- /bin/dingtalk-list: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const chalk = require('chalk'); 4 | const moment = require('moment'); 5 | const axios = require('axios'); 6 | const env = require('../src/env.js'); 7 | const logger = require('../src/logger.js'); 8 | 9 | const fail = logger.fail; 10 | const success = logger.success; 11 | 12 | console.log() 13 | process.on('exit', function () { 14 | console.log() 15 | }) 16 | 17 | const dingtalk_templates = env['dingtalk_templates']; 18 | 19 | function fetchTemplates(){ 20 | const url = dingtalk_templates.url; 21 | return new Promise(function(resolve, reject){ 22 | axios({ 23 | method: 'get', 24 | url: url, 25 | headers: { 26 | 'User-Agent': 'dingtalk-cli' 27 | } 28 | }) 29 | .then(function(res){ 30 | const data = res.data; 31 | if (res.status === 200){ 32 | resolve(data); 33 | } else { 34 | reject(res); 35 | } 36 | }) 37 | .catch(function(err){ 38 | reject(err); 39 | }); 40 | }); 41 | } 42 | 43 | success('await ... getting network data'); 44 | console.log(); 45 | 46 | fetchTemplates().then(function(data){ 47 | if (Array.isArray(data)){ 48 | console.log('Available official templates:'); 49 | console.log(); 50 | data.forEach(function(repo){ 51 | console.log( 52 | ' ' + chalk.yellow('★') + 53 | ' ' + chalk.blue(repo.name) + 54 | ' - ' + repo.description 55 | ); 56 | console.log( 57 | ' ' + chalk.green('- pushed at : ') + 58 | '' + moment(repo.pushed_at).format('YYYY-MM-DD HH:mm:ss:SSS') 59 | ); 60 | console.log(); 61 | }); 62 | success('done'); 63 | } else { 64 | fail('Not Found Meta Data'); 65 | } 66 | }).catch(function(err){ 67 | fail(JSON.stringify(err)); 68 | }); 69 | -------------------------------------------------------------------------------- /bin/dingtalk-search: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const chalk = require('chalk'); 4 | const commander = require('commander'); 5 | const axios = require('axios'); 6 | const logger = require('../src/logger.js'); 7 | const env = require('../src/env.js'); 8 | 9 | const fail = logger.fail; 10 | const bad = logger.bad; 11 | const success = logger.success; 12 | 13 | commander 14 | .usage('') 15 | 16 | console.log(); 17 | process.on('exit', function () { 18 | console.log(); 19 | }) 20 | 21 | commander.on('--help',function(){ 22 | console.log(' modules:'); 23 | console.log(); 24 | console.log(chalk.green(' # weex-dingtalk, weex-dingtalk-journey')); 25 | console.log(); 26 | console.log(' alias:'); 27 | console.log(); 28 | console.log(chalk.green(' # weex-dingtalk -> [wd], weex-dingtalk-journey -> [wdj]')); 29 | // console.log(chalk.green(' # weex-dingtalk, weex-dingtalk-journey, weex-dingtalk-cli, weex-dingtalk-render')); 30 | // console.log(chalk.green(' # weex-dingtalk-extension, weex-dingtalk-learned, weex-ebook')); 31 | console.log(); 32 | console.log(' Examples:'); 33 | console.log(); 34 | console.log(chalk.gray(' # search the specified dingtalk for modules')); 35 | console.log(' $ dingtalk search weex-dingtalk'); 36 | console.log(); 37 | }); 38 | 39 | function help(){ 40 | commander.parse(process.argv); 41 | if (commander.args.length < 1){ 42 | return commander.help(); 43 | } 44 | } 45 | 46 | help(); 47 | 48 | let moduleName = commander.args[0]; 49 | let moduleNameMap = { 50 | wd: 'weex-dingtalk', 51 | wdj: 'weex-dingtalk-journey', 52 | wdc: 'weex-dingtalk-cli', 53 | wvr: 'weex-vue-render', 54 | wtk: 'weex-toolkit' 55 | } 56 | let moduleAlias = Object.keys(moduleNameMap); 57 | let moduleFullNames = moduleAlias.map(function(v){ 58 | return moduleNameMap[v]; 59 | }); 60 | if (moduleAlias.indexOf(moduleName) > -1){ 61 | moduleName = moduleNameMap[moduleName]; 62 | run(); 63 | } else { 64 | if (moduleFullNames.indexOf(moduleName) > -1){ 65 | console.log(); 66 | console.log(); 67 | run(); 68 | } else { 69 | fail('please enter the correct module name'); 70 | } 71 | } 72 | 73 | function run(){ 74 | const package = env[moduleName]; 75 | const url = package.url; 76 | const type = package.type; 77 | success('await ... getting network data'); 78 | console.log(); 79 | axios({ 80 | method: 'get', 81 | url: url 82 | }).then(function(res){ 83 | const data = res.data; 84 | if (res.status === 200){ 85 | message(data); 86 | } else { 87 | bad(JSON.stringify(res)); 88 | } 89 | }).catch(function(err){ 90 | fail(JSON.stringify(err)); 91 | }); 92 | } 93 | 94 | function message(meta){ 95 | console.log( 96 | ' ' + chalk.yellow('★') + 97 | ' ' + chalk.blue(meta.name) + 98 | ' - ' + meta.description 99 | ); 100 | console.log( 101 | ' ' + chalk.green('- latest : ') + 102 | '' + meta['dist-tags'].latest 103 | ); 104 | console.log(); 105 | success('done'); 106 | } -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/open-dingtalk/weex-dingtalk-cli/0e85dcdcf2e036e7a97d0770a019b6f056a95266/docs/README.md -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var co = require('co'); 2 | var inquirer = require('inquirer'); 3 | 4 | co(function *(){ 5 | const c = yield new Promise(function(resolve){ 6 | inquirer.prompt({ 7 | type: 'input', 8 | message: 'enter Author, the default author is icepy:', 9 | name: 'author' 10 | }).then(function (answers) { 11 | resolve(answers.author || 'icepy'); 12 | }); 13 | }); 14 | console.log(c) 15 | }) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "weex-dingtalk-cli", 3 | "version": "0.0.6", 4 | "description": "A simple CLI for scaffolding Dingtalk Weex Microapp projects.", 5 | "main": "index.js", 6 | "bin": { 7 | "dingtalk": "bin/dingtalk", 8 | "dingtalk-init": "bin/dingtalk-init", 9 | "dingtalk-list": "bin/dingtalk-list", 10 | "dingtalk-search": "bin/dingtalk-search" 11 | }, 12 | "scripts": { 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/open-dingtalk/weex-dingtalk-cli.git" 18 | }, 19 | "keywords": [], 20 | "author": "icepy", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/open-dingtalk/weex-dingtalk-cli/issues" 24 | }, 25 | "homepage": "https://github.com/open-dingtalk/weex-dingtalk-cli#readme", 26 | "dependencies": { 27 | "axios": "^0.16.1", 28 | "chalk": "^1.1.3", 29 | "co": "^4.6.0", 30 | "commander": "^2.9.0", 31 | "download-git-repo": "^1.0.1", 32 | "handlebars": "^4.0.10", 33 | "inquirer": "^3.0.6", 34 | "metalsmith": "^2.3.0", 35 | "moment": "^2.18.1", 36 | "ora": "^1.2.0", 37 | "rimraf": "^2.6.1", 38 | "semver": "^5.3.0", 39 | "shelljs": "^0.7.7", 40 | "user-home": "^2.0.0" 41 | }, 42 | "engines": { 43 | "node": ">=6.9.0" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/check-version.js: -------------------------------------------------------------------------------- 1 | const axios = require('axios'); 2 | const chalk = require('chalk'); 3 | const semver = require('semver'); 4 | const packageConfig = require('../package.json'); 5 | const env = require('./env.js'); 6 | const logger = require('./logger.js'); 7 | 8 | const warn = logger.warn; 9 | const success = logger.success; 10 | const bad = logger.bad; 11 | 12 | function check_version(cb){ 13 | const cliVersion = env['weex-dingtalk-cli']; 14 | const url = cliVersion.url; 15 | if (!semver.satisfies(process.version, packageConfig.engines.node)){ 16 | return console.log(chalk.red( 17 | 'You must upgrade node to >=' + packageConfig.engines.node + '.x to use weex-dingtalk-cli' 18 | )); 19 | } 20 | axios({ 21 | method: 'get', 22 | url: url 23 | }) 24 | .then(function(res){ 25 | const data = res.data; 26 | if (res.status === 200){ 27 | const lastVersion = data['dist-tags'].latest; 28 | const currentVersion = packageConfig.version; 29 | if (semver.lt(currentVersion, lastVersion)){ 30 | warn('A newer version of dingtalk-cli is available.') 31 | success('latest: ' + lastVersion) 32 | bad('installed: ' + currentVersion) 33 | console.log(); 34 | } else { 35 | success('is the latest'); 36 | console.log(); 37 | } 38 | typeof cb === 'function' && cb(); 39 | } 40 | }) 41 | .catch(function(error){ 42 | bad(JSON.stringify(error)); 43 | typeof cb === 'function' && cb(); 44 | }); 45 | } 46 | 47 | module.exports = check_version; 48 | -------------------------------------------------------------------------------- /src/create-generate.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const Metalsmith = require('metalsmith'); 3 | const Handlebars = require('handlebars'); 4 | 5 | function generate(name, tmpPath, toPath, meta, cb){ 6 | const metalsmith = Metalsmith(path.join(tmpPath, 'template')); 7 | const data = Object.assign(Object.assign(metalsmith.metadata(),{ 8 | destDirName: name, 9 | inPlace: toPath === process.cwd(), 10 | noEscape: true 11 | }),meta); 12 | metalsmith.use(renderTemplateFiles(data)) 13 | metalsmith.clean(false) 14 | .source('.') 15 | .destination(toPath) 16 | .build(function(err, files){ 17 | typeof cb === 'function' && cb(err); 18 | }); 19 | } 20 | 21 | function renderTemplateFiles(data){ 22 | return function(files, metalsmith, done){ 23 | const keys = Object.keys(files); 24 | keys.forEach(function(conf){ 25 | const str = files[conf].contents.toString(); 26 | if ('package.json' === conf || 'README.md' === conf){ 27 | if (/{{([^{}]+)}}/g.test(str)){ 28 | const compile = Handlebars.compile(str); 29 | const res = compile(data); 30 | files[conf].contents = new Buffer(res); 31 | } 32 | } 33 | 34 | }); 35 | done(); 36 | } 37 | } 38 | 39 | module.exports = generate; 40 | -------------------------------------------------------------------------------- /src/env.js: -------------------------------------------------------------------------------- 1 | const npm_registry = 'http://registry.npmjs.org'; 2 | 3 | const weex_toolkit_info = { 4 | url: npm_registry + '/weex-toolkit', 5 | type: 'npm' 6 | } 7 | const weex_dingtalk_info = { 8 | url: npm_registry + '/weex-dingtalk', 9 | type: 'npm' 10 | } 11 | const weex_dingtalk_cli_info = { 12 | url: npm_registry + '/weex-dingtalk-cli', 13 | type: 'npm' 14 | } 15 | const weex_dingtalk_journey_info = { 16 | url: npm_registry + '/weex-dingtalk-journey', 17 | type: 'npm' 18 | } 19 | const weex_vue_render_info = { 20 | url: npm_registry + '/weex-vue-render', 21 | type: 'npm' 22 | } 23 | 24 | const dingtalk_templates = { 25 | url: 'https://api.github.com/users/dingtalk-templates/repos', 26 | type: 'git' 27 | } 28 | 29 | module.exports = { 30 | "weex-toolkit": weex_toolkit_info, 31 | "weex-dingtalk": weex_dingtalk_info, 32 | "weex-dingtalk-cli": weex_dingtalk_cli_info, 33 | "weex-vue-render": weex_vue_render_info, 34 | "dingtalk_templates": dingtalk_templates, 35 | "weex-dingtalk-journey": weex_dingtalk_journey_info 36 | }; 37 | -------------------------------------------------------------------------------- /src/local-path.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 使用 vue-cli local-path.js的代码 3 | */ 4 | 5 | const path = require('path') 6 | 7 | module.exports = { 8 | isLocalPath: function (templatePath) { 9 | return /^[./]|(^[a-zA-Z]:)/.test(templatePath) 10 | }, 11 | getTemplatePath: function (templatePath) { 12 | return path.isAbsolute(templatePath) 13 | ? templatePath 14 | : path.normalize(path.join(process.cwd(), templatePath)) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/logger.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const util = require('util'); 3 | const format = util.format; 4 | 5 | const prefix = ' dingtalk-cli'; 6 | const sep = chalk.gray('·'); 7 | 8 | function fail(){ 9 | const msg = format.apply(format,arguments); 10 | console.error(chalk.red(prefix),sep,msg); 11 | process.exit(1); 12 | } 13 | 14 | function success(){ 15 | const msg = format.apply(format,arguments); 16 | console.log(chalk.green(prefix),sep,msg); 17 | } 18 | 19 | function warn(){ 20 | const msg = format.apply(format,arguments); 21 | console.log(chalk.yellow(prefix),sep,msg); 22 | } 23 | 24 | function bad(){ 25 | const msg = format.apply(format,arguments); 26 | console.log(chalk.red(prefix),sep,msg); 27 | } 28 | 29 | module.exports = { 30 | fail: fail, 31 | success: success, 32 | warn: warn, 33 | bad: bad 34 | }; 35 | -------------------------------------------------------------------------------- /src/npm-install.js: -------------------------------------------------------------------------------- 1 | const shell = require('shelljs'); 2 | const logger = require('./logger'); 3 | const chalk = require('chalk'); 4 | const ora = require('ora'); 5 | const fail = logger.fail; 6 | const success = logger.success; 7 | 8 | function install(toPath){ 9 | shell.cd(toPath); 10 | let spinner = ora('install node modules'); 11 | spinner.start(); 12 | let child = shell.exec('npm install',{ silent:true, async:true }); 13 | child.stdout.on('data',function(data){ 14 | spinner.stop(); 15 | console.log(chalk.white(data)); 16 | spinner.start(); 17 | }); 18 | child.on('exit',function(code){ 19 | if (code === 0){ 20 | spinner.stop(); 21 | success('done thanks'); 22 | } else { 23 | fail('Error: npm install fail'); 24 | } 25 | }); 26 | } 27 | 28 | module.exports = install; -------------------------------------------------------------------------------- /src/template.vue: -------------------------------------------------------------------------------- 1 | < 6 | 22 | 23 | --------------------------------------------------------------------------------