@diia-inhouse/genproto 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitlab-ci.yml
CHANGED
|
@@ -4,15 +4,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const node_child_process_1 = require("node:child_process");
|
|
7
|
-
const
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
8
|
const index_1 = require("./index");
|
|
9
9
|
class TsCommandBuilder extends index_1.CommandBuilder {
|
|
10
|
+
// By default ts plugin should be linked to .bin dir but in case if it doesn't
|
|
11
|
+
// try to look it up in "standard" locations
|
|
12
|
+
tsPluginLocations = [
|
|
13
|
+
'./node_modules/.bin/protoc-gen-ts_proto',
|
|
14
|
+
'./node_modules/ts-proto/protoc-gen-ts_proto',
|
|
15
|
+
'./node_modules/@diia-inhouse/genproto/node_modules/ts-proto/protoc-gen-ts_proto',
|
|
16
|
+
];
|
|
17
|
+
async isFileExists(file) {
|
|
18
|
+
try {
|
|
19
|
+
await promises_1.default.access(file, promises_1.default.constants.F_OK);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
async getProtoTsPluginLocation() {
|
|
27
|
+
const pluginLocations = [];
|
|
28
|
+
for (const location of this.tsPluginLocations) {
|
|
29
|
+
try {
|
|
30
|
+
await promises_1.default.realpath(location);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
pluginLocations.push(location);
|
|
36
|
+
}
|
|
37
|
+
return pluginLocations.pop();
|
|
38
|
+
}
|
|
10
39
|
async protocCommand() {
|
|
11
40
|
let projectPlatform;
|
|
12
|
-
if (
|
|
41
|
+
if ((await this.isFileExists('package.json')) && !(await this.isFileExists('build.gradle'))) {
|
|
13
42
|
projectPlatform = index_1.Platform.ts;
|
|
14
43
|
}
|
|
15
|
-
else if (
|
|
44
|
+
else if (await this.isFileExists('build.gradle')) {
|
|
16
45
|
projectPlatform = index_1.Platform.java;
|
|
17
46
|
}
|
|
18
47
|
else {
|
|
@@ -36,10 +65,14 @@ class TsCommandBuilder extends index_1.CommandBuilder {
|
|
|
36
65
|
break;
|
|
37
66
|
}
|
|
38
67
|
}
|
|
68
|
+
const pluginLocation = this.getProtoTsPluginLocation();
|
|
69
|
+
if (!pluginLocation) {
|
|
70
|
+
throw new Error("Couldn't locate plugin in node modules. Are you sure that ts-proto is installed?");
|
|
71
|
+
}
|
|
39
72
|
const command = [
|
|
40
73
|
'protoc',
|
|
41
74
|
'--experimental_allow_proto3_optional',
|
|
42
|
-
|
|
75
|
+
`--plugin=${pluginLocation}`,
|
|
43
76
|
'--ts_proto_opt=useSnakeTypeName=false',
|
|
44
77
|
'--ts_proto_opt=unrecognizedEnum=false',
|
|
45
78
|
'--ts_proto_opt=stringEnums=true',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsCommandBuilder.js","sourceRoot":"","sources":["../../src/command/tsCommandBuilder.ts"],"names":[],"mappings":";;;;;AAAA,2DAA6C;AAC7C,
|
|
1
|
+
{"version":3,"file":"tsCommandBuilder.js","sourceRoot":"","sources":["../../src/command/tsCommandBuilder.ts"],"names":[],"mappings":";;;;;AAAA,2DAA6C;AAC7C,gEAAiC;AAEjC,mCAAkD;AAElD,MAAqB,gBAAiB,SAAQ,sBAAc;IACxD,8EAA8E;IAC9E,4CAA4C;IACpC,iBAAiB,GAAG;QACxB,yCAAyC;QACzC,6CAA6C;QAC7C,iFAAiF;KACpF,CAAA;IAEO,KAAK,CAAC,YAAY,CAAC,IAAY;QACnC,IAAI,CAAC;YACD,MAAM,kBAAE,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAE,CAAC,SAAS,CAAC,IAAI,CAAC,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,IAAI,SAAS,EAAE,CAAC;YAClC,MAAM,UAAU,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,KAAK,IAAI,WAAW,EAAE,CAAC,CAAA;YAEnG,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAA;QAC/B,CAAC;QAED,OAAO,OAAO,CAAA;IAClB,CAAC;CACJ;AA5GD,mCA4GC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diia-inhouse/genproto",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "JS codegen from proto with imports from @diia-inhouse/types",
|
|
5
5
|
"bin": {
|
|
6
6
|
"genproto": "./dist/genproto.js"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"ts-proto": ">=1.181.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@diia-inhouse/configs": "2.
|
|
33
|
+
"@diia-inhouse/configs": "2.2.0",
|
|
34
34
|
"@diia-inhouse/eslint-config": "5.1.0",
|
|
35
35
|
"@types/node": "20.14.10",
|
|
36
36
|
"eslint": "8.57.0",
|
|
@@ -1,15 +1,49 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process'
|
|
2
|
-
import fs from 'node:fs'
|
|
2
|
+
import fs from 'node:fs/promises'
|
|
3
3
|
|
|
4
4
|
import { CommandBuilder, Platform } from './index'
|
|
5
5
|
|
|
6
6
|
export default class TsCommandBuilder extends CommandBuilder {
|
|
7
|
+
// By default ts plugin should be linked to .bin dir but in case if it doesn't
|
|
8
|
+
// try to look it up in "standard" locations
|
|
9
|
+
private tsPluginLocations = [
|
|
10
|
+
'./node_modules/.bin/protoc-gen-ts_proto',
|
|
11
|
+
'./node_modules/ts-proto/protoc-gen-ts_proto',
|
|
12
|
+
'./node_modules/@diia-inhouse/genproto/node_modules/ts-proto/protoc-gen-ts_proto',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
private async isFileExists(file: string): Promise<boolean> {
|
|
16
|
+
try {
|
|
17
|
+
await fs.access(file, fs.constants.F_OK)
|
|
18
|
+
} catch {
|
|
19
|
+
return false
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getProtoTsPluginLocation(): Promise<string | undefined> {
|
|
26
|
+
const pluginLocations = []
|
|
27
|
+
|
|
28
|
+
for (const location of this.tsPluginLocations) {
|
|
29
|
+
try {
|
|
30
|
+
await fs.realpath(location)
|
|
31
|
+
} catch {
|
|
32
|
+
continue
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
pluginLocations.push(location)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return pluginLocations.pop()
|
|
39
|
+
}
|
|
40
|
+
|
|
7
41
|
async protocCommand(): Promise<string[]> {
|
|
8
42
|
let projectPlatform: Platform
|
|
9
43
|
|
|
10
|
-
if (
|
|
44
|
+
if ((await this.isFileExists('package.json')) && !(await this.isFileExists('build.gradle'))) {
|
|
11
45
|
projectPlatform = Platform.ts
|
|
12
|
-
} else if (
|
|
46
|
+
} else if (await this.isFileExists('build.gradle')) {
|
|
13
47
|
projectPlatform = Platform.java
|
|
14
48
|
} else {
|
|
15
49
|
throw new Error('Unable to identify platform type no package.json or build.gradle found')
|
|
@@ -35,10 +69,16 @@ export default class TsCommandBuilder extends CommandBuilder {
|
|
|
35
69
|
}
|
|
36
70
|
}
|
|
37
71
|
|
|
72
|
+
const pluginLocation = this.getProtoTsPluginLocation()
|
|
73
|
+
|
|
74
|
+
if (!pluginLocation) {
|
|
75
|
+
throw new Error("Couldn't locate plugin in node modules. Are you sure that ts-proto is installed?")
|
|
76
|
+
}
|
|
77
|
+
|
|
38
78
|
const command = [
|
|
39
79
|
'protoc',
|
|
40
80
|
'--experimental_allow_proto3_optional',
|
|
41
|
-
|
|
81
|
+
`--plugin=${pluginLocation}`,
|
|
42
82
|
'--ts_proto_opt=useSnakeTypeName=false',
|
|
43
83
|
'--ts_proto_opt=unrecognizedEnum=false',
|
|
44
84
|
'--ts_proto_opt=stringEnums=true',
|