@my-devkit/cli 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/dist/clean.d.ts +2 -0
- package/dist/clean.js +97 -0
- package/dist/clean.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +88 -0
- package/dist/index.js.map +1 -0
- package/package.json +29 -0
- package/src/clean.ts +66 -0
- package/src/index.ts +40 -0
- package/tsconfig.json +20 -0
package/dist/clean.d.ts
ADDED
package/dist/clean.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var fs = require("fs");
|
|
40
|
+
var path = require("path");
|
|
41
|
+
var clean = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
+
var tsConfig, config, outDir, baseUrl, cleanDirectory;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
if (!fs.existsSync('./tsconfig.json')) {
|
|
45
|
+
throw new Error("tsconfig.json file not found");
|
|
46
|
+
}
|
|
47
|
+
tsConfig = fs.readFileSync('./tsconfig.json', { encoding: 'utf-8' });
|
|
48
|
+
config = JSON.parse(tsConfig);
|
|
49
|
+
outDir = config.compilerOptions.outDir.replace('./', '');
|
|
50
|
+
baseUrl = config.compilerOptions.baseUrl;
|
|
51
|
+
if (!fs.existsSync(baseUrl) || !fs.lstatSync(baseUrl).isDirectory()) {
|
|
52
|
+
throw new Error("".concat(baseUrl, " is not a directory"));
|
|
53
|
+
}
|
|
54
|
+
if (!fs.existsSync(outDir)) {
|
|
55
|
+
console.warn("No build detected ".concat(outDir, "..."));
|
|
56
|
+
return [2 /*return*/];
|
|
57
|
+
}
|
|
58
|
+
cleanDirectory = function (dirPath) {
|
|
59
|
+
// Get and read the files in the directory
|
|
60
|
+
var files = fs.readdirSync(dirPath);
|
|
61
|
+
files.forEach(function (file) {
|
|
62
|
+
var filePath = path.join(dirPath, file);
|
|
63
|
+
// Check if this file is a directory or not, and if it is; recurse
|
|
64
|
+
if (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory()) {
|
|
65
|
+
cleanDirectory(filePath);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// Otherwise, check if it is a ts dist file
|
|
69
|
+
var match = filePath.match(/^(.*)\.js$/);
|
|
70
|
+
if (match) {
|
|
71
|
+
var extLess = match[1].substring(0, match[1].length);
|
|
72
|
+
var relPath = extLess.substring(outDir.length);
|
|
73
|
+
var srcPath = path.join(baseUrl, relPath);
|
|
74
|
+
// Check if there is either a ts, d.ts or tsx file corresponding to this d.ts files
|
|
75
|
+
if (!(fs.existsSync(srcPath + ".d.ts") ||
|
|
76
|
+
fs.existsSync(srcPath + ".ts") ||
|
|
77
|
+
fs.existsSync(srcPath + ".tsx"))) {
|
|
78
|
+
if (fs.existsSync(extLess + ".js"))
|
|
79
|
+
fs.unlinkSync(extLess + ".js");
|
|
80
|
+
if (fs.existsSync(extLess + ".js.map"))
|
|
81
|
+
fs.unlinkSync(extLess + ".js.map");
|
|
82
|
+
if (fs.existsSync(extLess + ".d.ts"))
|
|
83
|
+
fs.unlinkSync(extLess + ".d.ts");
|
|
84
|
+
if (fs.existsSync(extLess + ".d.ts.map"))
|
|
85
|
+
fs.unlinkSync(extLess + ".d.ts.map");
|
|
86
|
+
console.log("Build cleaner: removed ".concat(extLess));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
cleanDirectory(outDir);
|
|
93
|
+
return [2 /*return*/];
|
|
94
|
+
});
|
|
95
|
+
}); };
|
|
96
|
+
exports.default = clean;
|
|
97
|
+
//# sourceMappingURL=clean.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../src/clean.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAyB;AACzB,2BAA6B;AAE7B,IAAM,KAAK,GAAG;;;QACV,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE;YACnC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;SAClD;QACK,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,iBAAiB,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACrE,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC9B,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACzD,OAAO,GAAG,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC;QAE/C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;YACjE,MAAM,IAAI,KAAK,CAAC,UAAG,OAAO,wBAAqB,CAAC,CAAC;SACpD;QAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;YACxB,OAAO,CAAC,IAAI,CAAC,4BAAqB,MAAM,QAAK,CAAC,CAAC;YAC/C,sBAAO;SACV;QAEK,cAAc,GAAG,UA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AG,SAAS,CAAC,CAAC;4BACvC,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;gCAChC,EAAE,CAAC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC;4BACrC,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,GAAG,WAAW,CAAC;gCACpC,EAAE,CAAC,UAAU,CAAC,OAAO,GAAG,WAAW,CAAC,CAAC;4BAEzC,OAAO,CAAC,GAAG,CAAC,iCAA0B,OAAO,CAAE,CAAC,CAAC;yBACpD;qBACJ;iBACJ;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QAEF,cAAc,CAAC,MAAM,CAAC,CAAC;;;KAC1B,CAAC;AAEF,kBAAe,KAAK,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
14
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
+
function step(op) {
|
|
17
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
+
while (_) try {
|
|
19
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
20
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
+
switch (op[0]) {
|
|
22
|
+
case 0: case 1: t = op; break;
|
|
23
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
+
default:
|
|
27
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
+
if (t[2]) _.ops.pop();
|
|
32
|
+
_.trys.pop(); continue;
|
|
33
|
+
}
|
|
34
|
+
op = body.call(thisArg, _);
|
|
35
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
var child_process_1 = require("child_process");
|
|
41
|
+
var clean_1 = require("./clean");
|
|
42
|
+
var run = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
+
var _a, args, _b;
|
|
44
|
+
return __generator(this, function (_c) {
|
|
45
|
+
switch (_c.label) {
|
|
46
|
+
case 0:
|
|
47
|
+
_a = process.argv, args = _a.slice(2);
|
|
48
|
+
if (!args[0]) {
|
|
49
|
+
throw new Error("Please define the command to run");
|
|
50
|
+
}
|
|
51
|
+
_b = args[0];
|
|
52
|
+
switch (_b) {
|
|
53
|
+
case 'build': return [3 /*break*/, 1];
|
|
54
|
+
case 'watch': return [3 /*break*/, 3];
|
|
55
|
+
case 'publish-package': return [3 /*break*/, 5];
|
|
56
|
+
}
|
|
57
|
+
return [3 /*break*/, 6];
|
|
58
|
+
case 1:
|
|
59
|
+
console.log("Running clean & build");
|
|
60
|
+
return [4 /*yield*/, (0, clean_1.default)()];
|
|
61
|
+
case 2:
|
|
62
|
+
_c.sent();
|
|
63
|
+
(0, child_process_1.execSync)("npx tsc");
|
|
64
|
+
return [3 /*break*/, 7];
|
|
65
|
+
case 3:
|
|
66
|
+
console.log("Running clean & build in watch mode");
|
|
67
|
+
return [4 /*yield*/, (0, clean_1.default)()];
|
|
68
|
+
case 4:
|
|
69
|
+
_c.sent();
|
|
70
|
+
(0, child_process_1.execSync)("npx tsc -w");
|
|
71
|
+
return [3 /*break*/, 7];
|
|
72
|
+
case 5:
|
|
73
|
+
console.log("Publishing package");
|
|
74
|
+
return [3 /*break*/, 7];
|
|
75
|
+
case 6: throw new Error("Command ".concat(args[0], " not recognized!"));
|
|
76
|
+
case 7: return [2 /*return*/];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}); };
|
|
80
|
+
run().catch(function (e) {
|
|
81
|
+
if (e.message) {
|
|
82
|
+
console.error(e.message);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.error(e);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAyC;AAEzC,iCAA4B;AAE5B,IAAM,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
"main": "dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mdk": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "Jean-Guy BUON",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/BUONJG/my-devkit.git"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "node ./dist/index.js build",
|
|
19
|
+
"watch": "node ./dist/index.js watch",
|
|
20
|
+
"preinstall": "npx only-allow pnpm"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {},
|
|
23
|
+
"peerDependencies": {},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^14.14.19",
|
|
26
|
+
"eslint": "7.26.0",
|
|
27
|
+
"typescript": "^4.5.2"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/clean.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
const clean = async () => {
|
|
5
|
+
if (!fs.existsSync('./tsconfig.json')) {
|
|
6
|
+
throw new Error(`tsconfig.json file not found`)
|
|
7
|
+
}
|
|
8
|
+
const tsConfig = fs.readFileSync('./tsconfig.json', { encoding: 'utf-8' });
|
|
9
|
+
const config = JSON.parse(tsConfig);
|
|
10
|
+
const outDir = config.compilerOptions.outDir.replace('./', '');
|
|
11
|
+
const baseUrl = config.compilerOptions.baseUrl;
|
|
12
|
+
|
|
13
|
+
if (!fs.existsSync(baseUrl) || !fs.lstatSync(baseUrl).isDirectory()) {
|
|
14
|
+
throw new Error(`${baseUrl} is not a directory`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(outDir)) {
|
|
18
|
+
console.warn(`No build detected ${outDir}...`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const cleanDirectory = (dirPath: string) => {
|
|
23
|
+
// Get and read the files in the directory
|
|
24
|
+
const files = fs.readdirSync(dirPath);
|
|
25
|
+
files.forEach(file => {
|
|
26
|
+
const filePath = path.join(dirPath, file);
|
|
27
|
+
|
|
28
|
+
// Check if this file is a directory or not, and if it is; recurse
|
|
29
|
+
if (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory()) {
|
|
30
|
+
cleanDirectory(filePath);
|
|
31
|
+
} else {
|
|
32
|
+
// Otherwise, check if it is a ts dist file
|
|
33
|
+
const match = filePath.match(/^(.*)\.js$/);
|
|
34
|
+
if (match) {
|
|
35
|
+
const extLess = match[1].substring(0, match[1].length);
|
|
36
|
+
const relPath = extLess.substring(outDir.length);
|
|
37
|
+
const srcPath = path.join(baseUrl, relPath);
|
|
38
|
+
|
|
39
|
+
// Check if there is either a ts, d.ts or tsx file corresponding to this d.ts files
|
|
40
|
+
if (
|
|
41
|
+
!(
|
|
42
|
+
fs.existsSync(srcPath + ".d.ts") ||
|
|
43
|
+
fs.existsSync(srcPath + ".ts") ||
|
|
44
|
+
fs.existsSync(srcPath + ".tsx")
|
|
45
|
+
)
|
|
46
|
+
) {
|
|
47
|
+
if (fs.existsSync(extLess + ".js"))
|
|
48
|
+
fs.unlinkSync(extLess + ".js");
|
|
49
|
+
if (fs.existsSync(extLess + ".js.map"))
|
|
50
|
+
fs.unlinkSync(extLess + ".js.map");
|
|
51
|
+
if (fs.existsSync(extLess + ".d.ts"))
|
|
52
|
+
fs.unlinkSync(extLess + ".d.ts");
|
|
53
|
+
if (fs.existsSync(extLess + ".d.ts.map"))
|
|
54
|
+
fs.unlinkSync(extLess + ".d.ts.map");
|
|
55
|
+
|
|
56
|
+
console.log(`Build cleaner: removed ${extLess}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
cleanDirectory(outDir);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default clean;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from 'child_process';
|
|
3
|
+
|
|
4
|
+
import clean from './clean';
|
|
5
|
+
|
|
6
|
+
const run = async () => {
|
|
7
|
+
const [, , ...args] = process.argv;
|
|
8
|
+
|
|
9
|
+
if (!args[0]) {
|
|
10
|
+
throw new Error(`Please define the command to run`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
switch (args[0]) {
|
|
14
|
+
case 'build':
|
|
15
|
+
console.log(`Running clean & build`);
|
|
16
|
+
await clean();
|
|
17
|
+
execSync(`npx tsc`);
|
|
18
|
+
break;
|
|
19
|
+
case 'watch':
|
|
20
|
+
console.log(`Running clean & build in watch mode`);
|
|
21
|
+
await clean();
|
|
22
|
+
execSync(`npx tsc -w`);
|
|
23
|
+
break;
|
|
24
|
+
|
|
25
|
+
case 'publish-package':
|
|
26
|
+
console.log(`Publishing package`);
|
|
27
|
+
break;
|
|
28
|
+
|
|
29
|
+
default:
|
|
30
|
+
throw new Error(`Command ${args[0]} not recognized!`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
run().catch(e => {
|
|
35
|
+
if (e.message) {
|
|
36
|
+
console.error(e.message);
|
|
37
|
+
} else {
|
|
38
|
+
console.error(e)
|
|
39
|
+
}
|
|
40
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": false,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"lib": [
|
|
6
|
+
"es2016",
|
|
7
|
+
"dom"
|
|
8
|
+
],
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"baseUrl": "src",
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"emitDecoratorMetadata": true,
|
|
15
|
+
"experimentalDecorators": true,
|
|
16
|
+
"typeRoots": [
|
|
17
|
+
"node_modules/@types"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|