@grandlinex/swagger-mate 1.3.7 → 1.3.9

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.
@@ -5,6 +5,5 @@ export default class SwaggerClient {
5
5
  name?: string;
6
6
  version?: string;
7
7
  writeMeta?: boolean;
8
- module?: boolean;
9
8
  }): void;
10
9
  }
@@ -138,6 +138,7 @@ function interfaceHandler(conf) {
138
138
  }
139
139
  function buildCon(conf) {
140
140
  const template = (0, PathHelp_js_1.default)((0, PathHelp_js_1.getBaseFolder)(), '..', 'res', 'templates');
141
+ const fix = fs.readFileSync(Path.join(template, 'fix.js'), 'utf-8');
141
142
  const funcTemo = fs.readFileSync(Path.join(template, 'class', 'ApiCon.ts'), 'utf-8');
142
143
  const indexTemp = fs.readFileSync(Path.join(template, 'class', 'index.ts'), 'utf-8');
143
144
  const ifTemp = fs.readFileSync(Path.join(template, 'class', 'IApiCon.ts'), 'utf-8');
@@ -148,60 +149,87 @@ function buildCon(conf) {
148
149
  fs.writeFileSync(Path.join(baseGen, 'ApiCon.ts'), con);
149
150
  fs.writeFileSync(Path.join(baseGen, 'IApiCon.ts'), iCon);
150
151
  fs.writeFileSync(Path.join(baseGen, 'CApiCon.ts'), cCon);
152
+ fs.writeFileSync(Path.join(baseGen, '..', 'fix.js'), fix);
151
153
  }
152
- function createPackage(name, version, module) {
154
+ function createPackage(name, version) {
153
155
  const conf = {
154
156
  name: name || '@swagger/con',
155
157
  version: version || '0.0.1',
156
- main: 'dist/index.js',
157
- types: 'dist/index.d.ts',
158
- module: module ? 'dist/index.js' : undefined,
159
- type: module ? 'module' : undefined,
158
+ type: 'module',
159
+ exports: {
160
+ '.': {
161
+ import: {
162
+ types: './dist/mjs/index.d.ts',
163
+ default: './dist/mjs/index.js',
164
+ },
165
+ require: {
166
+ types: './dist/cjs/index.d.ts',
167
+ default: './dist/cjs/index.js',
168
+ },
169
+ },
170
+ },
171
+ types: 'dist/cjs/index.d.ts',
172
+ main: 'dist/cjs/index.js',
173
+ module: 'dist/mjs/index.js',
160
174
  devDependencies: {
161
175
  '@types/node': '22.15.32',
162
176
  typescript: '5.9.2',
163
177
  },
164
178
  peerDependencies: {
165
- '@grandlinex/base-con': '1.0.1',
179
+ '@grandlinex/base-con': '1.0.3',
166
180
  axios: '>=1.13.2',
167
181
  'form-data': '>=4.0.5',
168
182
  },
169
183
  scripts: {
170
- build: 'tsc',
171
- buildPack: 'tsc && npm pack',
184
+ build: 'npm run build-mjs && npm run build-cjs && npm run build-fix',
185
+ 'build-mjs': 'tsc',
186
+ 'build-cjs': 'tsc -p tsconfig-cjs.json',
187
+ 'build-fix': 'node ./fix.js',
188
+ buildPack: 'npm run build && npm pack',
172
189
  },
173
190
  };
174
191
  fs.writeFileSync(Path.join(baseR, 'package.json'), JSON.stringify(conf, null, 2));
175
- const tsConf = {
176
- compilerOptions: {
177
- jsx: 'react',
178
- baseUrl: './src',
179
- declaration: true,
180
- target: 'ES2020',
181
- module: module ? 'NodeNext' : 'commonjs',
182
- outDir: './dist',
183
- strict: true,
184
- esModuleInterop: true,
185
- experimentalDecorators: true,
186
- emitDecoratorMetadata: true,
187
- moduleResolution: module ? 'NodeNext' : undefined,
188
- skipLibCheck: true,
189
- forceConsistentCasingInFileNames: true,
190
- },
191
- exclude: ['node_modules', 'dist'],
192
- };
193
- fs.writeFileSync(Path.join(baseR, 'tsconfig.json'), JSON.stringify(tsConf, null, 2));
192
+ function tsConf(module) {
193
+ return {
194
+ compilerOptions: {
195
+ jsx: 'react',
196
+ baseUrl: './src',
197
+ declaration: true,
198
+ target: 'ES2020',
199
+ module: module ? 'NodeNext' : 'commonjs',
200
+ outDir: module ? './dist/mjs' : './dist/cjs',
201
+ strict: true,
202
+ ...(module ? { moduleResolution: 'NodeNext' } : {}),
203
+ esModuleInterop: true,
204
+ experimentalDecorators: true,
205
+ emitDecoratorMetadata: true,
206
+ skipLibCheck: true,
207
+ forceConsistentCasingInFileNames: true,
208
+ types: ['reflect-metadata', 'node'],
209
+ },
210
+ exclude: ['node_modules', 'dist'],
211
+ ...(module
212
+ ? {
213
+ 'ts-node': {
214
+ esm: true,
215
+ },
216
+ }
217
+ : {}),
218
+ };
219
+ }
220
+ fs.writeFileSync(Path.join(baseR, 'tsconfig.json'), JSON.stringify(tsConf(true), null, 2));
221
+ fs.writeFileSync(Path.join(baseR, 'tsconfig-cjs.json'), JSON.stringify(tsConf(false), null, 2));
194
222
  const ignore = ['src', 'node_modules', '*.tgz'];
195
223
  fs.writeFileSync(Path.join(baseR, '.npmignore'), ignore.join('\n'));
196
224
  }
197
225
  class SwaggerClient {
198
226
  static genAPICConnector(options) {
199
- const { name, version, writeMeta, module, conf } = options;
227
+ const { name, version, writeMeta, conf } = options;
200
228
  const template = (0, PathHelp_js_1.default)((0, PathHelp_js_1.getBaseFolder)(), '..', 'res', 'templates');
201
229
  core_1.XUtil.createFolderBulk(baseR, baseGen);
202
230
  cp(Path.join(template, 'class'), 'index.ts');
203
231
  buildCon(conf);
204
- createPackage(name, version, module);
232
+ createPackage(name, version);
205
233
  if (writeMeta || writeMeta === undefined) {
206
234
  SwaggerUtil_js_1.default.writeMeta(conf, 'JSON', baseR);
207
235
  }
@@ -5,6 +5,5 @@ export default class SwaggerClient {
5
5
  name?: string;
6
6
  version?: string;
7
7
  writeMeta?: boolean;
8
- module?: boolean;
9
8
  }): void;
10
9
  }
@@ -100,6 +100,7 @@ function interfaceHandler(conf) {
100
100
  }
101
101
  function buildCon(conf) {
102
102
  const template = PathHelp(getBaseFolder(), '..', 'res', 'templates');
103
+ const fix = fs.readFileSync(Path.join(template, 'fix.js'), 'utf-8');
103
104
  const funcTemo = fs.readFileSync(Path.join(template, 'class', 'ApiCon.ts'), 'utf-8');
104
105
  const indexTemp = fs.readFileSync(Path.join(template, 'class', 'index.ts'), 'utf-8');
105
106
  const ifTemp = fs.readFileSync(Path.join(template, 'class', 'IApiCon.ts'), 'utf-8');
@@ -110,60 +111,87 @@ function buildCon(conf) {
110
111
  fs.writeFileSync(Path.join(baseGen, 'ApiCon.ts'), con);
111
112
  fs.writeFileSync(Path.join(baseGen, 'IApiCon.ts'), iCon);
112
113
  fs.writeFileSync(Path.join(baseGen, 'CApiCon.ts'), cCon);
114
+ fs.writeFileSync(Path.join(baseGen, '..', 'fix.js'), fix);
113
115
  }
114
- function createPackage(name, version, module) {
116
+ function createPackage(name, version) {
115
117
  const conf = {
116
118
  name: name || '@swagger/con',
117
119
  version: version || '0.0.1',
118
- main: 'dist/index.js',
119
- types: 'dist/index.d.ts',
120
- module: module ? 'dist/index.js' : undefined,
121
- type: module ? 'module' : undefined,
120
+ type: 'module',
121
+ exports: {
122
+ '.': {
123
+ import: {
124
+ types: './dist/mjs/index.d.ts',
125
+ default: './dist/mjs/index.js',
126
+ },
127
+ require: {
128
+ types: './dist/cjs/index.d.ts',
129
+ default: './dist/cjs/index.js',
130
+ },
131
+ },
132
+ },
133
+ types: 'dist/cjs/index.d.ts',
134
+ main: 'dist/cjs/index.js',
135
+ module: 'dist/mjs/index.js',
122
136
  devDependencies: {
123
137
  '@types/node': '22.15.32',
124
138
  typescript: '5.9.2',
125
139
  },
126
140
  peerDependencies: {
127
- '@grandlinex/base-con': '1.0.1',
141
+ '@grandlinex/base-con': '1.0.3',
128
142
  axios: '>=1.13.2',
129
143
  'form-data': '>=4.0.5',
130
144
  },
131
145
  scripts: {
132
- build: 'tsc',
133
- buildPack: 'tsc && npm pack',
146
+ build: 'npm run build-mjs && npm run build-cjs && npm run build-fix',
147
+ 'build-mjs': 'tsc',
148
+ 'build-cjs': 'tsc -p tsconfig-cjs.json',
149
+ 'build-fix': 'node ./fix.js',
150
+ buildPack: 'npm run build && npm pack',
134
151
  },
135
152
  };
136
153
  fs.writeFileSync(Path.join(baseR, 'package.json'), JSON.stringify(conf, null, 2));
137
- const tsConf = {
138
- compilerOptions: {
139
- jsx: 'react',
140
- baseUrl: './src',
141
- declaration: true,
142
- target: 'ES2020',
143
- module: module ? 'NodeNext' : 'commonjs',
144
- outDir: './dist',
145
- strict: true,
146
- esModuleInterop: true,
147
- experimentalDecorators: true,
148
- emitDecoratorMetadata: true,
149
- moduleResolution: module ? 'NodeNext' : undefined,
150
- skipLibCheck: true,
151
- forceConsistentCasingInFileNames: true,
152
- },
153
- exclude: ['node_modules', 'dist'],
154
- };
155
- fs.writeFileSync(Path.join(baseR, 'tsconfig.json'), JSON.stringify(tsConf, null, 2));
154
+ function tsConf(module) {
155
+ return {
156
+ compilerOptions: {
157
+ jsx: 'react',
158
+ baseUrl: './src',
159
+ declaration: true,
160
+ target: 'ES2020',
161
+ module: module ? 'NodeNext' : 'commonjs',
162
+ outDir: module ? './dist/mjs' : './dist/cjs',
163
+ strict: true,
164
+ ...(module ? { moduleResolution: 'NodeNext' } : {}),
165
+ esModuleInterop: true,
166
+ experimentalDecorators: true,
167
+ emitDecoratorMetadata: true,
168
+ skipLibCheck: true,
169
+ forceConsistentCasingInFileNames: true,
170
+ types: ['reflect-metadata', 'node'],
171
+ },
172
+ exclude: ['node_modules', 'dist'],
173
+ ...(module
174
+ ? {
175
+ 'ts-node': {
176
+ esm: true,
177
+ },
178
+ }
179
+ : {}),
180
+ };
181
+ }
182
+ fs.writeFileSync(Path.join(baseR, 'tsconfig.json'), JSON.stringify(tsConf(true), null, 2));
183
+ fs.writeFileSync(Path.join(baseR, 'tsconfig-cjs.json'), JSON.stringify(tsConf(false), null, 2));
156
184
  const ignore = ['src', 'node_modules', '*.tgz'];
157
185
  fs.writeFileSync(Path.join(baseR, '.npmignore'), ignore.join('\n'));
158
186
  }
159
187
  export default class SwaggerClient {
160
188
  static genAPICConnector(options) {
161
- const { name, version, writeMeta, module, conf } = options;
189
+ const { name, version, writeMeta, conf } = options;
162
190
  const template = PathHelp(getBaseFolder(), '..', 'res', 'templates');
163
191
  XUtil.createFolderBulk(baseR, baseGen);
164
192
  cp(Path.join(template, 'class'), 'index.ts');
165
193
  buildCon(conf);
166
- createPackage(name, version, module);
194
+ createPackage(name, version);
167
195
  if (writeMeta || writeMeta === undefined) {
168
196
  SwaggerUtil.writeMeta(conf, 'JSON', baseR);
169
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grandlinex/swagger-mate",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -28,7 +28,7 @@
28
28
  "start-dev": "cross-env dev=true ts-node src/run.ts",
29
29
  "run-dev": "cross-env dev=true node --no-warnings=ExperimentalWarning --loader ts-node/esm src/tests/run.ts",
30
30
  "lint": "eslint src",
31
- "test": "cross-env dev=true jest --runInBand ",
31
+ "test": "cross-env dev=true jest --runInBand",
32
32
  "test-coverage": "cross-env dev=true jest --runInBand --ci --collectCoverage --coverageDirectory=\"./coverage\" --reporters=default --reporters=jest-junit",
33
33
  "makeDocs": "typedoc"
34
34
  },
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@grandlinex/core": "1.3.1",
41
- "@grandlinex/base-con": "1.0.1",
41
+ "@grandlinex/base-con": "1.0.3",
42
42
  "js-yaml": "4.1.1",
43
43
  "reflect-metadata": "0.2.2"
44
44
  },
@@ -0,0 +1,10 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ const __dirname = process.cwd();
4
+ fs.writeFileSync(path.join(__dirname,'dist','cjs','package.json'),`{
5
+ "type": "commonjs"
6
+ }`);
7
+
8
+ fs.writeFileSync(path.join(__dirname,'dist','mjs','package.json'),`{
9
+ "type": "module"
10
+ }`);