Commit c4ebe510 by ioclubs

ugen-cloud init

app
parent 123fa7cf
{ {
"tpl": { "tpl": {
"react": { "app": {
"url": "https://github.com/Windseek/reactssr.git", "url": "http://company.u-gen.net:10080/twb/ugen-cloud-app.git",
"branch": "master" "branch": "master"
} }
} }
......
...@@ -15,8 +15,8 @@ program ...@@ -15,8 +15,8 @@ program
.command('init') .command('init')
.description('Generate a new project') .description('Generate a new project')
.alias('i') .alias('i')
.action(() => { .action(async() => {
require('./init.js')() await require('./init.js')()
}) })
program.parse(process.argv) program.parse(process.argv)
'use strict' 'use strict'
const exec = require('child_process').exec const execSync = require('child_process').execSync
const co = require('co') const prompt = require('prompt-sync')()
const prompt = require('co-prompt') const config = require('./config.json')
const config = require('./template.json')
const chalk = require('chalk') const chalk = require('chalk')
module.exports = () => { module.exports = async () => {
co(function *() { let version = process.version
// 处理用户输入 if(version.substring(0,5) !== 'v8.11'){
let tplName = yield prompt('Template name (you can input one like react, vue, angular): ') console.log(chalk.red(`\n × Node version require 8.11.x, now ${version}`))
let projectName = yield prompt('Project name: ') return
let gitUrl,branch; }
console.log(config.tpl);
if (!config.tpl[tplName]) { // 处理用户输入
console.log(chalk.red('\n × Template does not support!')) let tplName = await prompt('Template name (you can input one like app, component ...): ')
process.exit() let projectName = await prompt('Project name: ')
}
gitUrl = config.tpl[tplName].url if ( fs.existsSync(projectName) ){
branch = config.tpl[tplName].branch console.log(chalk.red(`\n × File already exist`))
return
// git命令,远程拉取项目并自定义项目名 }
let cmdStr = `git clone ${gitUrl} ${projectName} && cd ${projectName} && git checkout ${branch}`
let gitUrl, branch;
exec(cmdStr, (error, stdout, stderr) => { console.log(config.tpl);
if (error) { if (!config.tpl[tplName]) {
console.log(error) console.log(chalk.red('\n × Template does not support!'))
process.exit() return
} }
console.log(chalk.green('\n √ Generation completed!')) gitUrl = config.tpl[tplName].url
console.log(`\n cd ${projectName} && npm install \n`) branch = config.tpl[tplName].branch
process.exit()
}) console.log('\n fetch repository');
}) // git命令,远程拉取项目并自定义项目名
let cmdStr = `git clone --depth=1 -b ${branch} ${gitUrl} ${projectName}`
await execSync(cmdStr)
const registry = 'http://company.u-gen.net:7001'
console.log('\n npm install');
await execSync(`cd ${projectName} && npm install --registry=${registry}`);
console.log(chalk.green('\n √ Generation completed!'));
} }
{ {
"name": "windssr", "name": "@ioclubs/ugen-cloud",
"version": "1.0.8", "version": "1.0.0",
"description": "a tool service for react-ssr", "description": "ugen cloud",
"private": false,
"main": "index.js", "main": "index.js",
"bin": { "bin": {
"windssr": "index.js" "ugen-cloud": "index.js"
}, },
"author": "windseek", "author": "ioclubs",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"chalk": "^2.4.2", "chalk": "^2.4.2",
"co": "^4.6.0", "commander": "^2.20.0",
"co-prompt": "^1.0.0", "prompt-sync": "^4.2.0"
"commander": "^2.20.0" }
},
"scripts": {
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Windseek/react-ssr-cli.git"
},
"keywords": [
"react",
"react-ssr",
"wind-ssr",
"react-ssr-cli"
],
"bugs": {
"url": "https://github.com/Windseek/react-ssr-cli/issues"
},
"homepage": "https://github.com/Windseek/react-ssr-cli#readme"
} }
##自建私有仓库
#### 上传
npm publish
##安装
npm i -g @ioclubs/ugen-cloud --registry={私有仓库地址}
## 使用
ugen-cloud init
选择app 和 文件夹名称
下载git仓库代码以及安装node_modules
## 测试
node start.js
访问
http://localhost:3000/openapi/custom/10000/test/test
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment