@gadgetinc/ggt 1.0.3 → 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 +73 -75
- 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 -93
- 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 -29512
package/lib/commands/dev.js
DELETED
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
import dayjs from "dayjs";
|
|
2
|
-
import ms from "ms";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import Watcher from "watcher";
|
|
5
|
-
import which from "which";
|
|
6
|
-
import { Changes } from "../services/filesync/changes.js";
|
|
7
|
-
import { YarnNotFoundError } from "../services/filesync/error.js";
|
|
8
|
-
import { FileSync } from "../services/filesync/filesync.js";
|
|
9
|
-
import { FileSyncStrategy, MergeConflictPreferenceArg } from "../services/filesync/strategy.js";
|
|
10
|
-
import { SyncJson, SyncJsonArgs, loadSyncJsonDirectory } from "../services/filesync/sync-json.js";
|
|
11
|
-
import { footer } from "../services/output/footer.js";
|
|
12
|
-
import { notify } from "../services/output/notify.js";
|
|
13
|
-
import { println } from "../services/output/print.js";
|
|
14
|
-
import { reportErrorAndExit } from "../services/output/report.js";
|
|
15
|
-
import { select } from "../services/output/select.js";
|
|
16
|
-
import { spin } from "../services/output/spinner.js";
|
|
17
|
-
import { sprint } from "../services/output/sprint.js";
|
|
18
|
-
import { symbol } from "../services/output/symbols.js";
|
|
19
|
-
import { unreachable } from "../services/util/assert.js";
|
|
20
|
-
import { debounceAsync } from "../services/util/function.js";
|
|
21
|
-
import { isAbortError } from "../services/util/is.js";
|
|
22
|
-
import { delay } from "../services/util/promise.js";
|
|
23
|
-
export const args = {
|
|
24
|
-
...SyncJsonArgs,
|
|
25
|
-
"--prefer": MergeConflictPreferenceArg,
|
|
26
|
-
"--file-push-delay": {
|
|
27
|
-
type: Number,
|
|
28
|
-
default: ms("100ms")
|
|
29
|
-
},
|
|
30
|
-
"--file-watch-debounce": {
|
|
31
|
-
type: Number,
|
|
32
|
-
default: ms("300ms")
|
|
33
|
-
},
|
|
34
|
-
"--file-watch-poll-interval": {
|
|
35
|
-
type: Number,
|
|
36
|
-
default: ms("3s")
|
|
37
|
-
},
|
|
38
|
-
"--file-watch-poll-timeout": {
|
|
39
|
-
type: Number,
|
|
40
|
-
default: ms("20s")
|
|
41
|
-
},
|
|
42
|
-
"--file-watch-rename-timeout": {
|
|
43
|
-
type: Number,
|
|
44
|
-
default: ms("1.25s")
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
export const usage = (_ctx)=>{
|
|
48
|
-
return sprint`
|
|
49
|
-
Clones your Gadget environment's files to your local machine and keeps it in sync, in order to
|
|
50
|
-
enable local development with your text editor and source code with Git.
|
|
51
|
-
|
|
52
|
-
If your app's local directory already exists, this command first performs a sync to ensure
|
|
53
|
-
that your local and environment directories match, changes are tracked since last sync. If any
|
|
54
|
-
conflicts are detected, they must be resolved before development starts.
|
|
55
|
-
|
|
56
|
-
{gray Usage}
|
|
57
|
-
$ ggt dev [DIRECTORY] [options]
|
|
58
|
-
|
|
59
|
-
DIRECTORY: The directory to sync files to (default: the current directory)
|
|
60
|
-
|
|
61
|
-
{gray Options}
|
|
62
|
-
-a, --app <app_name> Selects the app to sync files with. Default set on ".gadget/sync.json"
|
|
63
|
-
-e, --env <env_name> Selects the environment to sync files with. Default set on ".gadget/sync.json"
|
|
64
|
-
--prefer <source> Auto-select changes from 'local' or 'environment' source on conflict
|
|
65
|
-
--allow-unknown-directory Syncs to any local directory with existing files, even if the ".gadget/sync.json" file is missing
|
|
66
|
-
--allow-different-app Syncs with a different app using the --app command, instead of the one specified in the .gadget/sync.json file
|
|
67
|
-
|
|
68
|
-
{gray Ignoring files}
|
|
69
|
-
ggt dev uses a .ignore file, similar to .gitignore, to exclude specific files and
|
|
70
|
-
folders from syncing. These files are always ignored:
|
|
71
|
-
|
|
72
|
-
• .DS_Store
|
|
73
|
-
• .gadget
|
|
74
|
-
• .git
|
|
75
|
-
• node_modules
|
|
76
|
-
|
|
77
|
-
{gray Notes}
|
|
78
|
-
• "ggt dev" only works with development environments
|
|
79
|
-
• "ggt dev" only supports "yarn" v1 for installing dependencies
|
|
80
|
-
• Avoid deleting or moving all of your files while "ggt dev" is running
|
|
81
|
-
|
|
82
|
-
{gray Examples}
|
|
83
|
-
sync an app in a custom path
|
|
84
|
-
{cyanBright $ ggt dev ~/myGadgetApps/myBlog --app myBlogApp}
|
|
85
|
-
|
|
86
|
-
sync with a specific environment and preselect all local changes on conflicts
|
|
87
|
-
{cyanBright $ ggt dev --env main --prefer local}
|
|
88
|
-
|
|
89
|
-
sync a custom path with a specific app, environment and preselect all changes from local on conflicts
|
|
90
|
-
{cyanBright $ ggt dev ~/gadget/example --app=example --env=development --prefer=local}
|
|
91
|
-
`;
|
|
92
|
-
};
|
|
93
|
-
export const command = async (ctx)=>{
|
|
94
|
-
if (!await which("yarn", {
|
|
95
|
-
nothrow: true
|
|
96
|
-
})) {
|
|
97
|
-
throw new YarnNotFoundError();
|
|
98
|
-
}
|
|
99
|
-
const directory = await loadSyncJsonDirectory(ctx.args._[0] || process.cwd());
|
|
100
|
-
const syncJson = await SyncJson.loadOrInit(ctx, {
|
|
101
|
-
directory
|
|
102
|
-
});
|
|
103
|
-
footer({
|
|
104
|
-
ensureEmptyLineAbove: true
|
|
105
|
-
})(syncJson.sprint());
|
|
106
|
-
const filesync = new FileSync(syncJson);
|
|
107
|
-
const hashes = await filesync.hashes(ctx);
|
|
108
|
-
if (!hashes.inSync) {
|
|
109
|
-
// our local files don't match our environment's files
|
|
110
|
-
if (!syncJson.previousEnvironment || hashes.localChangesToPush.size === 0 && hashes.onlyDotGadgetFilesChanged) {
|
|
111
|
-
// one of the following is true:
|
|
112
|
-
// - we're developing on this environment for the first time
|
|
113
|
-
// - we're developing on the same environment as last time
|
|
114
|
-
// - we're developing on a different environment, but only .gadget/ files have changed
|
|
115
|
-
// merge the changes (if any) and continue
|
|
116
|
-
await filesync.merge(ctx, {
|
|
117
|
-
hashes,
|
|
118
|
-
printLocalChangesOptions: {
|
|
119
|
-
limit: 5
|
|
120
|
-
},
|
|
121
|
-
printEnvironmentChangesOptions: {
|
|
122
|
-
limit: 5
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
} else {
|
|
126
|
-
// we're switching environment's and files outside of .gadget/
|
|
127
|
-
// have changed, so ask the user what to do
|
|
128
|
-
await filesync.print(ctx, {
|
|
129
|
-
hashes
|
|
130
|
-
});
|
|
131
|
-
const choices = Object.values(FileSyncStrategy);
|
|
132
|
-
const strategy = await select({
|
|
133
|
-
ensureEmptyLineAbove: true,
|
|
134
|
-
choices: hashes.bothChanged ? choices : choices.filter((choice)=>choice !== FileSyncStrategy.MERGE),
|
|
135
|
-
formatChoice: (choice)=>{
|
|
136
|
-
switch(choice){
|
|
137
|
-
case FileSyncStrategy.CANCEL:
|
|
138
|
-
return sprint`Cancel (Ctrl+C)`;
|
|
139
|
-
case FileSyncStrategy.MERGE:
|
|
140
|
-
return sprint`Merge local and environment's changes`;
|
|
141
|
-
case FileSyncStrategy.PUSH:
|
|
142
|
-
switch(true){
|
|
143
|
-
case hashes.bothChanged:
|
|
144
|
-
return sprint`Push local changes and {underline discard environment's} changes`;
|
|
145
|
-
case hashes.localChanges.size > 0:
|
|
146
|
-
return sprint`Push local changes`;
|
|
147
|
-
case hashes.environmentChanges.size > 0:
|
|
148
|
-
return sprint`Discard environment's changes`;
|
|
149
|
-
default:
|
|
150
|
-
return unreachable("no changes to push or discard");
|
|
151
|
-
}
|
|
152
|
-
case FileSyncStrategy.PULL:
|
|
153
|
-
switch(true){
|
|
154
|
-
case hashes.bothChanged:
|
|
155
|
-
return sprint`Pull environment's changes and {underline discard local} changes`;
|
|
156
|
-
case hashes.localChanges.size > 0:
|
|
157
|
-
return sprint`Discard local changes`;
|
|
158
|
-
case hashes.environmentChanges.size > 0:
|
|
159
|
-
return sprint`Pull environment's changes`;
|
|
160
|
-
default:
|
|
161
|
-
return unreachable("no changes to pull or discard");
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
})`
|
|
166
|
-
{bold What do you want to do?}
|
|
167
|
-
`;
|
|
168
|
-
switch(strategy){
|
|
169
|
-
case FileSyncStrategy.CANCEL:
|
|
170
|
-
process.exit(0);
|
|
171
|
-
break;
|
|
172
|
-
case FileSyncStrategy.MERGE:
|
|
173
|
-
await filesync.merge(ctx, {
|
|
174
|
-
hashes
|
|
175
|
-
});
|
|
176
|
-
break;
|
|
177
|
-
case FileSyncStrategy.PUSH:
|
|
178
|
-
await filesync.push(ctx, {
|
|
179
|
-
hashes,
|
|
180
|
-
force: true
|
|
181
|
-
});
|
|
182
|
-
break;
|
|
183
|
-
case FileSyncStrategy.PULL:
|
|
184
|
-
await filesync.pull(ctx, {
|
|
185
|
-
hashes,
|
|
186
|
-
force: true
|
|
187
|
-
});
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* A list of filepaths that have changed because we (this ggt process)
|
|
194
|
-
* modified them. This is used to avoid reacting to filesystem events
|
|
195
|
-
* that we caused, which would cause an infinite loop.
|
|
196
|
-
*/ const recentWritesToLocalFilesystem = new Map();
|
|
197
|
-
const clearRecentWritesInterval = setInterval(()=>{
|
|
198
|
-
for (const [path, timestamp] of recentWritesToLocalFilesystem){
|
|
199
|
-
if (dayjs().isAfter(timestamp + ms("5s"))) {
|
|
200
|
-
// this change should have been seen by now
|
|
201
|
-
recentWritesToLocalFilesystem.delete(path);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}, ms("1s")).unref();
|
|
205
|
-
/**
|
|
206
|
-
* Subscribe to file changes on Gadget and apply them to the local
|
|
207
|
-
* filesystem.
|
|
208
|
-
*/ const filesyncSubscription = filesync.subscribeToEnvironmentChanges(ctx, {
|
|
209
|
-
onError: (error)=>ctx.abort(error),
|
|
210
|
-
beforeChanges: ({ changed, deleted })=>{
|
|
211
|
-
// add all the files and directories we're about to touch to
|
|
212
|
-
// recentWritesToLocalFilesystem so that we don't send them back
|
|
213
|
-
// to Gadget
|
|
214
|
-
for (const filepath of [
|
|
215
|
-
...changed,
|
|
216
|
-
...deleted
|
|
217
|
-
]){
|
|
218
|
-
recentWritesToLocalFilesystem.set(filepath, Date.now());
|
|
219
|
-
let dir = path.dirname(filepath);
|
|
220
|
-
while(dir !== "."){
|
|
221
|
-
recentWritesToLocalFilesystem.set(dir + "/", Date.now());
|
|
222
|
-
dir = path.dirname(dir);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
/**
|
|
228
|
-
* A buffer of local file changes to send to Gadget.
|
|
229
|
-
*/ const localChangesBuffer = new Changes();
|
|
230
|
-
/**
|
|
231
|
-
* A debounced function that sends the local file changes to Gadget.
|
|
232
|
-
*/ const mergeChangesWithEnvironment = debounceAsync(ctx.args["--file-push-delay"], async ()=>{
|
|
233
|
-
try {
|
|
234
|
-
const lastGitBranch = syncJson.gitBranch;
|
|
235
|
-
await syncJson.loadGitBranch();
|
|
236
|
-
if (lastGitBranch !== syncJson.gitBranch) {
|
|
237
|
-
println({
|
|
238
|
-
ensureEmptyLineAbove: true
|
|
239
|
-
})`
|
|
240
|
-
Your git branch changed.
|
|
241
|
-
|
|
242
|
-
${lastGitBranch} → ${syncJson.gitBranch}
|
|
243
|
-
`;
|
|
244
|
-
// we need all the changes to be sent in a single batch, so wait
|
|
245
|
-
// a bit in case there are changes the watcher hasn't seen yet
|
|
246
|
-
const spinner = spin({
|
|
247
|
-
ensureEmptyLineAbove: true
|
|
248
|
-
})("Waiting for file changes to settle.");
|
|
249
|
-
await delay("3s"); // this time was chosen arbitrarily
|
|
250
|
-
spinner.succeed();
|
|
251
|
-
}
|
|
252
|
-
const changes = new Changes(localChangesBuffer.entries());
|
|
253
|
-
localChangesBuffer.clear();
|
|
254
|
-
await filesync.mergeChangesWithEnvironment(ctx, {
|
|
255
|
-
changes
|
|
256
|
-
});
|
|
257
|
-
} catch (error) {
|
|
258
|
-
ctx.log.error("error sending changes to gadget", {
|
|
259
|
-
error
|
|
260
|
-
});
|
|
261
|
-
ctx.abort(error);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
ctx.log.debug("watching", {
|
|
265
|
-
path: syncJson.directory.path
|
|
266
|
-
});
|
|
267
|
-
/**
|
|
268
|
-
* Watches the local filesystem for changes.
|
|
269
|
-
*/ const fileWatcher = new Watcher(syncJson.directory.path, {
|
|
270
|
-
// don't emit an event for every watched file when we start watching
|
|
271
|
-
ignoreInitial: true,
|
|
272
|
-
// watch everything
|
|
273
|
-
recursive: true,
|
|
274
|
-
// don't emit changes to .gadget/ files because they're readonly (Gadget manages them)
|
|
275
|
-
ignore: (path)=>syncJson.directory.relative(path).startsWith(".gadget") || syncJson.directory.ignores(path),
|
|
276
|
-
// emit rename/renameDir events
|
|
277
|
-
renameDetection: true,
|
|
278
|
-
// how long to wait for an add event to be followed by an unlink
|
|
279
|
-
// event, and vice versa (i.e. a rename event)
|
|
280
|
-
renameTimeout: ctx.args["--file-watch-rename-timeout"],
|
|
281
|
-
// how long to wait before emitting a change event (helps avoid duplicate events)
|
|
282
|
-
debounce: ctx.args["--file-watch-debounce"]
|
|
283
|
-
}, (event, absolutePath, renamedPath)=>{
|
|
284
|
-
const filepath = event === "rename" || event === "renameDir" ? renamedPath : absolutePath;
|
|
285
|
-
const isDirectory = event === "renameDir" || event === "addDir" || event === "unlinkDir";
|
|
286
|
-
const normalizedPath = syncJson.directory.normalize(filepath, isDirectory);
|
|
287
|
-
ctx.log.trace("file event", {
|
|
288
|
-
event,
|
|
289
|
-
isDirectory,
|
|
290
|
-
path: normalizedPath
|
|
291
|
-
});
|
|
292
|
-
if (filepath === syncJson.directory.absolute(".ignore")) {
|
|
293
|
-
syncJson.directory.loadIgnoreFile().catch((error)=>ctx.abort(error));
|
|
294
|
-
} else if (syncJson.directory.ignores(filepath)) {
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
if (recentWritesToLocalFilesystem.delete(normalizedPath)) {
|
|
298
|
-
ctx.log.trace("ignoring event because we caused it", {
|
|
299
|
-
event,
|
|
300
|
-
path: normalizedPath
|
|
301
|
-
});
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
switch(event){
|
|
305
|
-
case "add":
|
|
306
|
-
case "addDir":
|
|
307
|
-
localChangesBuffer.set(normalizedPath, {
|
|
308
|
-
type: "create"
|
|
309
|
-
});
|
|
310
|
-
break;
|
|
311
|
-
case "rename":
|
|
312
|
-
case "renameDir":
|
|
313
|
-
{
|
|
314
|
-
const oldNormalizedPath = syncJson.directory.normalize(absolutePath, isDirectory);
|
|
315
|
-
localChangesBuffer.set(normalizedPath, {
|
|
316
|
-
type: "create",
|
|
317
|
-
oldPath: oldNormalizedPath
|
|
318
|
-
});
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
case "change":
|
|
322
|
-
{
|
|
323
|
-
localChangesBuffer.set(normalizedPath, {
|
|
324
|
-
type: "update"
|
|
325
|
-
});
|
|
326
|
-
break;
|
|
327
|
-
}
|
|
328
|
-
case "unlink":
|
|
329
|
-
case "unlinkDir":
|
|
330
|
-
{
|
|
331
|
-
localChangesBuffer.set(normalizedPath, {
|
|
332
|
-
type: "delete"
|
|
333
|
-
});
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
mergeChangesWithEnvironment();
|
|
338
|
-
}).once("error", (error)=>ctx.abort(error));
|
|
339
|
-
ctx.onAbort(async (reason)=>{
|
|
340
|
-
ctx.log.info("stopping", {
|
|
341
|
-
reason
|
|
342
|
-
});
|
|
343
|
-
filesyncSubscription.unsubscribe();
|
|
344
|
-
fileWatcher.close();
|
|
345
|
-
clearInterval(clearRecentWritesInterval);
|
|
346
|
-
await mergeChangesWithEnvironment.flush();
|
|
347
|
-
try {
|
|
348
|
-
await filesync.idle();
|
|
349
|
-
} catch (error) {
|
|
350
|
-
ctx.log.error("error while waiting for idle", {
|
|
351
|
-
error
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
if (isAbortError(reason)) {
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
notify(ctx, {
|
|
358
|
-
subtitle: "Uh oh!",
|
|
359
|
-
message: "An error occurred while syncing files"
|
|
360
|
-
});
|
|
361
|
-
await reportErrorAndExit(ctx, reason);
|
|
362
|
-
});
|
|
363
|
-
footer({
|
|
364
|
-
ensureEmptyLineAbove: true
|
|
365
|
-
})`
|
|
366
|
-
${syncJson.sprint({
|
|
367
|
-
indent: 4
|
|
368
|
-
})}
|
|
369
|
-
|
|
370
|
-
Waiting for file changes${symbol.ellipsis} {gray Press Ctrl+C to stop}
|
|
371
|
-
`;
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
//# sourceMappingURL=dev.js.map
|
package/lib/commands/dev.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/dev.ts"],"sourcesContent":["import dayjs from \"dayjs\";\nimport ms from \"ms\";\nimport path from \"node:path\";\nimport Watcher from \"watcher\";\nimport which from \"which\";\nimport type { ArgsDefinition } from \"../services/command/arg.js\";\nimport type { Command, Usage } from \"../services/command/command.js\";\nimport type { Context } from \"../services/command/context.js\";\nimport { Changes } from \"../services/filesync/changes.js\";\nimport { YarnNotFoundError } from \"../services/filesync/error.js\";\nimport { FileSync } from \"../services/filesync/filesync.js\";\nimport { FileSyncStrategy, MergeConflictPreferenceArg } from \"../services/filesync/strategy.js\";\nimport { SyncJson, SyncJsonArgs, loadSyncJsonDirectory } from \"../services/filesync/sync-json.js\";\nimport { footer } from \"../services/output/footer.js\";\nimport { notify } from \"../services/output/notify.js\";\nimport { println } from \"../services/output/print.js\";\nimport { reportErrorAndExit } from \"../services/output/report.js\";\nimport { select } from \"../services/output/select.js\";\nimport { spin } from \"../services/output/spinner.js\";\nimport { sprint } from \"../services/output/sprint.js\";\nimport { symbol } from \"../services/output/symbols.js\";\nimport { unreachable } from \"../services/util/assert.js\";\nimport { debounceAsync } from \"../services/util/function.js\";\nimport { isAbortError } from \"../services/util/is.js\";\nimport { delay } from \"../services/util/promise.js\";\nimport type { PullArgs } from \"./pull.js\";\nimport type { PushArgs } from \"./push.js\";\n\nexport type DevArgs = typeof args;\n\nexport const args = {\n ...SyncJsonArgs,\n \"--prefer\": MergeConflictPreferenceArg,\n \"--file-push-delay\": { type: Number, default: ms(\"100ms\") },\n \"--file-watch-debounce\": { type: Number, default: ms(\"300ms\") },\n \"--file-watch-poll-interval\": { type: Number, default: ms(\"3s\") },\n \"--file-watch-poll-timeout\": { type: Number, default: ms(\"20s\") },\n \"--file-watch-rename-timeout\": { type: Number, default: ms(\"1.25s\") },\n} satisfies ArgsDefinition;\n\nexport const usage: Usage = (_ctx) => {\n return sprint`\n Clones your Gadget environment's files to your local machine and keeps it in sync, in order to\n enable local development with your text editor and source code with Git.\n\n If your app's local directory already exists, this command first performs a sync to ensure\n that your local and environment directories match, changes are tracked since last sync. If any \n conflicts are detected, they must be resolved before development starts.\n\n {gray Usage}\n $ ggt dev [DIRECTORY] [options]\n\n DIRECTORY: The directory to sync files to (default: the current directory)\n \n {gray Options}\n -a, --app <app_name> Selects the app to sync files with. Default set on \".gadget/sync.json\"\n -e, --env <env_name> Selects the environment to sync files with. Default set on \".gadget/sync.json\"\n --prefer <source> Auto-select changes from 'local' or 'environment' source on conflict\n --allow-unknown-directory Syncs to any local directory with existing files, even if the \".gadget/sync.json\" file is missing\n --allow-different-app Syncs with a different app using the --app command, instead of the one specified in the .gadget/sync.json file\n\n {gray Ignoring files}\n ggt dev uses a .ignore file, similar to .gitignore, to exclude specific files and \n folders from syncing. These files are always ignored:\n\n • .DS_Store\n • .gadget\n • .git\n • node_modules\n \n {gray Notes}\n • \"ggt dev\" only works with development environments\n • \"ggt dev\" only supports \"yarn\" v1 for installing dependencies\n • Avoid deleting or moving all of your files while \"ggt dev\" is running\n \n {gray Examples}\n sync an app in a custom path \n {cyanBright $ ggt dev ~/myGadgetApps/myBlog --app myBlogApp}\n \n sync with a specific environment and preselect all local changes on conflicts\n {cyanBright $ ggt dev --env main --prefer local}\n\n sync a custom path with a specific app, environment and preselect all changes from local on conflicts\n {cyanBright $ ggt dev ~/gadget/example --app=example --env=development --prefer=local}\n `;\n};\n\nexport const command: Command<DevArgs> = async (ctx) => {\n if (!(await which(\"yarn\", { nothrow: true }))) {\n throw new YarnNotFoundError();\n }\n\n const directory = await loadSyncJsonDirectory(ctx.args._[0] || process.cwd());\n const syncJson = await SyncJson.loadOrInit(ctx, { directory });\n footer({ ensureEmptyLineAbove: true })(syncJson.sprint());\n\n const filesync = new FileSync(syncJson);\n const hashes = await filesync.hashes(ctx);\n\n if (!hashes.inSync) {\n // our local files don't match our environment's files\n if (!syncJson.previousEnvironment || (hashes.localChangesToPush.size === 0 && hashes.onlyDotGadgetFilesChanged)) {\n // one of the following is true:\n // - we're developing on this environment for the first time\n // - we're developing on the same environment as last time\n // - we're developing on a different environment, but only .gadget/ files have changed\n // merge the changes (if any) and continue\n await filesync.merge(ctx, {\n hashes,\n printLocalChangesOptions: {\n limit: 5,\n },\n printEnvironmentChangesOptions: {\n limit: 5,\n },\n });\n } else {\n // we're switching environment's and files outside of .gadget/\n // have changed, so ask the user what to do\n await filesync.print(ctx, { hashes });\n const choices = Object.values(FileSyncStrategy);\n\n const strategy = await select({\n ensureEmptyLineAbove: true,\n choices: hashes.bothChanged ? choices : choices.filter((choice) => choice !== FileSyncStrategy.MERGE),\n formatChoice: (choice) => {\n switch (choice) {\n case FileSyncStrategy.CANCEL:\n return sprint`Cancel (Ctrl+C)`;\n case FileSyncStrategy.MERGE:\n return sprint`Merge local and environment's changes`;\n case FileSyncStrategy.PUSH:\n switch (true) {\n case hashes.bothChanged:\n return sprint`Push local changes and {underline discard environment's} changes`;\n case hashes.localChanges.size > 0:\n return sprint`Push local changes`;\n case hashes.environmentChanges.size > 0:\n return sprint`Discard environment's changes`;\n default:\n return unreachable(\"no changes to push or discard\");\n }\n case FileSyncStrategy.PULL:\n switch (true) {\n case hashes.bothChanged:\n return sprint`Pull environment's changes and {underline discard local} changes`;\n case hashes.localChanges.size > 0:\n return sprint`Discard local changes`;\n case hashes.environmentChanges.size > 0:\n return sprint`Pull environment's changes`;\n default:\n return unreachable(\"no changes to pull or discard\");\n }\n }\n },\n })`\n {bold What do you want to do?}\n `;\n\n switch (strategy) {\n case FileSyncStrategy.CANCEL:\n process.exit(0);\n break;\n case FileSyncStrategy.MERGE:\n await filesync.merge(ctx, { hashes });\n break;\n case FileSyncStrategy.PUSH:\n await filesync.push(ctx as unknown as Context<PushArgs>, { hashes, force: true });\n break;\n case FileSyncStrategy.PULL:\n await filesync.pull(ctx as unknown as Context<PullArgs>, { hashes, force: true });\n break;\n }\n }\n }\n\n /**\n * A list of filepaths that have changed because we (this ggt process)\n * modified them. This is used to avoid reacting to filesystem events\n * that we caused, which would cause an infinite loop.\n */\n const recentWritesToLocalFilesystem = new Map<string, number>();\n\n const clearRecentWritesInterval = setInterval(() => {\n for (const [path, timestamp] of recentWritesToLocalFilesystem) {\n if (dayjs().isAfter(timestamp + ms(\"5s\"))) {\n // this change should have been seen by now\n recentWritesToLocalFilesystem.delete(path);\n }\n }\n }, ms(\"1s\")).unref();\n\n /**\n * Subscribe to file changes on Gadget and apply them to the local\n * filesystem.\n */\n const filesyncSubscription = filesync.subscribeToEnvironmentChanges(ctx, {\n onError: (error) => ctx.abort(error),\n beforeChanges: ({ changed, deleted }) => {\n // add all the files and directories we're about to touch to\n // recentWritesToLocalFilesystem so that we don't send them back\n // to Gadget\n for (const filepath of [...changed, ...deleted]) {\n recentWritesToLocalFilesystem.set(filepath, Date.now());\n\n let dir = path.dirname(filepath);\n while (dir !== \".\") {\n recentWritesToLocalFilesystem.set(dir + \"/\", Date.now());\n dir = path.dirname(dir);\n }\n }\n },\n });\n\n /**\n * A buffer of local file changes to send to Gadget.\n */\n const localChangesBuffer = new Changes();\n\n /**\n * A debounced function that sends the local file changes to Gadget.\n */\n const mergeChangesWithEnvironment = debounceAsync(ctx.args[\"--file-push-delay\"], async (): Promise<void> => {\n try {\n const lastGitBranch = syncJson.gitBranch;\n await syncJson.loadGitBranch();\n\n if (lastGitBranch !== syncJson.gitBranch) {\n println({ ensureEmptyLineAbove: true })`\n Your git branch changed.\n\n ${lastGitBranch} → ${syncJson.gitBranch}\n `;\n\n // we need all the changes to be sent in a single batch, so wait\n // a bit in case there are changes the watcher hasn't seen yet\n const spinner = spin({ ensureEmptyLineAbove: true })(\"Waiting for file changes to settle.\");\n await delay(\"3s\"); // this time was chosen arbitrarily\n spinner.succeed();\n }\n\n const changes = new Changes(localChangesBuffer.entries());\n localChangesBuffer.clear();\n\n await filesync.mergeChangesWithEnvironment(ctx, { changes });\n } catch (error) {\n ctx.log.error(\"error sending changes to gadget\", { error });\n ctx.abort(error);\n }\n });\n\n ctx.log.debug(\"watching\", { path: syncJson.directory.path });\n\n /**\n * Watches the local filesystem for changes.\n */\n const fileWatcher = new Watcher(\n syncJson.directory.path,\n {\n // don't emit an event for every watched file when we start watching\n ignoreInitial: true,\n // watch everything\n recursive: true,\n // don't emit changes to .gadget/ files because they're readonly (Gadget manages them)\n ignore: (path: string) => syncJson.directory.relative(path).startsWith(\".gadget\") || syncJson.directory.ignores(path),\n // emit rename/renameDir events\n renameDetection: true,\n // how long to wait for an add event to be followed by an unlink\n // event, and vice versa (i.e. a rename event)\n renameTimeout: ctx.args[\"--file-watch-rename-timeout\"],\n // how long to wait before emitting a change event (helps avoid duplicate events)\n debounce: ctx.args[\"--file-watch-debounce\"],\n },\n (event: string, absolutePath: string, renamedPath: string) => {\n const filepath = event === \"rename\" || event === \"renameDir\" ? renamedPath : absolutePath;\n const isDirectory = event === \"renameDir\" || event === \"addDir\" || event === \"unlinkDir\";\n const normalizedPath = syncJson.directory.normalize(filepath, isDirectory);\n\n ctx.log.trace(\"file event\", { event, isDirectory, path: normalizedPath });\n\n if (filepath === syncJson.directory.absolute(\".ignore\")) {\n syncJson.directory.loadIgnoreFile().catch((error) => ctx.abort(error));\n } else if (syncJson.directory.ignores(filepath)) {\n return;\n }\n\n if (recentWritesToLocalFilesystem.delete(normalizedPath)) {\n ctx.log.trace(\"ignoring event because we caused it\", { event, path: normalizedPath });\n return;\n }\n\n switch (event) {\n case \"add\":\n case \"addDir\":\n localChangesBuffer.set(normalizedPath, { type: \"create\" });\n break;\n case \"rename\":\n case \"renameDir\": {\n const oldNormalizedPath = syncJson.directory.normalize(absolutePath, isDirectory);\n localChangesBuffer.set(normalizedPath, { type: \"create\", oldPath: oldNormalizedPath });\n break;\n }\n case \"change\": {\n localChangesBuffer.set(normalizedPath, { type: \"update\" });\n break;\n }\n case \"unlink\":\n case \"unlinkDir\": {\n localChangesBuffer.set(normalizedPath, { type: \"delete\" });\n break;\n }\n }\n\n mergeChangesWithEnvironment();\n },\n ).once(\"error\", (error) => ctx.abort(error));\n\n ctx.onAbort(async (reason) => {\n ctx.log.info(\"stopping\", { reason });\n\n filesyncSubscription.unsubscribe();\n fileWatcher.close();\n clearInterval(clearRecentWritesInterval);\n await mergeChangesWithEnvironment.flush();\n\n try {\n await filesync.idle();\n } catch (error) {\n ctx.log.error(\"error while waiting for idle\", { error });\n }\n\n if (isAbortError(reason)) {\n return;\n }\n\n notify(ctx, { subtitle: \"Uh oh!\", message: \"An error occurred while syncing files\" });\n await reportErrorAndExit(ctx, reason);\n });\n\n footer({ ensureEmptyLineAbove: true })`\n${syncJson.sprint({ indent: 4 })}\n\n Waiting for file changes${symbol.ellipsis} {gray Press Ctrl+C to stop}\n `;\n};\n"],"names":["dayjs","ms","path","Watcher","which","Changes","YarnNotFoundError","FileSync","FileSyncStrategy","MergeConflictPreferenceArg","SyncJson","SyncJsonArgs","loadSyncJsonDirectory","footer","notify","println","reportErrorAndExit","select","spin","sprint","symbol","unreachable","debounceAsync","isAbortError","delay","args","type","Number","default","usage","_ctx","command","ctx","nothrow","directory","_","process","cwd","syncJson","loadOrInit","ensureEmptyLineAbove","filesync","hashes","inSync","previousEnvironment","localChangesToPush","size","onlyDotGadgetFilesChanged","merge","printLocalChangesOptions","limit","printEnvironmentChangesOptions","print","choices","Object","values","strategy","bothChanged","filter","choice","MERGE","formatChoice","CANCEL","PUSH","localChanges","environmentChanges","PULL","exit","push","force","pull","recentWritesToLocalFilesystem","Map","clearRecentWritesInterval","setInterval","timestamp","isAfter","delete","unref","filesyncSubscription","subscribeToEnvironmentChanges","onError","error","abort","beforeChanges","changed","deleted","filepath","set","Date","now","dir","dirname","localChangesBuffer","mergeChangesWithEnvironment","lastGitBranch","gitBranch","loadGitBranch","spinner","succeed","changes","entries","clear","log","debug","fileWatcher","ignoreInitial","recursive","ignore","relative","startsWith","ignores","renameDetection","renameTimeout","debounce","event","absolutePath","renamedPath","isDirectory","normalizedPath","normalize","trace","absolute","loadIgnoreFile","catch","oldNormalizedPath","oldPath","once","onAbort","reason","info","unsubscribe","close","clearInterval","flush","idle","subtitle","message","indent","ellipsis"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,QAAQ,KAAK;AACpB,OAAOC,UAAU,YAAY;AAC7B,OAAOC,aAAa,UAAU;AAC9B,OAAOC,WAAW,QAAQ;AAI1B,SAASC,OAAO,QAAQ,kCAAkC;AAC1D,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,QAAQ,QAAQ,mCAAmC;AAC5D,SAASC,gBAAgB,EAAEC,0BAA0B,QAAQ,mCAAmC;AAChG,SAASC,QAAQ,EAAEC,YAAY,EAAEC,qBAAqB,QAAQ,oCAAo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getApps } from "../services/app/app.js";
|
|
2
|
-
import { output } from "../services/output/output.js";
|
|
3
|
-
import { println } from "../services/output/print.js";
|
|
4
|
-
import { sprint, sprintln } from "../services/output/sprint.js";
|
|
5
|
-
import { printTable } from "../services/output/table.js";
|
|
6
|
-
import { getUserOrLogin } from "../services/user/user.js";
|
|
7
|
-
export const usage = ()=>sprint`
|
|
8
|
-
List the apps available to the currently logged-in user.
|
|
9
|
-
|
|
10
|
-
{bold Usage}
|
|
11
|
-
ggt list
|
|
12
|
-
`;
|
|
13
|
-
export const command = async (ctx)=>{
|
|
14
|
-
await getUserOrLogin(ctx);
|
|
15
|
-
const apps = await getApps(ctx);
|
|
16
|
-
if (apps.length === 0) {
|
|
17
|
-
println`
|
|
18
|
-
It doesn't look like you have any applications.
|
|
19
|
-
|
|
20
|
-
Visit https://gadget.new to create one!
|
|
21
|
-
`;
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (output.isInteractive) {
|
|
25
|
-
printTable({
|
|
26
|
-
json: apps,
|
|
27
|
-
headers: [
|
|
28
|
-
"Name",
|
|
29
|
-
"Domain"
|
|
30
|
-
],
|
|
31
|
-
rows: apps.map((app)=>[
|
|
32
|
-
app.slug,
|
|
33
|
-
app.primaryDomain
|
|
34
|
-
])
|
|
35
|
-
});
|
|
36
|
-
} else {
|
|
37
|
-
let simpleOutput = "";
|
|
38
|
-
for (const app of apps){
|
|
39
|
-
simpleOutput += sprintln`${app.slug}\t${app.primaryDomain}`;
|
|
40
|
-
}
|
|
41
|
-
println({
|
|
42
|
-
json: apps
|
|
43
|
-
})(simpleOutput);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=list.js.map
|
package/lib/commands/list.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/list.ts"],"sourcesContent":["import { getApps } from \"../services/app/app.js\";\nimport type { Command, Usage } from \"../services/command/command.js\";\nimport { output } from \"../services/output/output.js\";\nimport { println } from \"../services/output/print.js\";\nimport { sprint, sprintln } from \"../services/output/sprint.js\";\nimport { printTable } from \"../services/output/table.js\";\nimport { getUserOrLogin } from \"../services/user/user.js\";\n\nexport const usage: Usage = () => sprint`\n List the apps available to the currently logged-in user.\n\n {bold Usage}\n ggt list\n`;\n\nexport const command: Command = async (ctx) => {\n await getUserOrLogin(ctx);\n\n const apps = await getApps(ctx);\n if (apps.length === 0) {\n println`\n It doesn't look like you have any applications.\n\n Visit https://gadget.new to create one!\n `;\n return;\n }\n\n if (output.isInteractive) {\n printTable({\n json: apps,\n headers: [\"Name\", \"Domain\"],\n rows: apps.map((app) => [app.slug, app.primaryDomain]),\n });\n } else {\n let simpleOutput = \"\";\n for (const app of apps) {\n simpleOutput += sprintln`${app.slug}\\t${app.primaryDomain}`;\n }\n\n println({ json: apps })(simpleOutput);\n }\n};\n"],"names":["getApps","output","println","sprint","sprintln","printTable","getUserOrLogin","usage","command","ctx","apps","length","isInteractive","json","headers","rows","map","app","slug","primaryDomain","simpleOutput"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,OAAO,QAAQ,yBAAyB;AAEjD,SAASC,MAAM,QAAQ,+BAA+B;AACtD,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SAASC,MAAM,EAAEC,QAAQ,QAAQ,+BAA+B;AAChE,SAASC,UAAU,QAAQ,8BAA8B;AACzD,SAASC,cAAc,QAAQ,2BAA2B;AAE1D,OAAO,MAAMC,QAAe,IAAMJ,MAAM,CAAC;;;;;AAKzC,CAAC,CAAC;AAEF,OAAO,MAAMK,UAAmB,OAAOC;IACrC,MAAMH,eAAeG;IAErB,MAAMC,OAAO,MAAMV,QAAQS;IAC3B,IAAIC,KAAKC,MAAM,KAAK,GAAG;QACrBT,OAAO,CAAC;;;;IAIR,CAAC;QACD;IACF;IAEA,IAAID,OAAOW,aAAa,EAAE;QACxBP,WAAW;YACTQ,MAAMH;YACNI,SAAS;gBAAC;gBAAQ;aAAS;YAC3BC,MAAML,KAAKM,GAAG,CAAC,CAACC,MAAQ;oBAACA,IAAIC,IAAI;oBAAED,IAAIE,aAAa;iBAAC;QACvD;IACF,OAAO;QACL,IAAIC,eAAe;QACnB,KAAK,MAAMH,OAAOP,KAAM;YACtBU,gBAAgBhB,QAAQ,CAAC,EAAEa,IAAIC,IAAI,CAAC,EAAE,EAAED,IAAIE,aAAa,CAAC,CAAC;QAC7D;QAEAjB,QAAQ;YAAEW,MAAMH;QAAK,GAAGU;IAC1B;AACF,EAAE"}
|
package/lib/commands/login.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import getPort from "get-port";
|
|
2
|
-
import assert from "node:assert";
|
|
3
|
-
import http from "node:http";
|
|
4
|
-
import open from "open";
|
|
5
|
-
import { config } from "../services/config/config.js";
|
|
6
|
-
import { println } from "../services/output/print.js";
|
|
7
|
-
import { sprint } from "../services/output/sprint.js";
|
|
8
|
-
import { writeSession } from "../services/user/session.js";
|
|
9
|
-
import { getUser } from "../services/user/user.js";
|
|
10
|
-
export const usage = ()=>sprint`
|
|
11
|
-
Log in to your account.
|
|
12
|
-
|
|
13
|
-
{bold Usage}
|
|
14
|
-
ggt login
|
|
15
|
-
`;
|
|
16
|
-
export const login = async (ctx)=>{
|
|
17
|
-
let server;
|
|
18
|
-
try {
|
|
19
|
-
const port = await getPort();
|
|
20
|
-
const receiveSession = new Promise((resolve, reject)=>{
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
22
|
-
server = http.createServer(async (req, res)=>{
|
|
23
|
-
const landingPage = new URL(`https://${config.domains.services}/auth/cli`);
|
|
24
|
-
try {
|
|
25
|
-
assert(req.url, "missing url");
|
|
26
|
-
const session = new URL(req.url, `http://localhost:${port}`).searchParams.get("session");
|
|
27
|
-
assert(session, "missing session");
|
|
28
|
-
writeSession(session);
|
|
29
|
-
const user = await getUser(ctx);
|
|
30
|
-
assert(user, "missing user after successful login");
|
|
31
|
-
if (user.name) {
|
|
32
|
-
println({
|
|
33
|
-
ensureEmptyLineAbove: true
|
|
34
|
-
})`Hello, ${user.name} {gray (${user.email})}`;
|
|
35
|
-
} else {
|
|
36
|
-
println({
|
|
37
|
-
ensureEmptyLineAbove: true
|
|
38
|
-
})`Hello, ${user.email}`;
|
|
39
|
-
}
|
|
40
|
-
landingPage.searchParams.set("success", "true");
|
|
41
|
-
resolve();
|
|
42
|
-
} catch (error) {
|
|
43
|
-
writeSession(undefined);
|
|
44
|
-
landingPage.searchParams.set("success", "false");
|
|
45
|
-
reject(error);
|
|
46
|
-
} finally{
|
|
47
|
-
res.writeHead(303, {
|
|
48
|
-
Location: landingPage.toString()
|
|
49
|
-
});
|
|
50
|
-
res.end();
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
ctx.log.info("starting login server", {
|
|
54
|
-
port
|
|
55
|
-
});
|
|
56
|
-
server.listen(port);
|
|
57
|
-
});
|
|
58
|
-
// open the login page in the user's default browser have it
|
|
59
|
-
// redirect to the cli callback route. The cli callback route will
|
|
60
|
-
// send the session to the server we just started.
|
|
61
|
-
const url = new URL(`https://${config.domains.services}/auth/login`);
|
|
62
|
-
url.searchParams.set("returnTo", `https://${config.domains.services}/auth/cli/callback?port=${port}`);
|
|
63
|
-
try {
|
|
64
|
-
await open(url.toString());
|
|
65
|
-
println({
|
|
66
|
-
ensureEmptyLineAbove: true
|
|
67
|
-
})`
|
|
68
|
-
We've opened Gadget's login page using your default browser.
|
|
69
|
-
|
|
70
|
-
Please log in and then return to this terminal.
|
|
71
|
-
`;
|
|
72
|
-
} catch (error) {
|
|
73
|
-
ctx.log.error("failed to open browser", {
|
|
74
|
-
error
|
|
75
|
-
});
|
|
76
|
-
println({
|
|
77
|
-
ensureEmptyLineAbove: true
|
|
78
|
-
})`
|
|
79
|
-
Please open the following URL in your browser and log in:
|
|
80
|
-
|
|
81
|
-
{gray ${url.toString()}}
|
|
82
|
-
|
|
83
|
-
Once logged in, return to this terminal.
|
|
84
|
-
`;
|
|
85
|
-
}
|
|
86
|
-
await receiveSession;
|
|
87
|
-
} finally{
|
|
88
|
-
server?.close();
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
export const command = login;
|
|
92
|
-
|
|
93
|
-
//# sourceMappingURL=login.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/login.ts"],"sourcesContent":["import getPort from \"get-port\";\nimport assert from \"node:assert\";\nimport http, { type Server } from \"node:http\";\nimport open from \"open\";\nimport type { Command, Usage } from \"../services/command/command.js\";\nimport { config } from \"../services/config/config.js\";\nimport { println } from \"../services/output/print.js\";\nimport { sprint } from \"../services/output/sprint.js\";\nimport { writeSession } from \"../services/user/session.js\";\nimport { getUser } from \"../services/user/user.js\";\n\nexport const usage: Usage = () => sprint`\n Log in to your account.\n\n {bold Usage}\n ggt login\n`;\n\nexport const login: Command = async (ctx): Promise<void> => {\n let server: Server | undefined;\n\n try {\n const port = await getPort();\n const receiveSession = new Promise<void>((resolve, reject) => {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n server = http.createServer(async (req, res) => {\n const landingPage = new URL(`https://${config.domains.services}/auth/cli`);\n\n try {\n assert(req.url, \"missing url\");\n const session = new URL(req.url, `http://localhost:${port}`).searchParams.get(\"session\");\n assert(session, \"missing session\");\n\n writeSession(session);\n\n const user = await getUser(ctx);\n assert(user, \"missing user after successful login\");\n\n if (user.name) {\n println({ ensureEmptyLineAbove: true })`Hello, ${user.name} {gray (${user.email})}`;\n } else {\n println({ ensureEmptyLineAbove: true })`Hello, ${user.email}`;\n }\n\n landingPage.searchParams.set(\"success\", \"true\");\n resolve();\n } catch (error) {\n writeSession(undefined);\n landingPage.searchParams.set(\"success\", \"false\");\n reject(error as Error);\n } finally {\n res.writeHead(303, { Location: landingPage.toString() });\n res.end();\n }\n });\n\n ctx.log.info(\"starting login server\", { port });\n server.listen(port);\n });\n\n // open the login page in the user's default browser have it\n // redirect to the cli callback route. The cli callback route will\n // send the session to the server we just started.\n const url = new URL(`https://${config.domains.services}/auth/login`);\n url.searchParams.set(\"returnTo\", `https://${config.domains.services}/auth/cli/callback?port=${port}`);\n\n try {\n await open(url.toString());\n println({ ensureEmptyLineAbove: true })`\n We've opened Gadget's login page using your default browser.\n\n Please log in and then return to this terminal.\n `;\n } catch (error) {\n ctx.log.error(\"failed to open browser\", { error });\n println({ ensureEmptyLineAbove: true })`\n Please open the following URL in your browser and log in:\n\n {gray ${url.toString()}}\n\n Once logged in, return to this terminal.\n `;\n }\n\n await receiveSession;\n } finally {\n server?.close();\n }\n};\n\nexport const command = login;\n"],"names":["getPort","assert","http","open","config","println","sprint","writeSession","getUser","usage","login","ctx","server","port","receiveSession","Promise","resolve","reject","createServer","req","res","landingPage","URL","domains","services","url","session","searchParams","get","user","name","ensureEmptyLineAbove","email","set","error","undefined","writeHead","Location","toString","end","log","info","listen","close","command"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,aAAa,WAAW;AAC/B,OAAOC,YAAY,cAAc;AACjC,OAAOC,UAA2B,YAAY;AAC9C,OAAOC,UAAU,OAAO;AAExB,SAASC,MAAM,QAAQ,+BAA+B;AACtD,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SAASC,MAAM,QAAQ,+BAA+B;AACtD,SAASC,YAAY,QAAQ,8BAA8B;AAC3D,SAASC,OAAO,QAAQ,2BAA2B;AAEnD,OAAO,MAAMC,QAAe,IAAMH,MAAM,CAAC;;;;;AAKzC,CAAC,CAAC;AAEF,OAAO,MAAMI,QAAiB,OAAOC;IACnC,IAAIC;IAEJ,IAAI;QACF,MAAMC,OAAO,MAAMb;QACnB,MAAMc,iBAAiB,IAAIC,QAAc,CAACC,SAASC;YACjD,kEAAkE;YAClEL,SAASV,KAAKgB,YAA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CAAC,YAAY,CAAC,QAAQ,EAAE7B,OAAOmB,OAAO,CAACC,QAAQ,CAAC,wBAAwB,EAAEX,KAAK,CAAC;QAEpG,IAAI;YACF,MAAMV,KAAKsB,IAAIa,QAAQ;YACvBjC,QAAQ;gBAAE0B,sBAAsB;YAAK,EAAE,CAAC;;;;MAIxC,CAAC;QACH,EAAE,OAAOG,OAAO;YACdvB,IAAI6B,GAAG,CAACN,KAAK,CAAC,0BAA0B;gBAAEA;YAAM;YAChD7B,QAAQ;gBAAE0B,sBAAsB;YAAK,EAAE,CAAC;;;gBAG9B,EAAEN,IAAIa,QAAQ,GAAG;;;MAG3B,CAAC;QACH;QAEA,MAAMxB;IACR,SAAU;QACRF,QAAQ+B;IACV;AACF,EAAE;AAEF,OAAO,MAAMC,UAAUlC,MAAM"}
|
package/lib/commands/logout.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { println } from "../services/output/print.js";
|
|
2
|
-
import { sprint } from "../services/output/sprint.js";
|
|
3
|
-
import { readSession, writeSession } from "../services/user/session.js";
|
|
4
|
-
export const usage = ()=>sprint`
|
|
5
|
-
Log out of your account.
|
|
6
|
-
|
|
7
|
-
{bold Usage}
|
|
8
|
-
ggt logout
|
|
9
|
-
`;
|
|
10
|
-
export const command = (_ctx)=>{
|
|
11
|
-
const token = readSession();
|
|
12
|
-
if (token) {
|
|
13
|
-
writeSession(undefined);
|
|
14
|
-
println("Goodbye");
|
|
15
|
-
} else {
|
|
16
|
-
println("You are not logged in");
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
//# sourceMappingURL=logout.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/logout.ts"],"sourcesContent":["import type { Command, Usage } from \"../services/command/command.js\";\nimport { println } from \"../services/output/print.js\";\nimport { sprint } from \"../services/output/sprint.js\";\nimport { readSession, writeSession } from \"../services/user/session.js\";\n\nexport const usage: Usage = () => sprint`\n Log out of your account.\n\n {bold Usage}\n ggt logout\n`;\n\nexport const command: Command = (_ctx) => {\n const token = readSession();\n if (token) {\n writeSession(undefined);\n println(\"Goodbye\");\n } else {\n println(\"You are not logged in\");\n }\n};\n"],"names":["println","sprint","readSession","writeSession","usage","command","_ctx","token","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,OAAO,QAAQ,8BAA8B;AACtD,SAASC,MAAM,QAAQ,+BAA+B;AACtD,SAASC,WAAW,EAAEC,YAAY,QAAQ,8BAA8B;AAExE,OAAO,MAAMC,QAAe,IAAMH,MAAM,CAAC;;;;;AAKzC,CAAC,CAAC;AAEF,OAAO,MAAMI,UAAmB,CAACC;IAC/B,MAAMC,QAAQL;IACd,IAAIK,OAAO;QACTJ,aAAaK;QACbR,QAAQ;IACV,OAAO;QACLA,QAAQ;IACV;AACF,EAAE"}
|