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