@shopify/cli-kit 3.68.1 → 3.69.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.
- package/dist/cli/api/graphql/admin/generated/public_api_versions.d.ts +14 -0
- package/dist/cli/api/graphql/admin/generated/public_api_versions.js +28 -0
- package/dist/cli/api/graphql/admin/generated/public_api_versions.js.map +1 -0
- package/dist/private/node/api/graphql.d.ts +1 -1
- package/dist/private/node/api/graphql.js +1 -0
- package/dist/private/node/api/graphql.js.map +1 -1
- package/dist/private/node/api/headers.js +2 -2
- package/dist/private/node/api/headers.js.map +1 -1
- package/dist/private/node/api/rest.js +3 -1
- package/dist/private/node/api/rest.js.map +1 -1
- package/dist/private/node/api.d.ts +2 -2
- package/dist/private/node/api.js +8 -6
- package/dist/private/node/api.js.map +1 -1
- package/dist/private/node/constants.d.ts +0 -1
- package/dist/private/node/constants.js +0 -1
- package/dist/private/node/constants.js.map +1 -1
- package/dist/private/node/demo-recorder.js +1 -0
- package/dist/private/node/demo-recorder.js.map +1 -1
- package/dist/private/node/session/device-authorization.js +15 -7
- package/dist/private/node/session/device-authorization.js.map +1 -1
- package/dist/private/node/session/exchange.d.ts +0 -8
- package/dist/private/node/session/exchange.js +2 -19
- package/dist/private/node/session/exchange.js.map +1 -1
- package/dist/private/node/session/validate.js +1 -0
- package/dist/private/node/session/validate.js.map +1 -1
- package/dist/private/node/session.d.ts +5 -5
- package/dist/private/node/session.js +4 -12
- package/dist/private/node/session.js.map +1 -1
- package/dist/private/node/testing/ui.js +0 -3
- package/dist/private/node/testing/ui.js.map +1 -1
- package/dist/private/node/themes/generate-theme-name.js +1 -0
- package/dist/private/node/themes/generate-theme-name.js.map +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.test.js +0 -3
- package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/Banner.js +1 -0
- package/dist/private/node/ui/components/Banner.js.map +1 -1
- package/dist/private/node/ui/components/ConcurrentOutput.test.js +7 -7
- package/dist/private/node/ui/components/ConcurrentOutput.test.js.map +1 -1
- package/dist/private/node/ui/components/FatalError.js +1 -0
- package/dist/private/node/ui/components/FatalError.js.map +1 -1
- package/dist/private/node/ui/components/List.js +1 -1
- package/dist/private/node/ui/components/List.js.map +1 -1
- package/dist/private/node/ui/components/Prompts/InfoTable.js +1 -0
- package/dist/private/node/ui/components/Prompts/InfoTable.js.map +1 -1
- package/dist/private/node/ui/components/SelectInput.js +1 -1
- package/dist/private/node/ui/components/SelectInput.js.map +1 -1
- package/dist/private/node/ui/components/SelectPrompt.test.js +0 -4
- package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/Table/Row.js.map +1 -1
- package/dist/private/node/ui/components/Tasks.js +2 -1
- package/dist/private/node/ui/components/Tasks.js.map +1 -1
- package/dist/private/node/ui/components/TextPrompt.d.ts +1 -1
- package/dist/private/node/ui/components/TextPrompt.js.map +1 -1
- package/dist/private/node/ui/components/TokenizedText.js +1 -0
- package/dist/private/node/ui/components/TokenizedText.js.map +1 -1
- package/dist/private/node/ui/hooks/use-abort-signal.js +1 -1
- package/dist/private/node/ui/hooks/use-abort-signal.js.map +1 -1
- package/dist/private/node/ui.js +3 -1
- package/dist/private/node/ui.js.map +1 -1
- package/dist/public/common/array.js +1 -0
- package/dist/public/common/array.js.map +1 -1
- package/dist/public/common/string.js +3 -0
- package/dist/public/common/string.js.map +1 -1
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/api/admin.d.ts +14 -1
- package/dist/public/node/api/admin.js +29 -28
- package/dist/public/node/api/admin.js.map +1 -1
- package/dist/public/node/api/app-management.d.ts +5 -3
- package/dist/public/node/api/app-management.js +16 -11
- package/dist/public/node/api/app-management.js.map +1 -1
- package/dist/public/node/api/graphql.js +13 -1
- package/dist/public/node/api/graphql.js.map +1 -1
- package/dist/public/node/api/rest-api-throttler.js +10 -3
- package/dist/public/node/api/rest-api-throttler.js.map +1 -1
- package/dist/public/node/archiver.js +6 -2
- package/dist/public/node/archiver.js.map +1 -1
- package/dist/public/node/base-command.js +1 -1
- package/dist/public/node/base-command.js.map +1 -1
- package/dist/public/node/context/local.d.ts +0 -9
- package/dist/public/node/context/local.js +0 -13
- package/dist/public/node/context/local.js.map +1 -1
- package/dist/public/node/context/spin.js +1 -1
- package/dist/public/node/context/spin.js.map +1 -1
- package/dist/public/node/custom-oclif-loader.js +5 -4
- package/dist/public/node/custom-oclif-loader.js.map +1 -1
- package/dist/public/node/dot-env.js +2 -1
- package/dist/public/node/dot-env.js.map +1 -1
- package/dist/public/node/environments.js +1 -1
- package/dist/public/node/environments.js.map +1 -1
- package/dist/public/node/error-handler.js +1 -1
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/framework.js +5 -4
- package/dist/public/node/framework.js.map +1 -1
- package/dist/public/node/fs.d.ts +1 -1
- package/dist/public/node/fs.js +1 -1
- package/dist/public/node/fs.js.map +1 -1
- package/dist/public/node/git.js +2 -0
- package/dist/public/node/git.js.map +1 -1
- package/dist/public/node/github.js +2 -0
- package/dist/public/node/github.js.map +1 -1
- package/dist/public/node/hooks/deprecations.js +1 -1
- package/dist/public/node/hooks/deprecations.js.map +1 -1
- package/dist/public/node/hooks/postrun.js +2 -1
- package/dist/public/node/hooks/postrun.js.map +1 -1
- package/dist/public/node/hooks/prerun.js +1 -1
- package/dist/public/node/hooks/prerun.js.map +1 -1
- package/dist/public/node/http.js +2 -1
- package/dist/public/node/http.js.map +1 -1
- package/dist/public/node/json-schema.d.ts +1 -1
- package/dist/public/node/json-schema.js.map +1 -1
- package/dist/public/node/liquid.js +12 -2
- package/dist/public/node/liquid.js.map +1 -1
- package/dist/public/node/metadata.js +1 -0
- package/dist/public/node/metadata.js.map +1 -1
- package/dist/public/node/monorail.d.ts +2 -1
- package/dist/public/node/monorail.js +1 -1
- package/dist/public/node/monorail.js.map +1 -1
- package/dist/public/node/output.js +2 -1
- package/dist/public/node/output.js.map +1 -1
- package/dist/public/node/ruby.js +1 -0
- package/dist/public/node/ruby.js.map +1 -1
- package/dist/public/node/session.d.ts +7 -6
- package/dist/public/node/session.js +2 -1
- package/dist/public/node/session.js.map +1 -1
- package/dist/public/node/system.js +1 -1
- package/dist/public/node/system.js.map +1 -1
- package/dist/public/node/themes/api.js +34 -4
- package/dist/public/node/themes/api.js.map +1 -1
- package/dist/public/node/themes/factories.js +1 -0
- package/dist/public/node/themes/factories.js.map +1 -1
- package/dist/public/node/themes/types.d.ts +2 -3
- package/dist/public/node/themes/types.js.map +1 -1
- package/dist/public/node/themes/urls.d.ts +1 -0
- package/dist/public/node/themes/urls.js +3 -0
- package/dist/public/node/themes/urls.js.map +1 -1
- package/dist/public/node/tree-kill.js +8 -4
- package/dist/public/node/tree-kill.js.map +1 -1
- package/dist/public/node/ui.js +5 -2
- package/dist/public/node/ui.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -5
- package/assets/auth-error.html +0 -23
- package/assets/empty-url.html +0 -23
- package/assets/favicon.svg +0 -26
- package/assets/missing-code.html +0 -23
- package/assets/missing-state.html +0 -23
- package/assets/style.css +0 -58
- package/assets/success.html +0 -20
- package/dist/private/node/session/authorize.d.ts +0 -5
- package/dist/private/node/session/authorize.js +0 -69
- package/dist/private/node/session/authorize.js.map +0 -1
- package/dist/private/node/session/post-auth.d.ts +0 -10
- package/dist/private/node/session/post-auth.js +0 -61
- package/dist/private/node/session/post-auth.js.map +0 -1
- package/dist/private/node/session/redirect-listener.d.ts +0 -34
- package/dist/private/node/session/redirect-listener.js +0 -105
- package/dist/private/node/session/redirect-listener.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system.js","sourceRoot":"","sources":["../../../src/public/node/system.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAA;AACxC,OAAO,EAAC,GAAG,EA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O,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,CAAA;IACrC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB;IACvC,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QAC5B,OAAO,KAAK,CAAA;KACb;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC7D,CAAC","sourcesContent":["import {AbortSignal} from './abort.js'\nimport {ExternalError} from './error.js'\nimport {cwd} from './path.js'\nimport {treeKill} from './tree-kill.js'\nimport {isTruthy} from './context/utilities.js'\nimport {shouldDisplayColors, outputDebug} from '../../public/node/output.js'\nimport {execa, ExecaChildProcess} from 'execa'\nimport type {Writable, Readable} from 'stream'\n\nexport interface ExecOptions {\n cwd?: string\n env?: {[key: string]: string | undefined}\n stdin?: Readable | 'inherit'\n stdout?: Writable | 'inherit'\n stderr?: Writable | 'inherit'\n stdio?: 'inherit'\n input?: string\n signal?: AbortSignal\n // Custom handler if process exits with a non-zero code\n externalErrorHandler?: (error: unknown) => Promise<void>\n}\n\n/**\n * Opens a URL in the user's default browser.\n *\n * @param url - URL to open.\n */\nexport async function openURL(url: string): Promise<void> {\n const externalOpen = await import('open')\n await externalOpen.default(url)\n}\n\n/**\n * Runs a command asynchronously, aggregates the stdout data, and returns it.\n *\n * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @param options - Optional settings for how to run the command.\n * @returns A promise that resolves with the aggregatted stdout of the command.\n */\nexport async function captureOutput(command: string, args: string[], options?: ExecOptions): Promise<string> {\n const result = await buildExec(command, args, options)\n return result.stdout\n}\n\n/**\n * Runs a command asynchronously.\n *\n * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @param options - Optional settings for how to run the command.\n */\nexport async function exec(command: string, args: string[], options?: ExecOptions): Promise<void> {\n const commandProcess = buildExec(command, args, options)\n if (options?.stderr && options.stderr !== 'inherit') {\n commandProcess.stderr?.pipe(options.stderr, {end: false})\n }\n if (options?.stdout && options.stdout !== 'inherit') {\n commandProcess.stdout?.pipe(options.stdout, {end: false})\n }\n let aborted = false\n options?.signal?.addEventListener('abort', () => {\n const pid = commandProcess.pid\n if (pid) {\n outputDebug(`Killing process ${pid}: ${command} ${args.join(' ')}`)\n aborted = true\n treeKill(pid, 'SIGTERM')\n }\n })\n try {\n await commandProcess\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (processError: any) {\n // Windows will throw an error whenever the process is killed, no matter the reason.\n // The aborted flag tell use that we killed it, so we can ignore the error.\n if (aborted) return\n if (options?.externalErrorHandler) {\n await options.externalErrorHandler(processError)\n } else {\n const abortError = new ExternalError(processError.message, command, args)\n abortError.stack = processError.stack\n throw abortError\n }\n }\n}\n\n/**\n * Runs a command asynchronously.\n *\n * @param command - Command to be executed.\n * @param args - Arguments to pass to the command.\n * @param options - Optional settings for how to run the command.\n * @returns A promise for a result with stdout and stderr properties.\n */\nfunction buildExec(command: string, args: string[], options?: ExecOptions): ExecaChildProcess {\n const env = options?.env ?? process.env\n if (shouldDisplayColors()) {\n env.FORCE_COLOR = '1'\n }\n const commandProcess = execa(command, args, {\n env,\n cwd: options?.cwd,\n input: options?.input,\n stdio: options?.stdio,\n stdin: options?.stdin,\n stdout: options?.stdout === 'inherit' ? 'inherit' : undefined,\n stderr: options?.stderr === 'inherit' ? 'inherit' : undefined,\n // Setting this to false makes it possible to kill the main process\n // and all its sub-processes with Ctrl+C on Windows\n windowsHide: false,\n })\n outputDebug(`\nRunning system process:\n · Command: ${command} ${args.join(' ')}\n · Working directory: ${options?.cwd ?? cwd()}\n`)\n return commandProcess\n}\n\n/**\n * Waits for a given number of seconds.\n *\n * @param seconds - Number of seconds to wait.\n * @returns A Promise resolving after the number of seconds.\n */\nexport async function sleep(seconds: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, 1000 * seconds)\n })\n}\n\n/**\n * Check if the standard input and output streams support prompting.\n *\n * @returns True if the standard input and output streams support prompting.\n */\nexport function terminalSupportsPrompting(): boolean {\n if (isTruthy(process.env.CI)) {\n return false\n }\n return Boolean(process.stdin.isTTY && process.stdout.isTTY)\n}\n"]}
|
|
@@ -3,6 +3,8 @@ import * as throttler from '../api/rest-api-throttler.js';
|
|
|
3
3
|
import { restRequest } from '@shopify/cli-kit/node/api/admin';
|
|
4
4
|
import { AbortError } from '@shopify/cli-kit/node/error';
|
|
5
5
|
import { buildBulkUploadResults, buildChecksum, buildTheme, buildThemeAsset, } from '@shopify/cli-kit/node/themes/factories';
|
|
6
|
+
import { outputDebug } from '@shopify/cli-kit/node/output';
|
|
7
|
+
import { sleep } from '@shopify/cli-kit/node/system';
|
|
6
8
|
export async function fetchTheme(id, session) {
|
|
7
9
|
const response = await request('GET', `/themes/${id}`, session, undefined, { fields: 'id,name,role,processing' });
|
|
8
10
|
return buildTheme(response.json.theme);
|
|
@@ -34,7 +36,7 @@ export async function deleteThemeAsset(id, key, session) {
|
|
|
34
36
|
const response = await request('DELETE', `/themes/${id}/assets`, session, undefined, {
|
|
35
37
|
'asset[key]': key,
|
|
36
38
|
});
|
|
37
|
-
return
|
|
39
|
+
return response.status === 200;
|
|
38
40
|
}
|
|
39
41
|
export async function bulkUploadThemeAssets(id, assets, session) {
|
|
40
42
|
const response = await request('PUT', `/themes/${id}/assets/bulk`, session, { assets });
|
|
@@ -67,7 +69,7 @@ export async function deleteTheme(id, session) {
|
|
|
67
69
|
const response = await request('DELETE', `/themes/${id}`, session);
|
|
68
70
|
return buildTheme(response.json.theme);
|
|
69
71
|
}
|
|
70
|
-
async function request(method, path, session, params, searchParams = {}) {
|
|
72
|
+
async function request(method, path, session, params, searchParams = {}, retries = 1) {
|
|
71
73
|
const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams));
|
|
72
74
|
const status = response.status;
|
|
73
75
|
throttler.updateApiCallLimitFromResponse(response);
|
|
@@ -84,13 +86,33 @@ async function request(method, path, session, params, searchParams = {}) {
|
|
|
84
86
|
case status === 403:
|
|
85
87
|
return handleForbiddenError(response, session);
|
|
86
88
|
case status === 401:
|
|
87
|
-
|
|
89
|
+
// Retry 401 errors to be resilient to authentication errors.
|
|
90
|
+
return handleRetriableError({
|
|
91
|
+
path,
|
|
92
|
+
retries,
|
|
93
|
+
retry: () => {
|
|
94
|
+
return request(method, path, session, params, searchParams, retries + 1);
|
|
95
|
+
},
|
|
96
|
+
fail: () => {
|
|
97
|
+
throw new AbortError(`[${status}] API request unauthorized error`);
|
|
98
|
+
},
|
|
99
|
+
});
|
|
88
100
|
case status === 422:
|
|
89
101
|
throw new AbortError(`[${status}] API request unprocessable content: ${errors(response)}`);
|
|
90
102
|
case status >= 400 && status <= 499:
|
|
91
103
|
throw new AbortError(`[${status}] API request client error`);
|
|
92
104
|
case status >= 500 && status <= 599:
|
|
93
|
-
|
|
105
|
+
// Retry 500-family of errors as that may solve the issue (especially in 503 errors)
|
|
106
|
+
return handleRetriableError({
|
|
107
|
+
path,
|
|
108
|
+
retries,
|
|
109
|
+
retry: () => {
|
|
110
|
+
return request(method, path, session, params, searchParams, retries + 1);
|
|
111
|
+
},
|
|
112
|
+
fail: () => {
|
|
113
|
+
throw new AbortError(`[${status}] API request server error`);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
94
116
|
default:
|
|
95
117
|
throw new AbortError(`[${status}] API request unexpected error`);
|
|
96
118
|
}
|
|
@@ -121,4 +143,12 @@ function errorMessage(response) {
|
|
|
121
143
|
}
|
|
122
144
|
return '';
|
|
123
145
|
}
|
|
146
|
+
async function handleRetriableError({ path, retries, retry, fail }) {
|
|
147
|
+
if (retries >= 3) {
|
|
148
|
+
fail();
|
|
149
|
+
}
|
|
150
|
+
outputDebug(`[${retries}] Retrying '${path}' request...`);
|
|
151
|
+
await sleep(0.2);
|
|
152
|
+
return retry();
|
|
153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AA6B;QACrF,iFAAiF;QACjF,gCAAgC,CACnC,CAAA;AACH,CAAC;AAED,SAAS,MAAM,CAAC,QAAsB;IACpC,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC9C,CAAC;AAED,SAAS,YAAY,CAAC,QAAsB;IAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IAEtC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,OAAO,CAAA;KACf;IAED,OAAO,EAAE,CAAA;AACX,CAAC","sourcesContent":["import {storeAdminUrl} from './urls.js'\nimport * as throttler from '../api/rest-api-throttler.js'\nimport {restRequest, RestResponse} from '@shopify/cli-kit/node/api/admin'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\nimport {AbortError} from '@shopify/cli-kit/node/error'\nimport {\n buildBulkUploadResults,\n buildChecksum,\n buildTheme,\n buildThemeAsset,\n} from '@shopify/cli-kit/node/themes/factories'\nimport {Result, Checksum, Key, Theme, ThemeAsset} from '@shopify/cli-kit/node/themes/types'\n\nexport type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>\nexport type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'value' | 'attachment'>>\n\nexport async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('GET', `/themes/${id}`, session, undefined, {fields: 'id,name,role,processing'})\n return buildTheme(response.json.theme)\n}\n\nexport async function fetchThemes(session: AdminSession): Promise<Theme[]> {\n const response = await request('GET', '/themes', session, undefined, {fields: 'id,name,role,processing'})\n const themes = response.json?.themes\n if (themes?.length > 0) return themes.map(buildTheme)\n return []\n}\n\nexport async function createTheme(params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('POST', '/themes', session, {theme: {...params}})\n const minimumThemeAssets = [\n {key: 'config/settings_schema.json', value: '[]'},\n {key: 'layout/password.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n {key: 'layout/theme.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n ]\n\n await bulkUploadThemeAssets(response.json.theme.id, minimumThemeAssets, session)\n\n return buildTheme({...response.json.theme, createdAtRuntime: true})\n}\n\nexport async function fetchThemeAsset(id: number, key: Key, session: AdminSession): Promise<ThemeAsset | undefined> {\n const response = await request('GET', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n return buildThemeAsset(response.json.asset)\n}\n\nexport async function deleteThemeAsset(id: number, key: Key, session: AdminSession): Promise<boolean> {\n const response = await request('DELETE', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n return Boolean(response.json.message)\n}\n\nexport async function bulkUploadThemeAssets(\n id: number,\n assets: AssetParams[],\n session: AdminSession,\n): Promise<Result[]> {\n const response = await request('PUT', `/themes/${id}/assets/bulk`, session, {assets})\n if (response.status !== 207) {\n throw new AbortError('Upload failed, could not reach the server')\n }\n return buildBulkUploadResults(response.json.results, assets)\n}\n\nexport async function fetchChecksums(id: number, session: AdminSession): Promise<Checksum[]> {\n const response = await request('GET', `/themes/${id}/assets`, session, undefined, {fields: 'key,checksum'})\n const assets = response.json.assets\n\n if (assets?.length > 0) return assets.map(buildChecksum)\n\n return []\n}\n\ninterface UpgradeThemeOptions {\n fromTheme: number\n toTheme: number\n script?: string\n session: AdminSession\n}\n\nexport async function upgradeTheme(upgradeOptions: UpgradeThemeOptions): Promise<Theme | undefined> {\n const {fromTheme, toTheme, session, script} = upgradeOptions\n const params = {from_theme: fromTheme, to_theme: toTheme, ...(script && {script})}\n const response = await request('POST', `/themes`, session, params)\n return buildTheme(response.json.theme)\n}\n\nexport async function updateTheme(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('PUT', `/themes/${id}`, session, {theme: {id, ...params}})\n return buildTheme(response.json.theme)\n}\n\nexport async function publishTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n return updateTheme(id, {role: 'main'}, session)\n}\n\nexport async function deleteTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('DELETE', `/themes/${id}`, session)\n return buildTheme(response.json.theme)\n}\n\nasync function request<T>(\n method: string,\n path: string,\n session: AdminSession,\n params?: T,\n searchParams: {[name: string]: string} = {},\n): Promise<RestResponse> {\n const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams))\n\n const status = response.status\n\n throttler.updateApiCallLimitFromResponse(response)\n\n switch (true) {\n case status >= 200 && status <= 399:\n // Returns the successful reponse\n return response\n case status === 404:\n // Defer the decision when a resource is not found\n return response\n case status === 429:\n // Retry following the \"retry-after\" header\n return throttler.delayAwareRetry(response, () => request(method, path, session, params, searchParams))\n case status === 403:\n return handleForbiddenError(response, session)\n case status === 401:\n throw new AbortError(`[${status}] API request unauthorized error`)\n case status === 422:\n throw new AbortError(`[${status}] API request unprocessable content: ${errors(response)}`)\n case status >= 400 && status <= 499:\n throw new AbortError(`[${status}] API request client error`)\n case status >= 500 && status <= 599:\n throw new AbortError(`[${status}] API request server error`)\n default:\n throw new AbortError(`[${status}] API request unexpected error`)\n }\n}\n\nfunction handleForbiddenError(response: RestResponse, session: AdminSession): never {\n const store = session.storeFqdn\n const adminUrl = storeAdminUrl(session)\n const error = errorMessage(response)\n\n if (error.match(/Cannot delete generated asset/) !== null) {\n throw new AbortError(error)\n }\n\n throw new AbortError(\n `You are not authorized to edit themes on \"${store}\".`,\n \"You can't use Shopify CLI with development stores if you only have Partner staff \" +\n 'member access. If you want to use Shopify CLI to work on a development store, then ' +\n 'you should be the store owner or create a staff account on the store.' +\n '\\n\\n' +\n \"If you're the store owner, then you need to log in to the store directly using the \" +\n `store URL at least once (for example, using \"${adminUrl}\") before you log in using ` +\n 'Shopify CLI. Logging in to the Shopify admin directly connects the development ' +\n 'store with your Shopify login.',\n )\n}\n\nfunction errors(response: RestResponse) {\n return JSON.stringify(response.json?.errors)\n}\n\nfunction errorMessage(response: RestResponse): string {\n const message = response.json?.message\n\n if (typeof message === 'string') {\n return message\n }\n\n return ''\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/public/node/themes/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAC,WAAW,EAAe,MAAM,iCAAiC,CAAA;AAEzE,OAAO,EAAC,UAAU,EAAC,MAAM,6BAA6B,CAAA;AACtD,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,UAAU,EACV,eAAe,GAChB,MAAM,wCAAwC,CAAA;AAE/C,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAC,KAAK,EAAC,MAAM,8BAA8B,CAAA;AAKlD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,EAAU,EAAE,OAAqB;IAChE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAC,MAAM,EAAE,yBAAyB,EAAC,CAAC,CAAA;IAC/G,OAAO,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAqB;IACrD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,EAAC,MAAM,EAAE,yBAAyB,EAAC,CAAC,CAAA;IACzG,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACpC,IAAI,MAAM,EAAE,MAAM,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IACrD,OAAO,EAAE,CAAA;AACX,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAm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I,OAAO,eAAe,IAAI,cAAc,CAAC,CAAA;IAEzD,MAAM,KAAK,CAAC,GAAG,CAAC,CAAA;IAChB,OAAO,KAAK,EAAE,CAAA;AAChB,CAAC","sourcesContent":["import {storeAdminUrl} from './urls.js'\nimport * as throttler from '../api/rest-api-throttler.js'\nimport {restRequest, RestResponse} from '@shopify/cli-kit/node/api/admin'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\nimport {AbortError} from '@shopify/cli-kit/node/error'\nimport {\n buildBulkUploadResults,\n buildChecksum,\n buildTheme,\n buildThemeAsset,\n} from '@shopify/cli-kit/node/themes/factories'\nimport {Result, Checksum, Key, Theme, ThemeAsset} from '@shopify/cli-kit/node/themes/types'\nimport {outputDebug} from '@shopify/cli-kit/node/output'\nimport {sleep} from '@shopify/cli-kit/node/system'\n\nexport type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>\nexport type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'value' | 'attachment'>>\n\nexport async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('GET', `/themes/${id}`, session, undefined, {fields: 'id,name,role,processing'})\n return buildTheme(response.json.theme)\n}\n\nexport async function fetchThemes(session: AdminSession): Promise<Theme[]> {\n const response = await request('GET', '/themes', session, undefined, {fields: 'id,name,role,processing'})\n const themes = response.json?.themes\n if (themes?.length > 0) return themes.map(buildTheme)\n return []\n}\n\nexport async function createTheme(params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('POST', '/themes', session, {theme: {...params}})\n const minimumThemeAssets = [\n {key: 'config/settings_schema.json', value: '[]'},\n {key: 'layout/password.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n {key: 'layout/theme.liquid', value: '{{ content_for_header }}{{ content_for_layout }}'},\n ]\n\n await bulkUploadThemeAssets(response.json.theme.id, minimumThemeAssets, session)\n\n return buildTheme({...response.json.theme, createdAtRuntime: true})\n}\n\nexport async function fetchThemeAsset(id: number, key: Key, session: AdminSession): Promise<ThemeAsset | undefined> {\n const response = await request('GET', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n\n return buildThemeAsset(response.json.asset)\n}\n\nexport async function deleteThemeAsset(id: number, key: Key, session: AdminSession): Promise<boolean> {\n const response = await request('DELETE', `/themes/${id}/assets`, session, undefined, {\n 'asset[key]': key,\n })\n return response.status === 200\n}\n\nexport async function bulkUploadThemeAssets(\n id: number,\n assets: AssetParams[],\n session: AdminSession,\n): Promise<Result[]> {\n const response = await request('PUT', `/themes/${id}/assets/bulk`, session, {assets})\n if (response.status !== 207) {\n throw new AbortError('Upload failed, could not reach the server')\n }\n return buildBulkUploadResults(response.json.results, assets)\n}\n\nexport async function fetchChecksums(id: number, session: AdminSession): Promise<Checksum[]> {\n const response = await request('GET', `/themes/${id}/assets`, session, undefined, {fields: 'key,checksum'})\n const assets = response.json.assets\n\n if (assets?.length > 0) return assets.map(buildChecksum)\n\n return []\n}\n\ninterface UpgradeThemeOptions {\n fromTheme: number\n toTheme: number\n script?: string\n session: AdminSession\n}\n\nexport async function upgradeTheme(upgradeOptions: UpgradeThemeOptions): Promise<Theme | undefined> {\n const {fromTheme, toTheme, session, script} = upgradeOptions\n const params = {from_theme: fromTheme, to_theme: toTheme, ...(script && {script})}\n const response = await request('POST', `/themes`, session, params)\n return buildTheme(response.json.theme)\n}\n\nexport async function updateTheme(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('PUT', `/themes/${id}`, session, {theme: {id, ...params}})\n return buildTheme(response.json.theme)\n}\n\nexport async function publishTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n return updateTheme(id, {role: 'main'}, session)\n}\n\nexport async function deleteTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('DELETE', `/themes/${id}`, session)\n return buildTheme(response.json.theme)\n}\n\nasync function request<T>(\n method: string,\n path: string,\n session: AdminSession,\n params?: T,\n searchParams: {[name: string]: string} = {},\n retries = 1,\n): Promise<RestResponse> {\n const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams))\n\n const status = response.status\n\n throttler.updateApiCallLimitFromResponse(response)\n\n switch (true) {\n case status >= 200 && status <= 399:\n // Returns the successful reponse\n return response\n case status === 404:\n // Defer the decision when a resource is not found\n return response\n case status === 429:\n // Retry following the \"retry-after\" header\n return throttler.delayAwareRetry(response, () => request(method, path, session, params, searchParams))\n case status === 403:\n return handleForbiddenError(response, session)\n case status === 401:\n // Retry 401 errors to be resilient to authentication errors.\n return handleRetriableError({\n path,\n retries,\n retry: () => {\n return request(method, path, session, params, searchParams, retries + 1)\n },\n fail: () => {\n throw new AbortError(`[${status}] API request unauthorized error`)\n },\n })\n case status === 422:\n throw new AbortError(`[${status}] API request unprocessable content: ${errors(response)}`)\n case status >= 400 && status <= 499:\n throw new AbortError(`[${status}] API request client error`)\n case status >= 500 && status <= 599:\n // Retry 500-family of errors as that may solve the issue (especially in 503 errors)\n return handleRetriableError({\n path,\n retries,\n retry: () => {\n return request(method, path, session, params, searchParams, retries + 1)\n },\n fail: () => {\n throw new AbortError(`[${status}] API request server error`)\n },\n })\n default:\n throw new AbortError(`[${status}] API request unexpected error`)\n }\n}\n\nfunction handleForbiddenError(response: RestResponse, session: AdminSession): never {\n const store = session.storeFqdn\n const adminUrl = storeAdminUrl(session)\n const error = errorMessage(response)\n\n if (error.match(/Cannot delete generated asset/) !== null) {\n throw new AbortError(error)\n }\n\n throw new AbortError(\n `You are not authorized to edit themes on \"${store}\".`,\n \"You can't use Shopify CLI with development stores if you only have Partner staff \" +\n 'member access. If you want to use Shopify CLI to work on a development store, then ' +\n 'you should be the store owner or create a staff account on the store.' +\n '\\n\\n' +\n \"If you're the store owner, then you need to log in to the store directly using the \" +\n `store URL at least once (for example, using \"${adminUrl}\") before you log in using ` +\n 'Shopify CLI. Logging in to the Shopify admin directly connects the development ' +\n 'store with your Shopify login.',\n )\n}\n\nfunction errors(response: RestResponse) {\n return JSON.stringify(response.json?.errors)\n}\n\nfunction errorMessage(response: RestResponse): string {\n const message = response.json?.message\n\n if (typeof message === 'string') {\n return message\n }\n\n return ''\n}\n\ninterface RetriableErrorOptions {\n path: string\n retries: number\n retry: () => Promise<RestResponse>\n fail: () => never\n}\n\nasync function handleRetriableError({path, retries, retry, fail}: RetriableErrorOptions): Promise<RestResponse> {\n if (retries >= 3) {\n fail()\n }\n\n outputDebug(`[${retries}] Retrying '${path}' request...`)\n\n await sleep(0.2)\n return retry()\n}\n"]}
|
|
@@ -33,6 +33,7 @@ export function buildBulkUploadResults(bulkUploadResponse, assets) {
|
|
|
33
33
|
}
|
|
34
34
|
return bulkUploadResponse.map((bulkUpload, index) => {
|
|
35
35
|
return {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
36
37
|
key: assets[index].key,
|
|
37
38
|
success: bulkUpload.code === 200,
|
|
38
39
|
errors: bulkUpload.body.errors || {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.js","sourceRoot":"","sources":["../../../../src/public/node/themes/factories.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,SAAS,EAAC,MAAM,oCAAoC,CAAA;AAuBjG,MAAM,UAAU,UAAU,CAAC,SAA+B;IACxD,IAAI,CAAC,SAAS;QAAE,OAAM;IAEtB,SAAS,CAAC,UAAU,KAApB,SAAS,CAAC,UAAU,GAAK,KAAK,EAAA;IAC9B,SAAS,CAAC,gBAAgB,KAA1B,SAAS,CAAC,gBAAgB,GAAK,KAAK,EAAA;IAEpC,MAAM,EAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAC,GAAG,SAAS,CAAA;IAEhE,OAAO;QACL,EAAE;QACF,IAAI;QACJ,UAAU;QACV,gBAAgB;QAChB,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI;KACtC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAA2B;IACvD,IAAI,CAAC,KAAK;QAAE,OAAM;IAElB,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAC,GAAG,KAAK,CAAA;IAC7B,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,CAAA;AACxB,CAAC;AAID,MAAM,UAAU,eAAe,CAAC,KAA2B;IACzD,IAAI,CAAC,KAAK;QAAE,OAAM;IAElB,MAAM,EAAC,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAC,GAAG,KAAK,CAAA;IAChD,gGAAgG;IAChG,MAAM,KAAK,GAAG,EAAC,IAAI,EAAE,CAAC,KAAK,IAAI,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,EAAC,CAAA;IAC3E,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAC,CAAA;AAClD,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,kBAA8C,EAC9C,MAAqB;IAErB,IAAI,CAAC,kBAAkB,EAAE;QACvB,OAAO,EAAE,CAAA;KACV;IAED,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE;QAClD,OAAO;YACL,GAAG,EAAE,MAAM,CAAC,KAAK,CAAE,CAAC,GAAG;YACvB,OAAO,EAAE,UAAU,CAAC,IAAI,KAAK,GAAG;YAChC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE;YACpC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK;YAC5B,SAAS,EAAE,SAAS,CAAC,MAAM;SAC5B,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {AssetParams} from './api.js'\nimport {Result, Checksum, Theme, ThemeAsset, Operation} from '@shopify/cli-kit/node/themes/types'\n\ninterface RemoteThemeResponse {\n id: number\n name: string\n role: string\n createdAtRuntime?: boolean\n processing?: boolean\n}\n\ninterface RemoteAssetResponse {\n key: string\n checksum: string\n attachment: string | undefined\n // value is an empty string ('') when the file is empty\n value: string\n}\n\nexport interface RemoteBulkUploadResponse {\n body: {asset?: RemoteAssetResponse; errors?: {asset: string[]}}\n code: number\n}\n\nexport function buildTheme(themeJson?: RemoteThemeResponse): Theme | undefined {\n if (!themeJson) return\n\n themeJson.processing ??= false\n themeJson.createdAtRuntime ??= false\n\n const {id, name, role, processing, createdAtRuntime} = themeJson\n\n return {\n id,\n name,\n processing,\n createdAtRuntime,\n role: role === 'main' ? 'live' : role,\n }\n}\n\nexport function buildChecksum(asset?: RemoteAssetResponse): Checksum | undefined {\n if (!asset) return\n\n const {key, checksum} = asset\n return {key, checksum}\n}\n\nexport function buildThemeAsset(asset: undefined): undefined\nexport function buildThemeAsset(asset: RemoteAssetResponse): ThemeAsset\nexport function buildThemeAsset(asset?: RemoteAssetResponse): ThemeAsset | undefined {\n if (!asset) return\n\n const {key, checksum, attachment, value} = asset\n // Note: for attachments, this is the size of the base64 string, not the real length of the file\n const stats = {size: (value || attachment || '').length, mtime: Date.now()}\n return {key, checksum, attachment, value, stats}\n}\n\nexport function buildBulkUploadResults(\n bulkUploadResponse: RemoteBulkUploadResponse[],\n assets: AssetParams[],\n): Result[] {\n if (!bulkUploadResponse) {\n return []\n }\n\n return bulkUploadResponse.map((bulkUpload, index) => {\n return {\n key: assets[index]!.key,\n success: bulkUpload.code === 200,\n errors: bulkUpload.body.errors || {},\n asset: bulkUpload.body.asset,\n operation: Operation.Upload,\n }\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"factories.js","sourceRoot":"","sources":["../../../../src/public/node/themes/factories.ts"],"names":[],"mappings":"AACA,OAAO,EAAsC,SAAS,EAAC,MAAM,oCAAoC,CAAA;AAuBjG,MAAM,UAAU,UAAU,CAAC,SAA+B;IACxD,IAAI,CAAC,SAAS;QAAE,OAAM;IAEtB,SAAS,CAAC,UAAU,KAApB,SAA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C,KAAK,CAAE,CAAC,GAAG;YACvB,OAAO,EAAE,UAAU,CAAC,IAAI,KAAK,GAAG;YAChC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE;YACpC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK;YAC5B,SAAS,EAAE,SAAS,CAAC,MAAM;SAC5B,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {AssetParams} from './api.js'\nimport {Result, Checksum, Theme, ThemeAsset, Operation} from '@shopify/cli-kit/node/themes/types'\n\ninterface RemoteThemeResponse {\n id: number\n name: string\n role: string\n createdAtRuntime?: boolean\n processing?: boolean\n}\n\ninterface RemoteAssetResponse {\n key: string\n checksum: string\n attachment: string | undefined\n // value is an empty string ('') when the file is empty\n value: string\n}\n\nexport interface RemoteBulkUploadResponse {\n body: {asset?: RemoteAssetResponse; errors?: {asset: string[]}}\n code: number\n}\n\nexport function buildTheme(themeJson?: RemoteThemeResponse): Theme | undefined {\n if (!themeJson) return\n\n themeJson.processing ??= false\n themeJson.createdAtRuntime ??= false\n\n const {id, name, role, processing, createdAtRuntime} = themeJson\n\n return {\n id,\n name,\n processing,\n createdAtRuntime,\n role: role === 'main' ? 'live' : role,\n }\n}\n\nexport function buildChecksum(asset?: RemoteAssetResponse): Checksum | undefined {\n if (!asset) return\n\n const {key, checksum} = asset\n return {key, checksum}\n}\n\nexport function buildThemeAsset(asset: undefined): undefined\nexport function buildThemeAsset(asset: RemoteAssetResponse): ThemeAsset\nexport function buildThemeAsset(asset?: RemoteAssetResponse): ThemeAsset | undefined {\n if (!asset) return\n\n const {key, checksum, attachment, value} = asset\n // Note: for attachments, this is the size of the base64 string, not the real length of the file\n const stats = {size: (value || attachment || '').length, mtime: Date.now()}\n return {key, checksum, attachment, value, stats}\n}\n\nexport function buildBulkUploadResults(\n bulkUploadResponse: RemoteBulkUploadResponse[],\n assets: AssetParams[],\n): Result[] {\n if (!bulkUploadResponse) {\n return []\n }\n\n return bulkUploadResponse.map((bulkUpload, index) => {\n return {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n key: assets[index]!.key,\n success: bulkUpload.code === 200,\n errors: bulkUpload.body.errors || {},\n asset: bulkUpload.body.asset,\n operation: Operation.Upload,\n }\n })\n}\n"]}
|
|
@@ -9,6 +9,7 @@ type ThemeFSEvent = {
|
|
|
9
9
|
type: 'unlink';
|
|
10
10
|
payload: {
|
|
11
11
|
fileKey: Key;
|
|
12
|
+
onSync?: (fn: () => void) => void;
|
|
12
13
|
};
|
|
13
14
|
} | {
|
|
14
15
|
type: 'add' | 'change';
|
|
@@ -71,9 +72,7 @@ export interface VirtualFileSystem {
|
|
|
71
72
|
/**
|
|
72
73
|
* Add callbacks to run after certain events are fired.
|
|
73
74
|
*/
|
|
74
|
-
addEventListener:
|
|
75
|
-
<T extends ThemeFSEventName>(eventName: T, cb: (params: ThemeFSEventPayload<T>) => void): void;
|
|
76
|
-
};
|
|
75
|
+
addEventListener: <T extends ThemeFSEventName>(eventName: T, cb: (params: ThemeFSEventPayload<T>) => void) => void;
|
|
77
76
|
}
|
|
78
77
|
/**
|
|
79
78
|
* Represents a theme on the file system.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/public/node/themes/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/public/node/themes/types.ts"],"names":[],"mappings":"AAsNA,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;AACnB,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB","sourcesContent":["import {AdminSession} from '../session.js'\n\n/**\n * {@link Key} represents the unique identifier of a file in a theme.\n */\nexport type Key = string\n\nexport type ThemeFSEventName = 'add' | 'change' | 'unlink'\n\ntype ThemeFSEvent =\n | {\n type: 'unlink'\n payload: {fileKey: Key; onSync?: (fn: () => void) => void}\n }\n | {\n type: 'add' | 'change'\n payload: {\n fileKey: Key\n onContent: (fn: (content: string) => void) => void\n onSync: (fn: () => void) => void\n }\n }\n\nexport type ThemeFSEventPayload<T extends ThemeFSEventName = 'add'> = (ThemeFSEvent & {type: T})['payload']\n\nexport interface ThemeFileSystemOptions {\n filters?: {ignore?: string[]; only?: string[]}\n notify?: string\n}\n\n/**\n * Represents a theme on the file system.\n */\nexport interface VirtualFileSystem {\n /**\n * The root path of the theme.\n */\n root: string\n\n /**\n * Local files.\n */\n files: Map<Key, ThemeAsset>\n\n /**\n * File keys that have been modified in memory and are not uploaded yet.\n */\n unsyncedFileKeys: Set<Key>\n\n /**\n * Promise that resolves when all the initial files are found.\n */\n ready: () => Promise<void>\n\n /**\n * Removes a file from the local disk and updates the file system\n *\n * @param fileKey - The key of the file to remove\n */\n delete: (fileKey: Key) => Promise<void>\n\n /**\n * Writes a file to the local disk and updates the file system\n *\n * @param asset - The ThemeAsset representing the file to write\n */\n write: (asset: ThemeAsset) => Promise<void>\n\n /**\n * Reads a file from the local disk and updates the file system\n * Returns a ThemeAsset representing the file that was read\n * Returns undefined if the file does not exist\n *\n * @param fileKey - The key of the file to read\n */\n read: (fileKey: Key) => Promise<string | Buffer | undefined>\n\n /**\n * Add callbacks to run after certain events are fired.\n */\n addEventListener: <T extends ThemeFSEventName>(eventName: T, cb: (params: ThemeFSEventPayload<T>) => void) => void\n}\n\n/**\n * Represents a theme on the file system.\n */\nexport interface ThemeFileSystem extends VirtualFileSystem {\n /**\n * Starts a file watcher for the theme directory.\n *\n * @param themeId - The ID of the theme being watched.\n * @param adminSession - The admin session for API communication.\n * @returns A Promise that resolves to an FSWatcher instance.\n */\n startWatcher: (themeId: string, adminSession: AdminSession) => Promise<void>\n\n /**\n * Applies filters to ignore files from .shopifyignore file, --ignore and --only flags.\n */\n applyIgnoreFilters: <T extends {key: string}>(files: T[]) => T[]\n}\n\n/**\n * Represents a theme on the file system.\n */\nexport interface ThemeExtensionFileSystem extends VirtualFileSystem {\n /**\n * Starts a file watcher for the theme extension directory.\n */\n startWatcher: () => Promise<void>\n}\n\n/**\n * Represents a theme.\n */\nexport interface Theme {\n /**\n * The remote ID of the theme.\n */\n id: number\n\n /**\n * The remote name of the theme.\n */\n name: string\n\n /**\n * A boolean determining whether or not the theme was created at runtime.\n */\n createdAtRuntime: boolean\n\n /**\n * A boolean determining if the theme is processing at the theme library.\n */\n processing: boolean\n\n /**\n * The remote role of the theme.\n */\n role: string\n\n /**\n * A public URL where Shopify can access the theme code.\n */\n src?: string\n}\n\n/**\n * Represents the remote checksum for a file in a theme.\n */\nexport interface Checksum {\n /**\n * Identifier of the theme file.\n */\n key: Key\n\n /**\n * Represents the checksum value of the theme file.\n */\n checksum: string\n}\n\n/**\n * Represents a theme or theme extension asset.\n */\nexport interface ThemeAsset extends Checksum {\n /**\n * A base64-encoded image.\n */\n attachment?: string\n\n /**\n * The text content of the asset, such as the HTML and Liquid markup of a template file.\n */\n value?: string\n\n /**\n * File stats at time of last modification. For attachments, this is the size of the base64 string.\n */\n stats?: {mtime: number; size: number}\n}\n\n/**\n * Represents a single result for an upload or delete operation on a single file\n * Each result includes the unique identifier for the file, the type of the operation,\n * the success status of the operation, any errors that occurred, and the asset value of the file.\n */\nexport interface Result {\n /**\n * The unique identifier for the file being uploaded.\n */\n key: string\n\n /**\n * The operation associated with the result.\n */\n operation: Operation\n\n /**\n * Indicates whether the upload operation for this file was successful.\n */\n success: boolean\n\n /**\n * Error message that was generated during the upload operation for this file.\n */\n errors?: {asset?: string[]}\n\n /**\n * The asset that was uploaded as part of the upload operation for this file.\n */\n asset?: Omit<ThemeAsset, 'stats'>\n}\n\nexport enum Operation {\n Delete = 'DELETE',\n Upload = 'UPLOAD',\n}\n"]}
|
|
@@ -4,3 +4,4 @@ export declare function themePreviewUrl(theme: Theme, session: AdminSession): st
|
|
|
4
4
|
export declare function themeEditorUrl(theme: Theme, session: AdminSession): string;
|
|
5
5
|
export declare function codeEditorUrl(theme: Theme, session: AdminSession): string;
|
|
6
6
|
export declare function storeAdminUrl(session: AdminSession): string;
|
|
7
|
+
export declare function storePasswordPage(store: AdminSession['storeFqdn']): string;
|
|
@@ -17,4 +17,7 @@ export function storeAdminUrl(session) {
|
|
|
17
17
|
const store = session.storeFqdn;
|
|
18
18
|
return `https://${store}/admin`;
|
|
19
19
|
}
|
|
20
|
+
export function storePasswordPage(store) {
|
|
21
|
+
return `https://${store}/admin/online_store/preferences`;
|
|
22
|
+
}
|
|
20
23
|
//# sourceMappingURL=urls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.js","sourceRoot":"","sources":["../../../../src/public/node/themes/urls.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,OAAqB;IACjE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE;QACzB,OAAO,WAAW,KAAK,EAAE,CAAA;KAC1B;IAED,OAAO,WAAW,KAAK,qBAAqB,KAAK,CAAC,EAAE,EAAE,CAAA;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAY,EAAE,OAAqB;IAChE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,SAAS,CAAA;AAC3D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAY,EAAE,OAAqB;IAC/D,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,EAAE,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAqB;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,QAAQ,CAAA;AACjC,CAAC","sourcesContent":["import {Theme} from '@shopify/cli-kit/node/themes/types'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\n\nexport function themePreviewUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n if (theme.role === 'live') {\n return `https://${store}`\n }\n\n return `https://${store}?preview_theme_id=${theme.id}`\n}\n\nexport function themeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}/editor`\n}\n\nexport function codeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}`\n}\n\nexport function storeAdminUrl(session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin`\n}\n"]}
|
|
1
|
+
{"version":3,"file":"urls.js","sourceRoot":"","sources":["../../../../src/public/node/themes/urls.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,OAAqB;IACjE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE;QACzB,OAAO,WAAW,KAAK,EAAE,CAAA;KAC1B;IAED,OAAO,WAAW,KAAK,qBAAqB,KAAK,CAAC,EAAE,EAAE,CAAA;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAY,EAAE,OAAqB;IAChE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,SAAS,CAAA;AAC3D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAY,EAAE,OAAqB;IAC/D,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,EAAE,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAqB;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,QAAQ,CAAA;AACjC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAgC;IAChE,OAAO,WAAW,KAAK,iCAAiC,CAAA;AAC1D,CAAC","sourcesContent":["import {Theme} from '@shopify/cli-kit/node/themes/types'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\n\nexport function themePreviewUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n if (theme.role === 'live') {\n return `https://${store}`\n }\n\n return `https://${store}?preview_theme_id=${theme.id}`\n}\n\nexport function themeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}/editor`\n}\n\nexport function codeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}`\n}\n\nexport function storeAdminUrl(session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin`\n}\n\nexport function storePasswordPage(store: AdminSession['storeFqdn']) {\n return `https://${store}/admin/online_store/preferences`\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
1
2
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
3
|
/* eslint-disable jsdoc/require-throws */
|
|
3
4
|
/* eslint-disable no-restricted-imports */
|
|
@@ -38,7 +39,8 @@ function adaptedTreeKill(pid, killSignal, killRoot, callback) {
|
|
|
38
39
|
const rootPid = typeof pid === 'number' ? pid.toString() : pid;
|
|
39
40
|
if (Number.isNaN(rootPid)) {
|
|
40
41
|
if (callback) {
|
|
41
|
-
|
|
42
|
+
callback(new Error('pid must be a number'));
|
|
43
|
+
return;
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
46
|
throw new Error('pid must be a number');
|
|
@@ -100,14 +102,15 @@ function killAll(tree, killSignal, rootPid, killRoot, callback) {
|
|
|
100
102
|
catch (err) {
|
|
101
103
|
if (callback) {
|
|
102
104
|
// @ts-ignore
|
|
103
|
-
|
|
105
|
+
callback(err);
|
|
106
|
+
return;
|
|
104
107
|
}
|
|
105
108
|
else {
|
|
106
109
|
throw err;
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
if (callback) {
|
|
110
|
-
|
|
113
|
+
callback();
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
/**
|
|
@@ -147,7 +150,8 @@ function buildProcessTree(parentPid, tree, pidsToProcess, spawnChildProcessesLis
|
|
|
147
150
|
if (code !== 0) {
|
|
148
151
|
// no more parent processes
|
|
149
152
|
if (pidsToProcess.size === 0) {
|
|
150
|
-
|
|
153
|
+
cb();
|
|
154
|
+
return;
|
|
151
155
|
}
|
|
152
156
|
return;
|
|
153
157
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-kill.js","sourceRoot":"","sources":["../../../src/public/node/tree-kill.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,yCAAyC;AACzC,0CAA0C;AAE1C,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAA;AACvC,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAC,IAAI,EAAE,KAAK,EAAC,MAAM,eAAe,CAAA;AAQzC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAuB,OAAO,CAAC,GAAG,EAClC,UAAU,GAAG,SAAS,EACtB,QAAQ,GAAG,IAAI,EACf,QAA4B;IAE5B,MAAM,KAAK,GACT,QAAQ;QACR,CAAC,CAAC,KAAa,EAAE,EAAE;YACjB,IAAI,KAAK;gBAAE,WAAW,CAAC,0BAA0B,GAAG,KAAK,KAAK,EAAE,CAAC,CAAA;QACnE,CAAC,CAAC,CAAA;IACJ,eAAe,EAAE,CAAA;IACjB,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAA;AACnD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAS,eAAe,CACtB,GAAoB,EACpB,UAAkB,EAClB,QAAiB,EACj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AC7C,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;gBACtB,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAA;aACxE;QACH,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;IAED,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACzB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable jsdoc/require-throws */\n/* eslint-disable no-restricted-imports */\n\nimport {outputDebug} from './output.js'\nimport {printEventsJson} from '../../private/node/demo-recorder.js'\nimport {exec, spawn} from 'child_process'\n\ninterface ProcessTree {\n [key: string]: string[]\n}\n\ntype AfterKillCallback = (error?: Error) => void\n\n/**\n * Kills the process that calls the method and all its children.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nexport function treeKill(\n pid: number | string = process.pid,\n killSignal = 'SIGTERM',\n killRoot = true,\n callback?: AfterKillCallback,\n): void {\n const after =\n callback ??\n ((error?: Error) => {\n if (error) outputDebug(`Failed to kill process ${pid}: ${error}`)\n })\n printEventsJson()\n adaptedTreeKill(pid, killSignal, killRoot, after)\n}\n\n/**\n * Adapted from https://github.com/pkrumins/node-tree-kill.\n *\n * Our implementation allows to skip killing the root process. This is useful for example when\n * gracefully exiting the 'dev' process, as the default tree-kill implementation will cause it\n * to exit with a non-zero code. Instead, we want to treat it as a graceful termination.\n * In addition, we also add debug logging for better visibility in what tree-kill is doing.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nfunction adaptedTreeKill(\n pid: number | string,\n killSignal: string,\n killRoot: boolean,\n callback: (error?: Error) => void,\n): void {\n const rootPid = typeof pid === 'number' ? pid.toString() : pid\n\n if (Number.isNaN(rootPid)) {\n if (callback) {\n return callback(new Error('pid must be a number'))\n } else {\n throw new Error('pid must be a number')\n }\n }\n\n // A map from parent pid to an array of children pids\n const tree: ProcessTree = {}\n tree[rootPid] = []\n\n // A set of pids to visit. We use it to recursively find all the children pids\n const pidsToProcess: Set<string> = new Set()\n pidsToProcess.add(rootPid)\n\n switch (process.platform) {\n case 'win32':\n // @ts-ignore\n exec(`taskkill /pid ${pid} /T /F`, callback)\n break\n case 'darwin':\n buildProcessTree(\n rootPid,\n tree,\n pidsToProcess,\n function (parentPid: string) {\n return spawn('pgrep', ['-lfP', parentPid])\n },\n function () {\n killAll(tree, killSignal, rootPid, killRoot, callback)\n },\n )\n break\n // Linux\n default:\n buildProcessTree(\n rootPid,\n tree,\n pidsToProcess,\n function (parentPid: string) {\n return spawn('ps', ['-o', 'pid command', '--no-headers', '--ppid', parentPid])\n },\n function () {\n killAll(tree, killSignal, rootPid, killRoot, callback)\n },\n )\n break\n }\n}\n\n/**\n * Kills all processes in the process tree.\n *\n * @param tree - Process tree.\n * @param killSignal - Type of kill signal to be used.\n * @param rootPid - Pid of the root process.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nfunction killAll(\n tree: ProcessTree,\n killSignal: string,\n rootPid: string,\n killRoot: boolean,\n callback: AfterKillCallback,\n): void {\n const killed: Set<string> = new Set()\n try {\n Object.keys(tree).forEach(function (pid) {\n tree[pid]!.forEach(function (pidpid) {\n if (!killed.has(pidpid)) {\n killPid(pidpid, killSignal)\n killed.add(pidpid)\n }\n })\n if (pid === rootPid && killRoot && !killed.has(pid)) {\n killPid(pid, killSignal)\n killed.add(pid)\n }\n })\n } catch (err: unknown) {\n if (callback) {\n // @ts-ignore\n return callback(err)\n } else {\n throw err\n }\n }\n if (callback) {\n return callback()\n }\n}\n\n/**\n * Kills a process.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n */\nfunction killPid(pid: string, killSignal: string) {\n try {\n process.kill(parseInt(pid, 10), killSignal)\n } catch (err) {\n // @ts-ignore\n if (err.code !== 'ESRCH') throw err\n }\n}\n\n/**\n * Builds a process tree.\n *\n * @param parentPid - Pid of the parent process.\n * @param tree - Process tree.\n * @param pidsToProcess - Pids to process.\n * @param spawnChildProcessesList - Function to spawn child processes.\n * @param cb - Callback to run after building the process tree.\n */\nfunction buildProcessTree(\n parentPid: string,\n tree: ProcessTree,\n pidsToProcess: Set<string>,\n spawnChildProcessesList: (parentPid: string) => ReturnType<typeof spawn>,\n cb: () => void,\n) {\n const ps = spawnChildProcessesList(parentPid)\n let allData = ''\n ps.stdout?.on('data', function (data: Buffer) {\n const dataStr = data.toString('ascii')\n allData += dataStr\n })\n\n const onClose = (code: number) => {\n pidsToProcess.delete(parentPid)\n\n if (code !== 0) {\n // no more parent processes\n if (pidsToProcess.size === 0) {\n return cb()\n }\n return\n }\n\n allData\n .trim()\n .split('\\n')\n .forEach(function (line) {\n const match = line.match(/^(\\d+)\\s(.*)$/)\n if (match) {\n const pid = match[1]!\n const cmd = match[2]!\n tree[parentPid]!.push(pid)\n tree[pid] = []\n outputDebug(`Killing process ${pid}: ${cmd}`)\n pidsToProcess.add(pid)\n buildProcessTree(pid, tree, pidsToProcess, spawnChildProcessesList, cb)\n }\n })\n }\n\n ps.on('close', onClose)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tree-kill.js","sourceRoot":"","sources":["../../../src/public/node/tree-kill.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,sDAAsD;AACtD,yCAAyC;AACzC,0CAA0C;AAE1C,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAA;AACvC,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAC,IAAI,EAAE,KAAK,EAAC,MAAM,eAAe,CAAA;AAQzC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,MAAuB,OAAO,CAAC,GAAG,EAClC,UAAU,GAAG,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C;aACX,OAAO,CAAC,UAAU,IAAI;YACrB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;YACzC,IAAI,KAAK,EAAE;gBACT,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;gBACrB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;gBACrB,IAAI,CAAC,SAAS,CAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;gBACd,WAAW,CAAC,mBAAmB,GAAG,KAAK,GAAG,EAAE,CAAC,CAAA;gBAC7C,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;gBACtB,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAA;aACxE;QACH,CAAC,CAAC,CAAA;IACN,CAAC,CAAA;IAED,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACzB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable jsdoc/require-throws */\n/* eslint-disable no-restricted-imports */\n\nimport {outputDebug} from './output.js'\nimport {printEventsJson} from '../../private/node/demo-recorder.js'\nimport {exec, spawn} from 'child_process'\n\ninterface ProcessTree {\n [key: string]: string[]\n}\n\ntype AfterKillCallback = (error?: Error) => void\n\n/**\n * Kills the process that calls the method and all its children.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nexport function treeKill(\n pid: number | string = process.pid,\n killSignal = 'SIGTERM',\n killRoot = true,\n callback?: AfterKillCallback,\n): void {\n const after =\n callback ??\n ((error?: Error) => {\n if (error) outputDebug(`Failed to kill process ${pid}: ${error}`)\n })\n printEventsJson()\n adaptedTreeKill(pid, killSignal, killRoot, after)\n}\n\n/**\n * Adapted from https://github.com/pkrumins/node-tree-kill.\n *\n * Our implementation allows to skip killing the root process. This is useful for example when\n * gracefully exiting the 'dev' process, as the default tree-kill implementation will cause it\n * to exit with a non-zero code. Instead, we want to treat it as a graceful termination.\n * In addition, we also add debug logging for better visibility in what tree-kill is doing.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nfunction adaptedTreeKill(\n pid: number | string,\n killSignal: string,\n killRoot: boolean,\n callback: (error?: Error) => void,\n): void {\n const rootPid = typeof pid === 'number' ? pid.toString() : pid\n\n if (Number.isNaN(rootPid)) {\n if (callback) {\n callback(new Error('pid must be a number'))\n return\n } else {\n throw new Error('pid must be a number')\n }\n }\n\n // A map from parent pid to an array of children pids\n const tree: ProcessTree = {}\n tree[rootPid] = []\n\n // A set of pids to visit. We use it to recursively find all the children pids\n const pidsToProcess = new Set<string>()\n pidsToProcess.add(rootPid)\n\n switch (process.platform) {\n case 'win32':\n // @ts-ignore\n exec(`taskkill /pid ${pid} /T /F`, callback)\n break\n case 'darwin':\n buildProcessTree(\n rootPid,\n tree,\n pidsToProcess,\n function (parentPid: string) {\n return spawn('pgrep', ['-lfP', parentPid])\n },\n function () {\n killAll(tree, killSignal, rootPid, killRoot, callback)\n },\n )\n break\n // Linux\n default:\n buildProcessTree(\n rootPid,\n tree,\n pidsToProcess,\n function (parentPid: string) {\n return spawn('ps', ['-o', 'pid command', '--no-headers', '--ppid', parentPid])\n },\n function () {\n killAll(tree, killSignal, rootPid, killRoot, callback)\n },\n )\n break\n }\n}\n\n/**\n * Kills all processes in the process tree.\n *\n * @param tree - Process tree.\n * @param killSignal - Type of kill signal to be used.\n * @param rootPid - Pid of the root process.\n * @param killRoot - Whether to kill the root process.\n * @param callback - Optional callback to run after killing the processes.\n */\nfunction killAll(\n tree: ProcessTree,\n killSignal: string,\n rootPid: string,\n killRoot: boolean,\n callback: AfterKillCallback,\n): void {\n const killed = new Set<string>()\n try {\n Object.keys(tree).forEach(function (pid) {\n tree[pid]!.forEach(function (pidpid) {\n if (!killed.has(pidpid)) {\n killPid(pidpid, killSignal)\n killed.add(pidpid)\n }\n })\n if (pid === rootPid && killRoot && !killed.has(pid)) {\n killPid(pid, killSignal)\n killed.add(pid)\n }\n })\n } catch (err: unknown) {\n if (callback) {\n // @ts-ignore\n callback(err)\n return\n } else {\n throw err\n }\n }\n if (callback) {\n callback()\n }\n}\n\n/**\n * Kills a process.\n *\n * @param pid - Pid of the process to kill.\n * @param killSignal - Type of kill signal to be used.\n */\nfunction killPid(pid: string, killSignal: string) {\n try {\n process.kill(parseInt(pid, 10), killSignal)\n } catch (err) {\n // @ts-ignore\n if (err.code !== 'ESRCH') throw err\n }\n}\n\n/**\n * Builds a process tree.\n *\n * @param parentPid - Pid of the parent process.\n * @param tree - Process tree.\n * @param pidsToProcess - Pids to process.\n * @param spawnChildProcessesList - Function to spawn child processes.\n * @param cb - Callback to run after building the process tree.\n */\nfunction buildProcessTree(\n parentPid: string,\n tree: ProcessTree,\n pidsToProcess: Set<string>,\n spawnChildProcessesList: (parentPid: string) => ReturnType<typeof spawn>,\n cb: () => void,\n) {\n const ps = spawnChildProcessesList(parentPid)\n let allData = ''\n ps.stdout?.on('data', function (data: Buffer) {\n const dataStr = data.toString('ascii')\n allData += dataStr\n })\n\n const onClose = (code: number) => {\n pidsToProcess.delete(parentPid)\n\n if (code !== 0) {\n // no more parent processes\n if (pidsToProcess.size === 0) {\n cb()\n return\n }\n return\n }\n\n allData\n .trim()\n .split('\\n')\n .forEach(function (line) {\n const match = line.match(/^(\\d+)\\s(.*)$/)\n if (match) {\n const pid = match[1]!\n const cmd = match[2]!\n tree[parentPid]!.push(pid)\n tree[pid] = []\n outputDebug(`Killing process ${pid}: ${cmd}`)\n pidsToProcess.add(pid)\n buildProcessTree(pid, tree, pidsToProcess, spawnChildProcessesList, cb)\n }\n })\n }\n\n ps.on('close', onClose)\n}\n"]}
|
package/dist/public/node/ui.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
1
2
|
/* eslint-disable tsdoc/syntax */
|
|
2
3
|
import { AbortError, AbortSilentError, FatalErrorType } from './error.js';
|
|
3
4
|
import { collectLog, consoleError, consoleLog, outputContent, outputDebug, outputToken, outputWhereAppropriate, } from './output.js';
|
|
@@ -349,7 +350,7 @@ export async function renderAutocompletePrompt({ renderOptions, ...props }, uiDe
|
|
|
349
350
|
const lowerTerm = term.toLowerCase();
|
|
350
351
|
return Promise.resolve({
|
|
351
352
|
data: props.choices.filter((item) => {
|
|
352
|
-
return
|
|
353
|
+
return item.label.toLowerCase().includes(lowerTerm) || item.group?.toLowerCase().includes(lowerTerm);
|
|
353
354
|
}),
|
|
354
355
|
});
|
|
355
356
|
},
|
|
@@ -409,7 +410,9 @@ export async function renderTasks(tasks, { renderOptions } = {}) {
|
|
|
409
410
|
...renderOptions,
|
|
410
411
|
exitOnCtrlC: false,
|
|
411
412
|
})
|
|
412
|
-
.then(() =>
|
|
413
|
+
.then(() => {
|
|
414
|
+
resetRecordedSleep();
|
|
415
|
+
})
|
|
413
416
|
.catch(reject);
|
|
414
417
|
});
|
|
415
418
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/public/node/ui.tsx"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,OAAO,EAAC,UAAU,EAAE,gBAAgB,EAAuB,cAAc,EAAC,MAAM,YAAY,CAAA;AAC5F,OAAO,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EAGV,aAAa,EACb,WAAW,EACX,WAAW,EACX,sBAAsB,GACvB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAC,yBAAyB,EAAC,MA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IAC7C,MAAM,YAAY,GAAG;;EAErB,aAAa,CAAA,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,KAAK;;2IAEqF,CAAA;IACzI,MAAM,IAAI,UAAU,CAClB,YAAY,EACZ,mIAAmI,CACpI,CAAA;AACH,CAAC;AAID,OAAO,EAA2F,MAAM,EAAE,WAAW,EAAC,CAAA","sourcesContent":["/* eslint-disable tsdoc/syntax */\nimport {AbortError, AbortSilentError, FatalError as Fatal, FatalErrorType} from './error.js'\nimport {\n collectLog,\n consoleError,\n consoleLog,\n Logger,\n LogLevel,\n outputContent,\n outputDebug,\n outputToken,\n outputWhereAppropriate,\n} from './output.js'\nimport {isUnitTest} from './context/local.js'\nimport {terminalSupportsPrompting} from './system.js'\nimport {AbortController} from './abort.js'\nimport {runWithTimer} from './metadata.js'\nimport {ConcurrentOutput, ConcurrentOutputProps} from '../../private/node/ui/components/ConcurrentOutput.js'\nimport {handleCtrlC, render, renderOnce} from '../../private/node/ui.js'\nimport {alert, AlertOptions} from '../../private/node/ui/alert.js'\nimport {CustomSection} from '../../private/node/ui/components/Alert.js'\nimport {FatalError} from '../../private/node/ui/components/FatalError.js'\nimport ScalarDict from '../../private/node/ui/components/Table/ScalarDict.js'\nimport {Table, TableColumn, TableProps} from '../../private/node/ui/components/Table/Table.js'\nimport {\n Token,\n tokenItemToString,\n InlineToken,\n LinkToken,\n ListToken,\n TokenItem,\n} from '../../private/node/ui/components/TokenizedText.js'\nimport {\n DangerousConfirmationPrompt,\n DangerousConfirmationPromptProps,\n} from '../../private/node/ui/components/DangerousConfirmationPrompt.js'\nimport {SelectPrompt, SelectPromptProps} from '../../private/node/ui/components/SelectPrompt.js'\nimport {Tasks, Task} from '../../private/node/ui/components/Tasks.js'\nimport {TextPrompt, TextPromptProps} from '../../private/node/ui/components/TextPrompt.js'\nimport {AutocompletePromptProps, AutocompletePrompt} from '../../private/node/ui/components/AutocompletePrompt.js'\nimport {InfoTableSection} from '../../private/node/ui/components/Prompts/InfoTable.js'\nimport {recordUIEvent, resetRecordedSleep} from '../../private/node/demo-recorder.js'\nimport {InfoMessageProps} from '../../private/node/ui/components/Prompts/InfoMessage.js'\nimport React from 'react'\nimport {Key as InkKey, RenderOptions} from 'ink'\n\ntype PartialBy<T, TKey extends keyof T> = Omit<T, TKey> & Partial<Pick<T, TKey>>\n\ninterface UIDebugOptions {\n /** If true, don't check if the current terminal is interactive or not */\n skipTTYCheck?: boolean\n}\nconst defaultUIDebugOptions: UIDebugOptions = {\n skipTTYCheck: false,\n}\n\nexport interface RenderConcurrentOptions extends PartialBy<ConcurrentOutputProps, 'abortSignal'> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders output from concurrent processes to the terminal with {@link ConcurrentOutput}.\n * @example\n * 00:00:00 │ backend │ first backend message\n * 00:00:00 │ backend │ second backend message\n * 00:00:00 │ backend │ third backend message\n * 00:00:00 │ frontend │ first frontend message\n * 00:00:00 │ frontend │ second frontend message\n * 00:00:00 │ frontend │ third frontend message\n *\n */\nexport async function renderConcurrent({renderOptions, ...props}: RenderConcurrentOptions) {\n const abortSignal = props.abortSignal ?? new AbortController().signal\n\n return render(<ConcurrentOutput {...props} abortSignal={abortSignal} />, renderOptions)\n}\n\nexport type AlertCustomSection = CustomSection\nexport type RenderAlertOptions = Omit<AlertOptions, 'type'>\n\n/**\n * Renders an information banner to the console.\n * @example Basic\n * ╭─ info ───────────────────────────────────────────────────╮\n * │ │\n * │ CLI update available. │\n * │ │\n * │ Run `npm run shopify upgrade`. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n * @example Complete\n * ╭─ info ───────────────────────────────────────────────────╮\n * │ │\n * │ my-app initialized and ready to build. │\n * │ │\n * │ Next steps │\n * │ • Run `cd verification-app` │\n * │ • To preview your project, run `npm app dev` │\n * │ • To add extensions, run `npm generate extension` │\n * │ │\n * │ Reference │\n * │ • Run `npm shopify help` │\n * │ • Dev docs [1] │\n * │ │\n * │ Custom section │\n * │ • Item 1 [2] │\n * │ • Item 2 │\n * │ • Item 3 [3] │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * [1] https://shopify.dev\n * [2] https://www.google.com/search?q=jh56t9l34kpo35tw8s28hn7s\n * 9s2xvzla01d8cn6j7yq&rlz=1C1GCEU_enUS832US832&oq=jh56t9l34kpo\n * 35tw8s28hn7s9s2xvzla01d8cn6j7yq&aqs=chrome.0.35i39l2j0l4j46j\n * 69i60.2711j0j7&sourceid=chrome&ie=UTF-8\n * [3] https://shopify.com\n *\n */\nexport function renderInfo(options: RenderAlertOptions) {\n return alert({...options, type: 'info'})\n}\n\n/**\n * Renders a success banner to the console.\n * @example Basic\n * ╭─ success ────────────────────────────────────────────────╮\n * │ │\n * │ CLI updated. │\n * │ │\n * │ You are now running version 3.47. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n * @example Complete\n * ╭─ success ────────────────────────────────────────────────╮\n * │ │\n * │ Deployment successful. │\n * │ │\n * │ Your extensions have been uploaded to your Shopify │\n * │ Partners Dashboard. │\n * │ │\n * │ Next steps │\n * │ • See your deployment and set it live [1] │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * [1] https://partners.shopify.com/1797046/apps/4523695/deploy\n * ments\n *\n */\nexport function renderSuccess(options: RenderAlertOptions) {\n return alert({...options, type: 'success'})\n}\n\n/**\n * Renders a warning banner to the console.\n * @example Basic\n * ╭─ warning ────────────────────────────────────────────────╮\n * │ │\n * │ You have reached your limit of checkout extensions for │\n * │ this app. │\n * │ │\n * │ You can free up space for a new one by deleting an │\n * │ existing one. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n * @example Complete\n * ╭─ warning ────────────────────────────────────────────────╮\n * │ │\n * │ Required access scope update. │\n * │ │\n * │ The deadline for re-selecting your app scopes is May │\n * │ 1, 2022. │\n * │ │\n * │ Reference │\n * │ • Dev docs [1] │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * [1] https://shopify.dev/app/scopes\n *\n */\nexport function renderWarning(options: RenderAlertOptions) {\n return alert({...options, type: 'warning'})\n}\n\n/**\n * Renders an error banner to the console.\n * @example\n * ╭─ error ──────────────────────────────────────────────────╮\n * │ │\n * │ Version couldn't be released. │\n * │ │\n * │ This version needs to be submitted for review and │\n * │ approved by Shopify before it can be released. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n */\nexport function renderError(options: RenderAlertOptions) {\n return alert({...options, type: 'error'})\n}\n\ninterface RenderFatalErrorOptions {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a Fatal error to the console inside a banner.\n * @example Basic\n * ╭─ error ──────────────────────────────────────────────────╮\n * │ │\n * │ Something went wrong. │\n * │ │\n * │ To investigate the issue, examine this stack trace: │\n * │ at _compile (internal/modules/cjs/loader.js:1137) │\n * │ at js (internal/modules/cjs/loader.js:1157) │\n * │ at load (internal/modules/cjs/loader.js:985) │\n * │ at _load (internal/modules/cjs/loader.js:878) │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n * @example Complete\n * ╭─ error ──────────────────────────────────────────────────╮\n * │ │\n * │ No Organization found │\n * │ │\n * │ Next steps │\n * │ • Have you created a Shopify Partners organization │\n * │ [1]? │\n * │ • Have you confirmed your accounts from the emails │\n * │ you received? │\n * │ • Need to connect to a different App or │\n * │ organization? Run the command again with `--reset` │\n * │ │\n * │ amortizable-marketplace-ext │\n * │ • Some other error │\n * │ Validation errors │\n * │ • Missing expected key(s). │\n * │ │\n * │ amortizable-marketplace-ext-2 │\n * │ • Something was not found │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * [1] https://partners.shopify.com/signup\n *\n */\n// eslint-disable-next-line max-params\nexport function renderFatalError(error: Fatal, {renderOptions}: RenderFatalErrorOptions = {}) {\n recordUIEvent({\n type: 'fatalError',\n properties: {...error, errorType: error.type === FatalErrorType.Bug ? 'bug' : 'abort'},\n })\n\n return renderOnce(<FatalError error={error} />, {logLevel: 'error', logger: consoleError, renderOptions})\n}\n\nexport interface RenderSelectPromptOptions<T> extends Omit<SelectPromptProps<T>, 'onSubmit'> {\n isConfirmationPrompt?: boolean\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a select prompt to the console.\n * @example\n * ? Associate your project with the org Castile Ventures?\n *\n * ┃ Add\n * ┃ • new-ext\n * ┃\n * ┃ Remove\n * ┃ • integrated-demand-ext\n * ┃ • order-discount\n *\n * Automations\n * > fifth\n * sixth\n *\n * Merchant Admin\n * eighth\n * ninth\n *\n * Other\n * first\n * second\n * third (limit reached)\n * fourth\n * seventh\n * tenth\n *\n * Press ↑↓ arrows to select, enter to confirm.\n *\n */\n// eslint-disable-next-line max-params\nexport async function renderSelectPrompt<T>(\n {renderOptions, isConfirmationPrompt, ...props}: RenderSelectPromptOptions<T>,\n uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,\n): Promise<T> {\n throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)\n\n if (!isConfirmationPrompt) {\n recordUIEvent({type: 'selectPrompt', properties: {renderOptions, ...props}})\n }\n\n return runWithTimer('cmd_all_timing_prompts_ms')(async () => {\n let selectedValue: T\n try {\n await render(\n <SelectPrompt\n {...props}\n onSubmit={(value: T) => {\n selectedValue = value\n }}\n />,\n {\n ...renderOptions,\n exitOnCtrlC: false,\n },\n )\n return selectedValue!\n } finally {\n resetRecordedSleep()\n }\n })\n}\n\nexport interface RenderConfirmationPromptOptions\n extends Pick<SelectPromptProps<boolean>, 'message' | 'infoTable' | 'infoMessage' | 'abortSignal'> {\n confirmationMessage?: string\n cancellationMessage?: string\n renderOptions?: RenderOptions\n defaultValue?: boolean\n}\n\n/**\n * Renders a confirmation prompt to the console.\n * @example\n * ? Delete the following themes from the store?\n *\n * ┃ Info message title\n * ┃\n * ┃ Info message body\n * ┃\n * ┃ • first theme (#1)\n * ┃ • second theme (#2)\n *\n * > (y) Yes, confirm changes\n * (n) Cancel\n *\n * Press ↑↓ arrows to select, enter or a shortcut to\n * confirm.\n *\n */\nexport async function renderConfirmationPrompt({\n message,\n infoTable,\n confirmationMessage = 'Yes, confirm',\n cancellationMessage = 'No, cancel',\n renderOptions,\n defaultValue = true,\n abortSignal,\n infoMessage,\n}: RenderConfirmationPromptOptions): Promise<boolean> {\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'confirmationPrompt', properties: arguments[0]})\n\n const choices = [\n {\n label: confirmationMessage,\n value: true,\n key: 'y',\n },\n {\n label: cancellationMessage,\n value: false,\n key: 'n',\n },\n ]\n\n return renderSelectPrompt({\n choices,\n message,\n infoTable,\n renderOptions,\n defaultValue,\n isConfirmationPrompt: true,\n abortSignal,\n infoMessage,\n })\n}\n\nexport interface RenderAutocompleteOptions<T>\n extends PartialBy<Omit<AutocompletePromptProps<T>, 'onSubmit'>, 'search'> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders an autocomplete prompt to the console.\n * @example\n * ? Select a template: Type to search...\n *\n * ┃ Info message title\n * ┃\n * ┃ Info message body\n *\n * > first\n * second\n * third\n * fourth\n * fifth\n * sixth\n * seventh\n * eighth\n * ninth\n * tenth\n * eleventh\n * twelfth\n * thirteenth\n * fourteenth\n * fifteenth\n * sixteenth\n * seventeenth\n * eighteenth\n * nineteenth (disabled)\n * twentieth\n * twenty-first\n * twenty-second\n * twenty-third\n * twenty-fourth\n * twenty-fifth\n *\n * Press ↑↓ arrows to select, enter to confirm.\n *\n */\n// eslint-disable-next-line max-params\nexport async function renderAutocompletePrompt<T>(\n {renderOptions, ...props}: RenderAutocompleteOptions<T>,\n uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,\n): Promise<T> {\n throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)\n\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'autocompletePrompt', properties: arguments[0]})\n\n const newProps = {\n search(term: string) {\n const lowerTerm = term.toLowerCase()\n return Promise.resolve({\n data: props.choices.filter((item) => {\n return (\n item.label.toLowerCase().includes(lowerTerm) || (item.group && item.group.toLowerCase().includes(lowerTerm))\n )\n }),\n })\n },\n ...props,\n }\n\n return runWithTimer('cmd_all_timing_prompts_ms')(async () => {\n let selectedValue: T\n try {\n await render(\n <AutocompletePrompt\n {...newProps}\n onSubmit={(value: T) => {\n selectedValue = value\n }}\n />,\n {\n ...renderOptions,\n exitOnCtrlC: false,\n },\n )\n return selectedValue!\n } finally {\n resetRecordedSleep()\n }\n })\n}\n\ninterface RenderTableOptions<T extends ScalarDict> extends TableProps<T> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a table to the console.\n * @example\n * ID Name email\n * ── ────────── ─────────────\n * 1 John Doe jon@doe.com\n * 2 Jane Doe jane@doe.com\n * 3 John Smith jon@smith.com\n */\nexport function renderTable<T extends ScalarDict>({renderOptions, ...props}: RenderTableOptions<T>) {\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'table', properties: arguments[0]})\n\n return renderOnce(<Table {...props} />, {renderOptions})\n}\n\ninterface RenderTasksOptions {\n renderOptions?: RenderOptions\n}\n\n/**\n * Runs async tasks and displays their progress to the console.\n * @example\n * ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀\n * Installing dependencies ...\n */\n// eslint-disable-next-line max-params\nexport async function renderTasks<TContext>(tasks: Task<TContext>[], {renderOptions}: RenderTasksOptions = {}) {\n recordUIEvent({\n type: 'taskbar',\n properties: {\n // Rather than timing exactly, pretend each step takes 2 seconds. This\n // should be easy to tweak manually.\n steps: tasks.map((task) => {\n return {title: task.title, duration: 2}\n }),\n },\n })\n\n // eslint-disable-next-line max-params\n return new Promise<TContext>((resolve, reject) => {\n render(<Tasks tasks={tasks} onComplete={resolve} />, {\n ...renderOptions,\n exitOnCtrlC: false,\n })\n .then(() => resetRecordedSleep())\n .catch(reject)\n })\n}\n\nexport interface RenderTextPromptOptions extends Omit<TextPromptProps, 'onSubmit'> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a text prompt to the console.\n * @example\n * ? App project name (can be changed later):\n * > expansive commerce app\n * ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔\n *\n */\n// eslint-disable-next-line max-params\nexport async function renderTextPrompt(\n {renderOptions, ...props}: RenderTextPromptOptions,\n uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,\n): Promise<string> {\n throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)\n\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'textPrompt', properties: arguments[0]})\n\n return runWithTimer('cmd_all_timing_prompts_ms')(async () => {\n let enteredText = ''\n try {\n await render(\n <TextPrompt\n {...props}\n onSubmit={(value: string) => {\n enteredText = value\n }}\n />,\n {\n ...renderOptions,\n exitOnCtrlC: false,\n },\n )\n return enteredText\n } finally {\n resetRecordedSleep()\n }\n })\n}\n\nexport interface RenderDangerousConfirmationPromptOptions extends Omit<DangerousConfirmationPromptProps, 'onSubmit'> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a dangerous confirmation prompt to the console, forcing the user to\n * type a confirmation string to proceed.\n * @example\n * ? Release a new version of nightly-app-2023-06-19?\n *\n * ┃ Includes:\n * ┃ + web-px (new)\n * ┃ + sub-ui-ext\n * ┃ + theme-app-ext\n * ┃ + paymentify (from Partner Dashboard)\n * ┃\n * ┃ Removes:\n * ┃ - prod-discount-fun\n * ┃\n * ┃ This can permanently delete app user data.\n *\n * Type nightly-app-2023-06-19 to confirm, or press Escape\n * to cancel.\n * > █\n * ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔\n *\n */\n// eslint-disable-next-line max-params\nexport async function renderDangerousConfirmationPrompt(\n {renderOptions, ...props}: RenderDangerousConfirmationPromptOptions,\n uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,\n): Promise<boolean> {\n throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)\n\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'dangerousConfirmationPrompt', properties: arguments[0]})\n\n return runWithTimer('cmd_all_timing_prompts_ms')(async () => {\n let confirmed: boolean\n try {\n await render(\n <DangerousConfirmationPrompt\n {...props}\n onSubmit={(value: boolean) => {\n confirmed = value\n }}\n />,\n {\n ...renderOptions,\n exitOnCtrlC: false,\n },\n )\n return confirmed!\n } finally {\n resetRecordedSleep()\n }\n })\n}\n\ninterface RenderTextOptions {\n text: string\n logLevel?: LogLevel\n logger?: Logger\n}\n\n/** Renders a text string to the console.\n * Using this function makes sure that correct spacing is applied among the various components.\n * @example\n * Hello world!\n *\n */\nexport function renderText({text, logLevel = 'info', logger = consoleLog}: RenderTextOptions) {\n let textWithLineReturn = text\n if (!text.endsWith('\\n')) textWithLineReturn += '\\n'\n\n if (isUnitTest()) collectLog(logLevel, textWithLineReturn)\n outputWhereAppropriate(logLevel, logger, textWithLineReturn)\n return textWithLineReturn\n}\n\n/** Waits for any key to be pressed except Ctrl+C which will terminate the process. */\n// eslint-disable-next-line max-params\nexport const keypress = async (stdin = process.stdin, uiDebugOptions: UIDebugOptions = defaultUIDebugOptions) => {\n throwInNonTTY({message: 'Press any key'}, uiDebugOptions)\n\n return runWithTimer('cmd_all_timing_prompts_ms')(() => {\n // eslint-disable-next-line max-params\n return new Promise((resolve, reject) => {\n const handler = (buffer: Buffer) => {\n stdin.setRawMode(false)\n\n const bytes = Array.from(buffer)\n\n if (bytes.length && bytes[0] === 3) {\n outputDebug('Canceled keypress, User pressed CTRL+C')\n reject(new AbortSilentError())\n }\n stdin.unref()\n process.nextTick(resolve)\n }\n\n stdin.setRawMode(true)\n stdin.once('data', handler)\n\n // We want to indicate that we're still using stdin, so that the process\n // doesn't exit early.\n stdin.ref()\n })\n })\n}\n\ninterface IsTTYOptions {\n stdin?: NodeJS.ReadStream\n uiDebugOptions?: UIDebugOptions\n}\n\nexport function isTTY({stdin = undefined, uiDebugOptions = defaultUIDebugOptions}: IsTTYOptions = {}) {\n return Boolean(uiDebugOptions.skipTTYCheck || stdin || terminalSupportsPrompting())\n}\n\ninterface ThrowInNonTTYOptions {\n message: TokenItem\n stdin?: NodeJS.ReadStream\n}\n\n// eslint-disable-next-line max-params\nfunction throwInNonTTY({message, stdin = undefined}: ThrowInNonTTYOptions, uiDebugOptions: UIDebugOptions) {\n if (isTTY({stdin, uiDebugOptions})) return\n\n const promptText = tokenItemToString(message)\n const errorMessage = `Failed to prompt:\n\n${outputContent`${outputToken.cyan(promptText)}`.value}\n\nThis usually happens when running a command non-interactively, for example in a CI environment, or when piping to or from another process.`\n throw new AbortError(\n errorMessage,\n 'To resolve this, specify the option in the command, or run the command in an interactive environment such as your local terminal.',\n )\n}\n\nexport type Key = InkKey\nexport type InfoMessage = InfoMessageProps['message']\nexport {Token, Task, TokenItem, InlineToken, LinkToken, TableColumn, InfoTableSection, ListToken, render, handleCtrlC}\n"]}
|
|
1
|
+
{"version":3,"file":"ui.js","sourceRoot":"","sources":["../../../src/public/node/ui.tsx"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,iCAAiC;AACjC,OAAO,EAAC,UAAU,EAAE,gBAAgB,EAAuB,cAAc,EAAC,MAAM,YAAY,CAAA;AAC5F,OAAO,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EAGV,aAAa,EACb,WAAW,EACX,WAAW,EACX,sBAAsB,GACvB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAC,yBAAyB,EAAC,MAAM,aAAa,CAAA;AACrD,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAA;AAC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KAAK;;2IAEqF,CAAA;IACzI,MAAM,IAAI,UAAU,CAClB,YAAY,EACZ,mIAAmI,CACpI,CAAA;AACH,CAAC;AAID,OAAO,EAA2F,MAAM,EAAE,WAAW,EAAC,CAAA","sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable tsdoc/syntax */\nimport {AbortError, AbortSilentError, FatalError as Fatal, FatalErrorType} from './error.js'\nimport {\n collectLog,\n consoleError,\n consoleLog,\n Logger,\n LogLevel,\n outputContent,\n outputDebug,\n outputToken,\n outputWhereAppropriate,\n} from './output.js'\nimport {isUnitTest} from './context/local.js'\nimport {terminalSupportsPrompting} from './system.js'\nimport {AbortController} from './abort.js'\nimport {runWithTimer} from './metadata.js'\nimport {ConcurrentOutput, ConcurrentOutputProps} from '../../private/node/ui/components/ConcurrentOutput.js'\nimport {handleCtrlC, render, renderOnce} from '../../private/node/ui.js'\nimport {alert, AlertOptions} from '../../private/node/ui/alert.js'\nimport {CustomSection} from '../../private/node/ui/components/Alert.js'\nimport {FatalError} from '../../private/node/ui/components/FatalError.js'\nimport ScalarDict from '../../private/node/ui/components/Table/ScalarDict.js'\nimport {Table, TableColumn, TableProps} from '../../private/node/ui/components/Table/Table.js'\nimport {\n Token,\n tokenItemToString,\n InlineToken,\n LinkToken,\n ListToken,\n TokenItem,\n} from '../../private/node/ui/components/TokenizedText.js'\nimport {\n DangerousConfirmationPrompt,\n DangerousConfirmationPromptProps,\n} from '../../private/node/ui/components/DangerousConfirmationPrompt.js'\nimport {SelectPrompt, SelectPromptProps} from '../../private/node/ui/components/SelectPrompt.js'\nimport {Tasks, Task} from '../../private/node/ui/components/Tasks.js'\nimport {TextPrompt, TextPromptProps} from '../../private/node/ui/components/TextPrompt.js'\nimport {AutocompletePromptProps, AutocompletePrompt} from '../../private/node/ui/components/AutocompletePrompt.js'\nimport {InfoTableSection} from '../../private/node/ui/components/Prompts/InfoTable.js'\nimport {recordUIEvent, resetRecordedSleep} from '../../private/node/demo-recorder.js'\nimport {InfoMessageProps} from '../../private/node/ui/components/Prompts/InfoMessage.js'\nimport React from 'react'\nimport {Key as InkKey, RenderOptions} from 'ink'\n\ntype PartialBy<T, TKey extends keyof T> = Omit<T, TKey> & Partial<Pick<T, TKey>>\n\ninterface UIDebugOptions {\n /** If true, don't check if the current terminal is interactive or not */\n skipTTYCheck?: boolean\n}\nconst defaultUIDebugOptions: UIDebugOptions = {\n skipTTYCheck: false,\n}\n\nexport interface RenderConcurrentOptions extends PartialBy<ConcurrentOutputProps, 'abortSignal'> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders output from concurrent processes to the terminal with {@link ConcurrentOutput}.\n * @example\n * 00:00:00 │ backend │ first backend message\n * 00:00:00 │ backend │ second backend message\n * 00:00:00 │ backend │ third backend message\n * 00:00:00 │ frontend │ first frontend message\n * 00:00:00 │ frontend │ second frontend message\n * 00:00:00 │ frontend │ third frontend message\n *\n */\nexport async function renderConcurrent({renderOptions, ...props}: RenderConcurrentOptions) {\n const abortSignal = props.abortSignal ?? new AbortController().signal\n\n return render(<ConcurrentOutput {...props} abortSignal={abortSignal} />, renderOptions)\n}\n\nexport type AlertCustomSection = CustomSection\nexport type RenderAlertOptions = Omit<AlertOptions, 'type'>\n\n/**\n * Renders an information banner to the console.\n * @example Basic\n * ╭─ info ───────────────────────────────────────────────────╮\n * │ │\n * │ CLI update available. │\n * │ │\n * │ Run `npm run shopify upgrade`. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n * @example Complete\n * ╭─ info ───────────────────────────────────────────────────╮\n * │ │\n * │ my-app initialized and ready to build. │\n * │ │\n * │ Next steps │\n * │ • Run `cd verification-app` │\n * │ • To preview your project, run `npm app dev` │\n * │ • To add extensions, run `npm generate extension` │\n * │ │\n * │ Reference │\n * │ • Run `npm shopify help` │\n * │ • Dev docs [1] │\n * │ │\n * │ Custom section │\n * │ • Item 1 [2] │\n * │ • Item 2 │\n * │ • Item 3 [3] │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * [1] https://shopify.dev\n * [2] https://www.google.com/search?q=jh56t9l34kpo35tw8s28hn7s\n * 9s2xvzla01d8cn6j7yq&rlz=1C1GCEU_enUS832US832&oq=jh56t9l34kpo\n * 35tw8s28hn7s9s2xvzla01d8cn6j7yq&aqs=chrome.0.35i39l2j0l4j46j\n * 69i60.2711j0j7&sourceid=chrome&ie=UTF-8\n * [3] https://shopify.com\n *\n */\nexport function renderInfo(options: RenderAlertOptions) {\n return alert({...options, type: 'info'})\n}\n\n/**\n * Renders a success banner to the console.\n * @example Basic\n * ╭─ success ────────────────────────────────────────────────╮\n * │ │\n * │ CLI updated. │\n * │ │\n * │ You are now running version 3.47. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n * @example Complete\n * ╭─ success ────────────────────────────────────────────────╮\n * │ │\n * │ Deployment successful. │\n * │ │\n * │ Your extensions have been uploaded to your Shopify │\n * │ Partners Dashboard. │\n * │ │\n * │ Next steps │\n * │ • See your deployment and set it live [1] │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * [1] https://partners.shopify.com/1797046/apps/4523695/deploy\n * ments\n *\n */\nexport function renderSuccess(options: RenderAlertOptions) {\n return alert({...options, type: 'success'})\n}\n\n/**\n * Renders a warning banner to the console.\n * @example Basic\n * ╭─ warning ────────────────────────────────────────────────╮\n * │ │\n * │ You have reached your limit of checkout extensions for │\n * │ this app. │\n * │ │\n * │ You can free up space for a new one by deleting an │\n * │ existing one. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n * @example Complete\n * ╭─ warning ────────────────────────────────────────────────╮\n * │ │\n * │ Required access scope update. │\n * │ │\n * │ The deadline for re-selecting your app scopes is May │\n * │ 1, 2022. │\n * │ │\n * │ Reference │\n * │ • Dev docs [1] │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * [1] https://shopify.dev/app/scopes\n *\n */\nexport function renderWarning(options: RenderAlertOptions) {\n return alert({...options, type: 'warning'})\n}\n\n/**\n * Renders an error banner to the console.\n * @example\n * ╭─ error ──────────────────────────────────────────────────╮\n * │ │\n * │ Version couldn't be released. │\n * │ │\n * │ This version needs to be submitted for review and │\n * │ approved by Shopify before it can be released. │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n */\nexport function renderError(options: RenderAlertOptions) {\n return alert({...options, type: 'error'})\n}\n\ninterface RenderFatalErrorOptions {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a Fatal error to the console inside a banner.\n * @example Basic\n * ╭─ error ──────────────────────────────────────────────────╮\n * │ │\n * │ Something went wrong. │\n * │ │\n * │ To investigate the issue, examine this stack trace: │\n * │ at _compile (internal/modules/cjs/loader.js:1137) │\n * │ at js (internal/modules/cjs/loader.js:1157) │\n * │ at load (internal/modules/cjs/loader.js:985) │\n * │ at _load (internal/modules/cjs/loader.js:878) │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n *\n * @example Complete\n * ╭─ error ──────────────────────────────────────────────────╮\n * │ │\n * │ No Organization found │\n * │ │\n * │ Next steps │\n * │ • Have you created a Shopify Partners organization │\n * │ [1]? │\n * │ • Have you confirmed your accounts from the emails │\n * │ you received? │\n * │ • Need to connect to a different App or │\n * │ organization? Run the command again with `--reset` │\n * │ │\n * │ amortizable-marketplace-ext │\n * │ • Some other error │\n * │ Validation errors │\n * │ • Missing expected key(s). │\n * │ │\n * │ amortizable-marketplace-ext-2 │\n * │ • Something was not found │\n * │ │\n * ╰──────────────────────────────────────────────────────────╯\n * [1] https://partners.shopify.com/signup\n *\n */\n// eslint-disable-next-line max-params\nexport function renderFatalError(error: Fatal, {renderOptions}: RenderFatalErrorOptions = {}) {\n recordUIEvent({\n type: 'fatalError',\n properties: {...error, errorType: error.type === FatalErrorType.Bug ? 'bug' : 'abort'},\n })\n\n return renderOnce(<FatalError error={error} />, {logLevel: 'error', logger: consoleError, renderOptions})\n}\n\nexport interface RenderSelectPromptOptions<T> extends Omit<SelectPromptProps<T>, 'onSubmit'> {\n isConfirmationPrompt?: boolean\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a select prompt to the console.\n * @example\n * ? Associate your project with the org Castile Ventures?\n *\n * ┃ Add\n * ┃ • new-ext\n * ┃\n * ┃ Remove\n * ┃ • integrated-demand-ext\n * ┃ • order-discount\n *\n * Automations\n * > fifth\n * sixth\n *\n * Merchant Admin\n * eighth\n * ninth\n *\n * Other\n * first\n * second\n * third (limit reached)\n * fourth\n * seventh\n * tenth\n *\n * Press ↑↓ arrows to select, enter to confirm.\n *\n */\n// eslint-disable-next-line max-params\nexport async function renderSelectPrompt<T>(\n {renderOptions, isConfirmationPrompt, ...props}: RenderSelectPromptOptions<T>,\n uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,\n): Promise<T> {\n throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)\n\n if (!isConfirmationPrompt) {\n recordUIEvent({type: 'selectPrompt', properties: {renderOptions, ...props}})\n }\n\n return runWithTimer('cmd_all_timing_prompts_ms')(async () => {\n let selectedValue: T\n try {\n await render(\n <SelectPrompt\n {...props}\n onSubmit={(value: T) => {\n selectedValue = value\n }}\n />,\n {\n ...renderOptions,\n exitOnCtrlC: false,\n },\n )\n return selectedValue!\n } finally {\n resetRecordedSleep()\n }\n })\n}\n\nexport interface RenderConfirmationPromptOptions\n extends Pick<SelectPromptProps<boolean>, 'message' | 'infoTable' | 'infoMessage' | 'abortSignal'> {\n confirmationMessage?: string\n cancellationMessage?: string\n renderOptions?: RenderOptions\n defaultValue?: boolean\n}\n\n/**\n * Renders a confirmation prompt to the console.\n * @example\n * ? Delete the following themes from the store?\n *\n * ┃ Info message title\n * ┃\n * ┃ Info message body\n * ┃\n * ┃ • first theme (#1)\n * ┃ • second theme (#2)\n *\n * > (y) Yes, confirm changes\n * (n) Cancel\n *\n * Press ↑↓ arrows to select, enter or a shortcut to\n * confirm.\n *\n */\nexport async function renderConfirmationPrompt({\n message,\n infoTable,\n confirmationMessage = 'Yes, confirm',\n cancellationMessage = 'No, cancel',\n renderOptions,\n defaultValue = true,\n abortSignal,\n infoMessage,\n}: RenderConfirmationPromptOptions): Promise<boolean> {\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'confirmationPrompt', properties: arguments[0]})\n\n const choices = [\n {\n label: confirmationMessage,\n value: true,\n key: 'y',\n },\n {\n label: cancellationMessage,\n value: false,\n key: 'n',\n },\n ]\n\n return renderSelectPrompt({\n choices,\n message,\n infoTable,\n renderOptions,\n defaultValue,\n isConfirmationPrompt: true,\n abortSignal,\n infoMessage,\n })\n}\n\nexport interface RenderAutocompleteOptions<T>\n extends PartialBy<Omit<AutocompletePromptProps<T>, 'onSubmit'>, 'search'> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders an autocomplete prompt to the console.\n * @example\n * ? Select a template: Type to search...\n *\n * ┃ Info message title\n * ┃\n * ┃ Info message body\n *\n * > first\n * second\n * third\n * fourth\n * fifth\n * sixth\n * seventh\n * eighth\n * ninth\n * tenth\n * eleventh\n * twelfth\n * thirteenth\n * fourteenth\n * fifteenth\n * sixteenth\n * seventeenth\n * eighteenth\n * nineteenth (disabled)\n * twentieth\n * twenty-first\n * twenty-second\n * twenty-third\n * twenty-fourth\n * twenty-fifth\n *\n * Press ↑↓ arrows to select, enter to confirm.\n *\n */\n// eslint-disable-next-line max-params\nexport async function renderAutocompletePrompt<T>(\n {renderOptions, ...props}: RenderAutocompleteOptions<T>,\n uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,\n): Promise<T> {\n throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)\n\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'autocompletePrompt', properties: arguments[0]})\n\n const newProps = {\n search(term: string) {\n const lowerTerm = term.toLowerCase()\n return Promise.resolve({\n data: props.choices.filter((item) => {\n return item.label.toLowerCase().includes(lowerTerm) || item.group?.toLowerCase().includes(lowerTerm)\n }),\n })\n },\n ...props,\n }\n\n return runWithTimer('cmd_all_timing_prompts_ms')(async () => {\n let selectedValue: T\n try {\n await render(\n <AutocompletePrompt\n {...newProps}\n onSubmit={(value: T) => {\n selectedValue = value\n }}\n />,\n {\n ...renderOptions,\n exitOnCtrlC: false,\n },\n )\n return selectedValue!\n } finally {\n resetRecordedSleep()\n }\n })\n}\n\ninterface RenderTableOptions<T extends ScalarDict> extends TableProps<T> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a table to the console.\n * @example\n * ID Name email\n * ── ────────── ─────────────\n * 1 John Doe jon@doe.com\n * 2 Jane Doe jane@doe.com\n * 3 John Smith jon@smith.com\n */\nexport function renderTable<T extends ScalarDict>({renderOptions, ...props}: RenderTableOptions<T>) {\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'table', properties: arguments[0]})\n\n return renderOnce(<Table {...props} />, {renderOptions})\n}\n\ninterface RenderTasksOptions {\n renderOptions?: RenderOptions\n}\n\n/**\n * Runs async tasks and displays their progress to the console.\n * @example\n * ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀\n * Installing dependencies ...\n */\n// eslint-disable-next-line max-params\nexport async function renderTasks<TContext>(tasks: Task<TContext>[], {renderOptions}: RenderTasksOptions = {}) {\n recordUIEvent({\n type: 'taskbar',\n properties: {\n // Rather than timing exactly, pretend each step takes 2 seconds. This\n // should be easy to tweak manually.\n steps: tasks.map((task) => {\n return {title: task.title, duration: 2}\n }),\n },\n })\n\n // eslint-disable-next-line max-params\n return new Promise<TContext>((resolve, reject) => {\n render(<Tasks tasks={tasks} onComplete={resolve} />, {\n ...renderOptions,\n exitOnCtrlC: false,\n })\n .then(() => {\n resetRecordedSleep()\n })\n .catch(reject)\n })\n}\n\nexport interface RenderTextPromptOptions extends Omit<TextPromptProps, 'onSubmit'> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a text prompt to the console.\n * @example\n * ? App project name (can be changed later):\n * > expansive commerce app\n * ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔\n *\n */\n// eslint-disable-next-line max-params\nexport async function renderTextPrompt(\n {renderOptions, ...props}: RenderTextPromptOptions,\n uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,\n): Promise<string> {\n throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)\n\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'textPrompt', properties: arguments[0]})\n\n return runWithTimer('cmd_all_timing_prompts_ms')(async () => {\n let enteredText = ''\n try {\n await render(\n <TextPrompt\n {...props}\n onSubmit={(value: string) => {\n enteredText = value\n }}\n />,\n {\n ...renderOptions,\n exitOnCtrlC: false,\n },\n )\n return enteredText\n } finally {\n resetRecordedSleep()\n }\n })\n}\n\nexport interface RenderDangerousConfirmationPromptOptions extends Omit<DangerousConfirmationPromptProps, 'onSubmit'> {\n renderOptions?: RenderOptions\n}\n\n/**\n * Renders a dangerous confirmation prompt to the console, forcing the user to\n * type a confirmation string to proceed.\n * @example\n * ? Release a new version of nightly-app-2023-06-19?\n *\n * ┃ Includes:\n * ┃ + web-px (new)\n * ┃ + sub-ui-ext\n * ┃ + theme-app-ext\n * ┃ + paymentify (from Partner Dashboard)\n * ┃\n * ┃ Removes:\n * ┃ - prod-discount-fun\n * ┃\n * ┃ This can permanently delete app user data.\n *\n * Type nightly-app-2023-06-19 to confirm, or press Escape\n * to cancel.\n * > █\n * ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔\n *\n */\n// eslint-disable-next-line max-params\nexport async function renderDangerousConfirmationPrompt(\n {renderOptions, ...props}: RenderDangerousConfirmationPromptOptions,\n uiDebugOptions: UIDebugOptions = defaultUIDebugOptions,\n): Promise<boolean> {\n throwInNonTTY({message: props.message, stdin: renderOptions?.stdin}, uiDebugOptions)\n\n // eslint-disable-next-line prefer-rest-params\n recordUIEvent({type: 'dangerousConfirmationPrompt', properties: arguments[0]})\n\n return runWithTimer('cmd_all_timing_prompts_ms')(async () => {\n let confirmed: boolean\n try {\n await render(\n <DangerousConfirmationPrompt\n {...props}\n onSubmit={(value: boolean) => {\n confirmed = value\n }}\n />,\n {\n ...renderOptions,\n exitOnCtrlC: false,\n },\n )\n return confirmed!\n } finally {\n resetRecordedSleep()\n }\n })\n}\n\ninterface RenderTextOptions {\n text: string\n logLevel?: LogLevel\n logger?: Logger\n}\n\n/** Renders a text string to the console.\n * Using this function makes sure that correct spacing is applied among the various components.\n * @example\n * Hello world!\n *\n */\nexport function renderText({text, logLevel = 'info', logger = consoleLog}: RenderTextOptions) {\n let textWithLineReturn = text\n if (!text.endsWith('\\n')) textWithLineReturn += '\\n'\n\n if (isUnitTest()) collectLog(logLevel, textWithLineReturn)\n outputWhereAppropriate(logLevel, logger, textWithLineReturn)\n return textWithLineReturn\n}\n\n/** Waits for any key to be pressed except Ctrl+C which will terminate the process. */\n// eslint-disable-next-line max-params\nexport const keypress = async (stdin = process.stdin, uiDebugOptions: UIDebugOptions = defaultUIDebugOptions) => {\n throwInNonTTY({message: 'Press any key'}, uiDebugOptions)\n\n return runWithTimer('cmd_all_timing_prompts_ms')(() => {\n // eslint-disable-next-line max-params\n return new Promise((resolve, reject) => {\n const handler = (buffer: Buffer) => {\n stdin.setRawMode(false)\n\n const bytes = Array.from(buffer)\n\n if (bytes.length && bytes[0] === 3) {\n outputDebug('Canceled keypress, User pressed CTRL+C')\n reject(new AbortSilentError())\n }\n stdin.unref()\n process.nextTick(resolve)\n }\n\n stdin.setRawMode(true)\n stdin.once('data', handler)\n\n // We want to indicate that we're still using stdin, so that the process\n // doesn't exit early.\n stdin.ref()\n })\n })\n}\n\ninterface IsTTYOptions {\n stdin?: NodeJS.ReadStream\n uiDebugOptions?: UIDebugOptions\n}\n\nexport function isTTY({stdin = undefined, uiDebugOptions = defaultUIDebugOptions}: IsTTYOptions = {}) {\n return Boolean(uiDebugOptions.skipTTYCheck || stdin || terminalSupportsPrompting())\n}\n\ninterface ThrowInNonTTYOptions {\n message: TokenItem\n stdin?: NodeJS.ReadStream\n}\n\n// eslint-disable-next-line max-params\nfunction throwInNonTTY({message, stdin = undefined}: ThrowInNonTTYOptions, uiDebugOptions: UIDebugOptions) {\n if (isTTY({stdin, uiDebugOptions})) return\n\n const promptText = tokenItemToString(message)\n const errorMessage = `Failed to prompt:\n\n${outputContent`${outputToken.cyan(promptText)}`.value}\n\nThis usually happens when running a command non-interactively, for example in a CI environment, or when piping to or from another process.`\n throw new AbortError(\n errorMessage,\n 'To resolve this, specify the option in the command, or run the command in an interactive environment such as your local terminal.',\n )\n}\n\nexport type Key = InkKey\nexport type InfoMessage = InfoMessageProps['message']\nexport {Token, Task, TokenItem, InlineToken, LinkToken, TableColumn, InfoTableSection, ListToken, render, handleCtrlC}\n"]}
|