Skip to content

Commit 77a4d8f

Browse files
authored
Merge pull request #26 from Himenon/feat/support-windows
feat: support for windows
2 parents 0b4d455 + 19c6343 commit 77a4d8f

File tree

11 files changed

+42
-39
lines changed

11 files changed

+42
-39
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ on:
55

66
jobs:
77
build:
8-
runs-on: ubuntu-latest
8+
runs-on: ${{ matrix.os }}
99

1010
strategy:
1111
matrix:
1212
node-version: [12.x]
13+
os: [windows-latest, ubuntu-latest]
1314

1415
steps:
1516
- uses: actions/checkout@v2

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"node-fetch": "2.6.1"
7373
},
7474
"dependencies": {
75-
"@himenon/path-oriented-data-structure": "0.1.0",
75+
"@himenon/path-oriented-data-structure": "0.1.3",
7676
"@types/json-schema": "7.0.6",
7777
"ajv": "7.0.3",
7878
"dot-prop": "6.0.1",

scripts/tools/copyPackageSet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export const copyPackageSet = async (): Promise<void> => {
1313
const libDir = "lib";
1414
const publishPackageJson = path.join(libDir, "package.json");
1515
pkg.private = undefined;
16-
pkg.main = path.relative(libDir, pkg.main);
17-
pkg.module = path.relative(libDir, pkg.module);
18-
pkg.types = path.relative(libDir, pkg.types);
16+
pkg.main = path.posix.relative(libDir, pkg.main);
17+
pkg.module = path.posix.relative(libDir, pkg.module);
18+
pkg.types = path.posix.relative(libDir, pkg.types);
1919
pkg.directories = undefined;
2020
pkg.files = undefined;
2121
fs.writeFileSync(publishPackageJson, JSON.stringify(pkg, null, 2), {

src/CodeGenerator/factory/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const escapeIdentiferText = (text: string): string => {
1414
};
1515

1616
export const generateComment = (comment: string, deprecated?: boolean): Comment => {
17-
const splitComments = deprecated ? ["@deprecated"].concat(comment.split(EOL)) : comment.split(EOL);
17+
const splitComments = deprecated ? ["@deprecated"].concat(comment.split(/\r?\n/)) : comment.split(/\r?\n/);
1818
const comments = splitComments.filter((comment, index) => {
1919
if (index === splitComments.length - 1 && comment === "") {
2020
return false;

src/Converter/v3/TypeNodeContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface ReferencePathSet {
1616
const generatePath = (entryPoint: string, currentPoint: string, referencePath: string): ReferencePathSet => {
1717
const ext = Path.extname(currentPoint); // .yml
1818
const from = Path.relative(Path.dirname(entryPoint), currentPoint).replace(ext, ""); // components/schemas/A/B
19-
const base = Path.dirname(from);
20-
const result = Path.relative(base, referencePath); // remoteの場合? localの場合 referencePath.split("/")
19+
const base = Path.dirname(from).replace(Path.sep, "/");
20+
const result = Path.posix.relative(base, referencePath); // remoteの場合? localの場合 referencePath.split("/")
2121
const pathArray = result.split("/");
2222
return {
2323
pathArray,
@@ -29,7 +29,7 @@ const calculateReferencePath = (store: Store.Type, base: string, pathArray: stri
2929
let names: string[] = [];
3030
let unresolvedPaths: string[] = [];
3131
pathArray.reduce((previous, lastPath, index) => {
32-
const current = Path.join(previous, lastPath);
32+
const current = Path.posix.join(previous, lastPath);
3333
// ディレクトリが深い場合は相対パスが`..`を繰り返す可能性があり、
3434
// その場合はすでに登録されたnamesを削除する
3535
if (lastPath === ".." && names.length > 0) {

src/Converter/v3/components/Reference.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const generateLocalReference = (reference: OpenApi.Reference): LocalRefer
100100
return;
101101
}
102102
const name = reference.$ref.split(localReferencePattern)[1];
103-
const localPath = path.join(localReferenceComponents[localReferencePattern], name);
103+
const localPath = path.posix.join(localReferenceComponents[localReferencePattern], name);
104104
if (!localPath.startsWith("components")) {
105105
throw new DevelopmentError(`localPath is not start "components":\n${localPath}`);
106106
}
@@ -138,7 +138,7 @@ export const generate = <T>(entryPoint: string, currentPoint: string, reference:
138138

139139
const relativePathFromEntryPoint = path.relative(path.dirname(entryPoint), referencePoint); // components/hoge/fuga.yml
140140
const ext = path.extname(relativePathFromEntryPoint); // .yml
141-
const pathArray: string[] = relativePathFromEntryPoint.replace(ext, "").split("/"); // ["components", "hoge", "fuga"]
141+
const pathArray: string[] = relativePathFromEntryPoint.replace(ext, "").split(path.sep); // ["components", "hoge", "fuga"]
142142
const targetPath: string = pathArray.join("/"); // components/hoge/fuga
143143
const schemaName = pathArray[pathArray.length - 1]; // fuga
144144
const componentName = pathArray[0] === "components" ? pathArray[1] : "";

src/Converter/v3/components/Response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const generateReferenceNamespace = (
7777
kind: "namespace",
7878
name: nameWithStatusCode,
7979
});
80-
const headerNamespace = store.getStatement(path.join(responseReference.path, "Header"), "namespace");
80+
const headerNamespace = store.getStatement(path.posix.join(responseReference.path, "Header"), "namespace");
8181
if (headerNamespace) {
8282
store.addStatement(`${basePath}/Header`, {
8383
kind: "namespace",

src/Converter/v3/components/Responses.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const generateNamespace = (
4141
reference.referencePoint,
4242
store,
4343
factory,
44-
path.dirname(reference.path), // referencePoint basename === namespace name
44+
path.posix.dirname(reference.path), // referencePoint basename === namespace name
4545
reference.name,
4646
reference.data,
4747
context,
@@ -94,7 +94,7 @@ export const generateNamespaceWithStatusCode = (
9494
reference.referencePoint,
9595
store,
9696
factory,
97-
path.dirname(reference.path), // referencePoint basename === namespace name
97+
path.posix.dirname(reference.path), // referencePoint basename === namespace name
9898
reference.name,
9999
reference.data,
100100
context,
@@ -157,7 +157,7 @@ export const generateInterfacesWithStatusCode = (
157157
reference.referencePoint,
158158
store,
159159
factory,
160-
path.dirname(reference.path), // referencePoint basename === namespace name
160+
path.posix.dirname(reference.path), // referencePoint basename === namespace name
161161
reference.name,
162162
reference.data,
163163
context,

src/Converter/v3/store/Store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { relative } from "path";
1+
import * as Path from "path";
22

33
import { Tree } from "@himenon/path-oriented-data-structure";
44
import Dot from "dot-prop";
@@ -87,11 +87,11 @@ export const create = (factory: Factory.Type, rootDocument: OpenApi.Document): T
8787
if (!path.startsWith("components")) {
8888
throw new UnSupportError(`componentsから始まっていません。path=${path}`);
8989
}
90-
const targetPath = relative("components", path);
90+
const targetPath = Path.posix.relative("components", path);
9191
operator.set(targetPath, Structure.createInstance(statement));
9292
},
9393
getStatement: <T extends Structure.DataStructure.Kind>(path: string, kind: T): Structure.DataStructure.GetChild<T> | undefined => {
94-
const targetPath = relative("components", path);
94+
const targetPath = Path.posix.relative("components", path);
9595
return getChildByPaths(targetPath, kind);
9696
},
9797
getRootStatements,

src/DefaultCodeTemplate/ApiClientClass/MethodBody/__tests__/PathParameter-test.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { EOL } from "os";
2+
13
import ts from "typescript";
24

35
import { Factory } from "../../../../CodeGenerator";
@@ -40,68 +42,68 @@ describe("PathParameter Test", () => {
4042
return getText(expression);
4143
};
4244
test("generateUrlTemplateExpression", () => {
43-
expect(generate("/{a}", [{ in: "path", name: "a", required: true }])).toBe("`/${params.parameter.a}`;\n");
44-
expect(generate("/{a}/", [{ in: "path", name: "a", required: true }])).toBe("`/${params.parameter.a}/`;\n");
45-
expect(generate("/a/{b}", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}`;\n");
46-
expect(generate("/a/{b}/", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/`;\n");
47-
expect(generate("/a/{b}/c", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/c`;\n");
48-
expect(generate("/a/{b}/c/", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/c/`;\n");
49-
expect(generate("/a/b/{c}", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}`;\n");
50-
expect(generate("/a/b/{c}/", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}/`;\n");
45+
expect(generate("/{a}", [{ in: "path", name: "a", required: true }])).toBe("`/${params.parameter.a}`;" + EOL);
46+
expect(generate("/{a}/", [{ in: "path", name: "a", required: true }])).toBe("`/${params.parameter.a}/`;" + EOL);
47+
expect(generate("/a/{b}", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}`;" + EOL);
48+
expect(generate("/a/{b}/", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/`;" + EOL);
49+
expect(generate("/a/{b}/c", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/c`;" + EOL);
50+
expect(generate("/a/{b}/c/", [{ in: "path", name: "b", required: true }])).toBe("`/a/${params.parameter.b}/c/`;" + EOL);
51+
expect(generate("/a/b/{c}", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}`;" + EOL);
52+
expect(generate("/a/b/{c}/", [{ in: "path", name: "c", required: true }])).toBe("`/a/b/${params.parameter.c}/`;" + EOL);
5153

5254
expect(
5355
generate("/{a}/{b}", [
5456
{ in: "path", name: "a", required: true },
5557
{ in: "path", name: "b", required: true },
5658
]),
57-
).toBe("`/${params.parameter.a}/${params.parameter.b}`;\n");
59+
).toBe("`/${params.parameter.a}/${params.parameter.b}`;" + EOL);
5860
expect(
5961
generate("/{a}/{b}/", [
6062
{ in: "path", name: "a", required: true },
6163
{ in: "path", name: "b", required: true },
6264
]),
63-
).toBe("`/${params.parameter.a}/${params.parameter.b}/`;\n");
65+
).toBe("`/${params.parameter.a}/${params.parameter.b}/`;" + EOL);
6466
expect(
6567
generate("/{a}/{b}/c", [
6668
{ in: "path", name: "a", required: true },
6769
{ in: "path", name: "b", required: true },
6870
]),
69-
).toBe("`/${params.parameter.a}/${params.parameter.b}/c`;\n");
71+
).toBe("`/${params.parameter.a}/${params.parameter.b}/c`;" + EOL);
7072
expect(
7173
generate("/{a}/{b}/c/", [
7274
{ in: "path", name: "a", required: true },
7375
{ in: "path", name: "b", required: true },
7476
]),
75-
).toBe("`/${params.parameter.a}/${params.parameter.b}/c/`;\n");
77+
).toBe("`/${params.parameter.a}/${params.parameter.b}/c/`;" + EOL);
7678
expect(
7779
generate("/{a}/b/{c}", [
7880
{ in: "path", name: "a", required: true },
7981
{ in: "path", name: "c", required: true },
8082
]),
81-
).toBe("`/${params.parameter.a}/b/${params.parameter.c}`;\n");
83+
).toBe("`/${params.parameter.a}/b/${params.parameter.c}`;" + EOL);
8284
expect(
8385
generate("/{a}/b/{c}/", [
8486
{ in: "path", name: "a", required: true },
8587
{ in: "path", name: "c", required: true },
8688
]),
87-
).toBe("`/${params.parameter.a}/b/${params.parameter.c}/`;\n");
89+
).toBe("`/${params.parameter.a}/b/${params.parameter.c}/`;" + EOL);
8890
expect(
8991
generate("/a/{b}/{c}", [
9092
{ in: "path", name: "b", required: true },
9193
{ in: "path", name: "c", required: true },
9294
]),
93-
).toBe("`/a/${params.parameter.b}/${params.parameter.c}`;\n");
95+
).toBe("`/a/${params.parameter.b}/${params.parameter.c}`;" + EOL);
9496
expect(
9597
generate("/a/{b}/{c}/", [
9698
{ in: "path", name: "b", required: true },
9799
{ in: "path", name: "c", required: true },
98100
]),
99-
).toBe("`/a/${params.parameter.b}/${params.parameter.c}/`;\n");
101+
).toBe("`/a/${params.parameter.b}/${params.parameter.c}/`;" + EOL);
100102
expect(
101103
generate("/a/{b}...{c}/", [
102104
{ in: "path", name: "b", required: true },
103105
{ in: "path", name: "c", required: true },
104106
]),
105-
).toBe("`/a/${params.parameter.b}...${params.parameter.c}/`;\n");
107+
).toBe("`/a/${params.parameter.b}...${params.parameter.c}/`;" + EOL);
106108
});
107109
});

0 commit comments

Comments
 (0)