@lark-apaas/devtool-kits 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1147,36 +1147,39 @@ async function parseAndGenerateNestResourceTemplate(options) {
1147
1147
  tsConfigFilePath: options.tsConfigFilePath
1148
1148
  });
1149
1149
  const tables = parser.parseSchemaFile(options.schemaFilePath);
1150
- for (const table of tables) {
1151
- console.info(`\u751F\u6210 Nest.js ${table.variableName} \u6A21\u5757`);
1152
- const routePath = toKebabCase(table.variableName);
1153
- const moduleDir = join(options.moduleOutputDir, routePath);
1154
- if (existsSync(moduleDir)) {
1155
- console.info(`Nest.js \u6A21\u5757 ${routePath} \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u751F\u6210\u4EE3\u7801`);
1156
- continue;
1157
- }
1158
- const dto = generateDTO(table);
1159
- const controller = generateController(table);
1160
- const service = generateService(table);
1161
- const moduleFilePath = join(moduleDir, `${routePath}.module.ts`);
1162
- const module = generateModule(table);
1163
- try {
1164
- await mkdir(moduleDir, {
1165
- recursive: true
1166
- });
1167
- await mkdir(join(moduleDir, "dtos"), {
1168
- recursive: true
1169
- });
1170
- await writeFile(join(moduleDir, "dtos", `${routePath}.dto.ts`), dto);
1171
- await writeFile(join(moduleDir, `${routePath}.controller.ts`), controller);
1172
- await writeFile(join(moduleDir, `${routePath}.service.ts`), service);
1173
- await writeFile(moduleFilePath, module);
1174
- } catch (err) {
1175
- console.error(`\u751F\u6210 Nest.js ${routePath} \u6A21\u5757\u5931\u8D25: ${err.message}`);
1176
- await rm(moduleDir, {
1177
- recursive: true
1178
- });
1179
- }
1150
+ if (tables.length === 0) {
1151
+ console.warn("\u672A\u89E3\u6790\u5230\u4EFB\u4F55\u6570\u636E\u5E93\u8868\uFF0C\u65E0\u9700\u751F\u6210 Nest.js \u6A21\u5757\u6A21\u677F");
1152
+ return;
1153
+ }
1154
+ const table = tables[0];
1155
+ console.info(`\u751F\u6210 Nest.js ${table.variableName} \u6A21\u5757`);
1156
+ const routePath = toKebabCase(table.variableName);
1157
+ const moduleDir = join(options.moduleOutputDir, routePath);
1158
+ if (existsSync(moduleDir)) {
1159
+ console.info(`Nest.js \u6A21\u5757 ${routePath} \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7\u751F\u6210\u4EE3\u7801`);
1160
+ return;
1161
+ }
1162
+ const dto = generateDTO(table);
1163
+ const controller = generateController(table);
1164
+ const service = generateService(table);
1165
+ const moduleFilePath = join(moduleDir, `${routePath}.module.ts`);
1166
+ const module = generateModule(table);
1167
+ try {
1168
+ await mkdir(moduleDir, {
1169
+ recursive: true
1170
+ });
1171
+ await mkdir(join(moduleDir, "dtos"), {
1172
+ recursive: true
1173
+ });
1174
+ await writeFile(join(moduleDir, "dtos", `${routePath}.dto.ts`), dto);
1175
+ await writeFile(join(moduleDir, `${routePath}.controller.ts`), controller);
1176
+ await writeFile(join(moduleDir, `${routePath}.service.ts`), service);
1177
+ await writeFile(moduleFilePath, module);
1178
+ } catch (err) {
1179
+ console.error(`\u751F\u6210 Nest.js ${routePath} \u6A21\u5757\u5931\u8D25: ${err.message}`);
1180
+ await rm(moduleDir, {
1181
+ recursive: true
1182
+ });
1180
1183
  }
1181
1184
  }
1182
1185
  __name(parseAndGenerateNestResourceTemplate, "parseAndGenerateNestResourceTemplate");
@@ -1356,17 +1359,10 @@ function checkForErrors(logs) {
1356
1359
  return false;
1357
1360
  }
1358
1361
  __name(checkForErrors, "checkForErrors");
1359
- function injectErrorData(template, errorLogs, clientBasePath) {
1360
- let logsText = "";
1361
- if (errorLogs.length > 0) {
1362
- logsText = errorLogs.join("\n");
1363
- } else {
1364
- logsText = "\u672A\u627E\u5230\u76F8\u5173\u9519\u8BEF\u65E5\u5FD7";
1365
- }
1366
- return template.replace("{{.errorData.message}}", `\u670D\u52A1\u542F\u52A8\u5F02\u5E38\uFF0C\u8BF7\u6839\u636E\u65E5\u5FD7\u4FEE\u590D\u76F8\u5173\u95EE\u9898
1367
- ${JSON.stringify(logsText)}`).replace("{{.clientBasePath}}", clientBasePath);
1362
+ function injectTemplateData(template, clientBasePath) {
1363
+ return template.replace("{{.clientBasePath}}", clientBasePath);
1368
1364
  }
1369
- __name(injectErrorData, "injectErrorData");
1365
+ __name(injectTemplateData, "injectTemplateData");
1370
1366
  function handleDevProxyError(err, req, res, options) {
1371
1367
  const { logDir = path3.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target = `http://localhost:${process.env.SERVER_PORT || 3e3}`, clientBasePath = process.env.CLIENT_BASE_PATH || "/" } = options || {};
1372
1368
  const clientBasePathWithoutSlash = normalizeBasePath(clientBasePath);
@@ -1378,7 +1374,7 @@ function handleDevProxyError(err, req, res, options) {
1378
1374
  (async () => {
1379
1375
  try {
1380
1376
  const isConnError = isConnectionError(err);
1381
- const { logs: errorLogs, hasCompileError } = await readRecentErrorLogs(logDir, maxErrorLogs, logFileName);
1377
+ const { hasCompileError } = await readRecentErrorLogs(logDir, maxErrorLogs, logFileName);
1382
1378
  if (isConnError && !hasCompileError) {
1383
1379
  console.log("[Proxy Error]: Connection error without compile errors, possibly server restarting...");
1384
1380
  try {
@@ -1402,7 +1398,7 @@ function handleDevProxyError(err, req, res, options) {
1402
1398
  console.log("[Proxy Error]: Compile error or non-connection error, showing error page");
1403
1399
  }
1404
1400
  const template = getErrorHtmlTemplate();
1405
- const html = injectErrorData(template, errorLogs, clientBasePathWithoutSlash);
1401
+ const html = injectTemplateData(template, clientBasePathWithoutSlash);
1406
1402
  res.writeHead(200, {
1407
1403
  "Content-Type": "text/html; charset=utf-8",
1408
1404
  "Cache-Control": "no-cache, no-store, must-revalidate",