Commit 6a274c96 by ioclubs

获取远程js文件并运行,有前提环境检查和项目名和不同的项目git地址获取

  必须分成前端/后端/固件/ios/android 这几个大类
  缺少配置文件替换
parent 3fe93174
node_modules
.idea
/test
'use strict'
const execSync = require('child_process').execSync
const prompt = require('prompt-sync')()
const config = require('./config.json')
const chalk = require('chalk')
const fs = require('fs')
module.exports = async () => {
// 以下不用出现
// const execSync = require('child_process').execSync;
// const prompt = require('prompt-sync')();
// const chalk = require('chalk');
const config = {
"app": {
"url": "http://company.u-gen.net:10080/twb/ugen-cloud-app.git",
"branch": "master"
}
};
(async () => {
let version = process.version
if(version.substring(0,5) !== 'v8.11'){
console.log(chalk.red(`\n × Node version require 8.11.x, now ${version}`))
......@@ -22,27 +27,17 @@ module.exports = async () => {
}
let gitUrl, branch;
console.log(config.cloud);
if (!config.cloud[tplName]) {
if (!config[tplName]) {
console.log(chalk.red('\n × Template does not support!'))
return
}
gitUrl = config.cloud[tplName].url
branch = config.cloud[tplName].branch
gitUrl = config[tplName].url
branch = config[tplName].branch
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}`);
await execSync(`sh cloud-init.sh ${gitUrl} ${projectName}`);
await execSync(`git clone --depth=1 -b master ${gitUrl} ${projectName}`);
console.log(chalk.green('\n √ Generation completed!'));
console.log("bye bye");
}
})()
......@@ -5,18 +5,30 @@
process.env.NODE_PATH = __dirname + '/../node_modules/'
const program = require('commander')
const vm = require('vm')
const request = require('sync-request')
global.execSync = require('child_process').execSync
global.prompt = require('prompt-sync')()
// global.config = require('./config.json')
global.chalk = require('chalk')
global.fs = require('fs')
program
.version(require('./package').version)
program
.usage('<command>')
.usage('cloud')
program
.command('cloud')
.description('Generate a new cloud project')
.alias('i')
.action(async() => {
await require('./cloud.js')()
let res = await request('GET', 'http://localhost:8000/cloud.js');
const script = new vm.Script(res.body);
script.runInThisContext();
// await require('./cloud.js')()
})
program.parse(process.argv)
{
"name": "ugen-tool",
"version": "1.0.0",
"name": "@ugen/tool",
"version": "1.0.2",
"description": "ugen tool",
"private": false,
"main": "index.js",
......@@ -12,6 +12,7 @@
"dependencies": {
"chalk": "^2.4.2",
"commander": "^2.20.0",
"prompt-sync": "^4.2.0"
"prompt-sync": "^4.2.0",
"sync-request": "^6.1.0"
}
}
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