|
4 | 4 | OrganizationBetaFlagsQueryVariables, |
5 | 5 | organizationBetaFlagsQuery, |
6 | 6 | } from './app-management-client/graphql/organization_beta_flags.js' |
| 7 | +import {environmentVariableNames} from '../../constants.js' |
7 | 8 | import {RemoteSpecification} from '../../api/graphql/extension_specifications.js' |
8 | 9 | import { |
9 | 10 | DeveloperPlatformClient, |
@@ -133,6 +134,7 @@ import {outputDebug} from '@shopify/cli-kit/node/output' |
133 | 134 | import {developerDashboardFqdn} from '@shopify/cli-kit/node/context/fqdn' |
134 | 135 | import {webhooksRequest} from '@shopify/cli-kit/node/api/webhooks' |
135 | 136 | import {functionsRequestDoc} from '@shopify/cli-kit/node/api/functions' |
| 137 | +import {fileExists, readFile} from '@shopify/cli-kit/node/fs' |
136 | 138 |
|
137 | 139 | const TEMPLATE_JSON_URL = 'https://cdn.shopify.com/static/cli/extensions/templates.json' |
138 | 140 |
|
@@ -325,24 +327,27 @@ export class AppManagementClient implements DeveloperPlatformClient { |
325 | 327 | } |
326 | 328 |
|
327 | 329 | async templateSpecifications({organizationId}: MinimalAppIdentifiers): Promise<ExtensionTemplate[]> { |
328 | | - let response |
329 | 330 | let templates: GatedExtensionTemplate[] |
330 | | - try { |
331 | | - response = await fetch(TEMPLATE_JSON_URL) |
332 | | - templates = await (response.json() as Promise<GatedExtensionTemplate[]>) |
333 | | - } catch (_e) { |
334 | | - throw new AbortError( |
335 | | - [ |
| 331 | + const {templatesJsonPath} = environmentVariableNames |
| 332 | + const overrideFile = process.env[templatesJsonPath] |
| 333 | + if (overrideFile) { |
| 334 | + if (!(await fileExists(overrideFile))) { |
| 335 | + throw new AbortError('There is no file at the path specified for template specifications') |
| 336 | + } |
| 337 | + const templatesJson = await readFile(overrideFile) |
| 338 | + templates = JSON.parse(templatesJson) |
| 339 | + } else { |
| 340 | + try { |
| 341 | + const response = await fetch(TEMPLATE_JSON_URL) |
| 342 | + templates = await (response.json() as Promise<GatedExtensionTemplate[]>) |
| 343 | + } catch (_e) { |
| 344 | + throw new AbortError([ |
336 | 345 | 'Failed to fetch extension templates from', |
337 | 346 | {link: {url: TEMPLATE_JSON_URL}}, |
338 | 347 | {char: '.'}, |
339 | 348 | 'This likely means a problem with your internet connection.', |
340 | | - ], |
341 | | - [ |
342 | | - {link: {url: 'https://www.githubstatus.com', label: 'Check if GitHub is experiencing downtime'}}, |
343 | | - 'or try again later.', |
344 | | - ], |
345 | | - ) |
| 349 | + ]) |
| 350 | + } |
346 | 351 | } |
347 | 352 | // Fake the sortPriority as ascending, since the templates are already sorted |
348 | 353 | // in the static JSON file. This can be removed once PartnersClient, which |
|
0 commit comments