-
Notifications
You must be signed in to change notification settings - Fork 0
/
NpmSamplesDecoderLib.js
51 lines (43 loc) · 1.58 KB
/
NpmSamplesDecoderLib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import fs from "fs";
import path from "path";
// import * as typedoc from "typedoc";
const PACKAGE_JSON_FILE = "package.json";
export class NpmSamplesDecoderLib {
constructor() {
this._basePath = './npm-samples-decoder';
this._srcPath = path.join(this._basePath, "src");
this._inputSamplesPath = path.join(this._srcPath, "InputSamples.ts");
this._outputSamplesPath = path.join(this._srcPath, "OutputSamples.ts");
this._samplesTsCode = undefined;
this._protobufSamplesTsCode = undefined;
}
addSamplesTsCode(tsCode) {
this._samplesTsCode = tsCode;
}
addSamplesProtobufTsCode(protobufTsCode) {
this._protobufSamplesTsCode = protobufTsCode;
}
set version(value) {
this._version = value
}
make() {
fs.writeFileSync(this._inputSamplesPath, this._protobufSamplesTsCode);
fs.writeFileSync(this._outputSamplesPath, this._samplesTsCode);
if (this._version) {
const packagePath = path.join(this._basePath, PACKAGE_JSON_FILE);
let packageText = fs.readFileSync(packagePath);
const packageJson = JSON.parse(packageText);
packageJson["version"] = this._version;
packageText = JSON.stringify(packageJson, null, 2);
fs.writeFileSync(packagePath, packageText);
}
}
clear() {
if (fs.existsSync(this._inputSamplesPath)) {
fs.rmSync(this._inputSamplesPath);
}
if (fs.existsSync(this._outputSamplesPath)) {
fs.rmSync(this._outputSamplesPath);
}
}
}