Comparing version 0.0.1 to 0.0.2
@@ -7,3 +7,3 @@ 'use strict' | ||
const config = require('../templates') | ||
const util = require('../util') | ||
@@ -14,60 +14,97 @@ const chalk = require('chalk') | ||
const _ = require('lodash') | ||
module.exports = () => { | ||
co(function* () { | ||
let packagePath = process.cwd() + '/package.json'; | ||
if (fs.existsSync(packagePath)) { | ||
var config = JSON.parse(fs.readFileSync(packagePath)); | ||
if (!config.language) { | ||
console.log(chalk.red('not a uiauto plugin directory.\n')) | ||
process.exit() | ||
} else { | ||
var indexPath = '' | ||
if (['nodejs', 'node.js', 'js', 'javascript'].includes(config.language.toLowerCase())) { | ||
indexPath = process.cwd() + '/index.js'; | ||
if (!fs.existsSync(indexPath)) { | ||
console.log(chalk.red('not a uiauto plugin directory.\n')) | ||
process.exit() | ||
} | ||
} else if (['python', 'py'].includes(config.language.toLowerCase())) { | ||
indexPath = process.cwd() + '/index.py'; | ||
if (!fs.existsSync(indexPath)) { | ||
console.log(chalk.red('not a uiauto plugin directory.\n')) | ||
process.exit() | ||
} | ||
} else { | ||
console.log(chalk.red('not a uiauto plugin directory.\n')) | ||
process.exit() | ||
} | ||
// 分步接收用户输入的参数 | ||
let parentParams = [] | ||
let confirm = '' | ||
// 分步接收用户输入的参数 | ||
let tplName = yield prompt('Template name: ') | ||
let gitUrl = yield prompt('Git https link: ') | ||
let branch = yield prompt('Branch: ') | ||
// 避免重复添加 | ||
if (!config.tpl[tplName]) { | ||
config.tpl[tplName] = {} | ||
config.tpl[tplName]['url'] = gitUrl.replace(/[\u0000-\u0019]/g, '') // 过滤unicode字符 | ||
config.tpl[tplName]['branch'] = branch | ||
while (confirm == '' || confirm == 'yes') { | ||
let childParams = {} | ||
childParams.category_id = yield util.getArgument('category_id', true) | ||
childParams.category_name = yield util.getArgument('category_name', true) | ||
childParams.operation_id = yield util.getArgument('operation_id', true) | ||
childParams.operation_name = yield util.getArgument('operation_name', true) | ||
childParams.method = yield util.getArgument('method', true) | ||
childParams.type = yield util.getArgument('type (have only set =>[Start, Condition, Convention, Circulation, End])', true) | ||
childParams.input = [] | ||
childParams.output = {} | ||
childParams.output['is_allow_global_use'] = yield util.getArgument('[output] is_allow_global_use', false, true) | ||
childParams.output['description'] = yield util.getArgument('[output] description', true) | ||
childParams.output['value'] = yield util.getArgument('[output] value', true) | ||
parentParams.push(childParams) | ||
confirm = yield prompt('Do you want to continue filling in the parameters? (yes) ') | ||
} | ||
// 把模板信息写入package.json | ||
config.uiauto_config.operations = _.concat(config.uiauto_config.operations, parentParams); | ||
fs.writeFile(packagePath, JSON.stringify(config, "", "\t", 'utf-8'), 'utf-8', (err) => { | ||
if (err) { | ||
console.log(chalk.red(err)) | ||
process.exit() | ||
} else { | ||
if (['nodejs', 'node.js', 'js', 'javascript'].includes(config.language.toLowerCase())) { | ||
let defaultConfig = ""; | ||
_.each(parentParams, parentParam => { | ||
defaultConfig += "exports." + parentParam.method + " = function (params) {\n\n};\n\n" | ||
}) | ||
fs.writeFile(indexPath, defaultConfig, { flag: 'a', encoding: 'utf-8' }, (err) => { | ||
if (err) { | ||
console.log(chalk.red(err)) | ||
process.exit() | ||
} else { | ||
console.log(chalk.green('New config added!\n')) | ||
process.exit() | ||
} | ||
}) | ||
} else if (['python', 'py'].includes(config.language.toLowerCase())) { | ||
let defaultConfig = ""; | ||
_.each(parentParams, parentParam => { | ||
defaultConfig += "def " + parentParam.method + "(parmas):\n" + " " + "pass\n\n" | ||
}) | ||
fs.writeFile(indexPath, defaultConfig, { flag: 'a', encoding: 'utf-8' }, (err) => { | ||
if (err) { | ||
console.log(chalk.red(err)) | ||
process.exit() | ||
} else { | ||
console.log(chalk.green('New config added!\n')) | ||
process.exit() | ||
} | ||
}) | ||
} | ||
} | ||
}) | ||
} | ||
} else { | ||
console.log(chalk.red('Template has already existed!')) | ||
console.log(chalk.red('not a uiauto plugin directory.')) | ||
process.exit() | ||
} | ||
// 把模板信息写入templates.json | ||
fs.writeFile(__dirname + '/../templates.json', JSON.stringify(config), 'utf-8', (err) => { | ||
if (err) console.log(err) | ||
console.log(chalk.green('New template added!\n')) | ||
console.log(chalk.grey('The last template list is: \n')) | ||
console.log(config) | ||
console.log('\n') | ||
process.exit() | ||
}) | ||
}) | ||
} |
'use strict' | ||
const co = require('co') | ||
const prompt = require('co-prompt') | ||
const config = require('../templates') | ||
const co = require('co'); | ||
const prompt = require('co-prompt'); | ||
const config = require('../templates'); | ||
const chalk = require('chalk'); | ||
const fs = require('fs'); | ||
@@ -10,3 +11,3 @@ | ||
if (!pluginName || typeof pluginName !== 'string') { | ||
return console.error('need to name your plugin\n\neg: uiauto init "demo"\n'); | ||
return console.error(chalk.red('need to name your plugin\n\neg: uiauto init "demo"\n')); | ||
} | ||
@@ -33,3 +34,3 @@ | ||
let result; | ||
result = yield prompt(`${alertStr}${required ? '*' : ''}${defaultValue ? `(${defaultValue})` : ''}: `); | ||
result = yield prompt(`${alertStr}${required ? chalk.red('* ') : ''}${defaultValue ? `(${defaultValue})` : ''}: `); | ||
if (typeof defaultValue !== 'undefined') { | ||
@@ -74,7 +75,16 @@ !result && (result = defaultValue) | ||
fs.writeFile(`${pluginName}/package.json`, JSON.stringify(package_json, "", "\t", 'utf-8'), err => { | ||
// console.log(err); | ||
if (err) { | ||
console.log(chalk.red('Error writing to file!\n')) | ||
process.exit() | ||
} | ||
}); | ||
fs.writeFile(`${pluginName}/${main}`, '', err => { | ||
// console.log(err); | ||
if (err) { | ||
console.log(chalk.red('Error writing to file!\n')) | ||
process.exit() | ||
} else { | ||
console.log(chalk.green('The file has been initialized.\n')) | ||
process.exit() | ||
} | ||
}); | ||
@@ -81,0 +91,0 @@ }) |
{ | ||
"name": "uiauto-cli", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "uiauto rpa tools cli", | ||
@@ -21,4 +21,6 @@ "main": "index.js", | ||
"co-prompt": "^1.0.0", | ||
"commander": "^2.20.0" | ||
"commander": "^2.20.0", | ||
"lodash": "4.17.11", | ||
"ora": "3.4.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
12331
9
244
6
+ Addedlodash@4.17.11
+ Addedora@3.4.0
+ Addedansi-regex@4.1.1(transitive)
+ Addedcli-cursor@2.1.0(transitive)
+ Addedcli-spinners@2.9.2(transitive)
+ Addedclone@1.0.4(transitive)
+ Addeddefaults@1.0.4(transitive)
+ Addedlodash@4.17.11(transitive)
+ Addedlog-symbols@2.2.0(transitive)
+ Addedmimic-fn@1.2.0(transitive)
+ Addedonetime@2.0.1(transitive)
+ Addedora@3.4.0(transitive)
+ Addedrestore-cursor@2.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstrip-ansi@5.2.0(transitive)
+ Addedwcwidth@1.0.1(transitive)