tsrpc-cli
Advanced tools
Comparing version 0.4.1 to 0.4.2
44
index.js
@@ -131,3 +131,3 @@ #!/usr/bin/env node | ||
return __awaiter(this, void 0, void 0, function () { | ||
var originalCwd, exp, fileList, oldProtoPath, oldProto, services, typeProto, _i, fileList_1, filepath, match, typePath, src, compileResult, mod, conf, req, res, msg, encodeIds, _loop_1, _a, encodeIds_1, item, proto, imports_1, apis, msgs, usedNames_1, getAsName_1, addImport, _b, services_1, svc, match, lastName, importPath, op, op, importStr, reqStr, resStr, msgStr, fileContent; | ||
var oldProtoPath, oldProto, content, match, originalCwd, exp, fileList, services, typeProto, _i, fileList_1, filepath, match, typePath, src, compileResult, mod, conf, req, res, msg, encodeIds, _loop_1, _a, encodeIds_1, item, proto, imports_1, apis, msgs, usedNames_1, getAsName_1, addImport, _b, services_1, svc, match, lastName, importPath, op, op, importStr, reqStr, resStr, msgStr, fileContent; | ||
return __generator(this, function (_c) { | ||
@@ -146,18 +146,40 @@ switch (_c.label) { | ||
} | ||
originalCwd = process.cwd(); | ||
process.chdir(input); | ||
exp = /^(.*\/)?(Ptl|Msg)([^\.\/\\]+)\.ts$/; | ||
fileList = glob.sync('**/*.ts').filter(function (v) { return exp.test(v); }); | ||
oldProtoPath = compatible || output; | ||
if (!newMode && oldProtoPath) { | ||
try { | ||
oldProto = loadServiceProto(oldProtoPath); | ||
if (!oldProto && compatible) { | ||
throw new Error(formatStr(i18n_1.i18n.fileOpenError, { file: path.resolve(oldProtoPath) })); | ||
// Parse TS | ||
if (oldProtoPath.endsWith('.ts')) { | ||
content = fs.existsSync(oldProtoPath) && fs.readFileSync(oldProtoPath, 'utf-8'); | ||
if (content) { | ||
match = content.match(/[\s\S]*:\s*ServiceProto<ServiceType>\s*=\s*(\{[\s\S]+\});?\s*/); | ||
if (match) { | ||
try { | ||
oldProto = JSON.parse(match[1]); | ||
} | ||
catch (e) { | ||
throw error(i18n_1.i18n.compatibleError, { innerError: e.message }); | ||
} | ||
} | ||
else { | ||
console.error("Not invalid proto ts file: " + oldProtoPath); | ||
throw error(i18n_1.i18n.compatibleError); | ||
} | ||
} | ||
} | ||
catch (e) { | ||
throw error(i18n_1.i18n.compatibleError, { innerError: e.message }); | ||
// Parse JSON | ||
else { | ||
try { | ||
oldProto = loadServiceProto(oldProtoPath); | ||
if (!oldProto && compatible) { | ||
throw new Error(formatStr(i18n_1.i18n.fileOpenError, { file: path.resolve(oldProtoPath) })); | ||
} | ||
} | ||
catch (e) { | ||
throw error(i18n_1.i18n.compatibleError, { innerError: e.message }); | ||
} | ||
} | ||
} | ||
originalCwd = process.cwd(); | ||
process.chdir(input); | ||
exp = /^(.*\/)?(Ptl|Msg)([^\.\/\\]+)\.ts$/; | ||
fileList = glob.sync('**/*.ts').filter(function (v) { return exp.test(v); }); | ||
services = []; | ||
@@ -164,0 +186,0 @@ return [4 /*yield*/, new tsbuffer_proto_generator_1.TSBufferProtoGenerator({ verbose: verbose }).generate(fileList, { |
{ | ||
"name": "tsrpc-cli", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "TSRPC CLI Tools", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
53092
715