@herodevs/cli 0.2.2 → 0.2.3
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/main.cjs +986 -0
- package/package.json +13 -115
- package/README.md +0 -35
- package/bin/dev +0 -17
- package/bin/dev.cmd +0 -3
- package/bin/run +0 -5
- package/bin/run.cmd +0 -3
- package/dist/commands/report/committers.d.ts +0 -19
- package/dist/commands/report/committers.js +0 -190
- package/dist/commands/tracker/init.d.ts +0 -8
- package/dist/commands/tracker/init.js +0 -16
- package/dist/commands/tracker/run.d.ts +0 -11
- package/dist/commands/tracker/run.js +0 -37
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -5
- package/dist/package.json +0 -120
- package/dist/shared/command/base-command.d.ts +0 -22
- package/dist/shared/command/base-command.js +0 -47
- package/dist/shared/command/index.d.ts +0 -1
- package/dist/shared/command/index.js +0 -4
- package/dist/shared/config/environment.d.ts +0 -4
- package/dist/shared/config/environment.js +0 -10
- package/dist/shared/config/index.d.ts +0 -1
- package/dist/shared/config/index.js +0 -4
- package/dist/shared/enums/index.d.ts +0 -1
- package/dist/shared/enums/index.js +0 -4
- package/dist/shared/enums/log-colors.d.ts +0 -28
- package/dist/shared/enums/log-colors.js +0 -9
- package/dist/shared/index.d.ts +0 -4
- package/dist/shared/index.js +0 -7
- package/dist/shared/lib/index.d.ts +0 -2
- package/dist/shared/lib/index.js +0 -5
- package/dist/shared/lib/shell.d.ts +0 -7
- package/dist/shared/lib/shell.js +0 -34
- package/dist/shared/lib/version-update.d.ts +0 -3
- package/dist/shared/lib/version-update.js +0 -52
- package/dist/shared/tracker/default-config.d.ts +0 -3
- package/dist/shared/tracker/default-config.js +0 -19
- package/dist/shared/tracker/initialize.d.ts +0 -1
- package/dist/shared/tracker/initialize.js +0 -15
- package/dist/shared/tracker/models/aggregate-result.d.ts +0 -4
- package/dist/shared/tracker/models/aggregate-result.js +0 -2
- package/dist/shared/tracker/models/category-result.d.ts +0 -7
- package/dist/shared/tracker/models/category-result.js +0 -2
- package/dist/shared/tracker/models/category.d.ts +0 -9
- package/dist/shared/tracker/models/category.js +0 -2
- package/dist/shared/tracker/models/chart-config.d.ts +0 -24
- package/dist/shared/tracker/models/chart-config.js +0 -65
- package/dist/shared/tracker/models/config.d.ts +0 -8
- package/dist/shared/tracker/models/config.js +0 -2
- package/dist/shared/tracker/models/file-result.d.ts +0 -5
- package/dist/shared/tracker/models/file-result.js +0 -2
- package/dist/shared/tracker/models/process-result.d.ts +0 -6
- package/dist/shared/tracker/models/process-result.js +0 -2
- package/dist/shared/tracker/models/result.d.ts +0 -11
- package/dist/shared/tracker/models/result.js +0 -2
- package/dist/shared/tracker/models/total-result.d.ts +0 -4
- package/dist/shared/tracker/models/total-result.js +0 -2
- package/dist/shared/tracker/models/viz-dataset.d.ts +0 -4
- package/dist/shared/tracker/models/viz-dataset.js +0 -2
- package/dist/shared/tracker/models/viz-labels-datasets.d.ts +0 -5
- package/dist/shared/tracker/models/viz-labels-datasets.js +0 -2
- package/dist/shared/tracker/process-category.d.ts +0 -3
- package/dist/shared/tracker/process-category.js +0 -155
- package/dist/shared/tracker/process-config.d.ts +0 -3
- package/dist/shared/tracker/process-config.js +0 -16
- package/dist/shared/tracker/tracker-chart.d.ts +0 -0
- package/dist/shared/tracker/tracker-chart.js +0 -156
- package/dist/shared/tracker/util.d.ts +0 -17
- package/dist/shared/tracker/util.js +0 -98
- package/dist/shared/types/flags.type.d.ts +0 -4
- package/dist/shared/types/flags.type.js +0 -2
- package/dist/shared/types/index.d.ts +0 -1
- package/dist/shared/types/index.js +0 -4
- package/oclif.manifest.json +0 -118
package/main.cjs
ADDED
|
@@ -0,0 +1,986 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
// apps/cli/package.json
|
|
29
|
+
var require_package = __commonJS({
|
|
30
|
+
"apps/cli/package.json"(exports2, module2) {
|
|
31
|
+
module2.exports = {
|
|
32
|
+
name: "@herodevs/cli",
|
|
33
|
+
version: "0.0.0",
|
|
34
|
+
bin: "./main.cjs",
|
|
35
|
+
dependencies: {
|
|
36
|
+
tslib: "^2.3.0"
|
|
37
|
+
},
|
|
38
|
+
type: "commonjs",
|
|
39
|
+
main: "./main.cjs"
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// apps/cli/src/lib/cli.ts
|
|
45
|
+
var yargs = __toESM(require("yargs"));
|
|
46
|
+
var import_helpers = require("yargs/helpers");
|
|
47
|
+
|
|
48
|
+
// libs/report/committers/src/lib/committers.ts
|
|
49
|
+
var import_date_fns2 = require("date-fns");
|
|
50
|
+
|
|
51
|
+
// libs/utility/src/lib/get-root-dir.ts
|
|
52
|
+
var import_fs = require("fs");
|
|
53
|
+
var import_path = require("path");
|
|
54
|
+
function getRootDir(directory) {
|
|
55
|
+
if ((0, import_fs.existsSync)((0, import_path.join)(directory, "package.json"))) {
|
|
56
|
+
return directory;
|
|
57
|
+
}
|
|
58
|
+
return getRootDir((0, import_path.resolve)((0, import_path.join)(directory, "..")));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// libs/utility/src/lib/run-command.ts
|
|
62
|
+
var import_child_process = require("child_process");
|
|
63
|
+
async function runCommand(cmd) {
|
|
64
|
+
return new Promise((resolve4, reject) => {
|
|
65
|
+
const options = {
|
|
66
|
+
timeout: 1e4
|
|
67
|
+
};
|
|
68
|
+
(0, import_child_process.exec)(cmd, options, (err, stdout, stderr) => {
|
|
69
|
+
if (err) {
|
|
70
|
+
const rejection = {
|
|
71
|
+
err,
|
|
72
|
+
stdout,
|
|
73
|
+
stderr
|
|
74
|
+
};
|
|
75
|
+
reject(rejection);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
let result = stdout;
|
|
79
|
+
if (typeof stdout === "string") {
|
|
80
|
+
result = (stdout || "").trim();
|
|
81
|
+
}
|
|
82
|
+
resolve4(result);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// libs/utility/src/lib/get-project-types.ts
|
|
88
|
+
var import_fs2 = require("fs");
|
|
89
|
+
var path = require("path");
|
|
90
|
+
function getProjectTypes() {
|
|
91
|
+
const types = [];
|
|
92
|
+
if ((0, import_fs2.existsSync)(path.join(process.cwd(), "package.json"))) {
|
|
93
|
+
types.push("npm");
|
|
94
|
+
}
|
|
95
|
+
return types;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// libs/utility/src/lib/sort-by-name.ts
|
|
99
|
+
function sortByName(a, b) {
|
|
100
|
+
return a.name === b.name ? 0 : a.name > b.name ? 1 : -1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// libs/report/committers/src/lib/parse-date-flags.ts
|
|
104
|
+
var import_date_fns = require("date-fns");
|
|
105
|
+
function parseDateFlags(dateFormat2, startDate, endDate) {
|
|
106
|
+
return {
|
|
107
|
+
endDate: (0, import_date_fns.parse)(endDate, dateFormat2, /* @__PURE__ */ new Date()),
|
|
108
|
+
startDate: (0, import_date_fns.parse)(startDate, dateFormat2, /* @__PURE__ */ new Date())
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// libs/report/committers/src/lib/constants.ts
|
|
113
|
+
var dateFormat = "yyyy-MM-dd";
|
|
114
|
+
var gammaDelimiter = "\u0393\u0393\u0393\u0393";
|
|
115
|
+
var monthsToSubtract = 12;
|
|
116
|
+
var gitOutputFormat = `"${["%h", "%an", "%ad"].join(gammaDelimiter)}"`;
|
|
117
|
+
|
|
118
|
+
// libs/report/committers/src/lib/parse-git-log-entries.ts
|
|
119
|
+
function parseGitLogEntries(entries) {
|
|
120
|
+
return entries.map((entry) => {
|
|
121
|
+
const [commitHash, committer, date] = entry.split(gammaDelimiter);
|
|
122
|
+
return { commitHash, committer, date: new Date(date) };
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// libs/report/committers/src/lib/get-committer-counts.ts
|
|
127
|
+
function getCommitterCounts(entries) {
|
|
128
|
+
return entries.reduce((acc, entry) => {
|
|
129
|
+
let committerCount = acc.find((c) => c.name === entry.committer);
|
|
130
|
+
if (!committerCount) {
|
|
131
|
+
committerCount = { name: entry.committer, count: 0 };
|
|
132
|
+
acc.push(committerCount);
|
|
133
|
+
}
|
|
134
|
+
committerCount.count++;
|
|
135
|
+
return acc;
|
|
136
|
+
}, []).sort((a, b) => b.count - a.count);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// libs/report/committers/src/lib/committers.ts
|
|
140
|
+
var reportCommittersCommand = {
|
|
141
|
+
command: "committers",
|
|
142
|
+
describe: "show git committers",
|
|
143
|
+
aliases: [],
|
|
144
|
+
builder: {
|
|
145
|
+
startDate: {
|
|
146
|
+
alias: "s",
|
|
147
|
+
default: (0, import_date_fns2.format)(/* @__PURE__ */ new Date(), dateFormat),
|
|
148
|
+
describe: `Start Date (format: ${dateFormat})`,
|
|
149
|
+
string: true
|
|
150
|
+
},
|
|
151
|
+
endDate: {
|
|
152
|
+
alias: "e",
|
|
153
|
+
describe: `End Date (format: ${dateFormat})`,
|
|
154
|
+
required: false,
|
|
155
|
+
default: (0, import_date_fns2.format)((0, import_date_fns2.subMonths)(/* @__PURE__ */ new Date(), monthsToSubtract), dateFormat)
|
|
156
|
+
},
|
|
157
|
+
exclude: {
|
|
158
|
+
alias: "x",
|
|
159
|
+
array: true,
|
|
160
|
+
describe: 'Path Exclusions (eg -x="./src/bin" -x="./dist")',
|
|
161
|
+
required: false
|
|
162
|
+
},
|
|
163
|
+
json: {
|
|
164
|
+
describe: "Output to JSON format",
|
|
165
|
+
required: false,
|
|
166
|
+
default: false,
|
|
167
|
+
boolean: true
|
|
168
|
+
}
|
|
169
|
+
// monthly: {
|
|
170
|
+
// alias: 'm',
|
|
171
|
+
// describe:
|
|
172
|
+
// 'Break down by calendar month, rather than by committer. (eg -m)',
|
|
173
|
+
// required: false,
|
|
174
|
+
// default: false,
|
|
175
|
+
// },
|
|
176
|
+
},
|
|
177
|
+
handler: run
|
|
178
|
+
};
|
|
179
|
+
async function run(args) {
|
|
180
|
+
const { startDate, endDate } = parseDateFlags(dateFormat, args.startDate, args.endDate);
|
|
181
|
+
const ignores = args.exclude && args.exclude.length ? `-- . "!(${args.exclude.join("|")})"` : "";
|
|
182
|
+
const gitCommand = `git log --since "${endDate}" --until "${startDate}" --pretty=format:${gitOutputFormat} ${ignores}`;
|
|
183
|
+
const result = await runCommand(gitCommand);
|
|
184
|
+
const rawEntries = result.split("\n");
|
|
185
|
+
if (rawEntries.length === 1 && rawEntries[0] === "") {
|
|
186
|
+
const startDateStr = (0, import_date_fns2.format)(startDate, "yyyy-MM-dd");
|
|
187
|
+
const endDateStr = (0, import_date_fns2.format)(endDate, "yyyy-MM-dd");
|
|
188
|
+
console.log(`No commits found between ${endDateStr} and ${startDateStr}`);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const entries = parseGitLogEntries(rawEntries);
|
|
192
|
+
const committerCounts = getCommitterCounts(entries);
|
|
193
|
+
if (args.json) {
|
|
194
|
+
outputCommittersJson(committerCounts);
|
|
195
|
+
} else {
|
|
196
|
+
outputCommitters(committerCounts);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function outputCommitters(committerCounts) {
|
|
200
|
+
const longestNameLength = committerCounts.reduce((acc, c) => {
|
|
201
|
+
return c.name.length > acc ? c.name.length : acc;
|
|
202
|
+
}, "Committer".length);
|
|
203
|
+
const header = `Committer${" ".repeat(longestNameLength - 9)} | Commits`;
|
|
204
|
+
console.log(header);
|
|
205
|
+
console.log(
|
|
206
|
+
header.split("").map((c) => c === "|" ? "|" : "-").join("")
|
|
207
|
+
);
|
|
208
|
+
console.log(
|
|
209
|
+
committerCounts.map((c) => {
|
|
210
|
+
const committer = `${c.name}${" ".repeat(longestNameLength - c.name.length)}`;
|
|
211
|
+
const count = " ".repeat(7 - c.count.toString().length) + c.count;
|
|
212
|
+
return `${committer} | ${count}`;
|
|
213
|
+
}).join("\n")
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function outputCommittersJson(committerCounts) {
|
|
217
|
+
console.log(JSON.stringify(committerCounts, null, 2));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// libs/report/diagnostics/src/lib/diagnostics.ts
|
|
221
|
+
var import_prompts = require("@inquirer/prompts");
|
|
222
|
+
|
|
223
|
+
// libs/report/diagnostics/src/lib/get-file-contents.ts
|
|
224
|
+
var import_fs3 = require("fs");
|
|
225
|
+
function getFileContents(filePath) {
|
|
226
|
+
if (!(0, import_fs3.existsSync)(filePath)) {
|
|
227
|
+
return `${filePath} not found`;
|
|
228
|
+
}
|
|
229
|
+
const diagData = (0, import_fs3.readFileSync)(filePath, "utf8");
|
|
230
|
+
return diagData;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// libs/report/diagnostics/src/lib/get-package-json-section.ts
|
|
234
|
+
function getPackageJsonSection(section) {
|
|
235
|
+
const filePath = "package.json";
|
|
236
|
+
const pkg = JSON.parse(getFileContents(filePath));
|
|
237
|
+
const sectionData = pkg[section];
|
|
238
|
+
if (!sectionData) {
|
|
239
|
+
return `${section} not found in package.json`;
|
|
240
|
+
}
|
|
241
|
+
const diagData = JSON.stringify(sectionData, null, 2);
|
|
242
|
+
return diagData;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// libs/report/diagnostics/src/lib/get-diagnostic-types.ts
|
|
246
|
+
function getDiagnosticTypes() {
|
|
247
|
+
const diagTypeList = [
|
|
248
|
+
{ name: "Package JSON - dependencies", value: "dependencies" },
|
|
249
|
+
{ name: "Package JSON - devDependencies", value: "devDependencies" },
|
|
250
|
+
{ name: "Package JSON - overrides", value: "overrides" },
|
|
251
|
+
{ name: ".npmrc file contents", value: "npmrc" },
|
|
252
|
+
{ name: "npm config", value: "npm config" },
|
|
253
|
+
{ name: "List of installed packages (npm ls)", value: "npm ls" }
|
|
254
|
+
];
|
|
255
|
+
return diagTypeList;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// libs/report/diagnostics/src/lib/diagnostics.ts
|
|
259
|
+
var reportDiagnosticsCommand = {
|
|
260
|
+
command: "diagnostics",
|
|
261
|
+
describe: "show diagnostic information",
|
|
262
|
+
aliases: ["diag", "d"],
|
|
263
|
+
builder: {
|
|
264
|
+
all: {
|
|
265
|
+
describe: "Return all available diagnostics",
|
|
266
|
+
required: false,
|
|
267
|
+
default: false,
|
|
268
|
+
boolean: true
|
|
269
|
+
},
|
|
270
|
+
consent: {
|
|
271
|
+
describe: "Agree to understanding that sensitive data may be outputted",
|
|
272
|
+
required: false,
|
|
273
|
+
default: false,
|
|
274
|
+
boolean: true
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
handler: run2
|
|
278
|
+
};
|
|
279
|
+
async function run2(args) {
|
|
280
|
+
const consentPrompt = "Data produced may contain sensitive data, please review before sharing it.";
|
|
281
|
+
if (!args.consent) {
|
|
282
|
+
const answer = await (0, import_prompts.confirm)({
|
|
283
|
+
message: `${consentPrompt} Continue?`
|
|
284
|
+
});
|
|
285
|
+
if (!answer) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
console.log(consentPrompt);
|
|
290
|
+
}
|
|
291
|
+
const diagTypeList = getDiagnosticTypes().map((d) => ({
|
|
292
|
+
...d,
|
|
293
|
+
checked: true
|
|
294
|
+
}));
|
|
295
|
+
const diagTypes = args.all ? diagTypeList.map((d) => d.value) : await (0, import_prompts.checkbox)({
|
|
296
|
+
message: "select diagnostic(s) to run",
|
|
297
|
+
choices: diagTypeList,
|
|
298
|
+
required: true,
|
|
299
|
+
pageSize: diagTypeList.length
|
|
300
|
+
});
|
|
301
|
+
for (let i = 0; i < diagTypes.length; i++) {
|
|
302
|
+
let output = "";
|
|
303
|
+
let title = "";
|
|
304
|
+
switch (diagTypes[i]) {
|
|
305
|
+
case "dependencies":
|
|
306
|
+
title = "Package JSON - dependencies";
|
|
307
|
+
output = getPackageJsonSection("dependencies");
|
|
308
|
+
break;
|
|
309
|
+
case "devDependencies":
|
|
310
|
+
title = "Package JSON - devDependencies";
|
|
311
|
+
output = getPackageJsonSection("devDependencies");
|
|
312
|
+
break;
|
|
313
|
+
case "overrides":
|
|
314
|
+
title = "Package JSON - overrides";
|
|
315
|
+
output = getPackageJsonSection("overrides");
|
|
316
|
+
break;
|
|
317
|
+
case "npmrc":
|
|
318
|
+
title = ".npmrc file contents";
|
|
319
|
+
output = getFileContents(".npmrc");
|
|
320
|
+
break;
|
|
321
|
+
case "npm config":
|
|
322
|
+
try {
|
|
323
|
+
title = "npm config results";
|
|
324
|
+
output = await runCommand("npm config get");
|
|
325
|
+
} catch (e) {
|
|
326
|
+
output = e.stderr;
|
|
327
|
+
}
|
|
328
|
+
break;
|
|
329
|
+
case "npm ls":
|
|
330
|
+
title = "npm ls results";
|
|
331
|
+
output = await runCommand("npm ls --depth=1000");
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
const titleMsg = `*** ${title} ***`;
|
|
335
|
+
const titleWrapper = "*".repeat(titleMsg.length);
|
|
336
|
+
console.log(`${titleWrapper}
|
|
337
|
+
${titleMsg}
|
|
338
|
+
${titleWrapper}
|
|
339
|
+
${output}
|
|
340
|
+
`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// libs/tracker/init/src/lib/default-config.ts
|
|
345
|
+
var defaultConfig = {
|
|
346
|
+
categories: {
|
|
347
|
+
legacy: {
|
|
348
|
+
fileTypes: ["js", "ts", "html", "css", "scss", "less"],
|
|
349
|
+
includes: ["./legacy"],
|
|
350
|
+
jsTsPairs: "js"
|
|
351
|
+
},
|
|
352
|
+
modern: {
|
|
353
|
+
fileTypes: ["ts", "html", "css", "scss", "less"],
|
|
354
|
+
includes: ["./modern"],
|
|
355
|
+
jsTsPairs: "ts"
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
ignorePatterns: ["node_modules"],
|
|
359
|
+
outputDir: "hd-tracker"
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// libs/tracker/init/src/lib/init.ts
|
|
363
|
+
var import_path2 = require("path");
|
|
364
|
+
var import_fs4 = require("fs");
|
|
365
|
+
var trackerInitCommand = {
|
|
366
|
+
command: "init",
|
|
367
|
+
describe: "Initialize the tracker configuration",
|
|
368
|
+
aliases: [],
|
|
369
|
+
builder: {},
|
|
370
|
+
handler: run3
|
|
371
|
+
};
|
|
372
|
+
function run3(args) {
|
|
373
|
+
const rootDir = getRootDir(global.process.cwd());
|
|
374
|
+
const output = JSON.stringify(defaultConfig, null, 2);
|
|
375
|
+
const dir = (0, import_path2.join)(rootDir, "hd-tracker");
|
|
376
|
+
if (!(0, import_fs4.existsSync)(dir)) {
|
|
377
|
+
(0, import_fs4.mkdirSync)(dir);
|
|
378
|
+
}
|
|
379
|
+
(0, import_fs4.writeFileSync)((0, import_path2.join)(dir, "config.json"), output);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// libs/tracker/shared/src/lib/read-config.ts
|
|
383
|
+
var import_fs5 = require("fs");
|
|
384
|
+
var import_path3 = require("path");
|
|
385
|
+
function readConfig(rootDirectory, optionsPath) {
|
|
386
|
+
const path3 = optionsPath && (0, import_fs5.existsSync)((0, import_path3.join)(rootDirectory, optionsPath)) ? (0, import_path3.join)(rootDirectory, optionsPath) : (0, import_path3.join)(rootDirectory, "hd-tracker", "config.json");
|
|
387
|
+
const contents = (0, import_fs5.readFileSync)(path3).toString("utf-8");
|
|
388
|
+
return JSON.parse(contents);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// libs/tracker/run/src/lib/run.ts
|
|
392
|
+
var import_path6 = require("path");
|
|
393
|
+
|
|
394
|
+
// libs/tracker/run/src/lib/process-category.ts
|
|
395
|
+
var sloc = __toESM(require("sloc"));
|
|
396
|
+
var import_fs6 = require("fs");
|
|
397
|
+
var import_path4 = require("path");
|
|
398
|
+
function processCategory(rootDirectory, category, ignorePatterns) {
|
|
399
|
+
console.log(`Processing "${category.name}"...`);
|
|
400
|
+
const allFiles = category.includes.reduce((acc, include) => {
|
|
401
|
+
return [...acc, ...findAllFilesInDirectory((0, import_path4.join)(rootDirectory, include))];
|
|
402
|
+
}, []);
|
|
403
|
+
const includedFiles = findIncludedFiles(category, ignorePatterns, allFiles);
|
|
404
|
+
console.log(` ${includedFiles.length} files...`);
|
|
405
|
+
const results = includedFiles.map(getFileStats);
|
|
406
|
+
const resultMap = aggregateResults(results);
|
|
407
|
+
const aggregatedResults = Object.values(resultMap).map((val) => val);
|
|
408
|
+
const totals = aggregatedResults.reduce(
|
|
409
|
+
(totals2, curr) => ({
|
|
410
|
+
fileCount: totals2.fileCount + curr.fileCount,
|
|
411
|
+
total: totals2.total + curr.total,
|
|
412
|
+
source: totals2.source + curr.source,
|
|
413
|
+
comment: totals2.comment + curr.comment,
|
|
414
|
+
single: totals2.single + curr.single,
|
|
415
|
+
block: totals2.block + curr.block,
|
|
416
|
+
mixed: totals2.mixed + curr.mixed,
|
|
417
|
+
empty: totals2.empty + curr.empty,
|
|
418
|
+
todo: totals2.todo + curr.todo,
|
|
419
|
+
blockEmpty: totals2.blockEmpty + curr.blockEmpty
|
|
420
|
+
}),
|
|
421
|
+
{
|
|
422
|
+
fileCount: 0,
|
|
423
|
+
total: 0,
|
|
424
|
+
source: 0,
|
|
425
|
+
comment: 0,
|
|
426
|
+
single: 0,
|
|
427
|
+
block: 0,
|
|
428
|
+
mixed: 0,
|
|
429
|
+
empty: 0,
|
|
430
|
+
todo: 0,
|
|
431
|
+
blockEmpty: 0
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
const final = {
|
|
435
|
+
name: category.name,
|
|
436
|
+
totals,
|
|
437
|
+
fileTypes: aggregatedResults
|
|
438
|
+
};
|
|
439
|
+
console.log(` ${final.totals.total} total lines`);
|
|
440
|
+
return final;
|
|
441
|
+
}
|
|
442
|
+
function aggregateResults(results) {
|
|
443
|
+
return results.reduce((acc, result) => {
|
|
444
|
+
const fileTypeResults = acc[result.fileType];
|
|
445
|
+
if (!fileTypeResults) {
|
|
446
|
+
acc[result.fileType] = {
|
|
447
|
+
fileType: result.fileType,
|
|
448
|
+
fileCount: 1,
|
|
449
|
+
total: result.total,
|
|
450
|
+
source: result.source,
|
|
451
|
+
comment: result.comment,
|
|
452
|
+
single: result.single,
|
|
453
|
+
block: result.block,
|
|
454
|
+
mixed: result.mixed,
|
|
455
|
+
empty: result.empty,
|
|
456
|
+
todo: result.todo,
|
|
457
|
+
blockEmpty: result.blockEmpty
|
|
458
|
+
};
|
|
459
|
+
} else {
|
|
460
|
+
acc[result.fileType] = {
|
|
461
|
+
fileType: result.fileType,
|
|
462
|
+
fileCount: fileTypeResults.fileCount + 1,
|
|
463
|
+
total: fileTypeResults.total + result.total,
|
|
464
|
+
source: fileTypeResults.source + result.source,
|
|
465
|
+
comment: fileTypeResults.comment + result.comment,
|
|
466
|
+
single: fileTypeResults.single + result.single,
|
|
467
|
+
block: fileTypeResults.block + result.block,
|
|
468
|
+
mixed: fileTypeResults.mixed + result.mixed,
|
|
469
|
+
empty: fileTypeResults.empty + result.empty,
|
|
470
|
+
todo: fileTypeResults.todo + result.todo,
|
|
471
|
+
blockEmpty: fileTypeResults.blockEmpty + result.blockEmpty
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
return acc;
|
|
475
|
+
}, {});
|
|
476
|
+
}
|
|
477
|
+
function getFileStats(file) {
|
|
478
|
+
const contents = (0, import_fs6.readFileSync)(file).toString("utf-8");
|
|
479
|
+
const fileType = getFileExt(file);
|
|
480
|
+
const stats = sloc(contents, fileType);
|
|
481
|
+
return {
|
|
482
|
+
path: file,
|
|
483
|
+
fileType,
|
|
484
|
+
...stats
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function findIncludedFiles(category, ignorePatterns, allFiles) {
|
|
488
|
+
return allFiles.filter((file) => {
|
|
489
|
+
const ext = getFileExt(file);
|
|
490
|
+
let shouldBeIncluded = !!category.fileTypes.find(
|
|
491
|
+
(fileType) => fileType === ext
|
|
492
|
+
);
|
|
493
|
+
if (shouldBeIncluded) {
|
|
494
|
+
ignorePatterns?.forEach((ignorePattern) => {
|
|
495
|
+
if (file.indexOf(ignorePattern) !== -1) {
|
|
496
|
+
shouldBeIncluded = false;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
if (shouldBeIncluded) {
|
|
501
|
+
category.excludes?.forEach((exclude) => {
|
|
502
|
+
if (file.indexOf(exclude) !== -1) {
|
|
503
|
+
shouldBeIncluded = false;
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
return shouldBeIncluded;
|
|
508
|
+
}).filter((file, _index, files) => {
|
|
509
|
+
if (category.jsTsPairs === "ignore" || category.jsTsPairs === void 0) {
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
const fileExtToKeep = category.jsTsPairs;
|
|
513
|
+
const ext = getFileExt(file);
|
|
514
|
+
const fileExtToDiscard = fileExtToKeep === "js" ? "ts" : "js";
|
|
515
|
+
if (fileExtToKeep === ext || fileExtToDiscard !== ext) {
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
const counterpartExt = ext === "js" ? "ts" : "js";
|
|
519
|
+
const parts = file.split(".");
|
|
520
|
+
parts[parts.length - 1] = counterpartExt;
|
|
521
|
+
const counterpartExists = files.filter((f) => f === parts.join(".")).length !== 0;
|
|
522
|
+
if (counterpartExists) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
return true;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
function findAllFilesInDirectory(directory) {
|
|
529
|
+
const results = (0, import_fs6.readdirSync)(directory);
|
|
530
|
+
const subfiles = results.filter((result) => (0, import_fs6.lstatSync)((0, import_path4.join)(directory, result)).isDirectory()).reduce((acc, subdir) => {
|
|
531
|
+
const files2 = findAllFilesInDirectory((0, import_path4.join)(directory, subdir));
|
|
532
|
+
return [...acc, ...files2];
|
|
533
|
+
}, []);
|
|
534
|
+
const files = results.filter((result) => (0, import_fs6.lstatSync)((0, import_path4.join)(directory, result)).isFile()).map((fileName) => (0, import_path4.join)(directory, fileName));
|
|
535
|
+
return [...files, ...subfiles];
|
|
536
|
+
}
|
|
537
|
+
function getFileExt(file) {
|
|
538
|
+
return (0, import_path4.extname)(file).replace(/\./g, "");
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// libs/tracker/run/src/lib/get-git-commit.ts
|
|
542
|
+
var import_date_fns3 = require("date-fns");
|
|
543
|
+
var import_git_last_commit = require("git-last-commit");
|
|
544
|
+
async function getGitCommit() {
|
|
545
|
+
const commit = await getLastCommitAsPromise();
|
|
546
|
+
return {
|
|
547
|
+
hash: commit.hash,
|
|
548
|
+
timestamp: formatDate(getGitDate(commit.committedOn))
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
function getLastCommitAsPromise() {
|
|
552
|
+
return new Promise((resolve4, reject) => {
|
|
553
|
+
(0, import_git_last_commit.getLastCommit)((err, commit) => {
|
|
554
|
+
if (err) {
|
|
555
|
+
reject(err);
|
|
556
|
+
}
|
|
557
|
+
resolve4(commit);
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
function formatDate(date) {
|
|
562
|
+
return (0, import_date_fns3.format)(date, "yyyy-MM-dd-HH-mm-ss-SSS");
|
|
563
|
+
}
|
|
564
|
+
function getGitDate(date) {
|
|
565
|
+
return new Date(+date * 1e3);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// libs/tracker/run/src/lib/process-config.ts
|
|
569
|
+
async function processConfig(config, rootDirectory) {
|
|
570
|
+
console.log(`Starting...`);
|
|
571
|
+
const categoryResults = Object.entries(config.categories).map(
|
|
572
|
+
([name, category]) => processCategory(
|
|
573
|
+
rootDirectory,
|
|
574
|
+
{ ...category, name },
|
|
575
|
+
config.ignorePatterns || []
|
|
576
|
+
)
|
|
577
|
+
);
|
|
578
|
+
const commit = await getGitCommit();
|
|
579
|
+
return {
|
|
580
|
+
timestamp: commit.timestamp,
|
|
581
|
+
hash: commit.hash,
|
|
582
|
+
categories: categoryResults
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// libs/tracker/run/src/lib/get-data.ts
|
|
587
|
+
var import_fs7 = require("fs");
|
|
588
|
+
|
|
589
|
+
// libs/tracker/run/src/lib/get-data-filepath.ts
|
|
590
|
+
var import_path5 = require("path");
|
|
591
|
+
function getDataFilePath(localRootDir, outputDir) {
|
|
592
|
+
return (0, import_path5.resolve)((0, import_path5.join)(localRootDir, outputDir, "data.json"));
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// libs/tracker/run/src/lib/get-data.ts
|
|
596
|
+
function getData(localRootDir, outputDir) {
|
|
597
|
+
const outputPath = getDataFilePath(localRootDir, outputDir);
|
|
598
|
+
let contents = "";
|
|
599
|
+
if ((0, import_fs7.existsSync)(outputPath)) {
|
|
600
|
+
contents = (0, import_fs7.readFileSync)(outputPath).toString("utf-8");
|
|
601
|
+
}
|
|
602
|
+
return contents === "" ? [] : JSON.parse(contents);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// libs/tracker/run/src/lib/save-results.ts
|
|
606
|
+
var import_fs8 = require("fs");
|
|
607
|
+
function saveResults(localRootDir, outputDir, results) {
|
|
608
|
+
console.log("Outputting file");
|
|
609
|
+
const output = getData(localRootDir, outputDir);
|
|
610
|
+
if (!Array.isArray(output)) {
|
|
611
|
+
console.error("Invalid output file format");
|
|
612
|
+
}
|
|
613
|
+
output.push(results);
|
|
614
|
+
const outputPath = getDataFilePath(localRootDir, outputDir);
|
|
615
|
+
const outputText = JSON.stringify(output, null, 2);
|
|
616
|
+
(0, import_fs8.writeFileSync)(outputPath, outputText);
|
|
617
|
+
console.log(`Output written to: ${outputPath}`);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// libs/tracker/run/src/lib/run.ts
|
|
621
|
+
var trackerRunCommand = {
|
|
622
|
+
command: "run",
|
|
623
|
+
describe: "Run the tracker",
|
|
624
|
+
aliases: [],
|
|
625
|
+
builder: {
|
|
626
|
+
// root: Flags.string({ char: 'r', description: 'root dir of the project' }),
|
|
627
|
+
// config: Flags.string({ char: 'c', description: 'path to config file' }),
|
|
628
|
+
},
|
|
629
|
+
handler: run4
|
|
630
|
+
};
|
|
631
|
+
async function run4(args) {
|
|
632
|
+
const localRootDir = getRootDir(global.process.cwd());
|
|
633
|
+
const rootDirectory = args.root ? (0, import_path6.resolve)(args.root) : localRootDir;
|
|
634
|
+
const config = readConfig(localRootDir, args.config);
|
|
635
|
+
const results = await processConfig(config, rootDirectory);
|
|
636
|
+
saveResults(localRootDir, config.outputDir, results);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// apps/cli/src/lib/create-group-command.ts
|
|
640
|
+
function createGroupCommand(group, description, subCommand, subCommandDescription, aliases, commands, errorMessage) {
|
|
641
|
+
const cmd = {
|
|
642
|
+
command: `${group} <${subCommand}>`,
|
|
643
|
+
describe: description,
|
|
644
|
+
aliases,
|
|
645
|
+
positional: {
|
|
646
|
+
type: {
|
|
647
|
+
type: "string",
|
|
648
|
+
demandOption: true,
|
|
649
|
+
describe: subCommandDescription
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
builder: (yargs2) => {
|
|
653
|
+
return yargs2.command(commands);
|
|
654
|
+
},
|
|
655
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
656
|
+
handler: (args) => {
|
|
657
|
+
console.log(`${errorMessage} (${args[subCommand]})`);
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
return cmd;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// libs/nes/init/src/lib/init.ts
|
|
664
|
+
var import_prompts2 = require("@inquirer/prompts");
|
|
665
|
+
|
|
666
|
+
// libs/nes/init/src/lib/verify-project-type.ts
|
|
667
|
+
function verifyProjectType() {
|
|
668
|
+
const types = getProjectTypes();
|
|
669
|
+
let valid = true;
|
|
670
|
+
let error = void 0;
|
|
671
|
+
if (types.length === 0) {
|
|
672
|
+
valid = false;
|
|
673
|
+
error = "Unable to recognize a supported project type.";
|
|
674
|
+
}
|
|
675
|
+
return {
|
|
676
|
+
types,
|
|
677
|
+
valid,
|
|
678
|
+
error
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// libs/nes/init/src/lib/get-release-trains.ts
|
|
683
|
+
var import_core = require("@apollo/client/core");
|
|
684
|
+
async function getReleaseTrains(accessToken, types) {
|
|
685
|
+
const client = new import_core.ApolloClient({
|
|
686
|
+
cache: new import_core.InMemoryCache(),
|
|
687
|
+
uri: "https://api.nes.herodevs.com/graphql"
|
|
688
|
+
});
|
|
689
|
+
try {
|
|
690
|
+
const queryResult = await client.query({
|
|
691
|
+
query: import_core.gql`
|
|
692
|
+
query RT($input: LicensingReleaseTrainsInput) {
|
|
693
|
+
licensing {
|
|
694
|
+
releaseTrains(input: $input) {
|
|
695
|
+
results {
|
|
696
|
+
key
|
|
697
|
+
name
|
|
698
|
+
products {
|
|
699
|
+
id
|
|
700
|
+
key
|
|
701
|
+
name
|
|
702
|
+
}
|
|
703
|
+
entries {
|
|
704
|
+
packageVersion {
|
|
705
|
+
id
|
|
706
|
+
name
|
|
707
|
+
fqns
|
|
708
|
+
origination {
|
|
709
|
+
name
|
|
710
|
+
type
|
|
711
|
+
version
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
`,
|
|
720
|
+
variables: { input: { tenantId: 1e3, byToken: accessToken } }
|
|
721
|
+
});
|
|
722
|
+
const results = queryResult.data?.licensing?.releaseTrains?.results;
|
|
723
|
+
if (!results) {
|
|
724
|
+
throw new Error(`Error getting release trains`);
|
|
725
|
+
}
|
|
726
|
+
return results;
|
|
727
|
+
} catch (error) {
|
|
728
|
+
throw new Error(`Error getting release trains`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// libs/nes/init/src/lib/get-product-choices.ts
|
|
733
|
+
async function getProductChoices(accessToken, types) {
|
|
734
|
+
const releaseTrains = await getReleaseTrains(accessToken, types);
|
|
735
|
+
return releaseTrains.map((rt) => ({
|
|
736
|
+
name: rt.name,
|
|
737
|
+
value: rt
|
|
738
|
+
})).sort(sortByName);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// libs/nes/init/src/lib/get-package-choices.ts
|
|
742
|
+
function getPackageChoices(releaseTrain) {
|
|
743
|
+
return releaseTrain.entries.map((e) => ({
|
|
744
|
+
name: e.packageVersion.origination?.name || e.packageVersion.name,
|
|
745
|
+
value: e
|
|
746
|
+
})).sort(sortByName);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// libs/nes/init/src/lib/npm/configure-npm-project.ts
|
|
750
|
+
var import_fs9 = require("fs");
|
|
751
|
+
var path2 = require("path");
|
|
752
|
+
function configureNpmProject(accessToken, packages) {
|
|
753
|
+
updatePackageJson(packages);
|
|
754
|
+
updateNpmrc(accessToken);
|
|
755
|
+
}
|
|
756
|
+
function updatePackageJson(packages) {
|
|
757
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
758
|
+
const packageJsonContents = (0, import_fs9.readFileSync)(packageJsonPath, "utf8");
|
|
759
|
+
const packageJson = JSON.parse(packageJsonContents);
|
|
760
|
+
const pkgUpdates = packages.map((p) => ({
|
|
761
|
+
key: p.packageVersion.origination?.name || p.packageVersion.name,
|
|
762
|
+
value: p.packageVersion.fqns
|
|
763
|
+
})).reduce(
|
|
764
|
+
(acc, cur) => {
|
|
765
|
+
if (packageJson.devDependencies?.[cur.key]) {
|
|
766
|
+
acc.devDeps[cur.key] = `npm:${cur.value}`;
|
|
767
|
+
} else if (packageJson.peerDependencies?.[cur.key]) {
|
|
768
|
+
acc.peerDeps[cur.key] = `npm:${cur.value}`;
|
|
769
|
+
} else {
|
|
770
|
+
acc.deps[cur.key] = `npm:${cur.value}`;
|
|
771
|
+
}
|
|
772
|
+
acc.overrides[cur.key] = { ".": `npm:${cur.value}` };
|
|
773
|
+
return acc;
|
|
774
|
+
},
|
|
775
|
+
{ deps: {}, devDeps: {}, peerDeps: {}, overrides: {} }
|
|
776
|
+
);
|
|
777
|
+
packageJson.dependencies = {
|
|
778
|
+
...packageJson.dependencies || {},
|
|
779
|
+
...pkgUpdates.deps
|
|
780
|
+
};
|
|
781
|
+
packageJson.devDependencies = {
|
|
782
|
+
...packageJson.devDependencies || {},
|
|
783
|
+
...pkgUpdates.devDeps
|
|
784
|
+
};
|
|
785
|
+
packageJson.peerDependencies = {
|
|
786
|
+
...packageJson.peerDependencies || {},
|
|
787
|
+
...pkgUpdates.peerDeps
|
|
788
|
+
};
|
|
789
|
+
packageJson.overrides = {
|
|
790
|
+
...packageJson.overrides || {},
|
|
791
|
+
...pkgUpdates.overrides
|
|
792
|
+
};
|
|
793
|
+
(0, import_fs9.writeFileSync)(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
794
|
+
}
|
|
795
|
+
function updateNpmrc(accessToken) {
|
|
796
|
+
const npmrcPath = path2.join(process.cwd(), ".npmrc");
|
|
797
|
+
let npmrcContents = "";
|
|
798
|
+
if ((0, import_fs9.existsSync)(npmrcPath)) {
|
|
799
|
+
npmrcContents = (0, import_fs9.readFileSync)(npmrcPath, "utf8");
|
|
800
|
+
}
|
|
801
|
+
if (npmrcContents.includes(`@neverendingsupport:registry`)) {
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
const updatedContents = npmrcContents + `
|
|
805
|
+
|
|
806
|
+
@neverendingsupport:registry=https://registry.nes.herodevs.com/npm/pkg/
|
|
807
|
+
//registry.nes.herodevs.com/npm/pkg/:_authToken="${accessToken}"`;
|
|
808
|
+
(0, import_fs9.writeFileSync)(npmrcPath, updatedContents);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// libs/nes/init/src/lib/configure-project.ts
|
|
812
|
+
function configureProject(accessToken, projectTypes, packages) {
|
|
813
|
+
if (projectTypes.includes("npm")) {
|
|
814
|
+
configureNpmProject(accessToken, packages);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// libs/nes/init/src/lib/init.ts
|
|
819
|
+
var ora = __toESM(require("ora"));
|
|
820
|
+
var nesInitCommand = {
|
|
821
|
+
command: "init",
|
|
822
|
+
describe: "Initialize the NES project",
|
|
823
|
+
aliases: [],
|
|
824
|
+
builder: {},
|
|
825
|
+
handler: run5
|
|
826
|
+
};
|
|
827
|
+
async function run5(args) {
|
|
828
|
+
const spinner = ora();
|
|
829
|
+
const projectType = verifyProjectType();
|
|
830
|
+
if (!projectType.valid) {
|
|
831
|
+
console.error(projectType.error);
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
if (!await (0, import_prompts2.confirm)({
|
|
835
|
+
message: "Before initializing, please commit all changes. Continue?"
|
|
836
|
+
})) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const accessToken = await (0, import_prompts2.password)({
|
|
840
|
+
message: "Enter access token",
|
|
841
|
+
mask: "*"
|
|
842
|
+
});
|
|
843
|
+
spinner.start("loading your products");
|
|
844
|
+
const productList = await getProductChoices(accessToken, projectType.types);
|
|
845
|
+
spinner.stop();
|
|
846
|
+
const releaseTrain = await (0, import_prompts2.select)({
|
|
847
|
+
message: "select a product",
|
|
848
|
+
choices: productList,
|
|
849
|
+
pageSize: productList.length
|
|
850
|
+
// no scrolling
|
|
851
|
+
});
|
|
852
|
+
const packageList = getPackageChoices(releaseTrain).map((p) => ({
|
|
853
|
+
...p,
|
|
854
|
+
checked: true
|
|
855
|
+
}));
|
|
856
|
+
const packages = await (0, import_prompts2.checkbox)({
|
|
857
|
+
message: `select the package(s)`,
|
|
858
|
+
choices: packageList,
|
|
859
|
+
loop: false,
|
|
860
|
+
pageSize: packageList.length
|
|
861
|
+
// no scrolling
|
|
862
|
+
});
|
|
863
|
+
console.log("configuring your project...");
|
|
864
|
+
configureProject(accessToken, projectType.types, packages);
|
|
865
|
+
console.log("Your project is now configured to access your NES product");
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// apps/cli/src/lib/get-commands.ts
|
|
869
|
+
function getCommands() {
|
|
870
|
+
const nesCommand = createGroupCommand(
|
|
871
|
+
"nes",
|
|
872
|
+
"",
|
|
873
|
+
"command",
|
|
874
|
+
"nes command",
|
|
875
|
+
[],
|
|
876
|
+
[nesInitCommand],
|
|
877
|
+
"Invalid nes command"
|
|
878
|
+
);
|
|
879
|
+
const reportCommand = createGroupCommand(
|
|
880
|
+
"report",
|
|
881
|
+
"",
|
|
882
|
+
"type",
|
|
883
|
+
"type of report",
|
|
884
|
+
"r",
|
|
885
|
+
[reportCommittersCommand, reportDiagnosticsCommand],
|
|
886
|
+
"Invalid report type"
|
|
887
|
+
);
|
|
888
|
+
const trackerCommand = createGroupCommand(
|
|
889
|
+
"tracker",
|
|
890
|
+
"",
|
|
891
|
+
"command",
|
|
892
|
+
"tracker command",
|
|
893
|
+
[],
|
|
894
|
+
[trackerInitCommand, trackerRunCommand],
|
|
895
|
+
"Invalid tracker command"
|
|
896
|
+
);
|
|
897
|
+
return [nesCommand, reportCommand, trackerCommand];
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// apps/cli/src/lib/ensure-version.ts
|
|
901
|
+
var getJson = __toESM(require("get-json"));
|
|
902
|
+
|
|
903
|
+
// apps/cli/src/lib/log-colors.ts
|
|
904
|
+
function color(color2) {
|
|
905
|
+
return (...args) => {
|
|
906
|
+
return `${color2}${args.join(
|
|
907
|
+
` ${color2}`
|
|
908
|
+
/*reset color for nested color*/
|
|
909
|
+
)}${"\x1B[0m" /* Reset */}`;
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// apps/cli/src/lib/ensure-version.ts
|
|
914
|
+
var red = color("\x1B[31m" /* FgRed */);
|
|
915
|
+
var yellow = color("\x1B[33m" /* FgYellow */);
|
|
916
|
+
async function getLatestVersion(pkgName) {
|
|
917
|
+
return getJson(`https://registry.npmjs.org/${pkgName}`).then(
|
|
918
|
+
(packageData) => {
|
|
919
|
+
return packageData["dist-tags"].latest;
|
|
920
|
+
}
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
async function isVersionUpToDate(packageName, packageVersion, quietIfSuccessful = false) {
|
|
924
|
+
if (packageVersion === "0.0.0") {
|
|
925
|
+
return true;
|
|
926
|
+
}
|
|
927
|
+
const latestVersion = await getLatestVersion(packageName);
|
|
928
|
+
if (latestVersion === packageVersion) {
|
|
929
|
+
if (!quietIfSuccessful) {
|
|
930
|
+
console.log(`${packageName}@${latestVersion} is up to date`);
|
|
931
|
+
}
|
|
932
|
+
return true;
|
|
933
|
+
}
|
|
934
|
+
console.log(
|
|
935
|
+
`${yellow(
|
|
936
|
+
"Your version:",
|
|
937
|
+
red(`${packageName}@${packageVersion}`),
|
|
938
|
+
`is not up to date`
|
|
939
|
+
)}`
|
|
940
|
+
);
|
|
941
|
+
console.log(
|
|
942
|
+
`${yellow("Latest version:", red(`${packageName}@${latestVersion}...`))}`
|
|
943
|
+
);
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
async function ensureVersionIsUpToDate(packageName, packageVersion) {
|
|
947
|
+
const versionUpToDate = await isVersionUpToDate(packageName, packageVersion);
|
|
948
|
+
if (!versionUpToDate) {
|
|
949
|
+
console.log(
|
|
950
|
+
[
|
|
951
|
+
`
|
|
952
|
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
953
|
+
|
|
954
|
+
`,
|
|
955
|
+
`${red(`ERROR:`)} Did not run command.
|
|
956
|
+
|
|
957
|
+
`,
|
|
958
|
+
` - Rerun your command with the ${yellow(
|
|
959
|
+
"@latest"
|
|
960
|
+
)} tag to ensure correct output:
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
`,
|
|
964
|
+
` ${yellow(`npx ${packageName}@latest`)}
|
|
965
|
+
`,
|
|
966
|
+
`
|
|
967
|
+
|
|
968
|
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
969
|
+
`
|
|
970
|
+
].join(" ")
|
|
971
|
+
);
|
|
972
|
+
return process.exit(1);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// apps/cli/src/lib/cli.ts
|
|
977
|
+
function cli() {
|
|
978
|
+
const commands = getCommands();
|
|
979
|
+
const pkg = require_package();
|
|
980
|
+
const packageName = pkg.name;
|
|
981
|
+
const packageVersion = pkg.version;
|
|
982
|
+
yargs.scriptName(packageName).usage("Usage: $0 <command> [options]").middleware(() => ensureVersionIsUpToDate(packageName, packageVersion)).command(commands).parse((0, import_helpers.hideBin)(process.argv));
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// apps/cli/src/main.ts
|
|
986
|
+
cli();
|