@gadgetinc/ggt 1.0.4 → 1.0.5
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/add-4ME2KTJQ.js +84 -0
- package/dist/add-4ME2KTJQ.js.map +7 -0
- package/dist/build-4BGA4IZE.js +3 -0
- package/dist/build-4BGA4IZE.js.map +7 -0
- package/dist/chunk-57XALM2W.js +2 -0
- package/dist/chunk-57XALM2W.js.map +7 -0
- package/dist/chunk-5DLLJX5F.js +11 -0
- package/dist/chunk-5DLLJX5F.js.map +7 -0
- package/dist/chunk-5WC5D4WL.js +2 -0
- package/dist/chunk-5WC5D4WL.js.map +7 -0
- package/dist/chunk-BSCZOMV4.js +2 -0
- package/dist/chunk-BSCZOMV4.js.map +7 -0
- package/dist/chunk-BZY2AIPV.js +57 -0
- package/dist/chunk-BZY2AIPV.js.map +7 -0
- package/dist/chunk-D2K5XPNJ.js +2 -0
- package/dist/chunk-D2K5XPNJ.js.map +7 -0
- package/dist/chunk-F3EZ4KS3.js +2 -0
- package/dist/chunk-F3EZ4KS3.js.map +7 -0
- package/dist/chunk-G3VNV5Z6.js +33 -0
- package/dist/chunk-G3VNV5Z6.js.map +7 -0
- package/dist/chunk-GA7AL463.js +24 -0
- package/dist/chunk-GA7AL463.js.map +7 -0
- package/dist/chunk-GOBNB5VT.js +2 -0
- package/dist/chunk-GOBNB5VT.js.map +7 -0
- package/dist/chunk-HKBXEZNF.js +2 -0
- package/dist/chunk-HKBXEZNF.js.map +7 -0
- package/{lib/commands/push.js → dist/chunk-IKJVXTZK.js} +7 -48
- package/dist/chunk-IKJVXTZK.js.map +7 -0
- package/dist/chunk-KGSSHEEC.js +17 -0
- package/dist/chunk-KGSSHEEC.js.map +7 -0
- package/dist/chunk-KXK37C5D.js +183 -0
- package/dist/chunk-KXK37C5D.js.map +7 -0
- package/dist/chunk-NJIDVM2C.js +27 -0
- package/dist/chunk-NJIDVM2C.js.map +7 -0
- package/dist/chunk-Q5N5L6H3.js +6 -0
- package/dist/chunk-Q5N5L6H3.js.map +7 -0
- package/dist/chunk-QEVWPU3D.js +8 -0
- package/dist/chunk-QEVWPU3D.js.map +7 -0
- package/dist/chunk-X36GM74C.js +2 -0
- package/dist/chunk-X36GM74C.js.map +7 -0
- package/dist/chunk-YRP2UZ2I.js +126 -0
- package/dist/chunk-YRP2UZ2I.js.map +7 -0
- package/dist/deploy-6HOBYPE6.js +30 -0
- package/dist/deploy-6HOBYPE6.js.map +7 -0
- package/dist/dev-M3WDGK4D.js +57 -0
- package/dist/dev-M3WDGK4D.js.map +7 -0
- package/dist/esm-BL3OM5UJ.js +33 -0
- package/dist/esm-BL3OM5UJ.js.map +7 -0
- package/dist/list-725RHWD5.js +11 -0
- package/dist/list-725RHWD5.js.map +7 -0
- package/dist/login-I4RGMDLE.js +2 -0
- package/dist/login-I4RGMDLE.js.map +7 -0
- package/dist/logout-UZBACOIX.js +7 -0
- package/dist/logout-UZBACOIX.js.map +7 -0
- package/dist/main.js +45 -0
- package/dist/main.js.map +7 -0
- package/dist/open-GWKGQQG3.js +74 -0
- package/dist/open-GWKGQQG3.js.map +7 -0
- package/{lib/commands/pull.js → dist/pull-7C5A65KB.js} +7 -48
- package/dist/pull-7C5A65KB.js.map +7 -0
- package/dist/push-LPUIR4EO.js +2 -0
- package/dist/push-LPUIR4EO.js.map +7 -0
- package/dist/status-DFKKSRVB.js +14 -0
- package/dist/status-DFKKSRVB.js.map +7 -0
- package/dist/version-JD42JXWY.js +11 -0
- package/dist/version-JD42JXWY.js.map +7 -0
- package/dist/whoami-I23R6HOG.js +7 -0
- package/dist/whoami-I23R6HOG.js.map +7 -0
- package/package.json +72 -74
- package/lib/__generated__/graphql.js +0 -78
- package/lib/__generated__/graphql.js.map +0 -1
- package/lib/commands/add.js +0 -385
- package/lib/commands/add.js.map +0 -1
- package/lib/commands/deploy.js +0 -287
- package/lib/commands/deploy.js.map +0 -1
- package/lib/commands/dev.js +0 -374
- package/lib/commands/dev.js.map +0 -1
- package/lib/commands/list.js +0 -47
- package/lib/commands/list.js.map +0 -1
- package/lib/commands/login.js +0 -96
- package/lib/commands/login.js.map +0 -1
- package/lib/commands/logout.js +0 -20
- package/lib/commands/logout.js.map +0 -1
- package/lib/commands/open.js +0 -159
- package/lib/commands/open.js.map +0 -1
- package/lib/commands/pull.js.map +0 -1
- package/lib/commands/push.js.map +0 -1
- package/lib/commands/root.js +0 -110
- package/lib/commands/root.js.map +0 -1
- package/lib/commands/status.js +0 -56
- package/lib/commands/status.js.map +0 -1
- package/lib/commands/version.js +0 -18
- package/lib/commands/version.js.map +0 -1
- package/lib/commands/whoami.js +0 -23
- package/lib/commands/whoami.js.map +0 -1
- package/lib/ggt.js +0 -65
- package/lib/ggt.js.map +0 -1
- package/lib/main.js +0 -5
- package/lib/main.js.map +0 -1
- package/lib/services/app/api/api.js +0 -191
- package/lib/services/app/api/api.js.map +0 -1
- package/lib/services/app/api/operation.js +0 -23
- package/lib/services/app/api/operation.js.map +0 -1
- package/lib/services/app/app.js +0 -95
- package/lib/services/app/app.js.map +0 -1
- package/lib/services/app/arg.js +0 -28
- package/lib/services/app/arg.js.map +0 -1
- package/lib/services/app/client.js +0 -182
- package/lib/services/app/client.js.map +0 -1
- package/lib/services/app/edit/edit.js +0 -191
- package/lib/services/app/edit/edit.js.map +0 -1
- package/lib/services/app/edit/operation.js +0 -155
- package/lib/services/app/edit/operation.js.map +0 -1
- package/lib/services/app/error.js +0 -65
- package/lib/services/app/error.js.map +0 -1
- package/lib/services/command/arg.js +0 -55
- package/lib/services/command/arg.js.map +0 -1
- package/lib/services/command/command.js +0 -47
- package/lib/services/command/command.js.map +0 -1
- package/lib/services/command/context.js +0 -209
- package/lib/services/command/context.js.map +0 -1
- package/lib/services/config/config.js +0 -133
- package/lib/services/config/config.js.map +0 -1
- package/lib/services/config/env.js +0 -22
- package/lib/services/config/env.js.map +0 -1
- package/lib/services/config/package-json.js +0 -9
- package/lib/services/config/package-json.js.map +0 -1
- package/lib/services/filesync/changes.js +0 -134
- package/lib/services/filesync/changes.js.map +0 -1
- package/lib/services/filesync/conflicts.js +0 -140
- package/lib/services/filesync/conflicts.js.map +0 -1
- package/lib/services/filesync/directory.js +0 -269
- package/lib/services/filesync/directory.js.map +0 -1
- package/lib/services/filesync/error.js +0 -137
- package/lib/services/filesync/error.js.map +0 -1
- package/lib/services/filesync/file.js +0 -3
- package/lib/services/filesync/file.js.map +0 -1
- package/lib/services/filesync/filesync.js +0 -791
- package/lib/services/filesync/filesync.js.map +0 -1
- package/lib/services/filesync/hashes.js +0 -172
- package/lib/services/filesync/hashes.js.map +0 -1
- package/lib/services/filesync/strategy.js +0 -59
- package/lib/services/filesync/strategy.js.map +0 -1
- package/lib/services/filesync/sync-json.js +0 -475
- package/lib/services/filesync/sync-json.js.map +0 -1
- package/lib/services/http/auth.js +0 -70
- package/lib/services/http/auth.js.map +0 -1
- package/lib/services/http/http.js +0 -136
- package/lib/services/http/http.js.map +0 -1
- package/lib/services/output/confirm.js +0 -149
- package/lib/services/output/confirm.js.map +0 -1
- package/lib/services/output/footer.js +0 -22
- package/lib/services/output/footer.js.map +0 -1
- package/lib/services/output/log/field.js +0 -3
- package/lib/services/output/log/field.js.map +0 -1
- package/lib/services/output/log/format/format.js +0 -8
- package/lib/services/output/log/format/format.js.map +0 -1
- package/lib/services/output/log/format/json.js +0 -37
- package/lib/services/output/log/format/json.js.map +0 -1
- package/lib/services/output/log/format/pretty.js +0 -158
- package/lib/services/output/log/format/pretty.js.map +0 -1
- package/lib/services/output/log/level.js +0 -41
- package/lib/services/output/log/level.js.map +0 -1
- package/lib/services/output/log/logger.js +0 -53
- package/lib/services/output/log/logger.js.map +0 -1
- package/lib/services/output/log/structured.js +0 -52
- package/lib/services/output/log/structured.js.map +0 -1
- package/lib/services/output/notify.js +0 -27
- package/lib/services/output/notify.js.map +0 -1
- package/lib/services/output/output.js +0 -197
- package/lib/services/output/output.js.map +0 -1
- package/lib/services/output/print.js +0 -31
- package/lib/services/output/print.js.map +0 -1
- package/lib/services/output/problems.js +0 -84
- package/lib/services/output/problems.js.map +0 -1
- package/lib/services/output/prompt.js +0 -185
- package/lib/services/output/prompt.js.map +0 -1
- package/lib/services/output/report.js +0 -190
- package/lib/services/output/report.js.map +0 -1
- package/lib/services/output/select.js +0 -198
- package/lib/services/output/select.js.map +0 -1
- package/lib/services/output/spinner.js +0 -141
- package/lib/services/output/spinner.js.map +0 -1
- package/lib/services/output/sprint.js +0 -44
- package/lib/services/output/sprint.js.map +0 -1
- package/lib/services/output/symbols.js +0 -23
- package/lib/services/output/symbols.js.map +0 -1
- package/lib/services/output/table.js +0 -98
- package/lib/services/output/table.js.map +0 -1
- package/lib/services/output/timestamp.js +0 -12
- package/lib/services/output/timestamp.js.map +0 -1
- package/lib/services/output/update.js +0 -99
- package/lib/services/output/update.js.map +0 -1
- package/lib/services/user/session.js +0 -54
- package/lib/services/user/session.js.map +0 -1
- package/lib/services/user/user.js +0 -76
- package/lib/services/user/user.js.map +0 -1
- package/lib/services/util/assert.js +0 -11
- package/lib/services/util/assert.js.map +0 -1
- package/lib/services/util/boolean.js +0 -15
- package/lib/services/util/boolean.js.map +0 -1
- package/lib/services/util/collection.js +0 -38
- package/lib/services/util/collection.js.map +0 -1
- package/lib/services/util/function.js +0 -153
- package/lib/services/util/function.js.map +0 -1
- package/lib/services/util/is.js +0 -97
- package/lib/services/util/is.js.map +0 -1
- package/lib/services/util/json.js +0 -33
- package/lib/services/util/json.js.map +0 -1
- package/lib/services/util/number.js +0 -27
- package/lib/services/util/number.js.map +0 -1
- package/lib/services/util/object.js +0 -104
- package/lib/services/util/object.js.map +0 -1
- package/lib/services/util/paths.js +0 -36
- package/lib/services/util/paths.js.map +0 -1
- package/lib/services/util/promise.js +0 -74
- package/lib/services/util/promise.js.map +0 -1
- package/lib/services/util/types.js +0 -5
- package/lib/services/util/types.js.map +0 -1
- package/npm-shrinkwrap.json +0 -29545
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import chalkTemplate from "chalk-template";
|
|
3
|
-
import cliSpinners from "cli-spinners";
|
|
4
|
-
import assert from "node:assert";
|
|
5
|
-
import os from "node:os";
|
|
6
|
-
import { dedent } from "ts-dedent";
|
|
7
|
-
import { isString } from "../util/is.js";
|
|
8
|
-
import { output } from "./output.js";
|
|
9
|
-
import { isSprintOptions, sprintln } from "./sprint.js";
|
|
10
|
-
import { symbol } from "./symbols.js";
|
|
11
|
-
export let activeSpinner;
|
|
12
|
-
export const createSpin = (options)=>{
|
|
13
|
-
return (optionsOrString, ...values)=>{
|
|
14
|
-
if (isSprintOptions(optionsOrString)) {
|
|
15
|
-
return createSpin({
|
|
16
|
-
...options,
|
|
17
|
-
...optionsOrString
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
assert(!activeSpinner, "a spinner is already active");
|
|
21
|
-
let str = optionsOrString;
|
|
22
|
-
if (!isString(str)) {
|
|
23
|
-
str = sprintln(str, ...values);
|
|
24
|
-
}
|
|
25
|
-
const { ensureNewLine = true, ensureEmptyLineAbove = false, kind = "dots", color = "white", successSymbol = chalk.green(symbol.tick), failSymbol = chalk.red(symbol.cross) } = options;
|
|
26
|
-
let frameIndex = 0;
|
|
27
|
-
const frames = cliSpinners[kind].frames;
|
|
28
|
-
const interval = cliSpinners[kind].interval;
|
|
29
|
-
let firstRender = true;
|
|
30
|
-
const render = ({ symbol, message, final: finalRender = false })=>{
|
|
31
|
-
// strip leading and trailing newlines so we can add them back in
|
|
32
|
-
// the right place
|
|
33
|
-
while(message.startsWith("\n")){
|
|
34
|
-
message = message.slice(1);
|
|
35
|
-
}
|
|
36
|
-
while(message.endsWith("\n")){
|
|
37
|
-
message = message.slice(0, -1);
|
|
38
|
-
}
|
|
39
|
-
// if no symbol is provided, use the next frame
|
|
40
|
-
if (symbol === undefined) {
|
|
41
|
-
frameIndex = ++frameIndex % frames.length;
|
|
42
|
-
symbol = chalk[color](frames[frameIndex]);
|
|
43
|
-
}
|
|
44
|
-
if (message) {
|
|
45
|
-
// we have a message to display
|
|
46
|
-
if (symbol) {
|
|
47
|
-
// add the spinner symbol to the first line of the message
|
|
48
|
-
const lines = message.split(/\r?\n/);
|
|
49
|
-
lines[0] = `${symbol} ${lines[0]}`;
|
|
50
|
-
message = lines.join(os.EOL);
|
|
51
|
-
}
|
|
52
|
-
if (ensureEmptyLineAbove && !message.startsWith("\n")) {
|
|
53
|
-
// add an empty line before the symbol
|
|
54
|
-
message = "\n" + message;
|
|
55
|
-
}
|
|
56
|
-
if (ensureNewLine && !message.endsWith("\n")) {
|
|
57
|
-
// add a newline after the message
|
|
58
|
-
message += "\n";
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (finalRender) {
|
|
62
|
-
if (!output.isInteractive && ensureEmptyLineAbove) {
|
|
63
|
-
// we're in a non-interactive terminal, therefor
|
|
64
|
-
// ensureEmptyLineAbove only applies to the first render.
|
|
65
|
-
// strip it so that the final render of the spinner is right
|
|
66
|
-
// below the first render of the spinner
|
|
67
|
-
message = message.slice(1);
|
|
68
|
-
}
|
|
69
|
-
// this is the final render, so persist the spinner
|
|
70
|
-
output.persistSpinner(message);
|
|
71
|
-
activeSpinner = undefined;
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
// this is not the final render, so we need to update the spinner
|
|
75
|
-
if (output.isInteractive) {
|
|
76
|
-
// we're in an interactive terminal, so update the spinner
|
|
77
|
-
output.updateSpinner(message);
|
|
78
|
-
} else if (firstRender) {
|
|
79
|
-
// we're not in an interactive terminal, and this is the first
|
|
80
|
-
// render, so just write the first render to stdout
|
|
81
|
-
output.writeStdout(message);
|
|
82
|
-
firstRender = false;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
// render the first frame
|
|
86
|
-
render({
|
|
87
|
-
message: str
|
|
88
|
-
});
|
|
89
|
-
let spinnerInterval;
|
|
90
|
-
if (output.isInteractive) {
|
|
91
|
-
// we are in an interactive terminal, so keep rendering the spinner
|
|
92
|
-
spinnerInterval = setInterval(()=>render({
|
|
93
|
-
message: str
|
|
94
|
-
}), interval);
|
|
95
|
-
}
|
|
96
|
-
// setup the last render
|
|
97
|
-
const finalRender = (renderOptions)=>{
|
|
98
|
-
render({
|
|
99
|
-
...renderOptions,
|
|
100
|
-
final: true
|
|
101
|
-
});
|
|
102
|
-
clearInterval(spinnerInterval);
|
|
103
|
-
};
|
|
104
|
-
activeSpinner = {
|
|
105
|
-
text: str,
|
|
106
|
-
clear () {
|
|
107
|
-
this.text = "";
|
|
108
|
-
finalRender({
|
|
109
|
-
symbol: "",
|
|
110
|
-
message: ""
|
|
111
|
-
});
|
|
112
|
-
},
|
|
113
|
-
succeed (finalStr, ...values) {
|
|
114
|
-
finalStr ??= str;
|
|
115
|
-
if (!isString(finalStr)) {
|
|
116
|
-
finalStr = dedent(chalkTemplate(finalStr, ...values));
|
|
117
|
-
}
|
|
118
|
-
this.text = finalStr;
|
|
119
|
-
finalRender({
|
|
120
|
-
message: finalStr,
|
|
121
|
-
symbol: successSymbol
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
fail (finalStr, ...values) {
|
|
125
|
-
finalStr ??= str;
|
|
126
|
-
if (!isString(finalStr)) {
|
|
127
|
-
finalStr = dedent(chalkTemplate(finalStr, ...values));
|
|
128
|
-
}
|
|
129
|
-
this.text = finalStr;
|
|
130
|
-
finalRender({
|
|
131
|
-
message: finalStr,
|
|
132
|
-
symbol: failSymbol
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
return activeSpinner;
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
export const spin = createSpin({});
|
|
140
|
-
|
|
141
|
-
//# sourceMappingURL=spinner.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/output/spinner.ts"],"sourcesContent":["import type { ColorName } from \"chalk\";\nimport chalk from \"chalk\";\nimport chalkTemplate from \"chalk-template\";\nimport type { SpinnerName } from \"cli-spinners\";\nimport cliSpinners from \"cli-spinners\";\nimport assert from \"node:assert\";\nimport os from \"node:os\";\nimport { dedent } from \"ts-dedent\";\nimport { isString } from \"../util/is.js\";\nimport { output } from \"./output.js\";\nimport { isSprintOptions, sprintln } from \"./sprint.js\";\nimport { symbol } from \"./symbols.js\";\n\nexport type SpinnerOptions = {\n /**\n * Whether to ensure a new line is after the text.\n *\n * @default false\n */\n ensureNewLine?: boolean;\n\n /**\n * Whether to ensure an empty line is above the spinner.\n *\n * @default false\n */\n ensureEmptyLineAbove?: boolean;\n\n /**\n * The name of the spinner to use.\n *\n * @default \"dots\"\n * @see https://github.com/sindresorhus/cli-spinners\n */\n kind?: SpinnerName;\n\n /**\n * The color of the spinner.\n *\n * @default \"cyan\"\n * @see https://github.com/chalk/chalk\n */\n color?: ColorName;\n\n /**\n * The symbol to display when the spinner succeeds.\n *\n * @default \"✔\"\n */\n successSymbol?: string;\n\n /**\n * The symbol to display when the spinner fails.\n *\n * @default \"✖\"\n */\n failSymbol?: string;\n};\n\nexport type spin = {\n (str: string): spinner;\n (template: TemplateStringsArray, ...values: unknown[]): spinner;\n (options: Omit<SpinnerOptions, \"str\">): spin;\n};\n\nexport type spinner = {\n text: string;\n clear: () => void;\n succeed: {\n (str?: string): void;\n (template: TemplateStringsArray, ...values: unknown[]): void;\n };\n fail: {\n (str?: string): void;\n (template: TemplateStringsArray, ...values: unknown[]): void;\n };\n};\n\nexport let activeSpinner: spinner | undefined;\n\nexport const createSpin = (options: SpinnerOptions): spin => {\n return ((optionsOrString: SpinnerOptions | string | TemplateStringsArray, ...values: unknown[]): spin | spinner => {\n if (isSprintOptions(optionsOrString)) {\n return createSpin({ ...options, ...optionsOrString });\n }\n\n assert(!activeSpinner, \"a spinner is already active\");\n\n let str = optionsOrString as string;\n if (!isString(str)) {\n str = sprintln(str, ...values);\n }\n\n const {\n ensureNewLine = true,\n ensureEmptyLineAbove = false,\n kind = \"dots\",\n color = \"white\",\n successSymbol = chalk.green(symbol.tick),\n failSymbol = chalk.red(symbol.cross),\n } = options;\n\n let frameIndex = 0;\n const frames = cliSpinners[kind].frames;\n const interval = cliSpinners[kind].interval;\n\n type RenderOptions = { symbol?: string; message: string; final?: boolean };\n let firstRender = true;\n\n const render = ({ symbol, message, final: finalRender = false }: RenderOptions): void => {\n // strip leading and trailing newlines so we can add them back in\n // the right place\n while (message.startsWith(\"\\n\")) {\n message = message.slice(1);\n }\n\n while (message.endsWith(\"\\n\")) {\n message = message.slice(0, -1);\n }\n\n // if no symbol is provided, use the next frame\n if (symbol === undefined) {\n frameIndex = ++frameIndex % frames.length;\n symbol = chalk[color](frames[frameIndex]);\n }\n\n if (message) {\n // we have a message to display\n if (symbol) {\n // add the spinner symbol to the first line of the message\n const lines = message.split(/\\r?\\n/);\n lines[0] = `${symbol} ${lines[0]}`;\n message = lines.join(os.EOL);\n }\n\n if (ensureEmptyLineAbove && !message.startsWith(\"\\n\")) {\n // add an empty line before the symbol\n message = \"\\n\" + message;\n }\n\n if (ensureNewLine && !message.endsWith(\"\\n\")) {\n // add a newline after the message\n message += \"\\n\";\n }\n }\n\n if (finalRender) {\n if (!output.isInteractive && ensureEmptyLineAbove) {\n // we're in a non-interactive terminal, therefor\n // ensureEmptyLineAbove only applies to the first render.\n // strip it so that the final render of the spinner is right\n // below the first render of the spinner\n message = message.slice(1);\n }\n\n // this is the final render, so persist the spinner\n output.persistSpinner(message);\n activeSpinner = undefined;\n return;\n }\n\n // this is not the final render, so we need to update the spinner\n if (output.isInteractive) {\n // we're in an interactive terminal, so update the spinner\n output.updateSpinner(message);\n } else if (firstRender) {\n // we're not in an interactive terminal, and this is the first\n // render, so just write the first render to stdout\n output.writeStdout(message);\n firstRender = false;\n }\n };\n\n // render the first frame\n render({ message: str });\n\n let spinnerInterval: NodeJS.Timeout | undefined;\n if (output.isInteractive) {\n // we are in an interactive terminal, so keep rendering the spinner\n spinnerInterval = setInterval(() => render({ message: str }), interval);\n }\n\n // setup the last render\n const finalRender = (renderOptions: Omit<RenderOptions, \"final\">): void => {\n render({ ...renderOptions, final: true });\n clearInterval(spinnerInterval);\n };\n\n activeSpinner = {\n text: str,\n clear(): void {\n this.text = \"\";\n finalRender({ symbol: \"\", message: \"\" });\n },\n succeed(finalStr?: string | TemplateStringsArray, ...values: unknown[]): void {\n finalStr ??= str;\n if (!isString(finalStr)) {\n finalStr = dedent(chalkTemplate(finalStr, ...values));\n }\n this.text = finalStr;\n finalRender({ message: finalStr, symbol: successSymbol });\n },\n fail(finalStr?: string | TemplateStringsArray, ...values: unknown[]): void {\n finalStr ??= str;\n if (!isString(finalStr)) {\n finalStr = dedent(chalkTemplate(finalStr, ...values));\n }\n this.text = finalStr;\n finalRender({ message: finalStr, symbol: failSymbol });\n },\n };\n\n return activeSpinner;\n }) as spin;\n};\n\nexport const spin = createSpin({});\n"],"names":["chalk","chalkTemplate","cliSpinners","assert","os","dedent","isString","output","isSprintOptions","sprintln","symbol","activeSpinner","createSpin","options","optionsOrString","values","str","ensureNewLine","ensureEmptyLineAbove","kind","color","successSymbol","green","tick","failSymbol","red","cross","frameIndex","frames","interval","firstRender","render","message","final","finalRender","startsWith","slice","endsWith","undefined","length","lines","split","join","EOL","isInteractive","persistSpinner","updateSpinner","writeStdout","spinnerInterval","setInterval","renderOptions","clearInterval","text","clear","succeed","finalStr","fail","spin"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,mBAAmB,iBAAiB;AAE3C,OAAOC,iBAAiB,eAAe;AACvC,OAAOC,YAAY,cAAc;AACjC,OAAOC,QAAQ,UAAU;AACzB,SAASC,MAAM,QAAQ,YAAY;AACnC,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,M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B;QAEArC,gBAAgB;YACdyC,MAAMpC;YACNqC;gBACE,IAAI,CAACD,IAAI,GAAG;gBACZlB,YAAY;oBAAExB,QAAQ;oBAAIsB,SAAS;gBAAG;YACxC;YACAsB,SAAQC,QAAwC,EAAE,GAAGxC,MAAiB;gBACpEwC,aAAavC;gBACb,IAAI,CAACV,SAASiD,WAAW;oBACvBA,WAAWlD,OAAOJ,cAAcsD,aAAaxC;gBAC/C;gBACA,IAAI,CAACqC,IAAI,GAAGG;gBACZrB,YAAY;oBAAEF,SAASuB;oBAAU7C,QAAQW;gBAAc;YACzD;YACAmC,MAAKD,QAAwC,EAAE,GAAGxC,MAAiB;gBACjEwC,aAAavC;gBACb,IAAI,CAACV,SAASiD,WAAW;oBACvBA,WAAWlD,OAAOJ,cAAcsD,aAAaxC;gBAC/C;gBACA,IAAI,CAACqC,IAAI,GAAGG;gBACZrB,YAAY;oBAAEF,SAASuB;oBAAU7C,QAAQc;gBAAW;YACtD;QACF;QAEA,OAAOb;IACT;AACF,EAAE;AAEF,OAAO,MAAM8C,OAAO7C,WAAW,CAAC,GAAG"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import boxen from "boxen";
|
|
2
|
-
import chalkTemplate from "chalk-template";
|
|
3
|
-
import indentString from "indent-string";
|
|
4
|
-
import { dedent } from "ts-dedent";
|
|
5
|
-
import { isArray, isString } from "../util/is.js";
|
|
6
|
-
export const isSprintOptions = (value)=>{
|
|
7
|
-
return !isString(value) && !isArray(value);
|
|
8
|
-
};
|
|
9
|
-
const createSprint = (options)=>{
|
|
10
|
-
return (optionsOrString, ...values)=>{
|
|
11
|
-
if (isSprintOptions(optionsOrString)) {
|
|
12
|
-
return createSprint({
|
|
13
|
-
...options,
|
|
14
|
-
...optionsOrString
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
const { ensureNewLine = false, ensureEmptyLineAbove = false, indent = 0, boxen: boxenOptions } = options;
|
|
18
|
-
let str = optionsOrString;
|
|
19
|
-
if (!isString(str)) {
|
|
20
|
-
str = dedent(chalkTemplate(str, ...values));
|
|
21
|
-
}
|
|
22
|
-
if (ensureEmptyLineAbove && !str.startsWith("\n")) {
|
|
23
|
-
str = "\n" + str;
|
|
24
|
-
}
|
|
25
|
-
if (ensureNewLine && !str.endsWith("\n")) {
|
|
26
|
-
str += "\n";
|
|
27
|
-
}
|
|
28
|
-
if (boxenOptions) {
|
|
29
|
-
str = boxen(str, boxenOptions);
|
|
30
|
-
}
|
|
31
|
-
if (indent > 0) {
|
|
32
|
-
str = indentString(str, indent);
|
|
33
|
-
}
|
|
34
|
-
return str;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
export const sprint = createSprint({
|
|
38
|
-
ensureNewLine: false
|
|
39
|
-
});
|
|
40
|
-
export const sprintln = createSprint({
|
|
41
|
-
ensureNewLine: true
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
//# sourceMappingURL=sprint.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/output/sprint.ts"],"sourcesContent":["import type { Options as BoxenOptions } from \"boxen\";\nimport boxen from \"boxen\";\nimport chalkTemplate from \"chalk-template\";\nimport indentString from \"indent-string\";\nimport { dedent } from \"ts-dedent\";\nimport { isArray, isString } from \"../util/is.js\";\n\nexport type SprintOptions = {\n /**\n * Whether to ensure a new line is after the content.\n *\n * @default true\n */\n ensureNewLine?: boolean;\n\n /**\n * Whether to ensure an empty line is above the content.\n *\n * @default false\n */\n ensureEmptyLineAbove?: boolean;\n\n /**\n * The number of spaces to indent the text.\n *\n * @default 0\n */\n indent?: number;\n\n /**\n * Whether to wrap the text in a box.\n *\n * @default undefined (no box)\n */\n boxen?: BoxenOptions;\n};\n\nexport type sprint = {\n (str: string): string;\n (template: TemplateStringsArray, ...values: unknown[]): string;\n (options: SprintOptions): sprint;\n};\n\nexport const isSprintOptions = <const T extends SprintOptions>(value: string | TemplateStringsArray | SprintOptions): value is T => {\n return !isString(value) && !isArray(value);\n};\n\nconst createSprint = (options: SprintOptions): sprint => {\n return ((optionsOrString: SprintOptions | string | TemplateStringsArray, ...values: unknown[]): sprint | string => {\n if (isSprintOptions(optionsOrString)) {\n return createSprint({ ...options, ...optionsOrString });\n }\n\n const { ensureNewLine = false, ensureEmptyLineAbove = false, indent = 0, boxen: boxenOptions } = options;\n\n let str = optionsOrString as string;\n if (!isString(str)) {\n str = dedent(chalkTemplate(str, ...values));\n }\n\n if (ensureEmptyLineAbove && !str.startsWith(\"\\n\")) {\n str = \"\\n\" + str;\n }\n\n if (ensureNewLine && !str.endsWith(\"\\n\")) {\n str += \"\\n\";\n }\n\n if (boxenOptions) {\n str = boxen(str, boxenOptions);\n }\n\n if (indent > 0) {\n str = indentString(str, indent);\n }\n\n return str;\n }) as sprint;\n};\n\nexport const sprint = createSprint({ ensureNewLine: false });\nexport const sprintln = createSprint({ ensureNewLine: true });\n"],"names":["boxen","chalkTemplate","indentString","dedent","isArray","isString","isSprintOptions","value","createSprint","options","optionsOrString","values","ensureNewLine","ensureEmptyLineAbove","indent","boxenOptions","str","startsWith","endsWith","sprint","sprintln"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,mBAAmB,iBAAiB;AAC3C,OAAOC,kBAAkB,gBAAgB;AACzC,SAASC,MAAM,QAAQ,YAAY;AACnC,SAASC,OAAO,EAAEC,QAAQ,QAAQ,gBAAgB;AAsClD,OAAO,MAAMC,kBAAkB,CAAgCC;IAC7D,OAAO,CAACF,SAASE,UAAU,CAACH,QAAQG;AACtC,EAAE;AAEF,MAAMC,eAAe,CAACC;IACpB,OAAQ,CAACC,iBAAgE,GAAGC;QAC1E,IAAIL,gBAAgBI,kBAAkB;YACpC,OAAOF,aAAa;gBAAE,GAAGC,OAAO;gBAAE,GAAGC,eAAe;YAAC;QACvD;QAEA,MAAM,EAAEE,gBAAgB,KAAK,EAAEC,uBAAuB,KAAK,EAAEC,SAAS,CAAC,EAAEd,OAAOe,YAAY,EAAE,GAAGN;QAEjG,IAAIO,MAAMN;QACV,IAAI,CAACL,SAASW,MAAM;YAClBA,MAAMb,OAAOF,cAAce,QAAQL;QACrC;QAEA,IAAIE,wBAAwB,CAACG,IAAIC,UAAU,CAAC,OAAO;YACjDD,MAAM,OAAOA;QACf;QAEA,IAAIJ,iBAAiB,CAACI,IAAIE,QAAQ,CAAC,OAAO;YACxCF,OAAO;QACT;QAEA,IAAID,cAAc;YAChBC,MAAMhB,MAAMgB,KAAKD;QACnB;QAEA,IAAID,SAAS,GAAG;YACdE,MAAMd,aAAac,KAAKF;QAC1B;QAEA,OAAOE;IACT;AACF;AAEA,OAAO,MAAMG,SAASX,aAAa;IAAEI,eAAe;AAAM,GAAG;AAC7D,OAAO,MAAMQ,WAAWZ,aAAa;IAAEI,eAAe;AAAK,GAAG"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line no-restricted-imports -- this is the only place we're allowed to import figures
|
|
2
|
-
import figures, { mainSymbols } from "figures";
|
|
3
|
-
import isUnicodeSupported from "is-unicode-supported";
|
|
4
|
-
import { config } from "../config/config.js";
|
|
5
|
-
import { env } from "../config/env.js";
|
|
6
|
-
// we always use main symbols in tests rather than figures so that our
|
|
7
|
-
// tests are consistent across platforms (particularly Windows)
|
|
8
|
-
export const symbol = {
|
|
9
|
-
...env.testLike ? mainSymbols : figures
|
|
10
|
-
};
|
|
11
|
-
if (isUnicodeSupported() && config.windowsOrWsl) {
|
|
12
|
-
// when unicode is supported and we're on windows or wsl, these
|
|
13
|
-
// symbols end up rendering over two cells while only taking up one,
|
|
14
|
-
// so we add an extra space to each of them to make them take up two
|
|
15
|
-
for (const name of [
|
|
16
|
-
"tick",
|
|
17
|
-
"cross"
|
|
18
|
-
]){
|
|
19
|
-
symbol[name] += " ";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=symbols.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/output/symbols.ts"],"sourcesContent":["// eslint-disable-next-line no-restricted-imports -- this is the only place we're allowed to import figures\nimport figures, { mainSymbols } from \"figures\";\nimport isUnicodeSupported from \"is-unicode-supported\";\nimport { config } from \"../config/config.js\";\nimport { env } from \"../config/env.js\";\n\n// we always use main symbols in tests rather than figures so that our\n// tests are consistent across platforms (particularly Windows)\nexport const symbol = { ...(env.testLike ? mainSymbols : figures) };\n\nif (isUnicodeSupported() && config.windowsOrWsl) {\n // when unicode is supported and we're on windows or wsl, these\n // symbols end up rendering over two cells while only taking up one,\n // so we add an extra space to each of them to make them take up two\n for (const name of [\"tick\", \"cross\"] as const) {\n symbol[name] += \" \";\n }\n}\n"],"names":["figures","mainSymbols","isUnicodeSupported","config","env","symbol","testLike","windowsOrWsl","name"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,2GAA2G;AAC3G,OAAOA,WAAWC,WAAW,QAAQ,UAAU;AAC/C,OAAOC,wBAAwB,uBAAuB;AACtD,SAASC,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,GAAG,QAAQ,mBAAmB;AAEvC,sEAAsE;AACtE,+DAA+D;AAC/D,OAAO,MAAMC,SAAS;IAAE,GAAID,IAAIE,QAAQ,GAAGL,cAAcD,OAAO;AAAE,EAAE;AAEpE,IAAIE,wBAAwBC,OAAOI,YAAY,EAAE;IAC/C,+DAA+D;IAC/D,oEAAoE;IACpE,oEAAoE;IACpE,KAAK,MAAMC,QAAQ;QAAC;QAAQ;KAAQ,CAAW;QAC7CH,MAAM,CAACG,KAAK,IAAI;IAClB;AACF"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import CliTable3 from "cli-table3";
|
|
2
|
-
import indentString from "indent-string";
|
|
3
|
-
import { dedent } from "ts-dedent";
|
|
4
|
-
import { println } from "./print.js";
|
|
5
|
-
import { sprintln } from "./sprint.js";
|
|
6
|
-
export const sprintTable = ({ title, headers, rows, footer, ensureEmptyLineAboveBody = false, ensureEmptyLineAboveFooter = false, borders: borderType = "none", colAligns = [], colWidths = [], indent, ...printOptions })=>{
|
|
7
|
-
const table = new CliTable3({
|
|
8
|
-
chars: borders[borderType],
|
|
9
|
-
colAligns,
|
|
10
|
-
colWidths,
|
|
11
|
-
head: headers,
|
|
12
|
-
style: {
|
|
13
|
-
head: [],
|
|
14
|
-
border: []
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
table.push(...rows);
|
|
18
|
-
let text = table.toString() + "\n";
|
|
19
|
-
if (borderType === "none") {
|
|
20
|
-
// remove the left padding
|
|
21
|
-
text = dedent(text).slice(1);
|
|
22
|
-
}
|
|
23
|
-
// remove the right padding
|
|
24
|
-
text = text.split("\n").map((line)=>line.trimEnd()).join("\n");
|
|
25
|
-
if (indent) {
|
|
26
|
-
text = indentString(text, indent);
|
|
27
|
-
}
|
|
28
|
-
if (title) {
|
|
29
|
-
text = sprintln(title) + sprintln({
|
|
30
|
-
ensureEmptyLineAbove: ensureEmptyLineAboveBody
|
|
31
|
-
})(text);
|
|
32
|
-
}
|
|
33
|
-
if (footer) {
|
|
34
|
-
text = sprintln(text) + sprintln({
|
|
35
|
-
ensureEmptyLineAbove: ensureEmptyLineAboveFooter
|
|
36
|
-
})(footer);
|
|
37
|
-
}
|
|
38
|
-
return sprintln(printOptions)(text);
|
|
39
|
-
};
|
|
40
|
-
export const printTable = (options)=>{
|
|
41
|
-
println(options)(sprintTable(options));
|
|
42
|
-
};
|
|
43
|
-
// prettier-ignore
|
|
44
|
-
const borders = {
|
|
45
|
-
none: {
|
|
46
|
-
"top-left": "",
|
|
47
|
-
top: "",
|
|
48
|
-
"top-mid": "",
|
|
49
|
-
"top-right": "",
|
|
50
|
-
"left-mid": "",
|
|
51
|
-
mid: "",
|
|
52
|
-
"mid-mid": "",
|
|
53
|
-
"right-mid": "",
|
|
54
|
-
left: "",
|
|
55
|
-
middle: "",
|
|
56
|
-
right: "",
|
|
57
|
-
"bottom-left": "",
|
|
58
|
-
bottom: "",
|
|
59
|
-
"bottom-mid": "",
|
|
60
|
-
"bottom-right": ""
|
|
61
|
-
},
|
|
62
|
-
thin: {
|
|
63
|
-
"top-left": "┌",
|
|
64
|
-
top: "─",
|
|
65
|
-
"top-mid": "┬",
|
|
66
|
-
"top-right": "┐",
|
|
67
|
-
"left-mid": "├",
|
|
68
|
-
mid: "─",
|
|
69
|
-
"mid-mid": "┼",
|
|
70
|
-
"right-mid": "┤",
|
|
71
|
-
left: "│",
|
|
72
|
-
middle: "│",
|
|
73
|
-
right: "│",
|
|
74
|
-
"bottom-left": "└",
|
|
75
|
-
bottom: "─",
|
|
76
|
-
"bottom-mid": "┴",
|
|
77
|
-
"bottom-right": "┘"
|
|
78
|
-
},
|
|
79
|
-
thick: {
|
|
80
|
-
"top-left": "╔",
|
|
81
|
-
top: "═",
|
|
82
|
-
"top-mid": "╤",
|
|
83
|
-
"top-right": "╗",
|
|
84
|
-
left: "║",
|
|
85
|
-
middle: "│",
|
|
86
|
-
right: "║",
|
|
87
|
-
"left-mid": "╟",
|
|
88
|
-
mid: "─",
|
|
89
|
-
"mid-mid": "┼",
|
|
90
|
-
"right-mid": "╢",
|
|
91
|
-
"bottom-left": "╚",
|
|
92
|
-
bottom: "═",
|
|
93
|
-
"bottom-mid": "╧",
|
|
94
|
-
"bottom-right": "╝"
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
//# sourceMappingURL=table.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/output/table.ts"],"sourcesContent":["import CliTable3 from \"cli-table3\";\nimport indentString from \"indent-string\";\nimport { dedent } from \"ts-dedent\";\nimport { println, type PrintOptions } from \"./print.js\";\nimport { sprintln, type SprintOptions } from \"./sprint.js\";\n\nexport type SprintTableOptions = SprintOptions & {\n /**\n * The text to print above the table.\n */\n title?: string;\n\n /**\n * The headers of the table.\n */\n headers?: string[];\n\n /**\n * The rows of the table.\n */\n rows: string[][];\n\n /**\n * The text to print below the table.\n */\n footer?: string;\n\n /**\n * Whether to add an empty line above the body of the table.\n *\n * @default false\n */\n ensureEmptyLineAboveBody?: boolean;\n\n /**\n * Whether to add an empty line above the footer of the table.\n *\n * @default false\n */\n ensureEmptyLineAboveFooter?: boolean;\n\n /**\n * The type of borders to use.\n *\n * @default \"none\"\n */\n borders?: \"none\" | \"thin\" | \"thick\";\n\n /**\n * The alignment of the content in each column.\n *\n * @default [] (left-aligned)\n */\n colAligns?: (\"left\" | \"center\" | \"right\")[];\n\n /**\n * The width of each column.\n *\n * @default [] (auto-sized)\n */\n colWidths?: number[];\n};\n\nexport const sprintTable = ({\n title,\n headers,\n rows,\n footer,\n ensureEmptyLineAboveBody = false,\n ensureEmptyLineAboveFooter = false,\n borders: borderType = \"none\",\n colAligns = [],\n colWidths = [],\n indent,\n ...printOptions\n}: SprintTableOptions): string => {\n const table = new CliTable3({\n chars: borders[borderType],\n colAligns,\n colWidths,\n head: headers,\n style: { head: [], border: [] },\n });\n\n table.push(...rows);\n\n let text = table.toString() + \"\\n\";\n if (borderType === \"none\") {\n // remove the left padding\n text = dedent(text).slice(1);\n }\n\n // remove the right padding\n text = text\n .split(\"\\n\")\n .map((line) => line.trimEnd())\n .join(\"\\n\");\n\n if (indent) {\n text = indentString(text, indent);\n }\n\n if (title) {\n text = sprintln(title) + sprintln({ ensureEmptyLineAbove: ensureEmptyLineAboveBody })(text);\n }\n\n if (footer) {\n text = sprintln(text) + sprintln({ ensureEmptyLineAbove: ensureEmptyLineAboveFooter })(footer);\n }\n\n return sprintln(printOptions)(text);\n};\n\nexport type PrintTableOptions = PrintOptions & SprintTableOptions;\n\nexport const printTable = (options: PrintTableOptions): void => {\n println(options)(sprintTable(options));\n};\n\n// prettier-ignore\nconst borders = {\n none: {\n \"top-left\": \"\", top: \"\", \"top-mid\": \"\", \"top-right\": \"\",\n \"left-mid\": \"\", mid: \"\", \"mid-mid\": \"\", \"right-mid\": \"\",\n left: \"\", middle: \"\", right: \"\",\n \"bottom-left\": \"\", bottom: \"\", \"bottom-mid\": \"\", \"bottom-right\": \"\",\n },\n thin: {\n \"top-left\": \"┌\", top: \"─\", \"top-mid\": \"┬\", \"top-right\": \"┐\",\n \"left-mid\": \"├\", mid: \"─\", \"mid-mid\": \"┼\", \"right-mid\": \"┤\",\n left: \"│\", middle: \"│\", right: \"│\",\n \"bottom-left\": \"└\", bottom: \"─\", \"bottom-mid\": \"┴\", \"bottom-right\": \"┘\",\n },\n thick: {\n \"top-left\": \"╔\", top: \"═\", \"top-mid\": \"╤\", \"top-right\": \"╗\",\n left: \"║\", middle: \"│\", right: \"║\",\n \"left-mid\": \"╟\", mid: \"─\", \"mid-mid\": \"┼\", \"right-mid\": \"╢\",\n \"bottom-left\": \"╚\", bottom: \"═\", \"bottom-mid\": \"╧\", \"bottom-right\": \"╝\",\n },\n };\n"],"names":["CliTable3","indentString","dedent","println","sprintln","sprintTable","title","headers","rows","footer","ensureEmptyLineAboveBody","ensureEmptyLineAboveFooter","borders","borderType","colAligns","colWidths","indent","printOptions","table","chars","head","style","border","push","text","toString","slice","split","map","line","trimEnd","join","ensureEmptyLineAbove","printTable","options","none","top","mid","left","middle","right","bottom","thin","thick"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,eAAe,aAAa;AACnC,OAAOC,kBAAkB,gBAAgB;AACzC,SAASC,MAAM,QAAQ,YAAY;AACnC,SAASC,OAAO,QAA2B,aAAa;AACxD,SAASC,QAAQ,QAA4B,cAAc;AA2D3D,OAAO,MAAMC,cAAc,CAAC,EAC1BC,KAAK,EACLC,OAAO,EACPC,IAAI,EACJC,MAAM,EACNC,2BAA2B,KAAK,EAChCC,6BAA6B,KAAK,EAClCC,SAASC,aAAa,MAAM,E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MAAM;QAAKC,QAAQ;QAAKC,OAAO;QAC/B,eAAe;QAAKC,QAAQ;QAAK,cAAc;QAAK,gBAAgB;IACtE;IACAE,OAAO;QACL,YAAY;QAAKP,KAAK;QAAK,WAAW;QAAK,aAAa;QACxDE,MAAM;QAAKC,QAAQ;QAAKC,OAAO;QAC/B,YAAY;QAAKH,KAAK;QAAK,WAAW;QAAK,aAAa;QACxD,eAAe;QAAKI,QAAQ;QAAK,cAAc;QAAK,gBAAgB;IACtE;AACF"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import dayjs from "dayjs";
|
|
3
|
-
import { env } from "../config/env.js";
|
|
4
|
-
import { parseBoolean } from "../util/boolean.js";
|
|
5
|
-
export const ts = ()=>{
|
|
6
|
-
if (!env.testLike && parseBoolean(process.env["CI"])) {
|
|
7
|
-
return new Date().toISOString();
|
|
8
|
-
}
|
|
9
|
-
return chalk.gray(dayjs().format("hh:mm:ss A"));
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=timestamp.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/output/timestamp.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport dayjs from \"dayjs\";\nimport { env } from \"../config/env.js\";\nimport { parseBoolean } from \"../util/boolean.js\";\n\nexport const ts = (): string => {\n if (!env.testLike && parseBoolean(process.env[\"CI\"])) {\n return new Date().toISOString();\n }\n return chalk.gray(dayjs().format(\"hh:mm:ss A\"));\n};\n"],"names":["chalk","dayjs","env","parseBoolean","ts","testLike","process","Date","toISOString","gray","format"],"rangeMappings":";;;;;;;;;","mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,GAAG,QAAQ,mBAAmB;AACvC,SAASC,YAAY,QAAQ,qBAAqB;AAElD,OAAO,MAAMC,KAAK;IAChB,IAAI,CAACF,IAAIG,QAAQ,IAAIF,aAAaG,QAAQJ,GAAG,CAAC,KAAK,GAAG;QACpD,OAAO,IAAIK,OAAOC,WAAW;IAC/B;IACA,OAAOR,MAAMS,IAAI,CAACR,QAAQS,MAAM,CAAC;AACnC,EAAE"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import boxen from "boxen";
|
|
2
|
-
import dayjs from "dayjs";
|
|
3
|
-
import fs from "fs-extra";
|
|
4
|
-
import ms from "ms";
|
|
5
|
-
import assert from "node:assert";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import semver from "semver";
|
|
8
|
-
import { z } from "zod";
|
|
9
|
-
import { config } from "../config/config.js";
|
|
10
|
-
import { packageJson } from "../config/package-json.js";
|
|
11
|
-
import { http } from "../http/http.js";
|
|
12
|
-
import { println } from "./print.js";
|
|
13
|
-
import { sprint } from "./sprint.js";
|
|
14
|
-
const UPDATE_CHECK_FREQUENCY = ms("12 hours");
|
|
15
|
-
const Registry = z.object({
|
|
16
|
-
name: z.literal("ggt"),
|
|
17
|
-
"dist-tags": z.object({
|
|
18
|
-
latest: z.string(),
|
|
19
|
-
experimental: z.string()
|
|
20
|
-
})
|
|
21
|
-
});
|
|
22
|
-
export const getDistTags = async (ctx)=>{
|
|
23
|
-
const json = await http({
|
|
24
|
-
context: {
|
|
25
|
-
ctx
|
|
26
|
-
},
|
|
27
|
-
method: "GET",
|
|
28
|
-
url: "https://registry.npmjs.org/ggt",
|
|
29
|
-
responseType: "json",
|
|
30
|
-
resolveBodyOnly: true,
|
|
31
|
-
timeout: {
|
|
32
|
-
request: ms("5s")
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
return Registry.parse(json)["dist-tags"];
|
|
36
|
-
};
|
|
37
|
-
export const shouldCheckForUpdate = async ()=>{
|
|
38
|
-
try {
|
|
39
|
-
const lastCheck = Number(await fs.readFile(path.join(config.cacheDir, "last-update-check"), "utf8"));
|
|
40
|
-
assert(!Number.isNaN(lastCheck));
|
|
41
|
-
return dayjs().isAfter(lastCheck + UPDATE_CHECK_FREQUENCY);
|
|
42
|
-
} catch (error) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Checks for updates to the `ggt` npm package and logs a warning
|
|
48
|
-
* message if an update is available.
|
|
49
|
-
*
|
|
50
|
-
* @returns A Promise that resolves with void when the check is
|
|
51
|
-
* complete.
|
|
52
|
-
*/ export const warnIfUpdateAvailable = async (ctx)=>{
|
|
53
|
-
try {
|
|
54
|
-
const shouldCheck = await shouldCheckForUpdate();
|
|
55
|
-
if (!shouldCheck) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
await fs.outputFile(path.join(config.cacheDir, "last-update-check"), String(Date.now()));
|
|
59
|
-
const tags = await getDistTags(ctx);
|
|
60
|
-
let latest;
|
|
61
|
-
let updateAvailable;
|
|
62
|
-
let updateMessage;
|
|
63
|
-
if (packageJson.version.includes("experimental")) {
|
|
64
|
-
// this is an experimental release
|
|
65
|
-
latest = tags.experimental;
|
|
66
|
-
updateAvailable = packageJson.version !== latest;
|
|
67
|
-
updateMessage = sprint`
|
|
68
|
-
Update available! {red ${packageJson.version}} → {green ${latest}}
|
|
69
|
-
Run "npm install -g ${packageJson.name}@experimental" to update.
|
|
70
|
-
`;
|
|
71
|
-
} else {
|
|
72
|
-
// this is a stable release
|
|
73
|
-
latest = tags.latest;
|
|
74
|
-
updateAvailable = semver.lt(packageJson.version, latest);
|
|
75
|
-
updateMessage = sprint`
|
|
76
|
-
Update available! {red ${packageJson.version}} → {green ${latest}}
|
|
77
|
-
Changelog: https://github.com/gadget-inc/ggt/releases/tag/v${latest}
|
|
78
|
-
Run "npm install -g ${packageJson.name}" to update.
|
|
79
|
-
`;
|
|
80
|
-
}
|
|
81
|
-
if (updateAvailable) {
|
|
82
|
-
ctx.log.info("update available", {
|
|
83
|
-
current: packageJson.version,
|
|
84
|
-
latest
|
|
85
|
-
});
|
|
86
|
-
println(boxen(updateMessage, {
|
|
87
|
-
padding: 1,
|
|
88
|
-
borderStyle: "round",
|
|
89
|
-
textAlignment: "center"
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
} catch (error) {
|
|
93
|
-
ctx.log.error("failed to check for updates", {
|
|
94
|
-
error
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
//# sourceMappingURL=update.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/output/update.ts"],"sourcesContent":["import boxen from \"boxen\";\nimport dayjs from \"dayjs\";\nimport fs from \"fs-extra\";\nimport ms from \"ms\";\nimport assert from \"node:assert\";\nimport path from \"node:path\";\nimport semver from \"semver\";\nimport { z } from \"zod\";\nimport type { Context } from \"../command/context.js\";\nimport { config } from \"../config/config.js\";\nimport { packageJson } from \"../config/package-json.js\";\nimport { http } from \"../http/http.js\";\nimport { println } from \"./print.js\";\nimport { sprint } from \"./sprint.js\";\n\nconst UPDATE_CHECK_FREQUENCY = ms(\"12 hours\");\n\nconst Registry = z.object({\n name: z.literal(\"ggt\"),\n \"dist-tags\": z.object({\n latest: z.string(),\n experimental: z.string(),\n }),\n});\n\ntype Registry = z.infer<typeof Registry>;\n\nexport const getDistTags = async (ctx: Context): Promise<Registry[\"dist-tags\"]> => {\n const json = await http({\n context: { ctx },\n method: \"GET\",\n url: \"https://registry.npmjs.org/ggt\",\n responseType: \"json\",\n resolveBodyOnly: true,\n timeout: {\n request: ms(\"5s\"),\n },\n });\n\n return Registry.parse(json)[\"dist-tags\"];\n};\n\nexport const shouldCheckForUpdate = async (): Promise<boolean> => {\n try {\n const lastCheck = Number(await fs.readFile(path.join(config.cacheDir, \"last-update-check\"), \"utf8\"));\n assert(!Number.isNaN(lastCheck));\n return dayjs().isAfter(lastCheck + UPDATE_CHECK_FREQUENCY);\n } catch (error) {\n return true;\n }\n};\n\n/**\n * Checks for updates to the `ggt` npm package and logs a warning\n * message if an update is available.\n *\n * @returns A Promise that resolves with void when the check is\n * complete.\n */\nexport const warnIfUpdateAvailable = async (ctx: Context): Promise<void> => {\n try {\n const shouldCheck = await shouldCheckForUpdate();\n if (!shouldCheck) {\n return;\n }\n\n await fs.outputFile(path.join(config.cacheDir, \"last-update-check\"), String(Date.now()));\n\n const tags = await getDistTags(ctx);\n\n let latest: string;\n let updateAvailable: boolean;\n let updateMessage: string;\n\n if (packageJson.version.includes(\"experimental\")) {\n // this is an experimental release\n latest = tags.experimental;\n updateAvailable = packageJson.version !== latest;\n updateMessage = sprint`\n Update available! {red ${packageJson.version}} → {green ${latest}}\n Run \"npm install -g ${packageJson.name}@experimental\" to update.\n `;\n } else {\n // this is a stable release\n latest = tags.latest;\n updateAvailable = semver.lt(packageJson.version, latest);\n updateMessage = sprint`\n Update available! {red ${packageJson.version}} → {green ${latest}}\n Changelog: https://github.com/gadget-inc/ggt/releases/tag/v${latest}\n Run \"npm install -g ${packageJson.name}\" to update.\n `;\n }\n\n if (updateAvailable) {\n ctx.log.info(\"update available\", { current: packageJson.version, latest });\n println(\n boxen(updateMessage, {\n padding: 1,\n borderStyle: \"round\",\n textAlignment: \"center\",\n }),\n );\n }\n } catch (error) {\n ctx.log.error(\"failed to check for updates\", { error });\n }\n};\n"],"names":["boxen","dayjs","fs","ms","assert","path","semver","z","config","packageJson","http","println","sprint","UPDATE_CHECK_FREQUENCY","Registry","object","name","literal","latest","string","experimental","getDistTags","ctx","json","context","method","url","responseType","resolveBodyOnly","timeout","request","parse","shouldCheckForUpdate","lastCheck","Number","readFile","join","cacheDir","isNaN","isAfter","error","warnIfUpdateAvailable","shouldCheck","outputFile","String","Date","now","tags","updateAvailable","updateMessage","version","includes","lt","log","info","current","padding","borderStyle","textAlignment"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,OA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,GAAGyC,UAAU,CAACtC,KAAK+B,IAAI,CAAC5B,OAAO6B,QAAQ,EAAE,sBAAsBO,OAAOC,KAAKC,GAAG;QAEpF,MAAMC,OAAO,MAAM1B,YAAYC;QAE/B,IAAIJ;QACJ,IAAI8B;QACJ,IAAIC;QAEJ,IAAIxC,YAAYyC,OAAO,CAACC,QAAQ,CAAC,iBAAiB;YAChD,kCAAkC;YAClCjC,SAAS6B,KAAK3B,YAAY;YAC1B4B,kBAAkBvC,YAAYyC,OAAO,KAAKhC;YAC1C+B,gBAAgBrC,MAAM,CAAC;+BACE,EAAEH,YAAYyC,OAAO,CAAC,WAAW,EAAEhC,OAAO;4BAC7C,EAAET,YAAYO,IAAI,CAAC;MACzC,CAAC;QACH,OAAO;YACL,2BAA2B;YAC3BE,SAAS6B,KAAK7B,MAAM;YACpB8B,kBAAkB1C,OAAO8C,EAAE,CAAC3C,YAAYyC,OAAO,EAAEhC;YACjD+B,gBAAgBrC,MAAM,CAAC;+BACE,EAAEH,YAAYyC,OAAO,CAAC,WAAW,EAAEhC,OAAO;mEACN,EAAEA,OAAO;4BAChD,EAAET,YAAYO,IAAI,CAAC;MACzC,CAAC;QACH;QAEA,IAAIgC,iBAAiB;YACnB1B,IAAI+B,GAAG,CAACC,IAAI,CAAC,oBAAoB;gBAAEC,SAAS9C,YAAYyC,OAAO;gBAAEhC;YAAO;YACxEP,QACEX,MAAMiD,eAAe;gBACnBO,SAAS;gBACTC,aAAa;gBACbC,eAAe;YACjB;QAEJ;IACF,EAAE,OAAOlB,OAAO;QACdlB,IAAI+B,GAAG,CAACb,KAAK,CAAC,+BAA+B;YAAEA;QAAM;IACvD;AACF,EAAE"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import fs from "fs-extra";
|
|
2
|
-
import { configPath } from "../config/config.js";
|
|
3
|
-
import { swallowEnoent } from "../filesync/directory.js";
|
|
4
|
-
import { createLogger } from "../output/log/logger.js";
|
|
5
|
-
import { memo } from "../util/function.js";
|
|
6
|
-
const log = createLogger({
|
|
7
|
-
name: "session"
|
|
8
|
-
});
|
|
9
|
-
/**
|
|
10
|
-
* Reads the session from either the environment variable `GGT_SESSION`
|
|
11
|
-
* or from the `session.txt` file in the config directory.
|
|
12
|
-
*
|
|
13
|
-
* @returns The session string if found, otherwise undefined.
|
|
14
|
-
*/ export const readSession = memo(()=>{
|
|
15
|
-
if (process.env["GGT_SESSION"]) {
|
|
16
|
-
log.debug("reading session from env");
|
|
17
|
-
return process.env["GGT_SESSION"];
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
log.debug("reading session from disk");
|
|
21
|
-
return fs.readFileSync(configPath("session.txt"), "utf8");
|
|
22
|
-
} catch (error) {
|
|
23
|
-
swallowEnoent(error);
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* Writes the session to disk in the `session.txt` file in the config.
|
|
29
|
-
*
|
|
30
|
-
* @param session - The session to write to disk.
|
|
31
|
-
*/ export const writeSession = (session)=>{
|
|
32
|
-
readSession.clear();
|
|
33
|
-
if (process.env["GGT_SESSION"]) {
|
|
34
|
-
log.debug("writing session to env", {
|
|
35
|
-
session: Boolean(session)
|
|
36
|
-
});
|
|
37
|
-
process.env["GGT_SESSION"] = session;
|
|
38
|
-
}
|
|
39
|
-
log.debug("writing session to disk", {
|
|
40
|
-
session: Boolean(session),
|
|
41
|
-
path: configPath("session.txt")
|
|
42
|
-
});
|
|
43
|
-
if (session) {
|
|
44
|
-
fs.outputFileSync(configPath("session.txt"), session);
|
|
45
|
-
} else {
|
|
46
|
-
fs.removeSync(configPath("session.txt"));
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
export const readToken = ()=>{
|
|
50
|
-
log.debug("reading token from env");
|
|
51
|
-
return process.env["GGT_TOKEN"];
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
//# sourceMappingURL=session.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/services/user/session.ts"],"sourcesContent":["import fs from \"fs-extra\";\nimport { configPath } from \"../config/config.js\";\nimport { swallowEnoent } from \"../filesync/directory.js\";\nimport { createLogger } from \"../output/log/logger.js\";\nimport { memo } from \"../util/function.js\";\n\nconst log = createLogger({ name: \"session\" });\n\n/**\n * Reads the session from either the environment variable `GGT_SESSION`\n * or from the `session.txt` file in the config directory.\n *\n * @returns The session string if found, otherwise undefined.\n */\nexport const readSession = memo((): string | undefined => {\n if (process.env[\"GGT_SESSION\"]) {\n log.debug(\"reading session from env\");\n return process.env[\"GGT_SESSION\"];\n }\n\n try {\n log.debug(\"reading session from disk\");\n return fs.readFileSync(configPath(\"session.txt\"), \"utf8\");\n } catch (error) {\n swallowEnoent(error);\n return undefined;\n }\n});\n\n/**\n * Writes the session to disk in the `session.txt` file in the config.\n *\n * @param session - The session to write to disk.\n */\nexport const writeSession = (session: string | undefined): void => {\n readSession.clear();\n\n if (process.env[\"GGT_SESSION\"]) {\n log.debug(\"writing session to env\", { session: Boolean(session) });\n process.env[\"GGT_SESSION\"] = session;\n }\n\n log.debug(\"writing session to disk\", { session: Boolean(session), path: configPath(\"session.txt\") });\n\n if (session) {\n fs.outputFileSync(configPath(\"session.txt\"), session);\n } else {\n fs.removeSync(configPath(\"session.txt\"));\n }\n};\n\nexport const readToken = (): string | undefined => {\n log.debug(\"reading token from env\");\n return process.env[\"GGT_TOKEN\"];\n};\n"],"names":["fs","configPath","swallowEnoent","createLogger","memo","log","name","readSession","process","env","debug","readFileSync","error","undefined","writeSession","session","clear","Boolean","path","outputFileSync","removeSync","readToken"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,QAAQ,WAAW;AAC1B,SAASC,UAAU,QAAQ,sBAAsB;AACjD,SAASC,aAAa,QAAQ,2BAA2B;AACzD,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,IAAI,QAAQ,sBAAsB;AAE3C,MAAMC,MAAMF,aAAa;IAAEG,MAAM;AAAU;AAE3C;;;;;CAKC,GACD,OAAO,MAAMC,cAAcH,KAAK;IAC9B,IAAII,QAAQC,GAAG,CAAC,cAAc,EAAE;QAC9BJ,IAAIK,KAAK,CAAC;QACV,OAAOF,QAAQC,GAAG,CAAC,cAAc;IACnC;IAEA,IAAI;QACFJ,IAAIK,KAAK,CAAC;QACV,OAAOV,GAAGW,YAAY,CAACV,WAAW,gBAAgB;IACpD,EAAE,OAAOW,OAAO;QACdV,cAAcU;QACd,OAAOC;IACT;AACF,GAAG;AAEH;;;;CAIC,GACD,OAAO,MAAMC,eAAe,CAACC;IAC3BR,YAAYS,KAAK;IAEjB,IAAIR,QAAQC,GAAG,CAAC,cAAc,EAAE;QAC9BJ,IAAIK,KAAK,CAAC,0BAA0B;YAAEK,SAASE,QAAQF;QAAS;QAChEP,QAAQC,GAAG,CAAC,cAAc,GAAGM;IAC/B;IAEAV,IAAIK,KAAK,CAAC,2BAA2B;QAAEK,SAASE,QAAQF;QAAUG,MAAMjB,WAAW;IAAe;IAElG,IAAIc,SAAS;QACXf,GAAGmB,cAAc,CAAClB,WAAW,gBAAgBc;IAC/C,OAAO;QACLf,GAAGoB,UAAU,CAACnB,WAAW;IAC3B;AACF,EAAE;AAEF,OAAO,MAAMoB,YAAY;IACvBhB,IAAIK,KAAK,CAAC;IACV,OAAOF,QAAQC,GAAG,CAAC,YAAY;AACjC,EAAE"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import { login } from "../../commands/login.js";
|
|
4
|
-
import { config } from "../config/config.js";
|
|
5
|
-
import { loadAuthHeaders, swallowUnauthorized } from "../http/auth.js";
|
|
6
|
-
import { http } from "../http/http.js";
|
|
7
|
-
import { confirm } from "../output/confirm.js";
|
|
8
|
-
import { println } from "../output/print.js";
|
|
9
|
-
const User = z.object({
|
|
10
|
-
id: z.union([
|
|
11
|
-
z.string(),
|
|
12
|
-
z.number()
|
|
13
|
-
]).transform(Number),
|
|
14
|
-
name: z.string().nullish(),
|
|
15
|
-
email: z.string()
|
|
16
|
-
});
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves the currently logged in user from Gadgets API.
|
|
19
|
-
*
|
|
20
|
-
* @returns A Promise that resolves to a User object representing the
|
|
21
|
-
* current user, or undefined if the user is not authenticated.
|
|
22
|
-
*/ export const getUser = async (ctx)=>{
|
|
23
|
-
if (ctx.user) {
|
|
24
|
-
return ctx.user;
|
|
25
|
-
}
|
|
26
|
-
const headers = loadAuthHeaders();
|
|
27
|
-
if (!headers) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
const json = await http({
|
|
32
|
-
context: {
|
|
33
|
-
ctx
|
|
34
|
-
},
|
|
35
|
-
url: `https://${config.domains.services}/auth/api/current-user`,
|
|
36
|
-
headers: {
|
|
37
|
-
...headers
|
|
38
|
-
},
|
|
39
|
-
responseType: "json",
|
|
40
|
-
resolveBodyOnly: true
|
|
41
|
-
});
|
|
42
|
-
ctx.user = User.parse(json);
|
|
43
|
-
ctx.log.info("loaded user");
|
|
44
|
-
return ctx.user;
|
|
45
|
-
} catch (error) {
|
|
46
|
-
swallowUnauthorized(ctx, error);
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Retrieves the current user or prompts the user to log in if not
|
|
52
|
-
* already logged in.
|
|
53
|
-
*
|
|
54
|
-
* @param ctx - The current context.
|
|
55
|
-
* @returns A Promise that resolves to the current user.
|
|
56
|
-
*/ export const getUserOrLogin = async (ctx)=>{
|
|
57
|
-
let user = await getUser(ctx);
|
|
58
|
-
if (user) {
|
|
59
|
-
return user;
|
|
60
|
-
}
|
|
61
|
-
ctx.log.info("prompting user to log in");
|
|
62
|
-
println({
|
|
63
|
-
ensureEmptyLineAbove: true
|
|
64
|
-
})`
|
|
65
|
-
You must be logged in to use "ggt ${ctx.command}".
|
|
66
|
-
`;
|
|
67
|
-
await confirm({
|
|
68
|
-
ensureEmptyLineAbove: true
|
|
69
|
-
})("Would you like to log in?");
|
|
70
|
-
await login(ctx);
|
|
71
|
-
user = await getUser(ctx);
|
|
72
|
-
assert(user, "missing user after successful login");
|
|
73
|
-
return user;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
//# sourceMappingURL=user.js.map
|