Skip to content

Commit 43218fc

Browse files
committed
ESM
Signed-off-by: Sora Morimoto <[email protected]>
1 parent 8cc7cf4 commit 43218fc

Some content is hidden

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

57 files changed

+3765
-1259
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.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: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
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
8-
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");
3+
import { resolve } from "node:path";
4+
import { cli } from "./cli/index.js";
5+
import { name, version } from "./package.json";
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";
1810

1911
const codeGenBaseConfig = new CodeGenConfig({});
2012
const templateGenBaseConfig = new TemplatesGenConfig({});

package.json

Lines changed: 4 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": {
@@ -49,13 +50,16 @@
4950
"typescript": "~5.4.5"
5051
},
5152
"devDependencies": {
53+
"5to6-codemod": "1.8.0",
5254
"@biomejs/biome": "1.8.2",
5355
"@types/didyoumean": "1.2.2",
5456
"@types/js-yaml": "4.0.9",
57+
"@types/jscodeshift": "^0",
5558
"@types/lodash": "4.17.5",
5659
"@types/node": "20.14.6",
5760
"@types/swagger2openapi": "7.0.4",
5861
"axios": "1.7.2",
62+
"jscodeshift": "0.16.0",
5963
"shx": "0.3.4",
6064
"vitest": "1.6.0"
6165
},

src/code-formatter.js

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

55
class CodeFormatter {
66
/**
@@ -111,6 +111,4 @@ class TsLanguageServiceHost {
111111
}
112112
}
113113

114-
module.exports = {
115-
CodeFormatter,
116-
};
114+
export { CodeFormatter };

src/code-gen-process.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
const { SwaggerSchemaResolver } = require("./swagger-schema-resolver.js");
2-
const { SchemaComponentsMap } = require("./schema-components-map.js");
3-
const { NameResolver } = require("./util/name-resolver");
4-
const { Logger } = require("./util/logger.js");
5-
const { TypeNameFormatter } = require("./type-name-formatter.js");
6-
const _ = require("lodash");
7-
const { SchemaParserFabric } = require("./schema-parser/schema-parser-fabric");
8-
const { SchemaRoutes } = require("./schema-routes/schema-routes.js");
9-
const { CodeGenConfig } = require("./configuration.js");
10-
const { SchemaWalker } = require("./schema-walker");
11-
const { FileSystem } = require("./util/file-system");
12-
const { TemplatesWorker } = require("./templates-worker");
13-
const { JavascriptTranslator } = require("./translators/javascript");
14-
const ts = require("typescript");
15-
const { CodeFormatter } = require("./code-formatter");
16-
const { pascalCase } = require("./util/pascal-case");
17-
const { internalCase } = require("./util/internal-case");
18-
const { sortByProperty } = require("./util/sort-by-property");
1+
import _ from "lodash";
2+
import ts from "typescript";
3+
import { CodeFormatter } from "./code-formatter.js";
4+
import { CodeGenConfig } from "./configuration.js";
5+
import { SchemaComponentsMap } from "./schema-components-map.js";
6+
import { SchemaParserFabric } from "./schema-parser/schema-parser-fabric.js";
7+
import { SchemaRoutes } from "./schema-routes/schema-routes.js";
8+
import { SchemaWalker } from "./schema-walker.js";
9+
import { SwaggerSchemaResolver } from "./swagger-schema-resolver.js";
10+
import { TemplatesWorker } from "./templates-worker.js";
11+
import { JavascriptTranslator } from "./translators/javascript.js";
12+
import { TypeNameFormatter } from "./type-name-formatter.js";
13+
import { FileSystem } from "./util/file-system.js";
14+
import { internalCase } from "./util/internal-case.js";
15+
import { Logger } from "./util/logger.js";
16+
import { NameResolver } from "./util/name-resolver.js";
17+
import { pascalCase } from "./util/pascal-case.js";
18+
import { sortByProperty } from "./util/sort-by-property.js";
1919

2020
const PATCHABLE_INSTANCES = [
2121
"schemaWalker",
@@ -566,6 +566,4 @@ class CodeGenProcess {
566566
};
567567
}
568568

569-
module.exports = {
570-
CodeGenProcess,
571-
};
569+
export { CodeGenProcess };

src/commands/generate-templates/configuration.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { objectAssign } = require("../../util/object-assign");
2-
const { HTTP_CLIENT, PROJECT_VERSION } = require("../../constants");
1+
import { HTTP_CLIENT, PROJECT_VERSION } from "../../constants.js";
2+
import { objectAssign } from "../../util/object-assign.js";
33

44
/**
55
* @type {GenerateTemplatesParams}}
@@ -28,6 +28,4 @@ class TemplatesGenConfig {
2828
};
2929
}
3030

31-
module.exports = {
32-
TemplatesGenConfig,
33-
};
31+
export { TemplatesGenConfig };
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
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 { TemplatesGenProcess } from "./templates-gen-process.js";
84

9-
const { TemplatesGenProcess } = require("./templates-gen-process");
5+
async function generateTemplates(config) {
6+
const codeGenProcess = new TemplatesGenProcess(config);
7+
return await codeGenProcess.start();
8+
}
109

11-
module.exports = {
12-
generateTemplates: async (config) => {
13-
const codeGenProcess = new TemplatesGenProcess(config);
14-
return await codeGenProcess.start();
15-
},
16-
};
10+
export { generateTemplates };

src/commands/generate-templates/templates-gen-process.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { TemplatesGenConfig } = require("./configuration");
2-
const { FileSystem } = require("../../util/file-system");
3-
const { Logger } = require("../../util/logger");
4-
const path = require("node:path");
1+
import path from "node:path";
2+
import { FileSystem } from "../../util/file-system.js";
3+
import { Logger } from "../../util/logger.js";
4+
import { TemplatesGenConfig } from "./configuration.js";
55

66
class TemplatesGenProcess {
77
/**
@@ -199,6 +199,4 @@ class TemplatesGenProcess {
199199
};
200200
}
201201

202-
module.exports = {
203-
TemplatesGenProcess,
204-
};
202+
export { TemplatesGenProcess };

src/component-type-name-resolver.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { getRandomInt } = require("./util/random");
2-
const { NameResolver } = require("./util/name-resolver");
1+
import { NameResolver } from "./util/name-resolver.js";
2+
import { getRandomInt } from "./util/random.js";
33

44
class ComponentTypeNameResolver extends NameResolver {
55
counter = 1;
@@ -39,6 +39,4 @@ class ComponentTypeNameResolver extends NameResolver {
3939
}
4040
}
4141

42-
module.exports = {
43-
ComponentTypeNameResolver,
44-
};
42+
export { ComponentTypeNameResolver };

src/configuration.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/* eslint-disable no-unused-vars */
2-
const { objectAssign } = require("./util/object-assign");
3-
const _ = require("lodash");
4-
const CONSTANTS = require("./constants");
5-
const { ComponentTypeNameResolver } = require("./component-type-name-resolver");
6-
const { cosmiconfigSync } = require("cosmiconfig");
7-
const ts = require("typescript");
1+
import { cosmiconfigSync } from "cosmiconfig";
2+
import _ from "lodash";
3+
import ts from "typescript";
4+
import { ComponentTypeNameResolver } from "./component-type-name-resolver.js";
5+
import * as CONSTANTS from "./constants.js";
6+
import { objectAssign } from "./util/object-assign.js";
87

98
const TsKeyword = {
109
Number: "number",
@@ -443,6 +442,4 @@ const getDefaultPrettierOptions = () => {
443442
return { ...CONSTANTS.PRETTIER_OPTIONS };
444443
};
445444

446-
module.exports = {
447-
CodeGenConfig,
448-
};
445+
export { CodeGenConfig };

0 commit comments

Comments
 (0)