Skip to content

Commit dee7296

Browse files
authored
Merge pull request #242 from code0-tech/fix/ts-tooling
Fix tucana typescript tooling
2 parents df17b10 + a11fe1b commit dee7296

7 files changed

Lines changed: 49 additions & 12 deletions

File tree

build/ts/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules/
2-
pb/*
3-
!pb/.gitkeep
2+
pb/
3+
!pb/_generated/.gitkeep

build/ts/helpers/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./shared.struct_helper";

build/ts/helpers/shared.struct_helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Value} from "../pb/shared.struct_pb.js";
1+
import {Value} from "../pb/shared";
22

33
export type PlainValue = null | number | string | boolean | Array<PlainValue> | object;
44

build/ts/package.json

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,42 @@
1515
"type": "module",
1616
"main": "index.js",
1717
"scripts": {
18-
"generate:aquila": "protoc --ts_opt=add_pb_suffix --ts_opt=output_javascript_es2020 --ts_out=pb --proto_path=../../proto/aquila --proto_path=../../proto/shared ../../proto/aquila/*.proto",
19-
"generate:sagittarius": "protoc --ts_opt=add_pb_suffix --ts_opt=output_javascript_es2020 --ts_out=pb --proto_path=../../proto/sagittarius --proto_path=../../proto/shared ../../proto/sagittarius/*.proto",
20-
"generate:shared": "protoc --ts_opt=add_pb_suffix --ts_opt=output_javascript_es2020 --ts_out=pb --proto_path=../../proto/shared ../../proto/shared/*.proto",
21-
"generate": "npm run generate:shared && npm run generate:sagittarius && npm run generate:aquila"
18+
"generate:aquila": "protoc --ts_opt=add_pb_suffix --ts_opt=output_javascript --ts_opt=generate_dependencies --ts_out=pb/_generated --proto_path=../../proto/aquila --proto_path=../../proto/shared ../../proto/aquila/*.proto",
19+
"generate:sagittarius": "protoc --ts_opt=add_pb_suffix --ts_opt=output_javascript --ts_opt=generate_dependencies --ts_out=pb/_generated --proto_path=../../proto/sagittarius --proto_path=../../proto/shared ../../proto/sagittarius/*.proto",
20+
"generate:shared": "protoc --ts_opt=add_pb_suffix --ts_opt=output_javascript --ts_opt=generate_dependencies --ts_out=pb/_generated --proto_path=../../proto/shared ../../proto/shared/*.proto",
21+
"generate": "npm run generate:shared && npm run generate:sagittarius && npm run generate:aquila && npm run generate:exports",
22+
"generate:exports": "node scripts/generateExports.mjs"
2223
},
2324
"devDependencies": {
2425
"@protobuf-ts/plugin": "^2.11.1",
2526
"protoc": "^34.0.0"
2627
},
2728
"files": [
28-
"helpers/*.ts",
29-
"helpers/*.js",
30-
"pb/*.ts",
31-
"pb/*.js",
29+
"pb",
30+
"helpers",
31+
"index.ts",
3232
"index.js",
33+
"index.d.ts",
3334
"package.json"
3435
],
36+
"types": "index.d.ts",
37+
"exports": {
38+
".": {
39+
"import": "./index.js"
40+
},
41+
"./shared": {
42+
"import": "./pb/shared.js"
43+
},
44+
"./aquila": {
45+
"import": "./pb/aquila.js"
46+
},
47+
"./sagittarius": {
48+
"import": "./pb/sagittarius.js"
49+
},
50+
"./helpers": {
51+
"import": "./helpers/helpers.js"
52+
}
53+
},
3554
"publishConfig": {
3655
"access": "public"
3756
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { readdirSync, writeFileSync } from "fs";
2+
import { resolve } from "path";
3+
4+
const files = {}
5+
6+
readdirSync(resolve('./pb/_generated')).forEach((file) => {
7+
if (!file.endsWith('.js') && !file.endsWith('.ts')) return;
8+
9+
const category = file.split('.')[0];
10+
files[category] ||= [];
11+
files[category].push(file);
12+
});
13+
14+
Object.entries(files).forEach(([category, categoryFiles]) => {
15+
const fileContent = categoryFiles.map(file => `export * from "./_generated/${file.replace('.ts', '.js')}";`).join('\n');
16+
writeFileSync(`./pb/${category}.ts`, `${fileContent}\n`);
17+
});

build/ts/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2017",
3+
"target": "ES2020",
44
"lib": ["ES2017", "DOM"],
55
"module": "commonjs",
66
"strict": true

0 commit comments

Comments
 (0)