@gopowerteam/request-generate 0.2.0 → 0.2.1

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/bin/download.mts CHANGED
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
- import path from 'node:path'
4
3
  import fs from 'node:fs'
4
+ import path from 'node:path'
5
+ import process from 'node:process'
6
+ import { fileURLToPath } from 'node:url'
5
7
  import { program } from 'commander'
6
- import { fileURLToPath } from 'node:url';
7
8
 
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
9
+ const __filename = fileURLToPath(import.meta.url)
10
+ const __dirname = path.dirname(__filename)
10
11
  const RequestGenerate = await import(`file://${path.resolve(
11
12
  __dirname,
12
13
  '..',
13
14
  'dist',
14
- 'index.mjs'
15
+ 'index.mjs',
15
16
  )}`)
16
17
 
17
18
  const params = program
@@ -24,30 +25,30 @@ const params = program
24
25
  const configFilePaths = [
25
26
  'request.config.ts',
26
27
  'request-generate.config.cjs',
27
- 'request-generate.config.js'
28
+ 'request-generate.config.js',
28
29
  ]
29
30
 
30
31
  /**
31
32
  * 加载配置文件
32
33
  * @param {*} filePath
33
- * @returns
34
34
  */
35
35
  async function loadConfigFile(filePath) {
36
36
  if (filePath) {
37
37
  configFilePaths.unshift(filePath)
38
38
  }
39
39
 
40
- const configFilePath = configFilePaths.find((file) =>
41
- fs.existsSync(path.resolve(process.cwd(), file))
40
+ const configFilePath = configFilePaths.find(file =>
41
+ fs.existsSync(path.resolve(process.cwd(), file)),
42
42
  )
43
43
 
44
- if(!configFilePath){
45
- throw new Error("Not Found Config File.")
44
+ if (!configFilePath) {
45
+ throw new Error('Not Found Config File.')
46
46
  }
47
47
 
48
48
  if (configFilePath.endsWith('.js') || configFilePath.endsWith('.ts')) {
49
49
  return import(`file://${path.resolve(process.cwd(), configFilePath)}`)
50
- } else {
50
+ }
51
+ else {
51
52
  throw new Error('无法找到RequestGenerate配置文件')
52
53
  }
53
54
  }
@@ -57,6 +58,7 @@ if (RequestGenerate) {
57
58
 
58
59
  RequestGenerate.download(config)
59
60
  .then(() => {
61
+ // eslint-disable-next-line no-console
60
62
  console.log('接口文件更新完成')
61
63
  process.exit(0)
62
64
  })
package/bin/generate.mts CHANGED
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
- import path from 'node:path'
4
3
  import fs from 'node:fs'
4
+ import path from 'node:path'
5
+ import process from 'node:process'
6
+ import { fileURLToPath } from 'node:url'
5
7
  import { program } from 'commander'
6
- import { fileURLToPath } from 'node:url';
7
8
 
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
9
+ const __filename = fileURLToPath(import.meta.url)
10
+ const __dirname = path.dirname(__filename)
10
11
  const RequestGenerate = await import(`file://${path.resolve(
11
12
  __dirname,
12
13
  '..',
13
14
  'dist',
14
- 'index.mjs'
15
+ 'index.mjs',
15
16
  )}`)
16
17
 
17
18
  const params = program
@@ -24,32 +25,33 @@ const params = program
24
25
  const configFilePaths = [
25
26
  'request.config.ts',
26
27
  'request-generate.config.cjs',
27
- 'request-generate.config.js'
28
+ 'request-generate.config.js',
28
29
  ]
29
30
 
30
31
  /**
31
32
  * 加载配置文件
32
33
  * @param {*} filePath
33
- * @returns
34
34
  */
35
35
  async function loadConfigFile(filePath) {
36
36
  if (filePath) {
37
37
  configFilePaths.unshift(filePath)
38
38
  }
39
39
 
40
- const configFilePath = configFilePaths.find((file) =>
41
- fs.existsSync(path.resolve(process.cwd(), file))
40
+ const configFilePath = configFilePaths.find(file =>
41
+ fs.existsSync(path.resolve(process.cwd(), file)),
42
42
  )
43
43
 
44
- if(!configFilePath){
45
- throw new Error("Not Find Config File.")
44
+ if (!configFilePath) {
45
+ throw new Error('Not Find Config File.')
46
46
  }
47
47
 
48
48
  if (configFilePath.endsWith('js')) {
49
49
  return import(`file://${path.resolve(process.cwd(), configFilePath)}`)
50
- } else if (configFilePath.endsWith('ts')) {
50
+ }
51
+ else if (configFilePath.endsWith('ts')) {
51
52
  return import(`file://${path.resolve(process.cwd(), configFilePath)}`)
52
- } else {
53
+ }
54
+ else {
53
55
  throw new Error('无法找到RequestGenerate配置文件')
54
56
  }
55
57
  }
@@ -59,9 +61,11 @@ if (RequestGenerate) {
59
61
 
60
62
  try {
61
63
  await RequestGenerate.generate(config)
64
+ // eslint-disable-next-line no-console
62
65
  console.log('接口文件生成完成')
63
66
  process.exit(0)
64
- } catch (error) {
67
+ }
68
+ catch (error) {
65
69
  console.error(error)
66
70
  process.exit(1)
67
71
  }
package/dist/index.js CHANGED
@@ -982,11 +982,11 @@ var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
982
982
 
983
983
  var ConfigFileName = ".config.json";
984
984
  var ConfigFilePath = path2.default.resolve(".request", ConfigFileName);
985
- function updateOptionsFromLocalConfig(options) {
985
+ function updateOptionsFromLocalConfig(options, output) {
986
986
  const config = readLocalConfig();
987
987
  const toUpdateOptions = /* @__PURE__ */ new Map();
988
988
  options = options.filter((item) => {
989
- const md5 = isFindNewMd5(item.name, config);
989
+ const md5 = isNeedUpdate(item.name, config, output);
990
990
  if (md5) {
991
991
  toUpdateOptions.set(item.name, md5);
992
992
  return true;
@@ -997,15 +997,21 @@ function updateOptionsFromLocalConfig(options) {
997
997
  writeLocalConfig(toUpdateOptions, config);
998
998
  return options;
999
999
  }
1000
- function isFindNewMd5(name, config) {
1000
+ function isNeedUpdate(name, config, output) {
1001
1001
  const file = path2.default.resolve(".request", `${name}.json`);
1002
+ const outputDir = path2.default.resolve(output);
1002
1003
  if (!fs.default.existsSync(file)) {
1003
1004
  throw new Error(`\u672A\u627E\u5230\u76F8\u5E94\u7684\u914D\u7F6E\u6587\u4EF6: ${name}.json`);
1004
1005
  }
1005
1006
  const data = fs.default.readFileSync(file);
1006
1007
  const md5 = _crypto2.default.createHash("md5").update(data.toString()).digest("hex");
1008
+ if (!fs.default.existsSync(path2.default.join(outputDir, name))) {
1009
+ return md5;
1010
+ }
1007
1011
  const configItem = config.find((x) => x.name === name);
1008
- return !configItem || configItem.md5 !== md5 ? md5 : "";
1012
+ if (!configItem || configItem.md5 !== md5) {
1013
+ return md5;
1014
+ }
1009
1015
  }
1010
1016
  function readLocalConfig() {
1011
1017
  if (!fs.default.existsSync(ConfigFilePath)) {
@@ -1113,7 +1119,7 @@ var _Generate = class {
1113
1119
  _Generate.options = options;
1114
1120
  registerHandlebarTemplates();
1115
1121
  let applicationOptions = generateServiceOptions(options);
1116
- applicationOptions = updateOptionsFromLocalConfig(applicationOptions);
1122
+ applicationOptions = updateOptionsFromLocalConfig(applicationOptions, options.output);
1117
1123
  const applications = [];
1118
1124
  for (const applicationOption of applicationOptions) {
1119
1125
  const client = await _Generate.generateApplicationClient(applicationOption);
package/dist/index.mjs CHANGED
@@ -983,11 +983,11 @@ import fs3 from "node:fs";
983
983
  import path4 from "node:path";
984
984
  var ConfigFileName = ".config.json";
985
985
  var ConfigFilePath = path4.resolve(".request", ConfigFileName);
986
- function updateOptionsFromLocalConfig(options) {
986
+ function updateOptionsFromLocalConfig(options, output) {
987
987
  const config = readLocalConfig();
988
988
  const toUpdateOptions = /* @__PURE__ */ new Map();
989
989
  options = options.filter((item) => {
990
- const md5 = isFindNewMd5(item.name, config);
990
+ const md5 = isNeedUpdate(item.name, config, output);
991
991
  if (md5) {
992
992
  toUpdateOptions.set(item.name, md5);
993
993
  return true;
@@ -998,15 +998,21 @@ function updateOptionsFromLocalConfig(options) {
998
998
  writeLocalConfig(toUpdateOptions, config);
999
999
  return options;
1000
1000
  }
1001
- function isFindNewMd5(name, config) {
1001
+ function isNeedUpdate(name, config, output) {
1002
1002
  const file = path4.resolve(".request", `${name}.json`);
1003
+ const outputDir = path4.resolve(output);
1003
1004
  if (!fs3.existsSync(file)) {
1004
1005
  throw new Error(`\u672A\u627E\u5230\u76F8\u5E94\u7684\u914D\u7F6E\u6587\u4EF6: ${name}.json`);
1005
1006
  }
1006
1007
  const data = fs3.readFileSync(file);
1007
1008
  const md5 = crypto.createHash("md5").update(data.toString()).digest("hex");
1009
+ if (!fs3.existsSync(path4.join(outputDir, name))) {
1010
+ return md5;
1011
+ }
1008
1012
  const configItem = config.find((x) => x.name === name);
1009
- return !configItem || configItem.md5 !== md5 ? md5 : "";
1013
+ if (!configItem || configItem.md5 !== md5) {
1014
+ return md5;
1015
+ }
1010
1016
  }
1011
1017
  function readLocalConfig() {
1012
1018
  if (!fs3.existsSync(ConfigFilePath)) {
@@ -1114,7 +1120,7 @@ var _Generate = class {
1114
1120
  _Generate.options = options;
1115
1121
  registerHandlebarTemplates();
1116
1122
  let applicationOptions = generateServiceOptions(options);
1117
- applicationOptions = updateOptionsFromLocalConfig(applicationOptions);
1123
+ applicationOptions = updateOptionsFromLocalConfig(applicationOptions, options.output);
1118
1124
  const applications = [];
1119
1125
  for (const applicationOption of applicationOptions) {
1120
1126
  const client = await _Generate.generateApplicationClient(applicationOption);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gopowerteam/request-generate",
3
3
  "type": "commonjs",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "private": false,
6
6
  "keywords": [
7
7
  "gopowerteam",