Skip to content

Commit 57c3a2c

Browse files
authored
Merge pull request #788 from acacode/esm
ESM
2 parents fb60b78 + 9d04dfc commit 57c3a2c

File tree

99 files changed

+341
-1240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+341
-1240
lines changed

cli/constants.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,4 @@ const skip_command = Symbol("skip");
33

44
const reservedOptions = ["version", "help"];
55

6-
module.exports = {
7-
root_command,
8-
skip_command,
9-
reservedOptions,
10-
};
6+
export { root_command, skip_command, reservedOptions };

cli/execute.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const _ = require("lodash");
2-
const { root_command, skip_command } = require("./constants");
3-
const { parseArgs } = require("./parse-args");
4-
const didYouMean = require("didyoumean");
1+
import didYouMean from "didyoumean";
2+
import _ from "lodash";
3+
import { root_command, skip_command } from "./constants.js";
4+
import { parseArgs } from "./parse-args.js";
55

66
didYouMean.threshold = 0.5;
77

@@ -177,6 +177,4 @@ const processArgs = (commands, args) => {
177177
};
178178
};
179179

180-
module.exports = {
181-
execute,
182-
};
180+
export { execute };

cli/index.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
type CliStructOption = {
2-
flags?: string;
3-
description?: string;
42
default?: unknown;
3+
description?: string;
4+
flags?: string;
55
internal?: { name?: string; formatter?: (value: any) => any };
6+
required?: boolean;
67
};
78

89
type CliStruct = {
9-
inherited?: string | null;
10-
name?: string;
1110
alias?: string;
12-
version?: string;
11+
commands?: CliStruct[];
1312
description?: string;
13+
inherited?: string | null;
14+
name?: string;
1415
options: CliStructOption[];
15-
commands?: CliStruct[];
16+
version?: string;
1617
};
1718

1819
type ExecuteOptions = {

cli/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const _ = require("lodash");
2-
const { reservedOptions, root_command } = require("./constants");
3-
const { processOption } = require("./process-option");
4-
const { execute } = require("./execute");
5-
const { displayHelp } = require("./operations/display-help");
6-
const { displayVersion } = require("./operations/display-version");
1+
import _ from "lodash";
2+
import { reservedOptions, root_command } from "./constants.js";
3+
import { execute } from "./execute.js";
4+
import { displayHelp } from "./operations/display-help.js";
5+
import { displayVersion } from "./operations/display-version.js";
6+
import { processOption } from "./process-option.js";
77

88
const cli = (input) => {
99
const commands = {};
@@ -91,6 +91,4 @@ const cli = (input) => {
9191
return instance;
9292
};
9393

94-
module.exports = {
95-
cli,
96-
};
94+
export { cli };

cli/operations/display-help.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const _ = require("lodash");
2-
const { root_command } = require("../constants");
1+
import _ from "lodash";
2+
import { root_command } from "../constants.js";
33

44
const generateOptionsOutput = (options) =>
55
options.reduce(
@@ -174,6 +174,4 @@ ${command.description}`
174174
${outputTest}`);
175175
};
176176

177-
module.exports = {
178-
displayHelp,
179-
};
177+
export { displayHelp };

cli/operations/display-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ const displayVersion = (instance) => {
22
console.log(instance.input.version);
33
};
44

5-
module.exports = { displayVersion };
5+
export { displayVersion };

cli/parse-args.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,4 @@ const parseArgs = (args, type) => {
2121
}
2222
};
2323

24-
module.exports = {
25-
parseArgs,
26-
};
24+
export { parseArgs };

cli/process-option.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const _ = require("lodash");
1+
import _ from "lodash";
22

33
const optionFormatters = {
44
number: (str) => +str,
@@ -72,6 +72,4 @@ const processOption = (option) => {
7272
};
7373
};
7474

75-
module.exports = {
76-
processOption,
77-
};
75+
export { processOption };

index.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
#!/usr/bin/env node
22

3-
// Copyright (c) 2019-present acacode
4-
// Node module: swagger-typescript-api
5-
// This file is licensed under the MIT License.
6-
// License text available at https://opensource.org/licenses/MIT
7-
// Repository https://github.com/acacode/swagger-typescript-api
3+
import { createRequire } from "node:module";
4+
import { resolve } from "node:path";
5+
import { cli } from "./cli/index.js";
6+
import { TemplatesGenConfig } from "./src/commands/generate-templates/configuration.js";
7+
import { CodeGenConfig } from "./src/configuration.js";
8+
import { HTTP_CLIENT } from "./src/constants.js";
9+
import { generateApi, generateTemplates } from "./src/index.js";
810

9-
const { version, name } = require("./package.json");
10-
const { cli } = require("./cli");
11-
const { generateApi, generateTemplates } = require("./src");
12-
const { HTTP_CLIENT } = require("./src/constants");
13-
const { resolve } = require("node:path");
14-
const { CodeGenConfig } = require("./src/configuration");
15-
const {
16-
TemplatesGenConfig,
17-
} = require("./src/commands/generate-templates/configuration");
11+
const require = createRequire(import.meta.url);
12+
const packageJson = require("./package.json");
1813

1914
const codeGenBaseConfig = new CodeGenConfig({});
2015
const templateGenBaseConfig = new TemplatesGenConfig({});
2116

2217
const program = cli({
23-
name: name,
18+
name: packageJson.name,
2419
alias: "sta",
25-
version: version,
20+
version: packageJson.version,
2621
description:
2722
"Generate api via swagger scheme.\nSupports OA 3.0, 2.0, JSON, yaml.",
2823
options: [

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"contributors": [
1111
"Sora Morimoto <[email protected]>"
1212
],
13+
"type": "module",
1314
"main": "./src/index.js",
1415
"types": "./index.d.ts",
1516
"bin": {
@@ -50,6 +51,8 @@
5051
},
5152
"devDependencies": {
5253
"@biomejs/biome": "1.8.2",
54+
"@tsconfig/node18": "18.2.4",
55+
"@tsconfig/strictest": "2.0.5",
5356
"@types/didyoumean": "1.2.2",
5457
"@types/js-yaml": "4.0.9",
5558
"@types/lodash": "4.17.5",

0 commit comments

Comments
 (0)