Skip to content

Commit 7aa290c

Browse files
authored
Merge pull request #5134 from Shopify/make-tophatting-templates-changes-possible
Make tophatting templates changes possible
2 parents 27fceb7 + a8e7cd9 commit 7aa290c

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

packages/app/src/cli/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const environmentVariableNames = {
33
disableGraphiQLExplorer: 'SHOPIFY_CLI_DISABLE_GRAPHIQL',
44
useDynamicConfigSpecifications: 'SHOPIFY_CLI_DYNAMIC_CONFIG',
55
enableAppLogPolling: 'SHOPIFY_CLI_ENABLE_APP_LOG_POLLING',
6+
templatesJsonPath: 'SHOPIFY_CLI_APP_TEMPLATES_JSON_PATH',
67
}
78

89
export const configurationFileNames = {

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
OrganizationBetaFlagsQueryVariables,
55
organizationBetaFlagsQuery,
66
} from './app-management-client/graphql/organization_beta_flags.js'
7+
import {environmentVariableNames} from '../../constants.js'
78
import {RemoteSpecification} from '../../api/graphql/extension_specifications.js'
89
import {
910
DeveloperPlatformClient,
@@ -133,6 +134,7 @@ import {outputDebug} from '@shopify/cli-kit/node/output'
133134
import {developerDashboardFqdn} from '@shopify/cli-kit/node/context/fqdn'
134135
import {webhooksRequest} from '@shopify/cli-kit/node/api/webhooks'
135136
import {functionsRequestDoc} from '@shopify/cli-kit/node/api/functions'
137+
import {fileExists, readFile} from '@shopify/cli-kit/node/fs'
136138

137139
const TEMPLATE_JSON_URL = 'https://cdn.shopify.com/static/cli/extensions/templates.json'
138140

@@ -325,24 +327,27 @@ export class AppManagementClient implements DeveloperPlatformClient {
325327
}
326328

327329
async templateSpecifications({organizationId}: MinimalAppIdentifiers): Promise<ExtensionTemplate[]> {
328-
let response
329330
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([
336345
'Failed to fetch extension templates from',
337346
{link: {url: TEMPLATE_JSON_URL}},
338347
{char: '.'},
339348
'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+
}
346351
}
347352
// Fake the sortPriority as ascending, since the templates are already sorted
348353
// in the static JSON file. This can be removed once PartnersClient, which

0 commit comments

Comments
 (0)