Skip to content

Commit 6791be2

Browse files
committed
Added windows support for ts-codegen
1 parent 4b90df7 commit 6791be2

File tree

17 files changed

+11160
-8118
lines changed

17 files changed

+11160
-8118
lines changed

.yarn/install-state.gz

994 KB
Binary file not shown.

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
"repository": {
4747
"type": "git",
4848
"url": "https://github.com/hyperweb-io/ts-codegen"
49-
}
49+
},
50+
"packageManager": "yarn@4.6.0+sha512.5383cc12567a95f1d668fbe762dfe0075c595b4bfff433be478dbbe24e05251a8e8c3eb992a986667c1d53b6c3a9c85b8398c35a960587fbd9fa3a0915406728"
5051
}

packages/ast/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
},
1515
"scripts": {
1616
"copy": "copyfiles -f LICENSE-Apache LICENSE-MIT README.md package.json dist",
17-
"clean": "rimraf dist/**",
17+
"clean": "rimraf dist",
1818
"prepare": "npm run build",
1919
"codegen": "tsx ./scripts/build.ts",
20-
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
20+
"build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
2121
"lint": "eslint . --fix",
2222
"format": "prettier --write --log-level warn \"./**/*.ts\"",
2323
"test": "jest",

packages/ast/src/utils/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './babel';
2-
export { OPTIONAL_FUNDS_PARAM } from './constants';
3-
export { FIXED_EXECUTE_PARAMS } from './constants';
4-
export { PROVIDER_TYPES } from './constants';
2+
export * from './constants';
3+
export * from './path';
54
export * from './ref';
65
export * from './types';

packages/ast/src/utils/path.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { globSync } from 'glob';
2+
import { posix } from 'path';
3+
4+
/**
5+
* Replace all \\ to / for windows support purpose
6+
* @param input
7+
* @param options
8+
* @returns
9+
*/
10+
export const crossGlob = (input: string, options?: object) => {
11+
return globSync(toPosixPath(input), options);
12+
};
13+
14+
/**
15+
* Unify all the path to posixPath for windows support purpose
16+
* @param mixedPath
17+
* @returns
18+
*/
19+
export const toPosixPath = (mixedPath: string): string => {
20+
return mixedPath.replace(/\\/g, posix.sep);
21+
};

packages/ast/test-utils/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {
77
QueryMsg,
88
} from '@cosmwasm/ts-codegen-types';
99
import { readFileSync } from 'fs';
10-
import { globSync as glob } from 'glob';
1110
import { join } from 'path';
1211

1312
import { RenderContext } from '../src/context';
13+
import { crossGlob, toPosixPath } from '../src/utils';
1414

1515
export const expectCode = (ast: any): void => {
1616
expect(generate(ast).code).toMatchSnapshot();
@@ -50,11 +50,11 @@ const globCache: Record<string, GlobContractLegacy[] | GlobContract[]> = {};
5050
export const globIdlBasedContracts = (p: string): GlobContract[] => {
5151
if (globCache[p]) return globCache[p] as GlobContract[];
5252
// @ts-ignore
53-
const contracts: GlobContract[] = glob(join(fixtureDir, p, '/*.json'))
53+
const contracts: GlobContract[] = crossGlob(join(fixtureDir, p, '/*.json'))
5454
.sort()
5555
.map((file) => {
5656
return {
57-
name: file.split(join('__fixtures__', p))[1],
57+
name: file.split(toPosixPath(join('__fixtures__', p)))[1],
5858
content: JSON.parse(readFileSync(file, 'utf-8')),
5959
};
6060
});
@@ -65,11 +65,11 @@ export const globIdlBasedContracts = (p: string): GlobContract[] => {
6565
export const globLegacyContracts = (p: string): GlobContractLegacy[] => {
6666
if (globCache[p]) return globCache[p] as GlobContractLegacy[];
6767
// @ts-ignore
68-
const contracts: GlobContractLegacy[] = glob(join(fixtureDir, p, '/*.json'))
68+
const contracts: GlobContractLegacy[] = crossGlob(join(fixtureDir, p, '/*.json'))
6969
.sort()
7070
.map((file) => {
7171
return {
72-
name: file.split(join('__fixtures__', p))[1],
72+
name: file.split(toPosixPath(join('__fixtures__', p)))[1],
7373
content: JSON.parse(readFileSync(file, 'utf-8')),
7474
};
7575
});

packages/ts-codegen/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
},
1919
"scripts": {
2020
"copy": "copyfiles -f LICENSE-Apache LICENSE-MIT README.md package.json dist",
21-
"clean": "rimraf dist/**",
21+
"clean": "rimraf dist",
2222
"prepare": "npm run build",
2323
"cmds": "tsx ./scripts/cmds.ts",
24-
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
24+
"build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
2525
"lint": "eslint . --fix",
2626
"format": "prettier --write --log-level warn \"./**/*.ts\"",
2727
"test": "jest",

packages/ts-codegen/scripts/cmds.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { kebab, snake } from 'case';
22
import { writeFileSync } from 'fs';
3-
import { globSync as glob } from 'glob';
43
import { basename, resolve } from 'path';
4+
import { crossGlob, toPosixPath } from '../src/utils';
55

66
const srcDir = resolve(`${__dirname}/../src/commands`);
77

@@ -11,16 +11,16 @@ interface PathObj {
1111
safe: string;
1212
path: string;
1313
}
14-
const paths: PathObj[] = glob(`${srcDir}/**.[j|t]s`)
14+
const paths: PathObj[] = crossGlob(`${srcDir}/**.[j|t]s`)
1515
.sort()
1616
.map((file: string) => {
1717
const [, name] = file.match(/\/(.*)\.[j|t]s$/);
1818
return {
1919
name: basename(name),
2020
param: kebab(basename(name)),
2121
safe: snake(basename(name)),
22-
path: file
23-
.replace(srcDir, './commands')
22+
path: toPosixPath(file)
23+
.replace(toPosixPath(srcDir), './commands')
2424
.replace(/\.js$/, '')
2525
.replace(/\.ts$/, ''),
2626
};

packages/ts-codegen/src/commands/install.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { MinimistArgs } from '@cosmwasm/ts-codegen-types';
22
import { readFileSync, writeFileSync } from 'fs';
3-
import { globSync as glob } from 'glob';
43
import { sync as mkdirp } from 'mkdirp';
54
import { tmpdir } from 'os';
65
import { parse } from 'parse-package-name';
76
import { basename, dirname, extname, join, resolve } from 'path';
87
import { sync as rimraf } from 'rimraf';
98
import { exec } from 'shelljs';
109

10+
import { crossGlob, toPosixPath } from '../utils';
11+
1112
import { prompt } from '../utils/prompt';
1213

1314
const TMPDIR = tmpdir();
@@ -78,7 +79,7 @@ export default async (argv: MinimistArgs) => {
7879
);
7980

8081
// protos
81-
const pkgs = glob('./smart-contracts/**/package.json').sort();
82+
const pkgs = crossGlob('./smart-contracts/**/package.json').sort();
8283
const cmds = pkgs
8384
.filter((f) => {
8485
return f !== './smart-contracts/package.json';
@@ -89,7 +90,7 @@ export default async (argv: MinimistArgs) => {
8990
const dir = extDir.split('node_modules/')[1];
9091
const dst = basename(dir);
9192

92-
const files = glob(`${extDir}/**/*`, { nodir: true }).sort();
93+
const files = crossGlob(`${extDir}/**/*`, { nodir: true }).sort();
9394
files.forEach((f) => {
9495
if (
9596
extname(f) === '.json' ||

0 commit comments

Comments
 (0)