@ts-dev-tools/core 1.5.10 → 1.5.14
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/bin.d.ts +2 -0
- package/dist/bin.js +82 -0
- package/dist/install/command.d.ts +4 -0
- package/dist/install/command.js +74 -0
- package/dist/install/migrations/20201024173398-init.d.ts +2 -0
- package/dist/install/migrations/20201024173398-init.js +144 -0
- package/dist/services/CmdService.d.ts +3 -0
- package/dist/services/CmdService.js +56 -0
- package/dist/services/DuplicateDependenciesService.d.ts +6 -0
- package/dist/services/DuplicateDependenciesService.js +54 -0
- package/dist/services/GitService.d.ts +7 -0
- package/dist/services/GitService.js +89 -0
- package/dist/services/MigrationsService.d.ts +10 -0
- package/dist/services/MigrationsService.js +132 -0
- package/dist/services/PackageJson.d.ts +28 -0
- package/dist/services/PackageJson.js +99 -0
- package/dist/services/PackageJsonMerge.d.ts +8 -0
- package/dist/services/PackageJsonMerge.js +50 -0
- package/dist/services/PackageManagerService.d.ts +7 -0
- package/dist/services/PackageManagerService.js +22 -0
- package/dist/tests/console.d.ts +3 -0
- package/dist/tests/console.js +18 -0
- package/dist/tests/utils.d.ts +5 -0
- package/dist/tests/utils.js +69 -0
- package/package.json +11 -11
package/dist/bin.d.ts
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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 path_1 = require("path");
|
|
41
|
+
var command_1 = require("./install/command");
|
|
42
|
+
var PackageJson_1 = require("./services/PackageJson");
|
|
43
|
+
function bin() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
var _a, arg, params, _b;
|
|
46
|
+
return __generator(this, function (_c) {
|
|
47
|
+
switch (_c.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
_a = process.argv, arg = _a[2], params = _a.slice(3);
|
|
50
|
+
_b = true;
|
|
51
|
+
switch (_b) {
|
|
52
|
+
case arg === "install": return [3 /*break*/, 1];
|
|
53
|
+
case ["--version", "-v"].includes(arg): return [3 /*break*/, 3];
|
|
54
|
+
}
|
|
55
|
+
return [3 /*break*/, 4];
|
|
56
|
+
case 1:
|
|
57
|
+
// Check if script is not run by the package himself
|
|
58
|
+
if (process.cwd() === (0, path_1.dirname)(__dirname)) {
|
|
59
|
+
console.info("Do not install itself!");
|
|
60
|
+
return [3 /*break*/, 5];
|
|
61
|
+
}
|
|
62
|
+
return [4 /*yield*/, (0, command_1.install)({
|
|
63
|
+
cwd: process.cwd(),
|
|
64
|
+
dir: params[0],
|
|
65
|
+
})];
|
|
66
|
+
case 2:
|
|
67
|
+
_c.sent();
|
|
68
|
+
return [3 /*break*/, 5];
|
|
69
|
+
case 3:
|
|
70
|
+
console.info(PackageJson_1.PackageJson.fromDirPath((0, path_1.join)(__dirname, "..")).getPackageVersion());
|
|
71
|
+
return [3 /*break*/, 5];
|
|
72
|
+
case 4:
|
|
73
|
+
console.info("Usage\n ts-dev-tools install [path from project root]\n ");
|
|
74
|
+
_c.label = 5;
|
|
75
|
+
case 5: return [2 /*return*/];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
bin()
|
|
81
|
+
.then()
|
|
82
|
+
.catch(function (error) { return console.error(error); });
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
exports.install = void 0;
|
|
40
|
+
var path_1 = require("path");
|
|
41
|
+
var DuplicateDependenciesService_1 = require("../services/DuplicateDependenciesService");
|
|
42
|
+
var MigrationsService_1 = require("../services/MigrationsService");
|
|
43
|
+
var PackageJson_1 = require("../services/PackageJson");
|
|
44
|
+
function install(_a) {
|
|
45
|
+
var cwd = _a.cwd, _b = _a.dir, dir = _b === void 0 ? "." : _b;
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
var tsDevToolsRootPath, packageName, absoluteProjectDir, currentVersion;
|
|
48
|
+
return __generator(this, function (_c) {
|
|
49
|
+
switch (_c.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
tsDevToolsRootPath = (0, path_1.resolve)(__dirname, "../..");
|
|
52
|
+
packageName = PackageJson_1.PackageJson.fromDirPath(tsDevToolsRootPath).getPackageName();
|
|
53
|
+
absoluteProjectDir = (0, path_1.resolve)(cwd, dir);
|
|
54
|
+
if (!absoluteProjectDir.startsWith(cwd)) {
|
|
55
|
+
throw new Error(".. not allowed");
|
|
56
|
+
}
|
|
57
|
+
currentVersion = PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir).getTsDevToolsVersion();
|
|
58
|
+
if (currentVersion) {
|
|
59
|
+
console.info("Updating ".concat(packageName, " installation..."));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.info("Installing ".concat(packageName, "..."));
|
|
63
|
+
}
|
|
64
|
+
return [4 /*yield*/, MigrationsService_1.MigrationsService.executeMigrations(tsDevToolsRootPath, absoluteProjectDir, currentVersion)];
|
|
65
|
+
case 1:
|
|
66
|
+
_c.sent();
|
|
67
|
+
DuplicateDependenciesService_1.DuplicateDependenciesService.duplicateDependencies(tsDevToolsRootPath, absoluteProjectDir);
|
|
68
|
+
console.info("Installation done!");
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
exports.install = install;
|
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
exports.up = void 0;
|
|
40
|
+
var GitService_1 = require("../../services/GitService");
|
|
41
|
+
var PackageJson_1 = require("../../services/PackageJson");
|
|
42
|
+
var PackageManagerService_1 = require("../../services/PackageManagerService");
|
|
43
|
+
var up = function (absoluteProjectDir) { return __awaiter(void 0, void 0, void 0, function () {
|
|
44
|
+
var jest, eslintConfig, prettier, commitlint, lintStaged, importSort, scripts, packageJson, isGitRepository, packageManager, gitHooks, _i, _a, gitHookName, gitHookCommand;
|
|
45
|
+
return __generator(this, function (_b) {
|
|
46
|
+
switch (_b.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
jest = {
|
|
49
|
+
preset: "ts-jest",
|
|
50
|
+
testEnvironment: "node",
|
|
51
|
+
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).+(ts|tsx|js)"],
|
|
52
|
+
};
|
|
53
|
+
eslintConfig = {
|
|
54
|
+
root: true,
|
|
55
|
+
parser: "@typescript-eslint/parser",
|
|
56
|
+
plugins: ["@typescript-eslint", "jest"],
|
|
57
|
+
extends: [
|
|
58
|
+
"eslint:recommended",
|
|
59
|
+
"plugin:@typescript-eslint/recommended",
|
|
60
|
+
"plugin:jest/recommended",
|
|
61
|
+
"prettier",
|
|
62
|
+
],
|
|
63
|
+
env: {
|
|
64
|
+
es2021: true,
|
|
65
|
+
},
|
|
66
|
+
parserOptions: {
|
|
67
|
+
ecmaFeatures: {
|
|
68
|
+
jsx: true,
|
|
69
|
+
},
|
|
70
|
+
ecmaVersion: 12,
|
|
71
|
+
sourceType: "module",
|
|
72
|
+
},
|
|
73
|
+
settings: {
|
|
74
|
+
jest: {
|
|
75
|
+
version: "detect",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
prettier = {
|
|
80
|
+
semi: true,
|
|
81
|
+
printWidth: 100,
|
|
82
|
+
trailingComma: "es5",
|
|
83
|
+
};
|
|
84
|
+
commitlint = {
|
|
85
|
+
extends: ["@commitlint/config-conventional"],
|
|
86
|
+
};
|
|
87
|
+
lintStaged = {
|
|
88
|
+
"*.{js,ts,tsx}": ["eslint --fix"],
|
|
89
|
+
};
|
|
90
|
+
importSort = {
|
|
91
|
+
".js, .jsx, .ts, .tsx": {
|
|
92
|
+
style: "module",
|
|
93
|
+
parser: "typescript",
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
scripts = {
|
|
97
|
+
build: "tsc --noEmit",
|
|
98
|
+
format: "prettier --write '**/*.js'",
|
|
99
|
+
lint: 'eslint "src/**/*.{ts,tsx}"',
|
|
100
|
+
jest: "jest --detectOpenHandles --forceExit",
|
|
101
|
+
test: "yarn jest --maxWorkers=50%",
|
|
102
|
+
"test:watch": "yarn jest --watch --maxWorkers=25%",
|
|
103
|
+
"test:cov": "yarn jest --coverage",
|
|
104
|
+
"test:ci": "yarn test:cov --runInBand",
|
|
105
|
+
prepare: "ts-dev-tools install",
|
|
106
|
+
};
|
|
107
|
+
packageJson = PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir);
|
|
108
|
+
packageJson.merge({
|
|
109
|
+
eslintConfig: eslintConfig,
|
|
110
|
+
prettier: prettier,
|
|
111
|
+
commitlint: commitlint,
|
|
112
|
+
"lint-staged": lintStaged,
|
|
113
|
+
importSort: importSort,
|
|
114
|
+
scripts: scripts,
|
|
115
|
+
jest: jest,
|
|
116
|
+
});
|
|
117
|
+
return [4 /*yield*/, GitService_1.GitService.isGitRepository(absoluteProjectDir)];
|
|
118
|
+
case 1:
|
|
119
|
+
isGitRepository = _b.sent();
|
|
120
|
+
if (!isGitRepository) return [3 /*break*/, 5];
|
|
121
|
+
packageManager = PackageManagerService_1.PackageManagerService.detectPackageManager(absoluteProjectDir);
|
|
122
|
+
gitHooks = {
|
|
123
|
+
"pre-commit": "npx --no-install lint-staged && npx --no-install pretty-quick --staged",
|
|
124
|
+
"commit-msg": "npx --no-install commitlint --edit $1",
|
|
125
|
+
"pre-push": "".concat(packageManager, " run lint && ").concat(packageManager, " run build && ").concat(packageManager, " run test"),
|
|
126
|
+
};
|
|
127
|
+
_i = 0, _a = Object.keys(gitHooks);
|
|
128
|
+
_b.label = 2;
|
|
129
|
+
case 2:
|
|
130
|
+
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
131
|
+
gitHookName = _a[_i];
|
|
132
|
+
gitHookCommand = gitHooks[gitHookName];
|
|
133
|
+
return [4 /*yield*/, GitService_1.GitService.addGitHook(absoluteProjectDir, gitHookName, gitHookCommand)];
|
|
134
|
+
case 3:
|
|
135
|
+
_b.sent();
|
|
136
|
+
_b.label = 4;
|
|
137
|
+
case 4:
|
|
138
|
+
_i++;
|
|
139
|
+
return [3 /*break*/, 2];
|
|
140
|
+
case 5: return [2 /*return*/];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}); };
|
|
144
|
+
exports.up = up;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CmdService = void 0;
|
|
4
|
+
var child_process_1 = require("child_process");
|
|
5
|
+
var fs_1 = require("fs");
|
|
6
|
+
var CmdService = /** @class */ (function () {
|
|
7
|
+
function CmdService() {
|
|
8
|
+
}
|
|
9
|
+
CmdService.execCmd = function (args, cwd, silent) {
|
|
10
|
+
if (silent === void 0) { silent = false; }
|
|
11
|
+
if (!args.length) {
|
|
12
|
+
throw new Error("Command args must not be empty");
|
|
13
|
+
}
|
|
14
|
+
if (cwd) {
|
|
15
|
+
if (!(0, fs_1.existsSync)(cwd) || !(0, fs_1.statSync)(cwd).isDirectory()) {
|
|
16
|
+
throw new Error("Directory \"".concat(cwd, "\" does not exist"));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
var cmd;
|
|
20
|
+
if (Array.isArray(args)) {
|
|
21
|
+
cmd = args.shift() || "";
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
cmd = args;
|
|
25
|
+
args = [];
|
|
26
|
+
}
|
|
27
|
+
return new Promise(function (resolve, reject) {
|
|
28
|
+
var child = (0, child_process_1.spawn)(cmd, args, {
|
|
29
|
+
stdio: silent ? "pipe" : "inherit",
|
|
30
|
+
shell: true,
|
|
31
|
+
windowsVerbatimArguments: true,
|
|
32
|
+
cwd: cwd,
|
|
33
|
+
});
|
|
34
|
+
var output = "";
|
|
35
|
+
var error = "";
|
|
36
|
+
child.on("exit", function (code) {
|
|
37
|
+
if (code) {
|
|
38
|
+
return reject(error);
|
|
39
|
+
}
|
|
40
|
+
resolve(output);
|
|
41
|
+
});
|
|
42
|
+
if (child.stdout) {
|
|
43
|
+
child.stdout.on("data", function (data) {
|
|
44
|
+
output += "\n".concat(data);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (child.stderr) {
|
|
48
|
+
child.stderr.on("data", function (data) {
|
|
49
|
+
error += "\n".concat(data);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
return CmdService;
|
|
55
|
+
}());
|
|
56
|
+
exports.CmdService = CmdService;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class DuplicateDependenciesService {
|
|
2
|
+
static duplicateDependencies(tsDevToolsRootPath: string, absoluteProjectDir: string): void;
|
|
3
|
+
private static getProjectDuplicateDependencies;
|
|
4
|
+
private static getPluginDuplicateDependencies;
|
|
5
|
+
private static printDuplicateDependencies;
|
|
6
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DuplicateDependenciesService = void 0;
|
|
4
|
+
var path_1 = require("path");
|
|
5
|
+
var PackageJson_1 = require("./PackageJson");
|
|
6
|
+
var DuplicateDependenciesService = /** @class */ (function () {
|
|
7
|
+
function DuplicateDependenciesService() {
|
|
8
|
+
}
|
|
9
|
+
DuplicateDependenciesService.duplicateDependencies = function (tsDevToolsRootPath, absoluteProjectDir) {
|
|
10
|
+
console.info("Checking for duplicate dev dependencies...");
|
|
11
|
+
var duplicateDependencies = new Map();
|
|
12
|
+
DuplicateDependenciesService.getProjectDuplicateDependencies(tsDevToolsRootPath, absoluteProjectDir, duplicateDependencies);
|
|
13
|
+
DuplicateDependenciesService.printDuplicateDependencies(duplicateDependencies);
|
|
14
|
+
console.info("Check for duplicate dev dependencies done!");
|
|
15
|
+
};
|
|
16
|
+
DuplicateDependenciesService.getProjectDuplicateDependencies = function (tsDevToolsRootPath, absoluteProjectDir, duplicateDependencies) {
|
|
17
|
+
var projectPackageJson = PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir);
|
|
18
|
+
var installedPlugins = projectPackageJson.getInstalledPlugins();
|
|
19
|
+
var projectDevDependencies = projectPackageJson.getDevDependenciesPackageNames();
|
|
20
|
+
for (var _i = 0, installedPlugins_1 = installedPlugins; _i < installedPlugins_1.length; _i++) {
|
|
21
|
+
var plugin = installedPlugins_1[_i];
|
|
22
|
+
DuplicateDependenciesService.getPluginDuplicateDependencies(tsDevToolsRootPath, plugin, projectDevDependencies, duplicateDependencies);
|
|
23
|
+
}
|
|
24
|
+
return duplicateDependencies;
|
|
25
|
+
};
|
|
26
|
+
DuplicateDependenciesService.getPluginDuplicateDependencies = function (tsDevToolsRootPath, plugin, projectDevDependencies, duplicateDependencies) {
|
|
27
|
+
var absolutePluginDir = (0, path_1.resolve)(tsDevToolsRootPath, "../../", plugin);
|
|
28
|
+
// First check for duplicate of inherited plugins
|
|
29
|
+
DuplicateDependenciesService.getProjectDuplicateDependencies(tsDevToolsRootPath, absolutePluginDir, duplicateDependencies);
|
|
30
|
+
var pluginPackageJson = PackageJson_1.PackageJson.fromDirPath(absolutePluginDir);
|
|
31
|
+
var pluginDependencies = pluginPackageJson.getDependenciesPackageNames();
|
|
32
|
+
var pluginDuplicateDependencies = duplicateDependencies.get(plugin);
|
|
33
|
+
if (!pluginDuplicateDependencies) {
|
|
34
|
+
pluginDuplicateDependencies = new Set();
|
|
35
|
+
duplicateDependencies.set(plugin, pluginDuplicateDependencies);
|
|
36
|
+
}
|
|
37
|
+
for (var _i = 0, projectDevDependencies_1 = projectDevDependencies; _i < projectDevDependencies_1.length; _i++) {
|
|
38
|
+
var projectDevDependency = projectDevDependencies_1[_i];
|
|
39
|
+
if (pluginDependencies.includes(projectDevDependency)) {
|
|
40
|
+
pluginDuplicateDependencies.add(projectDevDependency);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
DuplicateDependenciesService.printDuplicateDependencies = function (duplicateDependencies) {
|
|
45
|
+
duplicateDependencies.forEach(function (pluginDuplicateDependencies, plugin) {
|
|
46
|
+
if (pluginDuplicateDependencies.size) {
|
|
47
|
+
var pluginDuplicateDependenciesValue = Array.from(pluginDuplicateDependencies);
|
|
48
|
+
console.info("Some dev dependencies are unnecessarily installed as their are already required by \"".concat(plugin, "\":\"\n - \"").concat(pluginDuplicateDependenciesValue.join("\n - "), "\n"));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
return DuplicateDependenciesService;
|
|
53
|
+
}());
|
|
54
|
+
exports.DuplicateDependenciesService = DuplicateDependenciesService;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class GitService {
|
|
2
|
+
static GIT_HOOK_MODE: number;
|
|
3
|
+
static GIT_HOOK_TEMPLATE: string;
|
|
4
|
+
static isGitRepository(absoluteProjectDir: string): Promise<boolean>;
|
|
5
|
+
static addGitHook(absoluteProjectDir: string, gitHookName: string, gitHookCommand: string): Promise<void>;
|
|
6
|
+
private static getFilePermissions;
|
|
7
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
exports.GitService = void 0;
|
|
40
|
+
var fs_1 = require("fs");
|
|
41
|
+
var path_1 = require("path");
|
|
42
|
+
var CmdService_1 = require("./CmdService");
|
|
43
|
+
var GitService = /** @class */ (function () {
|
|
44
|
+
function GitService() {
|
|
45
|
+
}
|
|
46
|
+
GitService.isGitRepository = function (absoluteProjectDir) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0: return [4 /*yield*/, CmdService_1.CmdService.execCmd("git rev-parse", absoluteProjectDir, true)
|
|
51
|
+
.then(function () { return true; })
|
|
52
|
+
.catch(function () { return false; })];
|
|
53
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
GitService.addGitHook = function (absoluteProjectDir, gitHookName, gitHookCommand) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
var gitHookDirPath, gitHookFilePath, mode;
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
gitHookDirPath = (0, path_1.join)(absoluteProjectDir, ".git/hooks");
|
|
63
|
+
gitHookFilePath = (0, path_1.join)(gitHookDirPath, gitHookName);
|
|
64
|
+
if ((0, fs_1.existsSync)(gitHookFilePath)) {
|
|
65
|
+
mode = GitService.getFilePermissions(gitHookFilePath);
|
|
66
|
+
if (mode !== GitService.GIT_HOOK_MODE) {
|
|
67
|
+
(0, fs_1.chmodSync)(gitHookFilePath, GitService.GIT_HOOK_MODE);
|
|
68
|
+
}
|
|
69
|
+
return [2 /*return*/];
|
|
70
|
+
}
|
|
71
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
72
|
+
var stream = (0, fs_1.createWriteStream)(gitHookFilePath, { mode: GitService.GIT_HOOK_MODE });
|
|
73
|
+
stream.on("close", function () { return resolve(undefined); });
|
|
74
|
+
stream.on("error", function (error) { return reject(error); });
|
|
75
|
+
stream.write(GitService.GIT_HOOK_TEMPLATE.replace("%gitHookCommand%", gitHookCommand));
|
|
76
|
+
stream.end();
|
|
77
|
+
})];
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
GitService.getFilePermissions = function (filePath) {
|
|
82
|
+
var mode = (0, fs_1.statSync)(filePath).mode;
|
|
83
|
+
return mode & parseInt("777", 8);
|
|
84
|
+
};
|
|
85
|
+
GitService.GIT_HOOK_MODE = 493;
|
|
86
|
+
GitService.GIT_HOOK_TEMPLATE = "#!/bin/sh\n\n# Created by ts-dev-tools (https://escemi-tech.github.io/ts-dev-tools/)\n\n%gitHookCommand%";
|
|
87
|
+
return GitService;
|
|
88
|
+
}());
|
|
89
|
+
exports.GitService = GitService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare type Migration = {
|
|
2
|
+
name: string;
|
|
3
|
+
path: string;
|
|
4
|
+
};
|
|
5
|
+
export declare type MigrationUpFunction = (absoluteProjectDir: string) => Promise<void>;
|
|
6
|
+
export declare class MigrationsService {
|
|
7
|
+
static executeMigrations(tsDevToolsRootPath: string, absoluteProjectDir: string, currentVersion: string | undefined): Promise<void>;
|
|
8
|
+
private static getAvailableMigrations;
|
|
9
|
+
private static getPluginMigrations;
|
|
10
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
exports.MigrationsService = void 0;
|
|
40
|
+
var fs_1 = require("fs");
|
|
41
|
+
var path_1 = require("path");
|
|
42
|
+
var PackageJson_1 = require("../services/PackageJson");
|
|
43
|
+
var MigrationsService = /** @class */ (function () {
|
|
44
|
+
function MigrationsService() {
|
|
45
|
+
}
|
|
46
|
+
MigrationsService.executeMigrations = function (tsDevToolsRootPath, absoluteProjectDir, currentVersion) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
var migrations, packageJson, packageJsonBackupPath, _i, migrations_1, migration, up, error_1;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
migrations = MigrationsService.getAvailableMigrations(tsDevToolsRootPath, absoluteProjectDir, currentVersion);
|
|
53
|
+
packageJson = PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir);
|
|
54
|
+
packageJsonBackupPath = packageJson.backup();
|
|
55
|
+
_a.label = 1;
|
|
56
|
+
case 1:
|
|
57
|
+
_a.trys.push([1, 6, , 7]);
|
|
58
|
+
_i = 0, migrations_1 = migrations;
|
|
59
|
+
_a.label = 2;
|
|
60
|
+
case 2:
|
|
61
|
+
if (!(_i < migrations_1.length)) return [3 /*break*/, 5];
|
|
62
|
+
migration = migrations_1[_i];
|
|
63
|
+
console.info("Applying migration \"".concat(migration.name, "\"..."));
|
|
64
|
+
up = require(migration.path).up;
|
|
65
|
+
// Apply migration
|
|
66
|
+
return [4 /*yield*/, up(absoluteProjectDir)];
|
|
67
|
+
case 3:
|
|
68
|
+
// Apply migration
|
|
69
|
+
_a.sent();
|
|
70
|
+
// Upgrade current version
|
|
71
|
+
PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir).merge({
|
|
72
|
+
tsDevTools: { version: migration.name },
|
|
73
|
+
});
|
|
74
|
+
console.info("Migration \"".concat(migration.name, "\" applied!"));
|
|
75
|
+
_a.label = 4;
|
|
76
|
+
case 4:
|
|
77
|
+
_i++;
|
|
78
|
+
return [3 /*break*/, 2];
|
|
79
|
+
case 5: return [3 /*break*/, 7];
|
|
80
|
+
case 6:
|
|
81
|
+
error_1 = _a.sent();
|
|
82
|
+
// Rollback package.json
|
|
83
|
+
packageJson.restore(packageJsonBackupPath);
|
|
84
|
+
throw error_1;
|
|
85
|
+
case 7:
|
|
86
|
+
(0, fs_1.unlinkSync)(packageJsonBackupPath);
|
|
87
|
+
return [2 /*return*/];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
MigrationsService.getAvailableMigrations = function (tsDevToolsRootPath, absoluteProjectDir, currentVersion) {
|
|
93
|
+
var packageJson = PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir);
|
|
94
|
+
var installedPlugins = packageJson.getInstalledPlugins();
|
|
95
|
+
var migrationFiles = [];
|
|
96
|
+
for (var _i = 0, installedPlugins_1 = installedPlugins; _i < installedPlugins_1.length; _i++) {
|
|
97
|
+
var installedPlugin = installedPlugins_1[_i];
|
|
98
|
+
migrationFiles.push.apply(migrationFiles, MigrationsService.getPluginMigrations(tsDevToolsRootPath, installedPlugin, currentVersion));
|
|
99
|
+
}
|
|
100
|
+
migrationFiles.sort(function (_a, _b) {
|
|
101
|
+
var nameA = _a.name;
|
|
102
|
+
var nameB = _b.name;
|
|
103
|
+
return nameA.localeCompare(nameB);
|
|
104
|
+
});
|
|
105
|
+
return Array.from(new Set(migrationFiles));
|
|
106
|
+
};
|
|
107
|
+
MigrationsService.getPluginMigrations = function (tsDevToolsRootPath, plugin, currentVersion) {
|
|
108
|
+
var pluginDirPath = (0, path_1.resolve)(tsDevToolsRootPath, "../../", plugin);
|
|
109
|
+
// First retrieve migration of inherited plugins
|
|
110
|
+
var migrationFiles = MigrationsService.getAvailableMigrations(tsDevToolsRootPath, pluginDirPath, currentVersion);
|
|
111
|
+
// Then retrieve
|
|
112
|
+
var pluginMigrationsDirPath = (0, path_1.resolve)(pluginDirPath, "dist/install/migrations");
|
|
113
|
+
for (var _i = 0, _a = (0, fs_1.readdirSync)(pluginMigrationsDirPath); _i < _a.length; _i++) {
|
|
114
|
+
var migrationFile = _a[_i];
|
|
115
|
+
if (!migrationFile.match(/^[0-9]{14}-[a-z]+\.(js|ts)$/)) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
var migrationName = migrationFile.split(".").slice(0, -1).join(".");
|
|
119
|
+
var shouldApplyMigration = !currentVersion || currentVersion.localeCompare(migrationName) < 0;
|
|
120
|
+
if (!shouldApplyMigration) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
migrationFiles.push({
|
|
124
|
+
name: migrationName,
|
|
125
|
+
path: (0, path_1.resolve)(pluginMigrationsDirPath, migrationFile),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return migrationFiles;
|
|
129
|
+
};
|
|
130
|
+
return MigrationsService;
|
|
131
|
+
}());
|
|
132
|
+
exports.MigrationsService = MigrationsService;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PackageJson as PackageJsonType } from "type-fest";
|
|
2
|
+
export declare type JsonArray = boolean[] | number[] | string[] | JsonFileData[] | Date[];
|
|
3
|
+
export declare type AnyJson = boolean | number | string | JsonFileData | Date | JsonArray | JsonArray[];
|
|
4
|
+
export declare type JsonFileData = {
|
|
5
|
+
[key: string]: AnyJson | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare type PackageJsonContent = JsonFileData & PackageJsonType;
|
|
8
|
+
export declare class PackageJson {
|
|
9
|
+
private path;
|
|
10
|
+
private content?;
|
|
11
|
+
constructor(path: string);
|
|
12
|
+
getPath(): string;
|
|
13
|
+
getContent(): PackageJsonContent;
|
|
14
|
+
setContent(content: PackageJsonContent): void;
|
|
15
|
+
getPackageName(): string | undefined;
|
|
16
|
+
getPackageVersion(): string | undefined;
|
|
17
|
+
isPrivate(): boolean;
|
|
18
|
+
getTsDevToolsVersion(): string | undefined;
|
|
19
|
+
getInstalledPlugins(): string[];
|
|
20
|
+
getDependenciesPackageNames(): string[];
|
|
21
|
+
getDevDependenciesPackageNames(): string[];
|
|
22
|
+
getAllDependenciesPackageNames(): string[];
|
|
23
|
+
merge(update: PackageJsonContent): void;
|
|
24
|
+
backup(): string;
|
|
25
|
+
restore(backupPath: string): void;
|
|
26
|
+
private write;
|
|
27
|
+
static fromDirPath(dirPath: string): PackageJson;
|
|
28
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PackageJson = void 0;
|
|
13
|
+
var fs_1 = require("fs");
|
|
14
|
+
var path_1 = require("path");
|
|
15
|
+
var PackageJsonMerge_1 = require("./PackageJsonMerge");
|
|
16
|
+
var PackageJson = /** @class */ (function () {
|
|
17
|
+
function PackageJson(path) {
|
|
18
|
+
this.path = path;
|
|
19
|
+
this.content = undefined;
|
|
20
|
+
if (!(0, fs_1.existsSync)(this.path)) {
|
|
21
|
+
throw new Error("Package.json \"".concat(this.path, "\" does not exist"));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
PackageJson.prototype.getPath = function () {
|
|
25
|
+
return this.path;
|
|
26
|
+
};
|
|
27
|
+
PackageJson.prototype.getContent = function () {
|
|
28
|
+
if (this.content) {
|
|
29
|
+
return this.content;
|
|
30
|
+
}
|
|
31
|
+
return (this.content = JSON.parse((0, fs_1.readFileSync)(this.path, "utf-8")));
|
|
32
|
+
};
|
|
33
|
+
PackageJson.prototype.setContent = function (content) {
|
|
34
|
+
this.content = content;
|
|
35
|
+
this.write();
|
|
36
|
+
};
|
|
37
|
+
PackageJson.prototype.getPackageName = function () {
|
|
38
|
+
return this.getContent().name;
|
|
39
|
+
};
|
|
40
|
+
PackageJson.prototype.getPackageVersion = function () {
|
|
41
|
+
return this.getContent().version;
|
|
42
|
+
};
|
|
43
|
+
PackageJson.prototype.isPrivate = function () {
|
|
44
|
+
return this.getContent().private === true;
|
|
45
|
+
};
|
|
46
|
+
PackageJson.prototype.getTsDevToolsVersion = function () {
|
|
47
|
+
var tsDevToolsConfig = this.getContent().tsDevTools;
|
|
48
|
+
var version = tsDevToolsConfig === null || tsDevToolsConfig === void 0 ? void 0 : tsDevToolsConfig.version;
|
|
49
|
+
return version;
|
|
50
|
+
};
|
|
51
|
+
PackageJson.prototype.getInstalledPlugins = function () {
|
|
52
|
+
var allDependenciesPackageNames = this.getAllDependenciesPackageNames();
|
|
53
|
+
if (!allDependenciesPackageNames.length) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
var plugins = allDependenciesPackageNames.filter(function (packageName) {
|
|
57
|
+
return packageName.match(/^@ts-dev-tools\/.*$/);
|
|
58
|
+
});
|
|
59
|
+
var sortPlugins = function (pluginA, pluginB) { return pluginA.localeCompare(pluginB); };
|
|
60
|
+
plugins.sort(sortPlugins);
|
|
61
|
+
return plugins;
|
|
62
|
+
};
|
|
63
|
+
PackageJson.prototype.getDependenciesPackageNames = function () {
|
|
64
|
+
var dependencies = this.getContent().dependencies;
|
|
65
|
+
return dependencies ? Object.keys(dependencies) : [];
|
|
66
|
+
};
|
|
67
|
+
PackageJson.prototype.getDevDependenciesPackageNames = function () {
|
|
68
|
+
var devDependencies = this.getContent().devDependencies;
|
|
69
|
+
return devDependencies ? Object.keys(devDependencies) : [];
|
|
70
|
+
};
|
|
71
|
+
PackageJson.prototype.getAllDependenciesPackageNames = function () {
|
|
72
|
+
return Array.from(new Set(__spreadArray(__spreadArray([], this.getDependenciesPackageNames(), true), this.getDevDependenciesPackageNames(), true)));
|
|
73
|
+
};
|
|
74
|
+
PackageJson.prototype.merge = function (update) {
|
|
75
|
+
this.content = PackageJsonMerge_1.PackageJsonMerge.merge(this.getContent(), update);
|
|
76
|
+
this.write();
|
|
77
|
+
};
|
|
78
|
+
PackageJson.prototype.backup = function () {
|
|
79
|
+
var backupPath = this.path + ".backup";
|
|
80
|
+
(0, fs_1.copyFileSync)(this.path, backupPath);
|
|
81
|
+
return backupPath;
|
|
82
|
+
};
|
|
83
|
+
PackageJson.prototype.restore = function (backupPath) {
|
|
84
|
+
(0, fs_1.copyFileSync)(backupPath, this.path);
|
|
85
|
+
this.content = undefined;
|
|
86
|
+
};
|
|
87
|
+
PackageJson.prototype.write = function () {
|
|
88
|
+
(0, fs_1.writeFileSync)(this.path, JSON.stringify(this.content, null, 2));
|
|
89
|
+
};
|
|
90
|
+
PackageJson.fromDirPath = function (dirPath) {
|
|
91
|
+
var packageJsonPath = (0, path_1.join)(dirPath, "package.json");
|
|
92
|
+
if (!(0, fs_1.existsSync)(packageJsonPath)) {
|
|
93
|
+
throw new Error("No package.json found in directory \"".concat(dirPath, "\""));
|
|
94
|
+
}
|
|
95
|
+
return new PackageJson(packageJsonPath);
|
|
96
|
+
};
|
|
97
|
+
return PackageJson;
|
|
98
|
+
}());
|
|
99
|
+
exports.PackageJson = PackageJson;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PackageJsonContent } from "./PackageJson";
|
|
2
|
+
export declare class PackageJsonMerge {
|
|
3
|
+
static merge(source: PackageJsonContent, update: PackageJsonContent): PackageJsonContent;
|
|
4
|
+
private static mergeValues;
|
|
5
|
+
private static mergeObjects;
|
|
6
|
+
private static mergeArrays;
|
|
7
|
+
private static typesEqual;
|
|
8
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PackageJsonMerge = void 0;
|
|
4
|
+
var PackageJsonMerge = /** @class */ (function () {
|
|
5
|
+
function PackageJsonMerge() {
|
|
6
|
+
}
|
|
7
|
+
PackageJsonMerge.merge = function (source, update) {
|
|
8
|
+
return PackageJsonMerge.mergeObjects(source, update);
|
|
9
|
+
};
|
|
10
|
+
PackageJsonMerge.mergeValues = function (source, update) {
|
|
11
|
+
if (source === undefined) {
|
|
12
|
+
return update;
|
|
13
|
+
}
|
|
14
|
+
if (!PackageJsonMerge.typesEqual(source, update)) {
|
|
15
|
+
throw new Error("Unable to merge package json value because types are different");
|
|
16
|
+
}
|
|
17
|
+
// Deal with arrays
|
|
18
|
+
if (Array.isArray(update)) {
|
|
19
|
+
return PackageJsonMerge.mergeArrays(source, update);
|
|
20
|
+
}
|
|
21
|
+
// Deal with objects
|
|
22
|
+
if (typeof update === "object") {
|
|
23
|
+
return PackageJsonMerge.mergeObjects(source, update);
|
|
24
|
+
}
|
|
25
|
+
return update;
|
|
26
|
+
};
|
|
27
|
+
PackageJsonMerge.mergeObjects = function (source, update) {
|
|
28
|
+
for (var updateKey in update) {
|
|
29
|
+
source[updateKey] = PackageJsonMerge.mergeValues(source[updateKey], update[updateKey]);
|
|
30
|
+
}
|
|
31
|
+
return source;
|
|
32
|
+
};
|
|
33
|
+
PackageJsonMerge.mergeArrays = function (source, update) {
|
|
34
|
+
for (var _i = 0, update_1 = update; _i < update_1.length; _i++) {
|
|
35
|
+
var item = update_1[_i];
|
|
36
|
+
if (!source.includes(item)) {
|
|
37
|
+
source.push(item);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return source;
|
|
41
|
+
};
|
|
42
|
+
PackageJsonMerge.typesEqual = function (sourceValue, updateValue) {
|
|
43
|
+
if (Array.isArray(sourceValue) && !Array.isArray(updateValue)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return typeof sourceValue === typeof updateValue;
|
|
47
|
+
};
|
|
48
|
+
return PackageJsonMerge;
|
|
49
|
+
}());
|
|
50
|
+
exports.PackageJsonMerge = PackageJsonMerge;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PackageManagerService = exports.PackageManagerType = void 0;
|
|
4
|
+
var fs_1 = require("fs");
|
|
5
|
+
var path_1 = require("path");
|
|
6
|
+
var PackageManagerType;
|
|
7
|
+
(function (PackageManagerType) {
|
|
8
|
+
PackageManagerType["yarn"] = "yarn";
|
|
9
|
+
PackageManagerType["npm"] = "npm";
|
|
10
|
+
})(PackageManagerType = exports.PackageManagerType || (exports.PackageManagerType = {}));
|
|
11
|
+
var PackageManagerService = /** @class */ (function () {
|
|
12
|
+
function PackageManagerService() {
|
|
13
|
+
}
|
|
14
|
+
PackageManagerService.detectPackageManager = function (dirPath) {
|
|
15
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(dirPath, "yarn.lock"))) {
|
|
16
|
+
return PackageManagerType.yarn;
|
|
17
|
+
}
|
|
18
|
+
return PackageManagerType.npm;
|
|
19
|
+
};
|
|
20
|
+
return PackageManagerService;
|
|
21
|
+
}());
|
|
22
|
+
exports.PackageManagerService = PackageManagerService;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConsoleInfoContent = exports.resetMockedConsoleInfo = exports.mockConsoleInfo = void 0;
|
|
4
|
+
var info = console.info;
|
|
5
|
+
function mockConsoleInfo() {
|
|
6
|
+
console.info = jest.fn();
|
|
7
|
+
}
|
|
8
|
+
exports.mockConsoleInfo = mockConsoleInfo;
|
|
9
|
+
function resetMockedConsoleInfo() {
|
|
10
|
+
console.info = info;
|
|
11
|
+
}
|
|
12
|
+
exports.resetMockedConsoleInfo = resetMockedConsoleInfo;
|
|
13
|
+
function getConsoleInfoContent() {
|
|
14
|
+
var _a;
|
|
15
|
+
var calls = (_a = console.info) === null || _a === void 0 ? void 0 : _a.mock.calls;
|
|
16
|
+
return calls.flat().join("\n");
|
|
17
|
+
}
|
|
18
|
+
exports.getConsoleInfoContent = getConsoleInfoContent;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const testProjectDir: string;
|
|
2
|
+
export declare function createTestProjectDir(filename: string): string;
|
|
3
|
+
export declare function getTsDevToolsRootPath(filename: string): string;
|
|
4
|
+
export declare function restorePackageJson(filename: string): void;
|
|
5
|
+
export declare function removeTestProjectDir(filename: string): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeTestProjectDir = exports.restorePackageJson = exports.getTsDevToolsRootPath = exports.createTestProjectDir = exports.testProjectDir = void 0;
|
|
4
|
+
var fs_1 = require("fs");
|
|
5
|
+
var os_1 = require("os");
|
|
6
|
+
var path_1 = require("path");
|
|
7
|
+
exports.testProjectDir = (0, path_1.resolve)("__tests__/test-project");
|
|
8
|
+
var getTestProjectDirPath = function (filename) {
|
|
9
|
+
return (0, path_1.join)((0, os_1.tmpdir)(), (0, path_1.basename)(filename).split(".")[0]);
|
|
10
|
+
};
|
|
11
|
+
var defaultPackageJsonPath = (0, path_1.join)(exports.testProjectDir, "package.json");
|
|
12
|
+
function createTestProjectDir(filename) {
|
|
13
|
+
var testProjectDirPath = getTestProjectDirPath(filename);
|
|
14
|
+
if ((0, fs_1.existsSync)(testProjectDirPath)) {
|
|
15
|
+
deleteFolderRecursive(testProjectDirPath);
|
|
16
|
+
}
|
|
17
|
+
(0, fs_1.mkdirSync)(testProjectDirPath);
|
|
18
|
+
(0, fs_1.mkdirSync)((0, path_1.join)(testProjectDirPath, ".git/hooks"), { recursive: true });
|
|
19
|
+
// Fake node_modules
|
|
20
|
+
var tsDevToolsRootPath = getTsDevToolsRootPath(filename);
|
|
21
|
+
(0, fs_1.mkdirSync)(tsDevToolsRootPath, { recursive: true });
|
|
22
|
+
(0, fs_1.copyFileSync)((0, path_1.resolve)(__dirname, "../../package.json"), (0, path_1.join)(tsDevToolsRootPath, "package.json"));
|
|
23
|
+
// Fake migrations
|
|
24
|
+
var tsDevToolsDistPath = (0, path_1.join)(tsDevToolsRootPath, "dist");
|
|
25
|
+
(0, fs_1.symlinkSync)((0, path_1.resolve)(__dirname, ".."), tsDevToolsDistPath);
|
|
26
|
+
restorePackageJson(filename);
|
|
27
|
+
return testProjectDirPath;
|
|
28
|
+
}
|
|
29
|
+
exports.createTestProjectDir = createTestProjectDir;
|
|
30
|
+
function getTsDevToolsRootPath(filename) {
|
|
31
|
+
var testProjectDirPath = getTestProjectDirPath(filename);
|
|
32
|
+
if (!(0, fs_1.existsSync)(testProjectDirPath)) {
|
|
33
|
+
throw new Error("Test project dir \"".concat(testProjectDirPath, "\" does not exist"));
|
|
34
|
+
}
|
|
35
|
+
return (0, path_1.join)(testProjectDirPath, "node_modules/@ts-dev-tools/core");
|
|
36
|
+
}
|
|
37
|
+
exports.getTsDevToolsRootPath = getTsDevToolsRootPath;
|
|
38
|
+
function restorePackageJson(filename) {
|
|
39
|
+
var testProjectDirPath = getTestProjectDirPath(filename);
|
|
40
|
+
if (!(0, fs_1.existsSync)(testProjectDirPath)) {
|
|
41
|
+
throw new Error("Test project dir \"".concat(testProjectDirPath, "\" does not exist"));
|
|
42
|
+
}
|
|
43
|
+
(0, fs_1.copyFileSync)(defaultPackageJsonPath, (0, path_1.join)(testProjectDirPath, "package.json"));
|
|
44
|
+
}
|
|
45
|
+
exports.restorePackageJson = restorePackageJson;
|
|
46
|
+
function removeTestProjectDir(filename) {
|
|
47
|
+
var testProjectDirPath = getTestProjectDirPath(filename);
|
|
48
|
+
if (!(0, fs_1.existsSync)(testProjectDirPath)) {
|
|
49
|
+
throw new Error("Test project dir \"".concat(testProjectDirPath, "\" does not exist"));
|
|
50
|
+
}
|
|
51
|
+
deleteFolderRecursive(testProjectDirPath);
|
|
52
|
+
}
|
|
53
|
+
exports.removeTestProjectDir = removeTestProjectDir;
|
|
54
|
+
function deleteFolderRecursive(path) {
|
|
55
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
56
|
+
(0, fs_1.readdirSync)(path).forEach(function (file) {
|
|
57
|
+
var curPath = (0, path_1.join)(path, file);
|
|
58
|
+
if ((0, fs_1.lstatSync)(curPath).isDirectory()) {
|
|
59
|
+
// recurse
|
|
60
|
+
deleteFolderRecursive(curPath);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// delete file
|
|
64
|
+
(0, fs_1.unlinkSync)(curPath);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
(0, fs_1.rmdirSync)(path);
|
|
68
|
+
}
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-dev-tools/core",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.14",
|
|
4
4
|
"description": "TS dev tools Core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"linter",
|
|
@@ -41,26 +41,26 @@
|
|
|
41
41
|
"url": "https://github.com/escemi-tech/ts-dev-tools/issues"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@commitlint/cli": "^16.0
|
|
44
|
+
"@commitlint/cli": "^16.1.0",
|
|
45
45
|
"@commitlint/config-conventional": "^16.0.0",
|
|
46
46
|
"@types/jest": "^27.4.0",
|
|
47
|
-
"@types/node": "^17.0.
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
49
|
-
"@typescript-eslint/parser": "^5.
|
|
50
|
-
"eslint": "^8.
|
|
47
|
+
"@types/node": "^17.0.10",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
|
49
|
+
"@typescript-eslint/parser": "^5.10.0",
|
|
50
|
+
"eslint": "^8.7.0",
|
|
51
51
|
"eslint-config-prettier": "^8.3.0",
|
|
52
52
|
"eslint-plugin-import": "^2.25.4",
|
|
53
|
-
"eslint-plugin-jest": "^25.
|
|
53
|
+
"eslint-plugin-jest": "^25.7.0",
|
|
54
54
|
"eslint-plugin-node": "^11.1.0",
|
|
55
55
|
"eslint-plugin-promise": "^6.0.0",
|
|
56
56
|
"import-sort-style-module": "^6.0.0",
|
|
57
57
|
"jest": "^27.4.7",
|
|
58
|
-
"lint-staged": "^12.
|
|
58
|
+
"lint-staged": "^12.2.2",
|
|
59
59
|
"prettier": "^2.5.1",
|
|
60
60
|
"prettier-plugin-import-sort": "^0.0.7",
|
|
61
61
|
"pretty-quick": "^3.1.3",
|
|
62
|
-
"ts-jest": "^27.1.
|
|
63
|
-
"typescript": "^4.5.
|
|
62
|
+
"ts-jest": "^27.1.3",
|
|
63
|
+
"typescript": "^4.5.5"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"pinst": "^2.1.6"
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"**/?(*.)+(spec|test).+(ts|tsx|js)"
|
|
107
107
|
]
|
|
108
108
|
},
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "532cde30efabc0e8fe34350565d6cba2605a0919"
|
|
110
110
|
}
|