proto-update-tool 1.0.0

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/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # 请下载 release.zip 并解压
2
+
3
+ ```bash
4
+ Usage: Proto 助手 [options]
5
+
6
+ 通过 Gitlab SSH 拉取 Proto 配置
7
+
8
+ Options:
9
+ -V, --version output the version number
10
+ -h, --help 显示帮助信息
11
+ -p, --path <path> 指定 Proto 配置文件路径 (default: "./proto.config.json")
12
+ ```
13
+
14
+ # 配置文件示例
15
+
16
+ ```json5
17
+ // proto.config.json 示例
18
+ [
19
+ {
20
+ // 仓库地址
21
+ "repository": "git@xxxx.git",
22
+ // 分支或标签
23
+ "ref": "version-1.1.0",
24
+ // 需要拉取的仓库目录
25
+ "outDir": "xxx",
26
+ // 文件过滤正则表达式,仅拉取匹配的文件
27
+ "fileFilter": "/\\.ts$/",
28
+ // 拉取到本地后的目标路径
29
+ "destPath": "xxx"
30
+ }
31
+ ]
32
+ ```
@@ -0,0 +1,9 @@
1
+ export interface GitImportOption {
2
+ repository: string;
3
+ ref: string;
4
+ outDir: string;
5
+ fileFilter: string;
6
+ destPath: string;
7
+ }
8
+ export declare function gitFactory(options: GitImportOption[]): Promise<void>;
9
+ //# sourceMappingURL=git.factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.factory.d.ts","sourceRoot":"","sources":["../src/git.factory.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE,eAAe,EAAE,iBA4C1D"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.gitFactory = gitFactory;
7
+ const fs_extra_1 = require("fs-extra");
8
+ const os_1 = require("os");
9
+ const path_1 = require("path");
10
+ const simple_git_1 = __importDefault(require("simple-git"));
11
+ async function gitFactory(options) {
12
+ const tempDir = (0, path_1.join)((0, os_1.homedir)(), '.proto-import-cache');
13
+ // console.log('tempDir:', tempDir);
14
+ if (!(0, fs_extra_1.existsSync)(tempDir))
15
+ (0, fs_extra_1.mkdirSync)(tempDir, { recursive: true });
16
+ await Promise.all(options.map(async (config) => {
17
+ const path = (0, path_1.join)(__dirname, '..', config.destPath);
18
+ if (!(0, fs_extra_1.existsSync)(path)) {
19
+ (0, fs_extra_1.mkdirSync)(path, { recursive: true });
20
+ }
21
+ const tempPath = (0, path_1.join)(tempDir, config.repository);
22
+ let isCloned = false;
23
+ if (!(0, fs_extra_1.existsSync)(tempPath)) {
24
+ (0, fs_extra_1.mkdirSync)(tempPath, { recursive: true });
25
+ isCloned = true;
26
+ }
27
+ const git = (0, simple_git_1.default)(tempPath);
28
+ if (isCloned) {
29
+ await git.clone(config.repository, tempPath);
30
+ }
31
+ await git.fetch(tempPath, 'origin', ['--tags']);
32
+ const tags = await git.tags();
33
+ console.log('可用 tags:', tags.all);
34
+ if (!tags.all.includes(config.ref)) {
35
+ throw new Error(`tag ${config.ref} not found`);
36
+ }
37
+ await git.checkout(config.ref);
38
+ const destPath = (0, path_1.join)(process.cwd(), config.destPath);
39
+ (0, fs_extra_1.removeSync)(destPath);
40
+ if (!(0, fs_extra_1.existsSync)(destPath))
41
+ (0, fs_extra_1.mkdirSync)(destPath, { recursive: true });
42
+ (0, fs_extra_1.copySync)((0, path_1.join)(tempPath, config.outDir), destPath, {
43
+ overwrite: true,
44
+ filter: (src) => {
45
+ if (src.startsWith('.git'))
46
+ return false;
47
+ if ((0, fs_extra_1.statSync)(src).isDirectory())
48
+ return true;
49
+ const regExp = new RegExp(eval(config.fileFilter));
50
+ if (regExp.test(src)) {
51
+ console.info(`copy ${src} to .${destPath.replace(process.cwd(), '')}`);
52
+ return true;
53
+ }
54
+ return false;
55
+ },
56
+ });
57
+ return true;
58
+ }));
59
+ }
60
+ //# sourceMappingURL=git.factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.factory.js","sourceRoot":"","sources":["../src/git.factory.ts"],"names":[],"mappings":"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"}
package/bin/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/bin/index.js ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const package_json_1 = require("../package.json");
6
+ const path_1 = require("path");
7
+ const fs_extra_1 = require("fs-extra");
8
+ const fs_1 = require("fs");
9
+ const git_factory_1 = require("./git.factory");
10
+ async function bootstrap() {
11
+ const program = new commander_1.Command();
12
+ program.version(package_json_1.version)
13
+ .name('Proto 助手')
14
+ .description('通过 Gitlab SSH 拉取 Proto 配置')
15
+ .option('-h, --help', '显示帮助信息')
16
+ .option('-p, --path <path>', '指定 Proto 配置文件路径', './proto.config.json')
17
+ .parse(process.argv);
18
+ const options = program.opts();
19
+ if (options.help) {
20
+ program.outputHelp();
21
+ process.exit(0);
22
+ }
23
+ const path = options.path || './proto.config.json';
24
+ const configPath = (0, path_1.join)(process.cwd(), path);
25
+ if (!(0, fs_extra_1.existsSync)(configPath)) {
26
+ throw new Error(`Proto 配置文件不存在: ${configPath}`);
27
+ }
28
+ const config = JSON.parse((0, fs_1.readFileSync)(configPath, 'utf-8'));
29
+ await (0, git_factory_1.gitFactory)(config);
30
+ return true;
31
+ }
32
+ bootstrap();
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,kDAA0C;AAC1C,+BAA4B;AAC5B,uCAAsC;AACtC,2BAAkC;AAClC,+CAA2C;AAE3C,KAAK,UAAU,SAAS;IACpB,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;IAE9B,OAAO,CAAC,OAAO,CAAC,sBAAO,CAAC;SACnB,IAAI,CAAC,UAAU,CAAC;SAChB,WAAW,CAAC,2BAA2B,CAAC;SACxC,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC;SAC9B,MAAM,CAAC,mBAAmB,EAAE,iBAAiB,EAAE,qBAAqB,CAAC;SACrE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,OAAO,CAAC,UAAU,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,qBAAqB,CAAC;IACnD,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;IAC7C,IAAI,CAAC,IAAA,qBAAU,EAAC,UAAU,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,kBAAkB,UAAU,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7D,MAAM,IAAA,wBAAU,EAAC,MAAM,CAAC,CAAC;IACzB,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ import * as ts from 'typescript';
2
+ import { GitImportOption } from './git.factory';
3
+ export interface GitImportPluginOptions {
4
+ transform: string;
5
+ type: string;
6
+ options: GitImportOption[];
7
+ }
8
+ export declare enum GitImportStatus {
9
+ Waiting = "waiting",
10
+ Pending = "pending",
11
+ Success = "success",
12
+ Failed = "failed"
13
+ }
14
+ export default function (program: ts.Program, { options }: GitImportPluginOptions): {
15
+ before: ((context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile)[];
16
+ };
17
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAc,eAAe,EAAE,MAAM,eAAe,CAAC;AAE5D,MAAM,WAAW,sBAAsB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,eAAe,EAAE,CAAC;CAC9B;AACD,oBAAY,eAAe;IACvB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;CACpB;AAKD,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,sBAAsB;uBAUlD,EAAE,CAAC,qBAAqB,MAEvC,YAAY,EAAE,CAAC,UAAU;EAOxC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitImportStatus = void 0;
4
+ exports.default = default_1;
5
+ const git_factory_1 = require("./git.factory");
6
+ var GitImportStatus;
7
+ (function (GitImportStatus) {
8
+ GitImportStatus["Waiting"] = "waiting";
9
+ GitImportStatus["Pending"] = "pending";
10
+ GitImportStatus["Success"] = "success";
11
+ GitImportStatus["Failed"] = "failed";
12
+ })(GitImportStatus || (exports.GitImportStatus = GitImportStatus = {}));
13
+ const buildStatus = {
14
+ id: new Date().toISOString().replace(/[:.]/g, '-'),
15
+ status: GitImportStatus.Waiting,
16
+ };
17
+ function default_1(program, { options }) {
18
+ if (buildStatus.status === GitImportStatus.Waiting) {
19
+ // console.log(111111, buildStatus, options);
20
+ buildStatus.status = GitImportStatus.Pending;
21
+ (0, git_factory_1.gitFactory)(options).then(() => {
22
+ buildStatus.status = GitImportStatus.Success;
23
+ }).catch(() => {
24
+ buildStatus.status = GitImportStatus.Failed;
25
+ });
26
+ }
27
+ function pullRepo(context) {
28
+ // console.log(2222);
29
+ return (sourceFile) => {
30
+ // console.log(3333, sourceFile.fileName);
31
+ // 转换逻辑
32
+ return sourceFile;
33
+ };
34
+ }
35
+ return { before: [pullRepo] };
36
+ }
37
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";;;AAkBA,4BAmBC;AApCD,+CAA4D;AAO5D,IAAY,eAKX;AALD,WAAY,eAAe;IACvB,sCAAmB,CAAA;IACnB,sCAAmB,CAAA;IACnB,sCAAmB,CAAA;IACnB,oCAAiB,CAAA;AACrB,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B;AACD,MAAM,WAAW,GAAG;IAChB,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;IAClD,MAAM,EAAE,eAAe,CAAC,OAAO;CAClC,CAAC;AACF,mBAAyB,OAAmB,EAAE,EAAE,OAAO,EAA0B;IAC7E,IAAI,WAAW,CAAC,MAAM,KAAK,eAAe,CAAC,OAAO,EAAE,CAAC;QACjD,6CAA6C;QAC7C,WAAW,CAAC,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC;QAC7C,IAAA,wBAAU,EAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YAC1B,WAAW,CAAC,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC;QACjD,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACV,WAAW,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;QAChD,CAAC,CAAC,CAAC;IACP,CAAC;IACD,SAAS,QAAQ,CAAC,OAAiC;QAC/C,qBAAqB;QACrB,OAAO,CAAC,UAAyB,EAAE,EAAE;YACjC,0CAA0C;YAC1C,OAAO;YACP,OAAO,UAAU,CAAC;QACtB,CAAC,CAAC;IACN,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;AAClC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "proto-update-tool",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "license": "ISC",
6
+ "author": "huaqingyi",
7
+ "type": "commonjs",
8
+ "main": "bin/index.js",
9
+ "bin": {
10
+ "proto-update-tool": "bin/index.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "build:linux-x64": "bun build --compile --minify-whitespace --minify-syntax --target bun-linux-x64 --outfile release/linux-x64 bin/index.js",
15
+ "build:linux-arm64": "bun build --compile --minify-whitespace --minify-syntax --target bun-linux-arm64 --outfile release/linux-arm64 bin/index.js",
16
+ "build:windows-x64": "bun build --compile --minify-whitespace --minify-syntax --target bun-windows-x64 --outfile release/windows-x64 bin/index.js",
17
+ "build:darwin-x64": "bun build --compile --minify-whitespace --minify-syntax --target bun-darwin-x64 --outfile release/darwin-x64 bin/index.js",
18
+ "build:darwin-arm64": "bun build --compile --minify-whitespace --minify-syntax --target bun-darwin-arm64 --outfile release/darwin-arm64 bin/index.js",
19
+ "build:linux-x64-musl": "bun build --compile --minify-whitespace --minify-syntax --target bun-linux-x64-musl --outfile release/linux-x64-musl bin/index.js",
20
+ "build:linux-arm64-musl": "bun build --compile --minify-whitespace --minify-syntax --target bun-linux-arm64-musl --outfile release/linux-arm64-musl bin/index.js",
21
+ "release": "npm run build:linux-x64 && npm run build:linux-arm64 && npm run build:windows-x64 && npm run build:darwin-x64 && npm run build:darwin-arm64 && npm run build:linux-x64-musl && npm run build:linux-arm64-musl"
22
+ },
23
+ "dependencies": {
24
+ "commander": "^14.0.2",
25
+ "fs-extra": "^11.3.3",
26
+ "simple-git": "^3.30.0",
27
+ "typescript": "^5.9.3"
28
+ },
29
+ "devDependencies": {
30
+ "@types/fs-extra": "^11.0.4"
31
+ }
32
+ }
@@ -0,0 +1,58 @@
1
+ import { copySync, existsSync, mkdirSync, removeSync, statSync } from 'fs-extra';
2
+ import { homedir } from 'os';
3
+ import { join } from 'path';
4
+ import simpleGit from 'simple-git';
5
+
6
+ export interface GitImportOption {
7
+ repository: string;
8
+ ref: string;
9
+ outDir: string;
10
+ fileFilter: string;
11
+ destPath: string;
12
+ }
13
+
14
+ export async function gitFactory(options: GitImportOption[]) {
15
+ const tempDir = join(homedir(), '.proto-import-cache');
16
+ // console.log('tempDir:', tempDir);
17
+ if (!existsSync(tempDir)) mkdirSync(tempDir, { recursive: true });
18
+ await Promise.all(options.map(async (config) => {
19
+ const path = join(__dirname, '..', config.destPath);
20
+ if (!existsSync(path)) {
21
+ mkdirSync(path, { recursive: true });
22
+ }
23
+ const tempPath = join(tempDir, config.repository);
24
+ let isCloned = false;
25
+ if (!existsSync(tempPath)) {
26
+ mkdirSync(tempPath, { recursive: true });
27
+ isCloned = true;
28
+ }
29
+ const git = simpleGit(tempPath);
30
+ if (isCloned) {
31
+ await git.clone(config.repository, tempPath);
32
+ }
33
+ await git.fetch(tempPath, 'origin', ['--tags']);
34
+ const tags = await git.tags();
35
+ console.log('可用 tags:', tags.all);
36
+ if (!tags.all.includes(config.ref)) {
37
+ throw new Error(`tag ${config.ref} not found`);
38
+ }
39
+ await git.checkout(config.ref);
40
+ const destPath = join(process.cwd(), config.destPath);
41
+ removeSync(destPath);
42
+ if (!existsSync(destPath)) mkdirSync(destPath, { recursive: true })
43
+ copySync(join(tempPath, config.outDir), destPath, {
44
+ overwrite: true,
45
+ filter: (src) => {
46
+ if (src.startsWith('.git')) return false;
47
+ if (statSync(src).isDirectory()) return true;
48
+ const regExp = new RegExp(eval(config.fileFilter));
49
+ if (regExp.test(src)) {
50
+ console.info(`copy ${src} to .${destPath.replace(process.cwd(), '')}`);
51
+ return true;
52
+ }
53
+ return false;
54
+ },
55
+ });
56
+ return true;
57
+ }));
58
+ }
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander";
4
+ import { version } from '../package.json';
5
+ import { join } from 'path';
6
+ import { existsSync } from "fs-extra";
7
+ import { readFileSync } from "fs";
8
+ import { gitFactory } from "./git.factory";
9
+
10
+ async function bootstrap() {
11
+ const program = new Command();
12
+
13
+ program.version(version)
14
+ .name('Proto 助手')
15
+ .description('通过 Gitlab SSH 拉取 Proto 配置')
16
+ .option('-h, --help', '显示帮助信息')
17
+ .option('-p, --path <path>', '指定 Proto 配置文件路径', './proto.config.json')
18
+ .parse(process.argv);
19
+
20
+ const options = program.opts();
21
+ if (options.help) {
22
+ program.outputHelp();
23
+ process.exit(0);
24
+ }
25
+ const path = options.path || './proto.config.json';
26
+ const configPath = join(process.cwd(), path);
27
+ if (!existsSync(configPath)) {
28
+ throw new Error(`Proto 配置文件不存在: ${configPath}`);
29
+ }
30
+ const config = JSON.parse(readFileSync(configPath, 'utf-8'));
31
+ await gitFactory(config);
32
+ return true;
33
+ }
34
+
35
+ bootstrap();
@@ -0,0 +1,38 @@
1
+ import * as ts from 'typescript';
2
+ import { gitFactory, GitImportOption } from './git.factory';
3
+
4
+ export interface GitImportPluginOptions {
5
+ transform: string;
6
+ type: string;
7
+ options: GitImportOption[];
8
+ }
9
+ export enum GitImportStatus {
10
+ Waiting = 'waiting',
11
+ Pending = 'pending',
12
+ Success = 'success',
13
+ Failed = 'failed',
14
+ }
15
+ const buildStatus = {
16
+ id: new Date().toISOString().replace(/[:.]/g, '-'),
17
+ status: GitImportStatus.Waiting,
18
+ };
19
+ export default function (program: ts.Program, { options }: GitImportPluginOptions) {
20
+ if (buildStatus.status === GitImportStatus.Waiting) {
21
+ // console.log(111111, buildStatus, options);
22
+ buildStatus.status = GitImportStatus.Pending;
23
+ gitFactory(options).then(() => {
24
+ buildStatus.status = GitImportStatus.Success;
25
+ }).catch(() => {
26
+ buildStatus.status = GitImportStatus.Failed;
27
+ });
28
+ }
29
+ function pullRepo(context: ts.TransformationContext) {
30
+ // console.log(2222);
31
+ return (sourceFile: ts.SourceFile) => {
32
+ // console.log(3333, sourceFile.fileName);
33
+ // 转换逻辑
34
+ return sourceFile;
35
+ };
36
+ }
37
+ return { before: [pullRepo] };
38
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ // Visit https://aka.ms/tsconfig to read more about this file
3
+ "compilerOptions": {
4
+ // File Layout
5
+ "rootDir": "./src",
6
+ "outDir": "./bin",
7
+
8
+ // Environment Settings
9
+ // See also https://aka.ms/tsconfig/module
10
+ "module": "nodenext",
11
+ "target": "esnext",
12
+ "types": [],
13
+ // For nodejs:
14
+ // "lib": ["esnext"],
15
+ // "types": ["node"],
16
+ // and npm install -D @types/node
17
+
18
+ // Other Outputs
19
+ "sourceMap": true,
20
+ "declaration": true,
21
+ "declarationMap": true,
22
+
23
+ // Stricter Typechecking Options
24
+ "noUncheckedIndexedAccess": true,
25
+ "exactOptionalPropertyTypes": true,
26
+
27
+ // Style Options
28
+ // "noImplicitReturns": true,
29
+ // "noImplicitOverride": true,
30
+ // "noUnusedLocals": true,
31
+ // "noUnusedParameters": true,
32
+ // "noFallthroughCasesInSwitch": true,
33
+ // "noPropertyAccessFromIndexSignature": true,
34
+
35
+ // Recommended Options
36
+ "strict": true,
37
+ "jsx": "react-jsx",
38
+ "verbatimModuleSyntax": false,
39
+ "isolatedModules": true,
40
+ "noUncheckedSideEffectImports": true,
41
+ "moduleDetection": "force",
42
+ "skipLibCheck": true,
43
+ "resolveJsonModule": true,
44
+ }
45
+ }