@gadgetinc/ggt 0.1.18 → 0.2.0

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.
Files changed (59) hide show
  1. package/README.md +6 -6
  2. package/bin/dev.js +24 -0
  3. package/bin/run.js +11 -0
  4. package/lib/__generated__/graphql.js +6 -9
  5. package/lib/__generated__/graphql.js.map +1 -1
  6. package/lib/commands/help.js +22 -37
  7. package/lib/commands/help.js.map +1 -1
  8. package/lib/commands/list.js +30 -56
  9. package/lib/commands/list.js.map +1 -1
  10. package/lib/commands/login.js +13 -29
  11. package/lib/commands/login.js.map +1 -1
  12. package/lib/commands/logout.js +17 -34
  13. package/lib/commands/logout.js.map +1 -1
  14. package/lib/commands/sync.js +483 -456
  15. package/lib/commands/sync.js.map +1 -1
  16. package/lib/commands/whoami.js +17 -34
  17. package/lib/commands/whoami.js.map +1 -1
  18. package/lib/index.js +2 -5
  19. package/lib/index.js.map +1 -1
  20. package/lib/utils/base-command.js +106 -147
  21. package/lib/utils/base-command.js.map +1 -1
  22. package/lib/utils/client.js +104 -113
  23. package/lib/utils/client.js.map +1 -1
  24. package/lib/utils/context.js +63 -119
  25. package/lib/utils/context.js.map +1 -1
  26. package/lib/utils/errors.js +161 -242
  27. package/lib/utils/errors.js.map +1 -1
  28. package/lib/utils/flags.js +23 -26
  29. package/lib/utils/flags.js.map +1 -1
  30. package/lib/utils/fs-utils.js +46 -73
  31. package/lib/utils/fs-utils.js.map +1 -1
  32. package/lib/utils/help.js +19 -26
  33. package/lib/utils/help.js.map +1 -1
  34. package/lib/utils/promise.js +32 -78
  35. package/lib/utils/promise.js.map +1 -1
  36. package/lib/utils/sleep.js +6 -11
  37. package/lib/utils/sleep.js.map +1 -1
  38. package/npm-shrinkwrap.json +7569 -6914
  39. package/oclif.manifest.json +1 -1
  40. package/package.json +45 -45
  41. package/bin/dev +0 -20
  42. package/bin/run +0 -7
  43. package/lib/__generated__/graphql.d.ts +0 -294
  44. package/lib/commands/help.d.ts +0 -14
  45. package/lib/commands/list.d.ts +0 -18
  46. package/lib/commands/login.d.ts +0 -7
  47. package/lib/commands/logout.d.ts +0 -7
  48. package/lib/commands/sync.d.ts +0 -146
  49. package/lib/commands/whoami.d.ts +0 -7
  50. package/lib/index.d.ts +0 -1
  51. package/lib/utils/base-command.d.ts +0 -64
  52. package/lib/utils/client.d.ts +0 -42
  53. package/lib/utils/context.d.ts +0 -57
  54. package/lib/utils/errors.d.ts +0 -100
  55. package/lib/utils/flags.d.ts +0 -1
  56. package/lib/utils/fs-utils.d.ts +0 -21
  57. package/lib/utils/help.d.ts +0 -19
  58. package/lib/utils/promise.d.ts +0 -35
  59. package/lib/utils/sleep.d.ts +0 -5
@@ -1 +1 @@
1
- {"version":3,"file":"sync.js","sourceRoot":"/","sources":["commands/sync.ts"],"names":[],"mappings":";;;;AAAA,sCAA0C;AAC1C,0DAA0B;AAC1B,4DAA4B;AAC5B,uCAAqC;AACrC,qEAAqC;AACrC,0DAA0B;AAE1B,gEAA0B;AAC1B,uCAAkC;AAElC,mCAAgC;AAChC,mCAAkC;AAClC,4EAA2C;AAC3C,0DAAyB;AACzB,8DAA6B;AAC7B,wDAAwB;AACxB,kEAAkC;AAClC,kEAA+B;AAC/B,0DAA0B;AAC1B,wDAAoD;AAEpD,4CAAyC;AACzC,8CAA2C;AAC3C,4CAAmG;AACnG,0CAAqC;AACrC,gDAAiF;AAWjF,sDAA4D;AAC5D,8CAAiD;AAEjD,MAAqB,IAAK,SAAQ,0BAAwB;IAA1D;;QAsGW;;;;mBAAc,IAAI;WAAC;QAE5B;;WAEG;QACH;;;;mBAAS,UAAU,CAAC,QAAQ;WAAC;QAE7B;;WAEG;QACH;;;;;WAAa;QAEb;;;WAGG;QACH;;;;mBAAsB,IAAI,GAAG,EAAU;WAAC;QAExC;;WAEG;QACH;;;;mBAAQ,IAAI,iBAAM,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;WAAC;QAEvC;;WAEG;QAC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EAAE,YAAK,CAAC,OAAO,CAAC;YACxC,IAAI,EAAE,0BAA0B;YAChC,OAAO,EAAE,0DAA0D;YACnE,SAAS,EAAE,MAAM;YACjB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,GAAG;YACZ,MAAM,EAAE,IAAI;SACb,CAAC;QACF,oBAAoB,EAAE,YAAK,CAAC,OAAO,CAAC;YAClC,IAAI,EAAE,oBAAoB;YAC1B,WAAW,EAAE,yDAAyD;YACtE,SAAS,EAAE,MAAM;YACjB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,GAAG;YACZ,MAAM,EAAE,IAAI;SACb,CAAC;KACH;EA/BoB,CA+BnB;AAEc;;;;WAAW;QACzB,IAAA,mBAAM,EAAC,IAAA,eAAK,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;KAyBX,CAAC;KACH;EA3BuB,CA2BtB;kBApGiB,IAAI;AAkqBzB,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,mDAAQ,CAAA;IACR,iDAAO,CAAA;IACP,mDAAQ,CAAA;IACR,iDAAO,CAAA;AACT,CAAC,EALW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAKrB;AAED,IAAY,MAIX;AAJD,WAAY,MAAM;IAChB,oCAA0B,CAAA;IAC1B,sDAA4C,CAAA;IAC5C,oDAA0C,CAAA;AAC5C,CAAC,EAJW,MAAM,GAAN,cAAM,KAAN,cAAM,QAIjB;AAEY,QAAA,oCAAoC,GAG/B;;;;;;;;;;;;;;;CAejB,CAAC;AAEW,QAAA,0BAA0B,GAAmF;;;;CAIzH,CAAC;AAEW,QAAA,iCAAiC,GAG5B;;;;;;CAMjB,CAAC","sourcesContent":["import { Args, Flags } from \"@oclif/core\";\nimport chalk from \"chalk\";\nimport assert from \"assert\";\nimport { FSWatcher } from \"chokidar\";\nimport format from \"date-fns/format\";\nimport execa from \"execa\";\nimport type { Stats } from \"fs-extra\";\nimport fs from \"fs-extra\";\nimport { prompt } from \"inquirer\";\nimport type { DebouncedFunc } from \"lodash\";\nimport { sortBy } from \"lodash\";\nimport { debounce } from \"lodash\";\nimport normalizePath from \"normalize-path\";\nimport pMap from \"p-map\";\nimport PQueue from \"p-queue\";\nimport path from \"path\";\nimport pluralize from \"pluralize\";\nimport dedent from \"ts-dedent\";\nimport which from \"which\";\nimport { BaseCommand } from \"../utils/base-command\";\nimport type { Query } from \"../utils/client\";\nimport { Client } from \"../utils/client\";\nimport { context } from \"../utils/context\";\nimport { InvalidSyncAppFlagError, InvalidSyncFileError, YarnNotFoundError } from \"../utils/errors\";\nimport { app } from \"../utils/flags\";\nimport { ignoreEnoent, FSIgnorer, isEmptyDir, walkDir } from \"../utils/fs-utils\";\nimport type {\n FileSyncChangedEventInput,\n FileSyncDeletedEventInput,\n PublishFileSyncEventsMutation,\n PublishFileSyncEventsMutationVariables,\n RemoteFilesVersionQuery,\n RemoteFilesVersionQueryVariables,\n RemoteFileSyncEventsSubscription,\n RemoteFileSyncEventsSubscriptionVariables,\n} from \"../__generated__/graphql\";\nimport { FileSyncEncoding } from \"../__generated__/graphql\";\nimport { PromiseSignal } from \"../utils/promise\";\n\nexport default class Sync extends BaseCommand<typeof Sync> {\n static override priority = 1;\n\n static override summary = \"Sync your Gadget application's source code to and from your local filesystem.\";\n\n static override usage = \"sync [DIRECTORY] [--app <name>]\";\n\n static override description = dedent(chalk`\n Sync provides the ability to sync your Gadget application's source code to and from your local\n filesystem. While {gray ggt sync} is running, local file changes are immediately reflected within\n Gadget, while files that are changed remotely are immediately saved to your local filesystem.\n\n Use cases for this include:\n - Developing locally with your own editor like VSCode {gray (https://code.visualstudio.com/)}\n - Storing your source code in a Git repository like GitHub {gray (https://github.com/)}\n\n Sync includes the concept of a {gray .ignore} file. This file may contain a list of files and\n directories that won't be received or sent to Gadget when syncing. The format of this file is\n identical to the one used by Git {gray (https://git-scm.com/docs/gitignore)}.\n\n The following files and directories are always ignored:\n - .gadget\n - .git\n - node_modules\n\n Note:\n - If you have separate development and production environments, {gray ggt sync} will only sync with your development environment\n - Gadget applications only support installing dependencies with Yarn 1 {gray (https://classic.yarnpkg.com/lang/en/)}\n - Since file changes are immediately reflected in Gadget, avoid the following while {gray ggt sync} is running:\n - Deleting all your files\n - Moving all your files to a different directory\n `);\n\n static override args = {\n directory: Args.string({\n description: \"The directory to sync files to. If the directory doesn't exist, it will be created.\",\n default: \".\",\n }),\n };\n\n static override flags = {\n app: app({\n summary: \"The Gadget application to sync files to.\",\n }),\n force: Flags.boolean({\n summary: \"Whether to sync even if we can't determine the state of your local files relative to your remote ones.\",\n default: false,\n }),\n \"file-push-delay\": Flags.integer({\n summary: \"Delay in milliseconds before pushing files to your app.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 100,\n hidden: true,\n }),\n \"file-stability-threshold\": Flags.integer({\n name: \"file-stability-threshold\",\n summary: \"Time in milliseconds a file's size must remain the same.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 500,\n hidden: true,\n }),\n \"file-poll-interval\": Flags.integer({\n name: \"file-poll-interval\",\n description: \"Interval in milliseconds between polling a file's size.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 100,\n hidden: true,\n }),\n };\n\n static override examples = [\n dedent(chalk`\n {gray $ ggt sync --app my-app ~/gadget/my-app}\n\n App my-app\n Editor https://my-app.gadget.app/edit\n Playground https://my-app.gadget.app/api/graphql/playground\n Docs https://docs.gadget.dev/api/my-app\n\n {underline Endpoints}\n - https://my-app.gadget.app\n - https://my-app--development.gadget.app\n\n Watching for file changes... {gray Press Ctrl+C to stop}\n\n Received {gray 12:00:00 PM}\n {green ←} routes/GET.js {gray (changed)}\n {green ←} user/signUp/signIn.js {gray (changed)}\n {gray 2 files in total. 2 changed, 0 deleted.}\n\n Sent {gray 12:00:03 PM}\n {green →} routes/GET.ts {gray (changed)}\n {gray 1 file in total. 1 changed, 0 deleted.}\n\n ^C Stopping... {gray (press Ctrl+C again to force)}\n Goodbye!\n `),\n ];\n\n override requireUser = true;\n\n /**\n * The current status of the sync process.\n */\n status = SyncStatus.STARTING;\n\n /**\n * The absolute path to the directory to sync files to.\n */\n dir!: string;\n\n /**\n * A list of filepaths that have changed because of a remote file-sync event. This is used to avoid sending files that\n * we recently received from a remote file-sync event.\n */\n recentRemoteChanges = new Set<string>();\n\n /**\n * A FIFO async callback queue that ensures we process file-sync events in the order they occurred.\n */\n queue = new PQueue({ concurrency: 1 });\n\n /**\n * A GraphQL client connected to the app's /edit/api/graphql-ws endpoint\n */\n client!: Client;\n\n /**\n * Loads the .ignore file and provides methods for checking if a file should be ignored.\n */\n ignorer!: FSIgnorer;\n\n /**\n * Watches the local filesystem for changes.\n */\n watcher!: FSWatcher;\n\n /**\n * Holds information about the state of the local filesystem. It's persisted to `.gadget/sync.json`.\n */\n metadata = {\n /**\n * The app this filesystem is synced to.\n */\n app: \"\",\n\n /**\n * The last filesVersion that was successfully written to the filesystem. This is used to determine if the remote\n * filesystem is ahead of the local one.\n */\n filesVersion: \"0\",\n\n /**\n * The largest mtime that was seen on the local filesystem before `ggt sync` stopped. This is used to determine if\n * the local filesystem has changed since the last sync.\n *\n * Note: This does not include the mtime of files that are ignored.\n */\n mtime: 0,\n };\n\n /**\n * A debounced function that enqueue's local file changes to be sent to Gadget.\n */\n publish!: DebouncedFunc<() => void>;\n\n /**\n * Gracefully stops the sync.\n */\n stop!: (error?: unknown) => Promise<void>;\n\n /**\n * Turns an absolute filepath into a relative one from {@linkcode dir}.\n */\n relative(to: string): string {\n return path.relative(this.dir, to);\n }\n\n /**\n * Combines path segments into an absolute filepath that starts at {@linkcode dir}.\n */\n absolute(...pathSegments: string[]): string {\n return path.resolve(this.dir, ...pathSegments);\n }\n\n /**\n * Similar to {@linkcode relative} in that it turns a filepath into a relative one from {@linkcode dir}. However, it\n * also changes any slashes to be posix/unix-like forward slashes, condenses repeated slashes into a single slash, and\n * adds a trailing slash if the filepath is a directory.\n *\n * This is used when sending file-sync events to Gadget to ensure that the paths are consistent across platforms.\n *\n * @see https://www.npmjs.com/package/normalize-path\n */\n normalize(filepath: string, isDirectory: boolean): string {\n return normalizePath(path.isAbsolute(filepath) ? this.relative(filepath) : filepath) + (isDirectory ? \"/\" : \"\");\n }\n\n /**\n * Pretty-prints changed and deleted filepaths to the console.\n *\n * @param prefix The prefix to print before each line.\n * @param changed The normalized paths that have changed.\n * @param deleted The normalized paths that have been deleted.\n * @param options.limit The maximum number of lines to print. Defaults to 10. If debug is enabled, this is ignored.\n */\n logPaths(prefix: string, changed: string[], deleted: string[], { limit = 10 } = {}): void {\n const lines = sortBy(\n [\n ...changed.map((normalizedPath) => chalk`{green ${prefix}} ${normalizedPath} {gray (changed)}`),\n ...deleted.map((normalizedPath) => chalk`{red ${prefix}} ${normalizedPath} {gray (deleted)}`),\n ],\n (line) => line.slice(line.indexOf(\" \") + 1)\n );\n\n let logged = 0;\n for (const line of lines) {\n this.log(line);\n if (++logged == limit && !this.debugEnabled) break;\n }\n\n if (lines.length > logged) {\n this.log(chalk`{gray … ${lines.length - logged} more}`);\n }\n\n this.log(chalk`{gray ${pluralize(\"file\", lines.length, true)} in total. ${changed.length} changed, ${deleted.length} deleted.}`);\n this.log();\n }\n\n /**\n * Initializes the sync process.\n * - Ensures the directory exists.\n * - Ensures the directory is empty or contains a `.gadget/sync.json` file.\n * - Ensures an app is selected and that it matches the app the directory was previously synced to.\n * - Ensures yarn v1 is installed.\n * - Prompts the user how to resolve conflicts if the local filesystem has changed since the last sync.\n */\n override async init(): Promise<void> {\n await super.init();\n\n this.dir =\n this.config.windows && this.args[\"directory\"].startsWith(\"~/\")\n ? path.join(this.config.home, this.args[\"directory\"].slice(2))\n : path.resolve(this.args[\"directory\"]);\n\n const getApp = async (): Promise<string> => {\n if (this.flags.app) return this.flags.app;\n if (this.metadata.app) return this.metadata.app;\n const selected = await prompt<{ app: string }>({\n type: \"list\",\n name: \"app\",\n message: \"Please select the app to sync to.\",\n choices: await context.getAvailableApps().then((apps) => apps.map((app) => app.slug)),\n });\n return selected.app;\n };\n\n if (await isEmptyDir(this.dir)) {\n this.metadata.app = await getApp();\n } else {\n try {\n this.metadata = await fs.readJson(this.absolute(\".gadget\", \"sync.json\"));\n if (!this.metadata.app) {\n this.metadata.app = await getApp();\n }\n } catch (error) {\n if (!this.flags.force) {\n throw new InvalidSyncFileError(error, this, this.flags.app);\n }\n this.metadata.app = await getApp();\n }\n }\n\n if (this.flags.app && this.flags.app !== this.metadata.app && !this.flags.force) {\n throw new InvalidSyncAppFlagError(this);\n }\n\n await context.setApp(this.metadata.app);\n\n this.client = new Client();\n\n // local files/folders that should never be published\n this.ignorer = new FSIgnorer(this.dir, [\"node_modules\", \".gadget\", \".git\"]);\n\n this.watcher = new FSWatcher({\n ignored: (filepath) => this.ignorer.ignores(filepath),\n // don't emit an event for every watched file on boot\n ignoreInitial: true,\n // make sure stats are always present on add/change events\n alwaysStat: true,\n // wait for the entire file to be written before emitting add/change events\n awaitWriteFinish: { pollInterval: this.flags[\"file-poll-interval\"], stabilityThreshold: this.flags[\"file-stability-threshold\"] },\n });\n\n this.debug(\"starting\");\n\n if (!which.sync(\"yarn\", { nothrow: true })) {\n throw new YarnNotFoundError();\n }\n\n await fs.ensureDir(this.dir);\n\n const { remoteFilesVersion } = await this.client.queryUnwrap({ query: REMOTE_FILES_VERSION_QUERY });\n const hasRemoteChanges = BigInt(remoteFilesVersion) > BigInt(this.metadata.filesVersion);\n\n const getChangedFiles = async (): Promise<Map<string, Stats>> => {\n const files = new Map();\n for await (const absolutePath of walkDir(this.dir, { ignorer: this.ignorer })) {\n const stats = await fs.stat(absolutePath);\n if (stats.mtime.getTime() > this.metadata.mtime) {\n files.set(this.normalize(absolutePath, stats.isDirectory()), stats);\n }\n }\n\n // never include the root directory\n files.delete(\"/\");\n\n return files;\n };\n\n const changedFiles = await getChangedFiles();\n const hasLocalChanges = changedFiles.size > 0;\n if (hasLocalChanges) {\n this.log(\"Local files have changed since you last synced\");\n this.logPaths(\"-\", Array.from(changedFiles.keys()), [], { limit: changedFiles.size });\n this.log();\n }\n\n this.debug(\"init %O\", { metadata: this.metadata, remoteFilesVersion, hasRemoteChanges, hasLocalChanges });\n\n let action: Action | undefined;\n if (hasLocalChanges) {\n ({ action } = await prompt({\n type: \"list\",\n name: \"action\",\n choices: [Action.CANCEL, Action.MERGE, Action.RESET],\n message: hasRemoteChanges ? \"Remote files have also changed. How would you like to proceed?\" : \"How would you like to proceed?\",\n }));\n }\n\n switch (action) {\n case Action.MERGE: {\n // get all the changed files again in case more changed\n const files = await getChangedFiles();\n\n // We purposefully don't set the returned remoteFilesVersion here because we haven't received the remote changes\n // yet. This will cause us to receive the local files that we just published + the remote files that were\n // changed since the last sync.\n await this.client.queryUnwrap({\n query: PUBLISH_FILE_SYNC_EVENTS_MUTATION,\n variables: {\n input: {\n expectedRemoteFilesVersion: remoteFilesVersion,\n changed: await pMap(files, async ([normalizedPath, stats]) => {\n if (stats.mtime.getTime() > this.metadata.mtime) {\n this.metadata.mtime = stats.mtime.getTime();\n }\n\n return {\n path: normalizedPath,\n mode: stats.mode,\n content: stats.isDirectory() ? \"\" : await fs.readFile(this.absolute(normalizedPath), \"base64\"),\n encoding: FileSyncEncoding.Base64,\n };\n }),\n deleted: [],\n },\n },\n });\n break;\n }\n case Action.RESET: {\n // delete all the local files that have changed since the last sync and set the files version to 0 so we receive\n // all the remote files again, including any files that we just deleted that still exist\n await pMap(changedFiles.keys(), (normalizedPath) => fs.remove(this.absolute(normalizedPath)));\n this.metadata.filesVersion = \"0\";\n break;\n }\n case Action.CANCEL: {\n process.exit(0);\n }\n }\n\n this.debug(\"started\");\n }\n\n /**\n * Runs the sync process until it is stopped or an error occurs.\n */\n async run(): Promise<void> {\n let error: unknown;\n const stopped = new PromiseSignal();\n\n this.stop = async (e?: unknown) => {\n if (this.status != SyncStatus.RUNNING) return;\n\n error = e;\n this.debug(\"stopping\");\n this.status = SyncStatus.STOPPING;\n\n try {\n unsubscribe();\n this.watcher.removeAllListeners();\n this.publish.flush();\n await this.queue.onIdle();\n } finally {\n await fs.outputJSON(this.absolute(\".gadget\", \"sync.json\"), this.metadata, { spaces: 2 });\n await Promise.allSettled([this.watcher.close(), this.client.dispose()]);\n\n this.debug(\"stopped\");\n this.status = SyncStatus.STOPPED;\n stopped.resolve();\n }\n };\n\n for (const signal of [\"SIGINT\", \"SIGTERM\"] as const) {\n process.on(signal, () => {\n if (this.status != SyncStatus.RUNNING) return;\n\n this.log(chalk` Stopping... {gray (press Ctrl+C again to force)}`);\n void this.stop();\n\n // When ggt is run via npx, and the user presses Ctrl+C, npx sends SIGINT twice in quick succession. In order to prevent the second\n // SIGINT from triggering the force exit listener, we wait a bit before registering it. This is a bit of a hack, but it works.\n setTimeout(() => {\n process.once(signal, () => {\n this.log(\" Exiting immediately. Note that files may not have finished syncing.\");\n process.exit(1);\n });\n }, 100).unref();\n });\n }\n\n const unsubscribe = this.client.subscribeUnwrap(\n {\n query: REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION,\n variables: () => ({ localFilesVersion: this.metadata.filesVersion }),\n },\n {\n error: (error) => void this.stop(error),\n next: ({ remoteFileSyncEvents }) => {\n const remoteFilesVersion = remoteFileSyncEvents.remoteFilesVersion;\n\n // we always ignore .gadget/ files so that we don't publish them (they're managed by gadget), but we still want to receive them\n const filter = (event: { path: string }) => event.path.startsWith(\".gadget/\") || !this.ignorer.ignores(event.path);\n const changed = remoteFileSyncEvents.changed.filter(filter);\n const deleted = remoteFileSyncEvents.deleted.filter(filter);\n\n this._enqueue(async () => {\n if (!changed.length && !deleted.length) {\n if (BigInt(remoteFilesVersion) > BigInt(this.metadata.filesVersion)) {\n // we still need to update filesVersion, otherwise our expectedFilesVersion will be behind the next time we publish\n this.debug(\"updated local files version from %s to %s\", this.metadata.filesVersion, remoteFilesVersion);\n this.metadata.filesVersion = remoteFilesVersion;\n }\n return;\n }\n\n this.log(chalk`Received {gray ${format(new Date(), \"pp\")}}`);\n this.logPaths(\n \"←\",\n changed.map((x) => x.path),\n deleted.map((x) => x.path)\n );\n\n // we need to processed deleted files first as we may delete an empty directory after a file has been put\n // into it. if processed out of order the new file is deleted as well\n await pMap(deleted, async (file) => {\n this.recentRemoteChanges.add(file.path);\n await fs.remove(this.absolute(file.path));\n });\n\n await pMap(changed, async (file) => {\n this.recentRemoteChanges.add(file.path);\n\n const absolutePath = this.absolute(file.path);\n if (file.path.endsWith(\"/\")) {\n await fs.ensureDir(absolutePath, { mode: 0o755 });\n return;\n }\n\n // we need to add the parent directory to recentRemoteChanges so that we don't try to publish it\n this.recentRemoteChanges.add(path.dirname(file.path) + \"/\");\n await fs.ensureDir(path.dirname(absolutePath), { mode: 0o755 });\n await fs.writeFile(absolutePath, Buffer.from(file.content, file.encoding), { mode: file.mode });\n\n if (absolutePath == this.absolute(\"yarn.lock\")) {\n await execa(\"yarn\", [\"install\"], { cwd: this.dir }).catch((err) => {\n this.debug(\"yarn install failed\");\n this.debug(err.message);\n });\n }\n\n if (absolutePath == this.ignorer.filepath) {\n this.ignorer.reload();\n }\n });\n\n this.debug(\"updated local files version from %s to %s\", this.metadata.filesVersion, remoteFilesVersion);\n this.metadata.filesVersion = remoteFilesVersion;\n\n // always remove the root directory from recentRemoteChanges\n this.recentRemoteChanges.delete(\"./\");\n\n // remove any files in recentRemoteChanges that are ignored (e.g. .gadget/ files)\n for (const filepath of this.recentRemoteChanges) {\n if (this.ignorer.ignores(filepath)) {\n this.recentRemoteChanges.delete(filepath);\n }\n }\n });\n },\n }\n );\n\n const localFilesBuffer = new Map<string, { mode: number; isDirectory: boolean } | { isDeleted: true; isDirectory: boolean }>();\n\n this.publish = debounce(() => {\n const localFiles = new Map(localFilesBuffer.entries());\n localFilesBuffer.clear();\n\n this._enqueue(async () => {\n const changed: FileSyncChangedEventInput[] = [];\n const deleted: FileSyncDeletedEventInput[] = [];\n\n await pMap(localFiles, async ([normalizedPath, file]) => {\n if (\"isDeleted\" in file) {\n deleted.push({ path: normalizedPath });\n return;\n }\n\n try {\n changed.push({\n path: normalizedPath,\n mode: file.mode,\n content: file.isDirectory ? \"\" : await fs.readFile(this.absolute(normalizedPath), \"base64\"),\n encoding: FileSyncEncoding.Base64,\n });\n } catch (error) {\n // A file could have been changed and then deleted before we process the change event, so the readFile\n // above will raise an ENOENT. This is normal operation, so just ignore this event.\n ignoreEnoent(error);\n }\n });\n\n if (!changed.length && !deleted.length) {\n return;\n }\n\n const data = await this.client.queryUnwrap({\n query: PUBLISH_FILE_SYNC_EVENTS_MUTATION,\n variables: { input: { expectedRemoteFilesVersion: this.metadata.filesVersion, changed, deleted } },\n });\n\n this.log(chalk`Sent {gray ${format(new Date(), \"pp\")}}`);\n this.logPaths(\n \"→\",\n changed.map((x) => x.path),\n deleted.map((x) => x.path)\n );\n\n const { remoteFilesVersion } = data.publishFileSyncEvents;\n this.debug(\"remote files version after publishing %s\", remoteFilesVersion);\n\n if (BigInt(remoteFilesVersion) > BigInt(this.metadata.filesVersion)) {\n this.debug(\"updated local files version from %s to %s\", this.metadata.filesVersion, remoteFilesVersion);\n this.metadata.filesVersion = remoteFilesVersion;\n }\n });\n }, this.flags[\"file-push-delay\"]);\n\n this.watcher\n .add(`${this.dir}/**/*`)\n .on(\"error\", (error) => void this.stop(error))\n .on(\"all\", (event, absolutePath, stats) => {\n const normalizedPath = this.normalize(absolutePath, event == \"addDir\" || event == \"unlinkDir\");\n\n if (stats?.isSymbolicLink?.()) {\n this.debug(\"skipping event caused by symlink %s\", normalizedPath);\n return;\n }\n\n if (absolutePath == this.ignorer.filepath) {\n this.ignorer.reload();\n } else if (this.ignorer.ignores(absolutePath)) {\n this.debug(\"skipping event caused by ignored file %s\", normalizedPath);\n return;\n }\n\n // we only update the mtime if the file is not ignored, because if we restart and the mtime is set to an ignored\n // file, then it could be greater than the mtime of all non ignored files and we'll think that local files have\n // changed when only an ignored one has\n if (stats && stats.mtime.getTime() > this.metadata.mtime) {\n this.metadata.mtime = stats.mtime.getTime();\n }\n\n if (this.recentRemoteChanges.delete(normalizedPath)) {\n this.debug(\"skipping event caused by recent write %s\", normalizedPath);\n return;\n }\n\n this.debug(\"file changed %s\", normalizedPath, event);\n\n switch (event) {\n case \"add\":\n case \"change\":\n assert(stats, \"missing stats on add/change event\");\n localFilesBuffer.set(normalizedPath, { mode: stats.mode, isDirectory: false });\n break;\n case \"addDir\":\n assert(stats, \"missing stats on addDir event\");\n localFilesBuffer.set(normalizedPath, { mode: stats.mode, isDirectory: true });\n break;\n case \"unlinkDir\":\n case \"unlink\":\n localFilesBuffer.set(normalizedPath, { isDeleted: true, isDirectory: event === \"unlinkDir\" });\n break;\n }\n\n this.publish();\n });\n\n this.status = SyncStatus.RUNNING;\n\n // app should be defined at this point\n assert(context.app);\n\n this.log();\n this.log(\n dedent(chalk`\n {bold ggt v${this.config.version}}\n\n App ${context.app.slug}\n Editor https://${context.app.slug}.gadget.app/edit\n Playground https://${context.app.slug}.gadget.app/api/graphql/playground\n Docs https://docs.gadget.dev/api/${context.app.slug}\n\n {underline Endpoints} ${\n context.app.hasSplitEnvironments\n ? `\n - https://${context.app.primaryDomain}\n - https://${context.app.slug}--development.gadget.app`\n : `\n - https://${context.app.primaryDomain}`\n }\n\n Watching for file changes... {gray Press Ctrl+C to stop}\n `)\n );\n this.log();\n\n await stopped;\n\n if (error) {\n this.notify({ subtitle: \"Uh oh!\", message: \"An error occurred while syncing files\" });\n throw error;\n } else {\n this.log(\"Goodbye!\");\n }\n }\n\n /**\n * Enqueues a function that handles file-sync events onto the {@linkcode queue}.\n *\n * @param fn The function to enqueue.\n */\n private _enqueue(fn: () => Promise<unknown>): void {\n void this.queue.add(fn).catch(this.stop);\n }\n}\n\nexport enum SyncStatus {\n STARTING,\n RUNNING,\n STOPPING,\n STOPPED,\n}\n\nexport enum Action {\n CANCEL = \"Cancel (Ctrl+C)\",\n MERGE = \"Merge local files with remote ones\",\n RESET = \"Reset local files to remote ones\",\n}\n\nexport const REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION: Query<\n RemoteFileSyncEventsSubscription,\n RemoteFileSyncEventsSubscriptionVariables\n> = /* GraphQL */ `\n subscription RemoteFileSyncEvents($localFilesVersion: String!) {\n remoteFileSyncEvents(localFilesVersion: $localFilesVersion, encoding: base64) {\n remoteFilesVersion\n changed {\n path\n mode\n content\n encoding\n }\n deleted {\n path\n }\n }\n }\n`;\n\nexport const REMOTE_FILES_VERSION_QUERY: Query<RemoteFilesVersionQuery, RemoteFilesVersionQueryVariables> = /* GraphQL */ `\n query RemoteFilesVersion {\n remoteFilesVersion\n }\n`;\n\nexport const PUBLISH_FILE_SYNC_EVENTS_MUTATION: Query<\n PublishFileSyncEventsMutation,\n PublishFileSyncEventsMutationVariables\n> = /* GraphQL */ `\n mutation PublishFileSyncEvents($input: PublishFileSyncEventsInput!) {\n publishFileSyncEvents(input: $input) {\n remoteFilesVersion\n }\n }\n`;\n"]}
1
+ {"version":3,"sources":["../../src/commands/sync.ts"],"sourcesContent":["import { Args, Flags } from \"@oclif/core\";\nimport assert from \"assert\";\nimport chalkTemplate from \"chalk-template\";\nimport { FSWatcher } from \"chokidar\";\nimport { format } from \"date-fns\";\nimport { execa } from \"execa\";\nimport type { Stats } from \"fs-extra\";\nimport fs from \"fs-extra\";\nimport inquirer from \"inquirer\";\nimport _ from \"lodash\";\nimport normalizePath from \"normalize-path\";\nimport pMap from \"p-map\";\nimport PQueue from \"p-queue\";\nimport path from \"path\";\nimport pluralize from \"pluralize\";\nimport { dedent } from \"ts-dedent\";\nimport which from \"which\";\nimport type {\n FileSyncChangedEventInput,\n FileSyncDeletedEventInput,\n PublishFileSyncEventsMutation,\n PublishFileSyncEventsMutationVariables,\n RemoteFileSyncEventsSubscription,\n RemoteFileSyncEventsSubscriptionVariables,\n RemoteFilesVersionQuery,\n RemoteFilesVersionQueryVariables,\n} from \"../__generated__/graphql.js\";\nimport { FileSyncEncoding } from \"../__generated__/graphql.js\";\nimport { BaseCommand } from \"../utils/base-command.js\";\nimport type { Query } from \"../utils/client.js\";\nimport { Client } from \"../utils/client.js\";\nimport { context } from \"../utils/context.js\";\nimport { InvalidSyncAppFlagError, InvalidSyncFileError, YarnNotFoundError } from \"../utils/errors.js\";\nimport { app } from \"../utils/flags.js\";\nimport { FSIgnorer, ignoreEnoent, isEmptyDir, walkDir } from \"../utils/fs-utils.js\";\nimport { PromiseSignal } from \"../utils/promise.js\";\n\nexport default class Sync extends BaseCommand<typeof Sync> {\n static override priority = 1;\n\n static override summary = \"Sync your Gadget application's source code to and from your local filesystem.\";\n\n static override usage = \"sync [DIRECTORY] [--app <name>]\";\n\n static override description = dedent(chalkTemplate`\n Sync provides the ability to sync your Gadget application's source code to and from your local\n filesystem. While {gray ggt sync} is running, local file changes are immediately reflected within\n Gadget, while files that are changed remotely are immediately saved to your local filesystem.\n\n Use cases for this include:\n - Developing locally with your own editor like VSCode {gray (https://code.visualstudio.com/)}\n - Storing your source code in a Git repository like GitHub {gray (https://github.com/)}\n\n Sync includes the concept of a {gray .ignore} file. This file may contain a list of files and\n directories that won't be received or sent to Gadget when syncing. The format of this file is\n identical to the one used by Git {gray (https://git-scm.com/docs/gitignore)}.\n\n The following files and directories are always ignored:\n - .gadget\n - .git\n - node_modules\n\n Note:\n - If you have separate development and production environments, {gray ggt sync} will only sync with your development environment\n - Gadget applications only support installing dependencies with Yarn 1 {gray (https://classic.yarnpkg.com/lang/en/)}\n - Since file changes are immediately reflected in Gadget, avoid the following while {gray ggt sync} is running:\n - Deleting all your files\n - Moving all your files to a different directory\n `);\n\n static override args = {\n directory: Args.string({\n description: \"The directory to sync files to. If the directory doesn't exist, it will be created.\",\n default: \".\",\n }),\n };\n\n static override flags = {\n app: app({\n summary: \"The Gadget application to sync files to.\",\n }),\n force: Flags.boolean({\n summary: \"Whether to sync even if we can't determine the state of your local files relative to your remote ones.\",\n default: false,\n }),\n \"file-push-delay\": Flags.integer({\n summary: \"Delay in milliseconds before pushing files to your app.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 100,\n hidden: true,\n }),\n \"file-stability-threshold\": Flags.integer({\n name: \"file-stability-threshold\",\n summary: \"Time in milliseconds a file's size must remain the same.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 500,\n hidden: true,\n }),\n \"file-poll-interval\": Flags.integer({\n name: \"file-poll-interval\",\n description: \"Interval in milliseconds between polling a file's size.\",\n helpGroup: \"file\",\n helpValue: \"ms\",\n default: 100,\n hidden: true,\n }),\n };\n\n static override examples = [\n dedent(chalkTemplate`\n {gray $ ggt sync --app my-app ~/gadget/my-app}\n\n App my-app\n Editor https://my-app.gadget.app/edit\n Playground https://my-app.gadget.app/api/graphql/playground\n Docs https://docs.gadget.dev/api/my-app\n\n {underline Endpoints}\n - https://my-app.gadget.app\n - https://my-app--development.gadget.app\n\n Watching for file changes... {gray Press Ctrl+C to stop}\n\n Received {gray 12:00:00 PM}\n {green ←} routes/GET.js {gray (changed)}\n {green ←} user/signUp/signIn.js {gray (changed)}\n {gray 2 files in total. 2 changed, 0 deleted.}\n\n Sent {gray 12:00:03 PM}\n {green →} routes/GET.ts {gray (changed)}\n {gray 1 file in total. 1 changed, 0 deleted.}\n\n ^C Stopping... {gray (press Ctrl+C again to force)}\n Goodbye!\n `),\n ];\n\n override requireUser = true;\n\n /**\n * The current status of the sync process.\n */\n status = SyncStatus.STARTING;\n\n /**\n * The absolute path to the directory to sync files to.\n */\n dir!: string;\n\n /**\n * A list of filepaths that have changed because of a remote file-sync event. This is used to avoid sending files that\n * we recently received from a remote file-sync event.\n */\n recentRemoteChanges = new Set<string>();\n\n /**\n * A FIFO async callback queue that ensures we process file-sync events in the order they occurred.\n */\n queue = new PQueue({ concurrency: 1 });\n\n /**\n * A GraphQL client connected to the app's /edit/api/graphql-ws endpoint\n */\n client!: Client;\n\n /**\n * Loads the .ignore file and provides methods for checking if a file should be ignored.\n */\n ignorer!: FSIgnorer;\n\n /**\n * Watches the local filesystem for changes.\n */\n watcher!: FSWatcher;\n\n /**\n * The state of the local filesystem.\n */\n state!: SyncState;\n\n /**\n * A debounced function that enqueue's local file changes to be sent to Gadget.\n */\n publish!: _.DebouncedFunc<() => void>;\n\n /**\n * Gracefully stops the sync.\n */\n stop!: (error?: unknown) => Promise<void>;\n\n /**\n * Turns an absolute filepath into a relative one from {@linkcode dir}.\n */\n relative(to: string): string {\n return path.relative(this.dir, to);\n }\n\n /**\n * Combines path segments into an absolute filepath that starts at {@linkcode dir}.\n */\n absolute(...pathSegments: string[]): string {\n return path.resolve(this.dir, ...pathSegments);\n }\n\n /**\n * Similar to {@linkcode relative} in that it turns a filepath into a relative one from {@linkcode dir}. However, it\n * also changes any slashes to be posix/unix-like forward slashes, condenses repeated slashes into a single slash, and\n * adds a trailing slash if the filepath is a directory.\n *\n * This is used when sending file-sync events to Gadget to ensure that the paths are consistent across platforms.\n *\n * @see https://www.npmjs.com/package/normalize-path\n */\n normalize(filepath: string, isDirectory: boolean): string {\n return normalizePath(path.isAbsolute(filepath) ? this.relative(filepath) : filepath) + (isDirectory ? \"/\" : \"\");\n }\n\n /**\n * Instead of deleting files, we move them to .gadget/backup so that users can recover them if something goes wrong.\n */\n async softDelete(normalizedPath: string): Promise<void> {\n try {\n await fs.move(this.absolute(normalizedPath), this.absolute(\".gadget/backup\", normalizedPath), {\n overwrite: true,\n });\n } catch (error) {\n // replicate the behavior of `rm -rf` and ignore ENOENT\n ignoreEnoent(error);\n }\n }\n\n /**\n * Pretty-prints changed and deleted filepaths to the console.\n *\n * @param prefix The prefix to print before each line.\n * @param changed The normalized paths that have changed.\n * @param deleted The normalized paths that have been deleted.\n * @param options.limit The maximum number of lines to print. Defaults to 10. If debug is enabled, this is ignored.\n */\n logPaths(prefix: string, changed: string[], deleted: string[], { limit = 10 } = {}): void {\n const lines = _.sortBy(\n [\n ...changed.map((normalizedPath) => chalkTemplate`{green ${prefix}} ${normalizedPath} {gray (changed)}`),\n ...deleted.map((normalizedPath) => chalkTemplate`{red ${prefix}} ${normalizedPath} {gray (deleted)}`),\n ],\n (line) => line.slice(line.indexOf(\" \") + 1)\n );\n\n let logged = 0;\n for (const line of lines) {\n this.log(line);\n if (++logged == limit && !this.debugEnabled) break;\n }\n\n if (lines.length > logged) {\n this.log(chalkTemplate`{gray … ${lines.length - logged} more}`);\n }\n\n this.log(\n chalkTemplate`{gray ${pluralize(\"file\", lines.length, true)} in total. ${changed.length} changed, ${deleted.length} deleted.}`\n );\n this.log();\n }\n\n /**\n * Initializes the sync process.\n * - Ensures the directory exists.\n * - Ensures the directory is empty or contains a `.gadget/sync.json` file.\n * - Ensures an app is selected and that it matches the app the directory was previously synced to.\n * - Ensures yarn v1 is installed.\n * - Prompts the user how to resolve conflicts if the local filesystem has changed since the last sync.\n */\n override async init(): Promise<void> {\n await super.init();\n\n assert(_.isString(this.args[\"directory\"]));\n\n this.dir =\n this.config.windows && this.args[\"directory\"].startsWith(\"~/\")\n ? path.join(this.config.home, this.args[\"directory\"].slice(2))\n : path.resolve(this.args[\"directory\"]);\n\n const getApp = async (): Promise<string> => {\n if (this.flags.app) return this.flags.app;\n if (this.state?.app) return this.state.app;\n const selected = await inquirer.prompt<{ app: string }>({\n type: \"list\",\n name: \"app\",\n message: \"Please select the app to sync to.\",\n choices: await context.getAvailableApps().then((apps) => apps.map((app) => app.slug)),\n });\n return selected.app;\n };\n\n if (await isEmptyDir(this.dir)) {\n const app = await getApp();\n this.state = SyncState.create(this.dir, { app });\n } else {\n try {\n this.state = SyncState.load(this.dir);\n } catch (error) {\n if (!this.flags.force) {\n throw new InvalidSyncFileError(error, this, this.flags.app);\n }\n const app = await getApp();\n this.state = SyncState.create(this.dir, { app });\n }\n }\n\n if (this.flags.app && this.flags.app !== this.state.app && !this.flags.force) {\n throw new InvalidSyncAppFlagError(this);\n }\n\n await context.setApp(this.state.app);\n\n this.client = new Client();\n\n // local files/folders that should never be published\n this.ignorer = new FSIgnorer(this.dir, [\"node_modules\", \".gadget\", \".git\"]);\n\n this.watcher = new FSWatcher({\n ignored: (filepath) => this.ignorer.ignores(filepath),\n // don't emit an event for every watched file on boot\n ignoreInitial: true,\n // make sure stats are always present on add/change events\n alwaysStat: true,\n // wait for the entire file to be written before emitting add/change events\n awaitWriteFinish: { pollInterval: this.flags[\"file-poll-interval\"], stabilityThreshold: this.flags[\"file-stability-threshold\"] },\n });\n\n this.debug(\"starting\");\n\n if (!which.sync(\"yarn\", { nothrow: true })) {\n throw new YarnNotFoundError();\n }\n\n await fs.ensureDir(this.dir);\n\n const { remoteFilesVersion } = await this.client.queryUnwrap({ query: REMOTE_FILES_VERSION_QUERY });\n const hasRemoteChanges = BigInt(remoteFilesVersion) > BigInt(this.state.filesVersion);\n\n const getChangedFiles = async (): Promise<Map<string, Stats>> => {\n const files = new Map();\n for await (const absolutePath of walkDir(this.dir, { ignorer: this.ignorer })) {\n const stats = await fs.stat(absolutePath);\n if (stats.mtime.getTime() > this.state.mtime) {\n files.set(this.normalize(absolutePath, stats.isDirectory()), stats);\n }\n }\n\n // never include the root directory\n files.delete(\"/\");\n\n return files;\n };\n\n const changedFiles = await getChangedFiles();\n const hasLocalChanges = changedFiles.size > 0;\n if (hasLocalChanges) {\n this.log(\"Local files have changed since you last synced\");\n this.logPaths(\"-\", Array.from(changedFiles.keys()), [], { limit: changedFiles.size });\n this.log();\n }\n\n this.debug(\"init %O\", { metadata: this.state, remoteFilesVersion, hasRemoteChanges, hasLocalChanges });\n\n let action: Action | undefined;\n if (hasLocalChanges) {\n ({ action } = await inquirer.prompt({\n type: \"list\",\n name: \"action\",\n choices: [Action.CANCEL, Action.MERGE, Action.RESET],\n message: hasRemoteChanges ? \"Remote files have also changed. How would you like to proceed?\" : \"How would you like to proceed?\",\n }));\n }\n\n switch (action) {\n case Action.MERGE: {\n // get all the changed files again in case more changed\n const files = await getChangedFiles();\n\n // We purposefully don't set the returned remoteFilesVersion here because we haven't received the remote changes\n // yet. This will cause us to receive the local files that we just published + the remote files that were\n // changed since the last sync.\n await this.client.queryUnwrap({\n query: PUBLISH_FILE_SYNC_EVENTS_MUTATION,\n variables: {\n input: {\n expectedRemoteFilesVersion: remoteFilesVersion,\n changed: await pMap(files, async ([normalizedPath, stats]) => {\n if (stats.mtime.getTime() > this.state.mtime) {\n this.state.mtime = stats.mtime.getTime();\n }\n\n return {\n path: normalizedPath,\n mode: stats.mode,\n content: stats.isDirectory() ? \"\" : await fs.readFile(this.absolute(normalizedPath), \"base64\"),\n encoding: FileSyncEncoding.Base64,\n };\n }),\n deleted: [],\n },\n },\n });\n break;\n }\n case Action.RESET: {\n // delete all the local files that have changed since the last sync and set the files version to 0 so we receive\n // all the remote files again, including any files that we just deleted that still exist\n await pMap(changedFiles.keys(), (normalizedPath) => this.softDelete(normalizedPath));\n this.state.filesVersion = 0n;\n break;\n }\n case Action.CANCEL: {\n process.exit(0);\n }\n }\n\n this.debug(\"started\");\n }\n\n /**\n * Runs the sync process until it is stopped or an error occurs.\n */\n async run(): Promise<void> {\n let error: unknown;\n const stopped = new PromiseSignal();\n\n this.stop = async (e?: unknown) => {\n if (this.status != SyncStatus.RUNNING) return;\n\n error = e;\n this.debug(\"stopping\");\n this.status = SyncStatus.STOPPING;\n\n try {\n unsubscribe();\n this.watcher.removeAllListeners();\n this.publish.flush();\n await this.queue.onIdle();\n } finally {\n this.state.flush();\n await Promise.allSettled([this.watcher.close(), this.client.dispose()]);\n\n this.debug(\"stopped\");\n this.status = SyncStatus.STOPPED;\n stopped.resolve();\n }\n };\n\n for (const signal of [\"SIGINT\", \"SIGTERM\"] as const) {\n process.on(signal, () => {\n if (this.status != SyncStatus.RUNNING) return;\n\n this.log(chalkTemplate` Stopping... {gray (press Ctrl+C again to force)}`);\n void this.stop();\n\n // When ggt is run via npx, and the user presses Ctrl+C, npx sends SIGINT twice in quick succession. In order to prevent the second\n // SIGINT from triggering the force exit listener, we wait a bit before registering it. This is a bit of a hack, but it works.\n setTimeout(() => {\n process.once(signal, () => {\n this.log(\" Exiting immediately. Note that files may not have finished syncing.\");\n process.exit(1);\n });\n }, 100).unref();\n });\n }\n\n const unsubscribe = this.client.subscribeUnwrap(\n {\n query: REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION,\n variables: () => ({ localFilesVersion: String(this.state.filesVersion) }),\n },\n {\n error: (error) => void this.stop(error),\n next: ({ remoteFileSyncEvents }) => {\n const remoteFilesVersion = remoteFileSyncEvents.remoteFilesVersion;\n\n // we always ignore .gadget/ files so that we don't publish them (they're managed by gadget), but we still want to receive them\n const filter = (event: { path: string }) => event.path.startsWith(\".gadget/\") || !this.ignorer.ignores(event.path);\n const changed = remoteFileSyncEvents.changed.filter(filter);\n const deleted = remoteFileSyncEvents.deleted.filter(filter);\n\n this._enqueue(async () => {\n if (!changed.length && !deleted.length) {\n if (BigInt(remoteFilesVersion) > this.state.filesVersion) {\n // we still need to update filesVersion, otherwise our expectedFilesVersion will be behind the next time we publish\n this.debug(\"updated local files version from %s to %s\", this.state.filesVersion, remoteFilesVersion);\n this.state.filesVersion = remoteFilesVersion;\n }\n return;\n }\n\n this.log(chalkTemplate`Received {gray ${format(new Date(), \"pp\")}}`);\n this.logPaths(\n \"←\",\n changed.map((x) => x.path),\n deleted.map((x) => x.path)\n );\n\n // we need to processed deleted files first as we may delete an empty directory after a file has been put\n // into it. if processed out of order the new file will be deleted as well\n await pMap(deleted, async (file) => {\n this.recentRemoteChanges.add(file.path);\n await this.softDelete(file.path);\n });\n\n await pMap(changed, async (file) => {\n this.recentRemoteChanges.add(file.path);\n\n const absolutePath = this.absolute(file.path);\n if (file.path.endsWith(\"/\")) {\n await fs.ensureDir(absolutePath, { mode: 0o755 });\n return;\n }\n\n // we need to add the parent directory to recentRemoteChanges so that we don't try to publish it\n this.recentRemoteChanges.add(path.dirname(file.path) + \"/\");\n await fs.ensureDir(path.dirname(absolutePath), { mode: 0o755 });\n await fs.writeFile(absolutePath, Buffer.from(file.content, file.encoding), { mode: file.mode });\n\n if (absolutePath == this.absolute(\"yarn.lock\")) {\n await execa(\"yarn\", [\"install\"], { cwd: this.dir }).catch((err) => {\n this.debug(\"yarn install failed\");\n this.debug(err.message);\n });\n }\n\n if (absolutePath == this.ignorer.filepath) {\n this.ignorer.reload();\n }\n });\n\n this.debug(\"updated local files version from %s to %s\", this.state.filesVersion, remoteFilesVersion);\n this.state.filesVersion = remoteFilesVersion;\n\n // always remove the root directory from recentRemoteChanges\n this.recentRemoteChanges.delete(\"./\");\n\n // remove any files in recentRemoteChanges that are ignored (e.g. .gadget/ files)\n for (const filepath of this.recentRemoteChanges) {\n if (this.ignorer.ignores(filepath)) {\n this.recentRemoteChanges.delete(filepath);\n }\n }\n });\n },\n }\n );\n\n const localFilesBuffer = new Map<string, { mode: number; isDirectory: boolean } | { isDeleted: true; isDirectory: boolean }>();\n\n this.publish = _.debounce(() => {\n const localFiles = new Map(localFilesBuffer.entries());\n localFilesBuffer.clear();\n\n this._enqueue(async () => {\n const changed: FileSyncChangedEventInput[] = [];\n const deleted: FileSyncDeletedEventInput[] = [];\n\n await pMap(localFiles, async ([normalizedPath, file]) => {\n if (\"isDeleted\" in file) {\n deleted.push({ path: normalizedPath });\n return;\n }\n\n try {\n changed.push({\n path: normalizedPath,\n mode: file.mode,\n content: file.isDirectory ? \"\" : await fs.readFile(this.absolute(normalizedPath), \"base64\"),\n encoding: FileSyncEncoding.Base64,\n });\n } catch (error) {\n // A file could have been changed and then deleted before we process the change event, so the readFile\n // above will raise an ENOENT. This is normal operation, so just ignore this event.\n ignoreEnoent(error);\n }\n });\n\n if (!changed.length && !deleted.length) {\n return;\n }\n\n const data = await this.client.queryUnwrap({\n query: PUBLISH_FILE_SYNC_EVENTS_MUTATION,\n variables: { input: { expectedRemoteFilesVersion: String(this.state.filesVersion), changed, deleted } },\n });\n\n this.log(chalkTemplate`Sent {gray ${format(new Date(), \"pp\")}}`);\n this.logPaths(\n \"→\",\n changed.map((x) => x.path),\n deleted.map((x) => x.path)\n );\n\n const { remoteFilesVersion } = data.publishFileSyncEvents;\n this.debug(\"remote files version after publishing %s\", remoteFilesVersion);\n\n if (BigInt(remoteFilesVersion) > this.state.filesVersion) {\n this.debug(\"updated local files version from %s to %s\", this.state.filesVersion, remoteFilesVersion);\n this.state.filesVersion = remoteFilesVersion;\n }\n });\n }, this.flags[\"file-push-delay\"]);\n\n this.watcher\n .add(`${this.dir}/**/*`)\n .on(\"error\", (error) => void this.stop(error))\n .on(\"all\", (event, absolutePath, stats) => {\n const normalizedPath = this.normalize(absolutePath, event == \"addDir\" || event == \"unlinkDir\");\n\n if (stats?.isSymbolicLink?.()) {\n this.debug(\"skipping event caused by symlink %s\", normalizedPath);\n return;\n }\n\n if (absolutePath == this.ignorer.filepath) {\n this.ignorer.reload();\n } else if (this.ignorer.ignores(absolutePath)) {\n this.debug(\"skipping event caused by ignored file %s\", normalizedPath);\n return;\n }\n\n // we only update the mtime if the file is not ignored, because if we restart and the mtime is set to an ignored\n // file, then it could be greater than the mtime of all non ignored files and we'll think that local files have\n // changed when only an ignored one has\n if (stats && stats.mtime.getTime() > this.state.mtime) {\n this.state.mtime = stats.mtime.getTime();\n }\n\n if (this.recentRemoteChanges.delete(normalizedPath)) {\n this.debug(\"skipping event caused by recent write %s\", normalizedPath);\n return;\n }\n\n this.debug(\"file changed %s\", normalizedPath, event);\n\n switch (event) {\n case \"add\":\n case \"change\":\n assert(stats, \"missing stats on add/change event\");\n localFilesBuffer.set(normalizedPath, { mode: stats.mode, isDirectory: false });\n break;\n case \"addDir\":\n assert(stats, \"missing stats on addDir event\");\n localFilesBuffer.set(normalizedPath, { mode: stats.mode, isDirectory: true });\n break;\n case \"unlinkDir\":\n case \"unlink\":\n localFilesBuffer.set(normalizedPath, { isDeleted: true, isDirectory: event === \"unlinkDir\" });\n break;\n }\n\n this.publish();\n });\n\n this.status = SyncStatus.RUNNING;\n\n // app should be defined at this point\n assert(context.app);\n\n this.log();\n this.log(\n dedent(chalkTemplate`\n {bold ggt v${this.config.version}}\n\n App ${context.app.slug}\n Editor https://${context.app.slug}.gadget.app/edit\n Playground https://${context.app.slug}.gadget.app/api/graphql/playground\n Docs https://docs.gadget.dev/api/${context.app.slug}\n\n {underline Endpoints} ${\n context.app.hasSplitEnvironments\n ? `\n - https://${context.app.primaryDomain}\n - https://${context.app.slug}--development.gadget.app`\n : `\n - https://${context.app.primaryDomain}`\n }\n\n Watching for file changes... {gray Press Ctrl+C to stop}\n `)\n );\n this.log();\n\n await stopped;\n\n if (error) {\n this.notify({ subtitle: \"Uh oh!\", message: \"An error occurred while syncing files\" });\n throw error;\n } else {\n this.log(\"Goodbye!\");\n }\n }\n\n /**\n * Enqueues a function that handles file-sync events onto the {@linkcode queue}.\n *\n * @param fn The function to enqueue.\n */\n private _enqueue(fn: () => Promise<unknown>): void {\n void this.queue.add(fn).catch(this.stop);\n }\n}\n\n/**\n * Holds information about the state of the local filesystem. It's persisted to `.gadget/sync.json`.\n */\nexport class SyncState {\n private _inner: {\n app: string;\n filesVersion: string;\n mtime: number;\n };\n\n /**\n * Saves the current state of the filesystem to `.gadget/sync.json`.\n */\n #save = _.debounce(() => {\n fs.outputJSONSync(path.join(this._rootDir, \".gadget/sync.json\"), this._inner, { spaces: 2 });\n }, 100);\n\n private constructor(private _rootDir: string, inner: { app: string; filesVersion: string; mtime: number }) {\n this._inner = inner;\n }\n\n /**\n * The app this filesystem is synced to.\n */\n get app(): string {\n return this._inner.app;\n }\n\n /**\n * The last filesVersion that was successfully written to the filesystem. This is used to determine if the remote\n * filesystem is ahead of the local one.\n */\n get filesVersion(): bigint {\n return BigInt(this._inner.filesVersion);\n }\n\n set filesVersion(value: bigint | string) {\n this._inner.filesVersion = String(value);\n this.#save();\n }\n\n /**\n * The largest mtime that was seen on the local filesystem before `ggt sync` stopped. This is used to determine if\n * the local filesystem has changed since the last sync.\n *\n * Note: This does not include the mtime of files that are ignored.\n */\n // eslint-disable-next-line @typescript-eslint/member-ordering\n get mtime(): number {\n return this._inner.mtime;\n }\n\n set mtime(value: number) {\n this._inner.mtime = value;\n this.#save();\n }\n\n /**\n * Creates a new SyncFile instance and saves it to the filesystem.\n *\n * @param rootDir The root directory of the app.\n * @param app The app slug.\n * @returns A new SyncFile instance.\n */\n static create(rootDir: string, opts: { app: string; filesVersion?: string; mtime?: number }): SyncState {\n const state = new SyncState(rootDir, { filesVersion: \"0\", mtime: 0, ...opts });\n state.#save();\n state.flush();\n return state;\n }\n\n /**\n * Loads a SyncFile instance from the filesystem.\n *\n * @param rootDir The root directory of the app.\n * @returns The SyncFile instance.\n */\n static load(rootDir: string): SyncState {\n const state = fs.readJsonSync(path.join(rootDir, \".gadget/sync.json\"));\n\n assert(_.isString(state.app), \"missing or invalid app\");\n assert(_.isString(state.filesVersion), \"missing or invalid filesVersion\");\n assert(_.isNumber(state.mtime), \"missing or invalid mtime\");\n\n return new SyncState(rootDir, {\n app: state.app,\n filesVersion: state.filesVersion,\n mtime: state.mtime,\n });\n }\n\n /**\n * Flushes any pending writes to the filesystem.\n */\n flush(): void {\n this.#save.flush();\n }\n}\n\nexport enum SyncStatus {\n STARTING,\n RUNNING,\n STOPPING,\n STOPPED,\n}\n\nexport enum Action {\n CANCEL = \"Cancel (Ctrl+C)\",\n MERGE = \"Merge local files with remote ones\",\n RESET = \"Reset local files to remote ones\",\n}\n\nexport const REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION: Query<\n RemoteFileSyncEventsSubscription,\n RemoteFileSyncEventsSubscriptionVariables\n> = /* GraphQL */ `\n subscription RemoteFileSyncEvents($localFilesVersion: String!) {\n remoteFileSyncEvents(localFilesVersion: $localFilesVersion, encoding: base64) {\n remoteFilesVersion\n changed {\n path\n mode\n content\n encoding\n }\n deleted {\n path\n }\n }\n }\n`;\n\nexport const REMOTE_FILES_VERSION_QUERY: Query<RemoteFilesVersionQuery, RemoteFilesVersionQueryVariables> = /* GraphQL */ `\n query RemoteFilesVersion {\n remoteFilesVersion\n }\n`;\n\nexport const PUBLISH_FILE_SYNC_EVENTS_MUTATION: Query<\n PublishFileSyncEventsMutation,\n PublishFileSyncEventsMutationVariables\n> = /* GraphQL */ `\n mutation PublishFileSyncEvents($input: PublishFileSyncEventsInput!) {\n publishFileSyncEvents(input: $input) {\n remoteFilesVersion\n }\n }\n`;\n"],"names":["Args","Flags","assert","chalkTemplate","FSWatcher","format","execa","fs","inquirer","_","normalizePath","pMap","PQueue","path","pluralize","dedent","which","FileSyncEncoding","BaseCommand","Client","context","InvalidSyncAppFlagError","InvalidSyncFileError","YarnNotFoundError","app","FSIgnorer","ignoreEnoent","isEmptyDir","walkDir","PromiseSignal","Sync","relative","to","dir","absolute","pathSegments","resolve","normalize","filepath","isDirectory","isAbsolute","softDelete","normalizedPath","move","overwrite","error","logPaths","prefix","changed","deleted","limit","lines","sortBy","map","line","slice","indexOf","logged","log","debugEnabled","length","init","isString","args","config","windows","startsWith","join","home","getApp","flags","state","selected","prompt","type","name","message","choices","getAvailableApps","then","apps","slug","SyncState","create","load","force","setApp","client","ignorer","watcher","ignored","ignores","ignoreInitial","alwaysStat","awaitWriteFinish","pollInterval","stabilityThreshold","debug","sync","nothrow","ensureDir","remoteFilesVersion","queryUnwrap","query","REMOTE_FILES_VERSION_QUERY","hasRemoteChanges","BigInt","filesVersion","getChangedFiles","files","Map","absolutePath","stats","stat","mtime","getTime","set","delete","changedFiles","hasLocalChanges","size","Array","from","keys","metadata","action","Action","CANCEL","MERGE","RESET","PUBLISH_FILE_SYNC_EVENTS_MUTATION","variables","input","expectedRemoteFilesVersion","mode","content","readFile","encoding","Base64","process","exit","run","stopped","stop","e","status","SyncStatus","RUNNING","STOPPING","unsubscribe","removeAllListeners","publish","flush","queue","onIdle","Promise","allSettled","close","dispose","STOPPED","signal","on","setTimeout","once","unref","subscribeUnwrap","REMOTE_FILE_SYNC_EVENTS_SUBSCRIPTION","localFilesVersion","String","next","remoteFileSyncEvents","filter","event","_enqueue","Date","x","file","recentRemoteChanges","add","endsWith","dirname","writeFile","Buffer","cwd","catch","err","reload","localFilesBuffer","debounce","localFiles","entries","clear","push","data","publishFileSyncEvents","isSymbolicLink","isDeleted","version","hasSplitEnvironments","primaryDomain","notify","subtitle","fn","requireUser","STARTING","Set","concurrency","priority","summary","usage","description","directory","string","default","boolean","integer","helpGroup","helpValue","hidden","examples","_inner","value","save","rootDir","opts","readJsonSync","isNumber","_rootDir","inner","outputJSONSync","spaces"],"mappings":";;;;AAAA,SAASA,IAAI,EAAEC,KAAK,QAAQ,cAAc;AAC1C,OAAOC,YAAY,SAAS;AAC5B,OAAOC,mBAAmB,iBAAiB;AAC3C,SAASC,SAAS,QAAQ,WAAW;AACrC,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,KAAK,QAAQ,QAAQ;AAE9B,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,cAAc,WAAW;AAChC,OAAOC,OAAO,SAAS;AACvB,OAAOC,mBAAmB,iBAAiB;AAC3C,OAAOC,UAAU,QAAQ;AACzB,OAAOC,YAAY,UAAU;AAC7B,OAAOC,UAAU,OAAO;AACxB,OAAOC,eAAe,YAAY;AAClC,SAASC,MAAM,QAAQ,YAAY;AACnC,OAAOC,WAAW,QAAQ;AAW1B,SAASC,gBAAgB,QAAQ,8BAA8B;AAC/D,SAASC,WAAW,QAAQ,2BAA2B;AAEvD,SAASC,MAAM,QAAQ,qBAAqB;AAC5C,SAASC,OAAO,QAAQ,sBAAsB;AAC9C,SAASC,uBAAuB,EAAEC,oBAAoB,EAAEC,iBAAiB,QAAQ,qBAAqB;AACtG,SAASC,GAAG,QAAQ,oBAAoB;AACxC,SAASC,SAAS,EAAEC,YAAY,EAAEC,UAAU,EAAEC,OAAO,QAAQ,uBAAuB;AACpF,SAASC,aAAa,QAAQ,sBAAsB;AAErC,MAAMC,aAAaZ;IA2JhC;;GAEC,GACDa,SAASC,EAAU,EAAU;QAC3B,OAAOnB,KAAKkB,SAAS,IAAI,CAACE,KAAKD;IACjC;IAEA;;GAEC,GACDE,SAAS,GAAGC,YAAsB,EAAU;QAC1C,OAAOtB,KAAKuB,QAAQ,IAAI,CAACH,QAAQE;IACnC;IAEA;;;;;;;;GAQC,GACDE,UAAUC,QAAgB,EAAEC,WAAoB,EAAU;QACxD,OAAO7B,cAAcG,KAAK2B,WAAW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AkBC,KAA2D,CAAE;+BAA/ED;QAb5B,uBAAQP,UAAR,KAAA;QASA,gCAAA;;mBAAA,KAAA;;wBAI4BO;uCAJ3BL,OAAOrN,EAAEmL,SAAS;YACjBrL,GAAG8N,eAAexN,KAAKsD,KAAK,IAAI,CAACgK,UAAU,sBAAsB,IAAI,CAACP,QAAQ;gBAAEU,QAAQ;YAAE;QAC5F,GAAG;QAGD,IAAI,CAACV,SAASQ;IAChB;AA8EF;WAEO;UAAKlF,UAAU;IAAVA,WAAAA,WACV0D,cAAAA,KAAAA;IADU1D,WAAAA,WAEVC,aAAAA,KAAAA;IAFUD,WAAAA,WAGVE,cAAAA,KAAAA;IAHUF,WAAAA,WAIVa,aAAAA,KAAAA;GAJUb,eAAAA;WAOL;UAAKpB,MAAM;IAANA,OACVC,YAAS;IADCD,OAEVE,WAAQ;IAFEF,OAGVG,WAAQ;GAHEH,WAAAA;AAMZ,OAAO,MAAMwC,uCAGT,WAAW,GAAG,CAAC;;;;;;;;;;;;;;;AAenB,CAAC,CAAC;AAEF,OAAO,MAAM9D,6BAA+F,WAAW,GAAG,CAAC;;;;AAI3H,CAAC,CAAC;AAEF,OAAO,MAAM0B,oCAGT,WAAW,GAAG,CAAC;;;;;;AAMnB,CAAC,CAAC"}
@@ -1,47 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
5
- const ts_dedent_1 = tslib_1.__importDefault(require("ts-dedent"));
6
- const base_command_1 = require("../utils/base-command");
7
- const context_1 = require("../utils/context");
8
- class Whoami extends base_command_1.BaseCommand {
1
+ import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
+ import chalkTemplate from "chalk-template";
3
+ import { dedent } from "ts-dedent";
4
+ import { BaseCommand } from "../utils/base-command.js";
5
+ import { context } from "../utils/context.js";
6
+ class Whoami extends BaseCommand {
9
7
  async run() {
10
- const user = await context_1.context.getUser();
8
+ const user = await context.getUser();
11
9
  if (!user) {
12
10
  this.log("You are not logged in");
13
11
  return;
14
12
  }
15
13
  if (user.name) {
16
- this.log((0, chalk_1.default) `You are logged in as ${user.name} {gray (${user.email})}`);
17
- }
18
- else {
14
+ this.log(chalkTemplate`You are logged in as ${user.name} {gray (${user.email})}`);
15
+ } else {
19
16
  this.log(`You are logged in as ${user.email}`);
20
17
  }
21
18
  }
22
19
  }
23
- Object.defineProperty(Whoami, "summary", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: "Show the name and email address of the currently logged in user."
28
- });
29
- Object.defineProperty(Whoami, "usage", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: "whoami"
34
- });
35
- Object.defineProperty(Whoami, "examples", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: [
40
- (0, ts_dedent_1.default)((0, chalk_1.default) `
20
+ _define_property(Whoami, "summary", "Show the name and email address of the currently logged in user.");
21
+ _define_property(Whoami, "usage", "whoami");
22
+ _define_property(Whoami, "examples", [
23
+ dedent(chalkTemplate`
41
24
  {gray $ ggt whoami}
42
25
  You are logged in as Jane Doe {gray (jane@example.com)}
43
- `),
44
- ]
45
- });
46
- exports.default = Whoami;
26
+ `)
27
+ ]);
28
+ export { Whoami as default };
29
+
47
30
  //# sourceMappingURL=whoami.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"whoami.js","sourceRoot":"/","sources":["commands/whoami.ts"],"names":[],"mappings":";;;AAAA,0DAA0B;AAC1B,kEAA+B;AAC/B,wDAAoD;AACpD,8CAA2C;AAE3C,MAAqB,MAAO,SAAQ,0BAA0B;IAY5D,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,GAAG,MAAM,iBAAO,CAAC,OAAO,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;YAClC,OAAO;SACR;QAED,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,IAAI,CAAC,GAAG,CAAC,IAAA,eAAK,EAAA,wBAAwB,IAAI,CAAC,IAAI,WAAW,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;SAC3E;aAAM;YACL,IAAI,CAAC,GAAG,CAAC,wBAAwB,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;SAChD;IACH,CAAC;;AAvBe;;;;WAAU,kEAAkE;GAAC;AAE7E;;;;WAAQ,QAAQ;GAAC;AAEjB;;;;WAAW;QACzB,IAAA,mBAAM,EAAC,IAAA,eAAK,EAAA;;;KAGX,CAAC;KACH;GAAC;kBAViB,MAAM","sourcesContent":["import chalk from \"chalk\";\nimport dedent from \"ts-dedent\";\nimport { BaseCommand } from \"../utils/base-command\";\nimport { context } from \"../utils/context\";\n\nexport default class Whoami extends BaseCommand<typeof Whoami> {\n static override summary = \"Show the name and email address of the currently logged in user.\";\n\n static override usage = \"whoami\";\n\n static override examples = [\n dedent(chalk`\n {gray $ ggt whoami}\n You are logged in as Jane Doe {gray (jane@example.com)}\n `),\n ];\n\n async run(): Promise<void> {\n const user = await context.getUser();\n if (!user) {\n this.log(\"You are not logged in\");\n return;\n }\n\n if (user.name) {\n this.log(chalk`You are logged in as ${user.name} {gray (${user.email})}`);\n } else {\n this.log(`You are logged in as ${user.email}`);\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/commands/whoami.ts"],"sourcesContent":["import chalkTemplate from \"chalk-template\";\nimport { dedent } from \"ts-dedent\";\nimport { BaseCommand } from \"../utils/base-command.js\";\nimport { context } from \"../utils/context.js\";\n\nexport default class Whoami extends BaseCommand<typeof Whoami> {\n static override summary = \"Show the name and email address of the currently logged in user.\";\n\n static override usage = \"whoami\";\n\n static override examples = [\n dedent(chalkTemplate`\n {gray $ ggt whoami}\n You are logged in as Jane Doe {gray (jane@example.com)}\n `),\n ];\n\n async run(): Promise<void> {\n const user = await context.getUser();\n if (!user) {\n this.log(\"You are not logged in\");\n return;\n }\n\n if (user.name) {\n this.log(chalkTemplate`You are logged in as ${user.name} {gray (${user.email})}`);\n } else {\n this.log(`You are logged in as ${user.email}`);\n }\n }\n}\n"],"names":["chalkTemplate","dedent","BaseCommand","context","Whoami","run","user","getUser","log","name","email","summary","usage","examples"],"mappings":";AAAA,OAAOA,mBAAmB,iBAAiB;AAC3C,SAASC,MAAM,QAAQ,YAAY;AACnC,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SAASC,OAAO,QAAQ,sBAAsB;AAE/B,MAAMC,eAAeF;IAYlC,MAAMG,MAAqB;QACzB,MAAMC,OAAO,MAAMH,QAAQI;QAC3B,IAAI,CAACD,MAAM;YACT,IAAI,CAACE,IAAI;YACT;QACF;QAEA,IAAIF,KAAKG,MAAM;YACb,IAAI,CAACD,IAAIR,aAAa,CAAC,qBAAqB,EAAEM,KAAKG,KAAK,QAAQ,EAAEH,KAAKI,MAAM,EAAE,CAAC;QAClF,OAAO;YACL,IAAI,CAACF,IAAI,CAAC,qBAAqB,EAAEF,KAAKI,MAAM,CAAC;QAC/C;IACF;AACF;AAxBE,iBADmBN,QACHO,WAAU;AAE1B,iBAHmBP,QAGHQ,SAAQ;AAExB,iBALmBR,QAKHS,YAAW;IACzBZ,OAAOD,aAAa,CAAC;;;IAGrB,CAAC;CACF;AAVH,SAAqBI,oBAyBpB"}
package/lib/index.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- var core_1 = require("@oclif/core");
5
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return core_1.run; } });
1
+ export { run } from "@oclif/core";
2
+
6
3
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;AAAA,oCAAkC;AAAzB,2FAAA,GAAG,OAAA","sourcesContent":["export { run } from \"@oclif/core\";\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { run } from \"@oclif/core\";\n"],"names":["run"],"mappings":"AAAA,SAASA,GAAG,QAAQ,cAAc"}