koatty_cli
Advanced tools
Comparing version 3.9.2 to 3.9.3
@@ -15,6 +15,8 @@ { | ||
"args": [ | ||
"controller", | ||
"-t", | ||
"grpc", | ||
"hello", | ||
"service", | ||
"test", | ||
// "controller", | ||
// "-t", | ||
// "grpc", | ||
// "hello", | ||
// "new", | ||
@@ -21,0 +23,0 @@ // "-t", |
@@ -5,2 +5,9 @@ # Changelog | ||
### [3.9.3](https://github.com/koatty/koatty_cli/compare/v3.9.2...v3.9.3) (2023-09-11) | ||
### Bug Fixes | ||
* 支持service接口 ([086afe6](https://github.com/koatty/koatty_cli/commit/086afe639a1d0fb2374b41396b856c1b0d32268e)) | ||
### [3.9.2](https://github.com/koatty/koatty_cli/compare/v3.7.3...v3.9.2) (2023-08-17) | ||
@@ -7,0 +14,0 @@ |
{ | ||
"name": "koatty_cli", | ||
"version": "3.9.2", | ||
"version": "3.9.3", | ||
"description": "Koatty command line tool.", | ||
@@ -32,2 +32,8 @@ "scripts": { | ||
}, | ||
"maintainers": [ | ||
{ | ||
"name": "richenlin", | ||
"email": "richenlin@gmail.com" | ||
} | ||
], | ||
"homepage": "https://github.com/koatty/koatty_cli", | ||
@@ -49,12 +55,6 @@ "devDependencies": { | ||
"ncp": "^2.0.0", | ||
"replace": "^1.2.1", | ||
"tslib": "^2.6.1", | ||
"replace": "^1.2.2", | ||
"tslib": "^2.6.2", | ||
"update-notifier": "^5.1.0" | ||
}, | ||
"maintainers": [ | ||
{ | ||
"name": "richenlin", | ||
"email": "richenlin@gmail.com" | ||
} | ||
] | ||
} | ||
} |
@@ -6,3 +6,3 @@ /* | ||
* @Date: 2020-12-22 17:51:07 | ||
* @LastEditTime: 2023-01-06 17:11:46 | ||
* @LastEditTime: 2023-09-11 11:26:33 | ||
*/ | ||
@@ -86,2 +86,5 @@ const path = require('path'); | ||
break; | ||
case 'service': | ||
args = createService(name, type, opt); | ||
break; | ||
default: | ||
@@ -147,3 +150,3 @@ args = createDefault(name, type, opt); | ||
function parseArgs(name, type) { | ||
let targetDir = path.resolve(`${getAppPath()}/${type}/`); | ||
let destPath = path.resolve(`${getAppPath()}/${type}/`); | ||
@@ -160,3 +163,3 @@ const sourcePath = path.resolve(templatePath, `${type}.template`); | ||
sourceName = subNames[1]; | ||
targetDir = `${targetDir}/${subModule}`; | ||
destPath = `${destPath}/${subModule}`; | ||
} else { | ||
@@ -167,7 +170,9 @@ sourceName = subNames[0]; | ||
let newName = `${string.toPascal(sourceName)}${string.toPascal(type)}`; | ||
let camelName = `${sourceName}${string.toPascal(type)}`; | ||
if (type == "proto") { | ||
subFix = ".proto" | ||
newName = `${string.toPascal(sourceName)}`; | ||
camelName = `${string.toPascal(sourceName)}`; | ||
} | ||
const destPath = path.resolve(targetDir, `${newName}${subFix}`); | ||
const destFile = path.resolve(destPath, `${newName}${subFix}`); | ||
@@ -178,3 +183,4 @@ // replace map | ||
'_NEW': sourceName, | ||
'_CLASS_NAME': newName | ||
'_CLASS_NAME': newName, | ||
'_CAMEL_NAME': camelName | ||
}; | ||
@@ -184,4 +190,4 @@ | ||
//if target file is exist, ignore it | ||
if (ufs.isExist(destPath) && type != "controller") { | ||
log.error('Module existed' + ' : ' + destPath); | ||
if (ufs.isExist(destFile) && type != "controller") { | ||
log.error('Module existed' + ' : ' + destFile); | ||
return; | ||
@@ -191,5 +197,5 @@ } | ||
const destMap = { | ||
[sourcePath]: destPath, | ||
[sourcePath]: destFile, | ||
}; | ||
return { sourceName, sourcePath, newName, subModule, destMap, replaceMap, destPath }; | ||
return { sourceName, sourcePath, newName, subModule, destMap, replaceMap, destPath, destFile }; | ||
} | ||
@@ -223,4 +229,4 @@ | ||
let exCtlContent = ""; | ||
if (ufs.isExist(args.destPath)) { | ||
exCtlContent = ufs.readFile(args.destPath); | ||
if (ufs.isExist(args.destFile)) { | ||
exCtlContent = ufs.readFile(args.destFile); | ||
} | ||
@@ -274,3 +280,3 @@ Object.keys(service).map(key => { | ||
args.createMap[args.destPath] = exCtlContent; | ||
args.createMap[args.destFile] = exCtlContent; | ||
@@ -442,3 +448,3 @@ const destPath = path.resolve(`${getAppPath()}/dto/`); | ||
if (!ufs.isExist(destPath)) { | ||
args.destMap[tplPath] = path.resolve(`${getAppPath()}/plugin/`, newName); | ||
args.destMap[tplPath] = destPath; | ||
} | ||
@@ -477,2 +483,36 @@ | ||
*/ | ||
function createService(name, type, opt) { | ||
const args = parseArgs(name, type); | ||
if (!args) { | ||
process.exit(0); | ||
} | ||
const sourcePath = path.resolve(templatePath, `service.template`); | ||
const serviceName = `${args.newName}.ts`; | ||
const serviceDest = path.resolve(`${args.destPath}/impl`, serviceName); | ||
if (!ufs.isExist(serviceDest)) { | ||
args.destMap[sourcePath] = serviceDest; | ||
} | ||
// args.destMap[args.sourcePath] = ""; | ||
const tplPath = path.resolve(templatePath, `service.interface.template`); | ||
const newName = `I${args.newName}.ts`; | ||
const destPath = path.resolve(args.destPath, newName); | ||
if (!ufs.isExist(destPath)) { | ||
args.destMap[tplPath] = destPath; | ||
} | ||
return args; | ||
} | ||
/** | ||
* | ||
* | ||
* @param {*} name | ||
* @param {*} type | ||
* @param {*} opt | ||
* @returns {*} | ||
*/ | ||
function createDefault(name, type, opt) { | ||
@@ -479,0 +519,0 @@ const args = parseArgs(name, type); |
46719
1033
Updatedreplace@^1.2.2
Updatedtslib@^2.6.2