Skip to content

Commit 37bd585

Browse files
committed
shopify app data import-definitions
1 parent bd265d7 commit 37bd585

File tree

11 files changed

+369
-28
lines changed

11 files changed

+369
-28
lines changed

.changeset/bumpy-doors-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/app': minor
3+
---
4+
5+
Add `shopify app data import-definitions` -- a command to automatically convert existing metafields and metaobjects to declarative TOML.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This is an autogenerated file. Don't edit this file manually.
2+
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'
3+
4+
const data: ReferenceEntityTemplateSchema = {
5+
name: 'app data import-definitions',
6+
description: `Import metafield and metaobject definitions from your development store. [Read more about declarative custom data definitions](/docs/apps/build/custom-data/declarative-custom-data-definitions).`,
7+
overviewPreviewDescription: `Import metafield and metaobject definitions.`,
8+
type: 'command',
9+
isVisualComponent: false,
10+
defaultExample: {
11+
codeblock: {
12+
tabs: [
13+
{
14+
title: 'app data import-definitions',
15+
code: './examples/app-data-import-definitions.example.sh',
16+
language: 'bash',
17+
},
18+
],
19+
title: 'app data import-definitions',
20+
},
21+
},
22+
definitions: [
23+
{
24+
title: 'Flags',
25+
description: 'The following flags are available for the `app data import-definitions` command:',
26+
type: 'appdataimportdefinitions',
27+
},
28+
],
29+
category: 'app',
30+
related: [
31+
],
32+
}
33+
34+
export default data
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shopify app data import-definitions [flags]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This is an autogenerated file. Don't edit this file manually.
2+
export interface appdataimportdefinitions {
3+
/**
4+
* The Client ID of your app.
5+
* @environment SHOPIFY_FLAG_CLIENT_ID
6+
*/
7+
'--client-id <value>'?: string
8+
9+
/**
10+
* The name of the app configuration.
11+
* @environment SHOPIFY_FLAG_APP_CONFIG
12+
*/
13+
'-c, --config <value>'?: string
14+
15+
/**
16+
* Disable color output.
17+
* @environment SHOPIFY_FLAG_NO_COLOR
18+
*/
19+
'--no-color'?: ''
20+
21+
/**
22+
* The path to your app directory.
23+
* @environment SHOPIFY_FLAG_PATH
24+
*/
25+
'--path <value>'?: string
26+
27+
/**
28+
* Reset all your settings.
29+
* @environment SHOPIFY_FLAG_RESET
30+
*/
31+
'--reset'?: ''
32+
33+
/**
34+
* Store URL. Must be an existing development or Shopify Plus sandbox store.
35+
* @environment SHOPIFY_FLAG_STORE
36+
*/
37+
'-s, --store <value>'?: string
38+
39+
/**
40+
* Increase the verbosity of the output.
41+
* @environment SHOPIFY_FLAG_VERBOSE
42+
*/
43+
'--verbose'?: ''
44+
}

docs-shopify.dev/generated/generated_docs_data.json

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,107 @@
275275
"category": "app",
276276
"related": []
277277
},
278+
{
279+
"name": "app data import-definitions",
280+
"description": "Import metafield and metaobject definitions from your development store. [Read more about declarative custom data definitions](/docs/apps/build/custom-data/declarative-custom-data-definitions).",
281+
"overviewPreviewDescription": "Import metafield and metaobject definitions.",
282+
"type": "command",
283+
"isVisualComponent": false,
284+
"defaultExample": {
285+
"codeblock": {
286+
"tabs": [
287+
{
288+
"title": "app data import-definitions",
289+
"code": "shopify app data import-definitions [flags]",
290+
"language": "bash"
291+
}
292+
],
293+
"title": "app data import-definitions"
294+
}
295+
},
296+
"definitions": [
297+
{
298+
"title": "Flags",
299+
"description": "The following flags are available for the `app data import-definitions` command:",
300+
"type": "appdataimportdefinitions",
301+
"typeDefinitions": {
302+
"appdataimportdefinitions": {
303+
"filePath": "docs-shopify.dev/commands/interfaces/app-data-import-definitions.interface.ts",
304+
"name": "appdataimportdefinitions",
305+
"description": "",
306+
"members": [
307+
{
308+
"filePath": "docs-shopify.dev/commands/interfaces/app-data-import-definitions.interface.ts",
309+
"syntaxKind": "PropertySignature",
310+
"name": "--client-id <value>",
311+
"value": "string",
312+
"description": "The Client ID of your app.",
313+
"isOptional": true,
314+
"environmentValue": "SHOPIFY_FLAG_CLIENT_ID"
315+
},
316+
{
317+
"filePath": "docs-shopify.dev/commands/interfaces/app-data-import-definitions.interface.ts",
318+
"syntaxKind": "PropertySignature",
319+
"name": "--no-color",
320+
"value": "\"\"",
321+
"description": "Disable color output.",
322+
"isOptional": true,
323+
"environmentValue": "SHOPIFY_FLAG_NO_COLOR"
324+
},
325+
{
326+
"filePath": "docs-shopify.dev/commands/interfaces/app-data-import-definitions.interface.ts",
327+
"syntaxKind": "PropertySignature",
328+
"name": "--path <value>",
329+
"value": "string",
330+
"description": "The path to your app directory.",
331+
"isOptional": true,
332+
"environmentValue": "SHOPIFY_FLAG_PATH"
333+
},
334+
{
335+
"filePath": "docs-shopify.dev/commands/interfaces/app-data-import-definitions.interface.ts",
336+
"syntaxKind": "PropertySignature",
337+
"name": "--reset",
338+
"value": "\"\"",
339+
"description": "Reset all your settings.",
340+
"isOptional": true,
341+
"environmentValue": "SHOPIFY_FLAG_RESET"
342+
},
343+
{
344+
"filePath": "docs-shopify.dev/commands/interfaces/app-data-import-definitions.interface.ts",
345+
"syntaxKind": "PropertySignature",
346+
"name": "--verbose",
347+
"value": "\"\"",
348+
"description": "Increase the verbosity of the output.",
349+
"isOptional": true,
350+
"environmentValue": "SHOPIFY_FLAG_VERBOSE"
351+
},
352+
{
353+
"filePath": "docs-shopify.dev/commands/interfaces/app-data-import-definitions.interface.ts",
354+
"syntaxKind": "PropertySignature",
355+
"name": "-c, --config <value>",
356+
"value": "string",
357+
"description": "The name of the app configuration.",
358+
"isOptional": true,
359+
"environmentValue": "SHOPIFY_FLAG_APP_CONFIG"
360+
},
361+
{
362+
"filePath": "docs-shopify.dev/commands/interfaces/app-data-import-definitions.interface.ts",
363+
"syntaxKind": "PropertySignature",
364+
"name": "-s, --store <value>",
365+
"value": "string",
366+
"description": "Store URL. Must be an existing development or Shopify Plus sandbox store.",
367+
"isOptional": true,
368+
"environmentValue": "SHOPIFY_FLAG_STORE"
369+
}
370+
],
371+
"value": "export interface appdataimportdefinitions {\n /**\n * The Client ID of your app.\n * @environment SHOPIFY_FLAG_CLIENT_ID\n */\n '--client-id <value>'?: string\n\n /**\n * The name of the app configuration.\n * @environment SHOPIFY_FLAG_APP_CONFIG\n */\n '-c, --config <value>'?: string\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * The path to your app directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Reset all your settings.\n * @environment SHOPIFY_FLAG_RESET\n */\n '--reset'?: ''\n\n /**\n * Store URL. Must be an existing development or Shopify Plus sandbox store.\n * @environment SHOPIFY_FLAG_STORE\n */\n '-s, --store <value>'?: string\n\n /**\n * Increase the verbosity of the output.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
372+
}
373+
}
374+
}
375+
],
376+
"category": "app",
377+
"related": []
378+
},
278379
{
279380
"name": "app deploy",
280381
"description": "[Builds the app](/docs/api/shopify-cli/app/app-build), then deploys your app configuration and extensions.\n\n This command creates an app version, which is a snapshot of your app configuration and all extensions. This version is then released to users.\n\n This command doesn't deploy your [web app](/docs/apps/tools/cli/structure#web-components). You need to [deploy your web app](/docs/apps/deployment/web) to your own hosting solution.\n ",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {appFlags} from '../../../flags.js'
2+
import {checkFolderIsValidApp} from '../../../models/app/loader.js'
3+
import AppLinkedCommand, {AppLinkedCommandOutput} from '../../../utilities/app-linked-command.js'
4+
import {linkedAppContext} from '../../../services/app-context.js'
5+
import {storeContext} from '../../../services/store-context.js'
6+
import {importDeclarativeDefinitions} from '../../../services/generate/shop-import/declarative-definitions.js'
7+
import {Flags} from '@oclif/core'
8+
import {normalizeStoreFqdn} from '@shopify/cli-kit/node/context/fqdn'
9+
import {globalFlags} from '@shopify/cli-kit/node/cli'
10+
import {renderSingleTask} from '@shopify/cli-kit/node/ui'
11+
import {outputContent} from '@shopify/cli-kit/node/output'
12+
13+
export default class ImportDefinitions extends AppLinkedCommand {
14+
static summary = 'Import metafield and metaobject definitions.'
15+
16+
static descriptionWithMarkdown = `Import metafield and metaobject definitions from your development store. [Read more about declarative custom data definitions](https://shopify.dev/docs/apps/build/custom-data/declarative-custom-data-definitions).`
17+
18+
static description = this.descriptionWithoutMarkdown()
19+
20+
static flags = {
21+
...globalFlags,
22+
...appFlags,
23+
store: Flags.string({
24+
char: 's',
25+
description: 'Store URL. Must be an existing development or Shopify Plus sandbox store.',
26+
env: 'SHOPIFY_FLAG_STORE',
27+
parse: async (input) => normalizeStoreFqdn(input),
28+
}),
29+
}
30+
31+
public async run(): Promise<AppLinkedCommandOutput> {
32+
const {appContextResult, ...options} = await renderSingleTask({
33+
title: outputContent`Loading application`,
34+
task: async () => {
35+
const {flags} = await this.parse(ImportDefinitions)
36+
37+
await checkFolderIsValidApp(flags.path)
38+
39+
const appContextResult = await linkedAppContext({
40+
directory: flags.path,
41+
clientId: flags['client-id'],
42+
forceRelink: flags.reset,
43+
userProvidedConfigName: flags.config,
44+
})
45+
const store = await storeContext({
46+
appContextResult,
47+
storeFqdn: flags.store,
48+
forceReselectStore: flags.reset,
49+
})
50+
51+
return {
52+
appContextResult,
53+
remoteApp: appContextResult.remoteApp,
54+
store,
55+
}
56+
},
57+
})
58+
await importDeclarativeDefinitions(options)
59+
60+
return {app: appContextResult.app}
61+
}
62+
}

packages/app/src/cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import AppLinkedCommand from './utilities/app-linked-command.js'
3030
import DevClean from './commands/app/dev/clean.js'
3131
import AppUnlinkedCommand from './utilities/app-unlinked-command.js'
3232
import FunctionInfo from './commands/app/function/info.js'
33+
import ImportDefinitions from './commands/app/data/import-definitions.js'
3334

3435
/**
3536
* All app commands should extend AppCommand.
@@ -60,6 +61,7 @@ export const commands: {[key: string]: typeof AppLinkedCommand | typeof AppUnlin
6061
'app:generate:extension': AppGenerateExtension,
6162
'app:versions:list': VersionsList,
6263
'app:webhook:trigger': WebhookTrigger,
64+
'app:data:import-definitions': ImportDefinitions,
6365
'webhook:trigger': WebhookTriggerDeprecated,
6466
'demo:watcher': DemoWatcher,
6567
}

packages/app/src/cli/services/generate/shop-import/declarative-definitions.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import {
77
MetaObject,
88
ValidationRule,
99
} from './dcdd.js'
10-
import {AppLinkedInterface} from '../../../models/app/app.js'
11-
import {RemoteAwareExtensionSpecification} from '../../../models/extensions/specification.js'
12-
import {Organization, OrganizationApp} from '../../../models/organization.js'
13-
import {DeveloperPlatformClient} from '../../../utilities/developer-platform-client.js'
14-
import {storeContext} from '../../store-context.js'
10+
import {OrganizationApp, OrganizationStore} from '../../../models/organization.js'
1511
import {
1612
MetafieldDefinitions,
1713
MetafieldForImportFragment,
@@ -40,11 +36,8 @@ import {isEmpty} from '@shopify/cli-kit/common/object'
4036
import {sleep} from '@shopify/cli-kit/node/system'
4137

4238
interface ImportDeclarativeDefinitionsOptions {
43-
app: AppLinkedInterface
4439
remoteApp: OrganizationApp
45-
developerPlatformClient: DeveloperPlatformClient
46-
organization: Organization
47-
specifications: RemoteAwareExtensionSpecification[]
40+
store: OrganizationStore
4841
}
4942

5043
interface ProcessNodesResult {
@@ -200,13 +193,8 @@ export function processDeclarativeDefinitionNodes(
200193
}
201194
}
202195

203-
async function _importDeclarativeDefinitions(options: ImportDeclarativeDefinitionsOptions) {
204-
const adminSession = await renderSingleTask({
205-
title: outputContent`Connecting to shop`,
206-
task: async () => {
207-
return createAdminApiSessionForShop(options)
208-
},
209-
})
196+
export async function importDeclarativeDefinitions(options: ImportDeclarativeDefinitionsOptions) {
197+
const adminSession = await createAdminApiSessionForShop(options)
210198
const shopName = adminSession.storeFqdn
211199

212200
const dcddOwnerToGraphQLMapping: {
@@ -365,18 +353,7 @@ type ConvertedMetafield =
365353
}
366354

367355
async function createAdminApiSessionForShop(options: ImportDeclarativeDefinitionsOptions) {
368-
const {app, remoteApp, developerPlatformClient, organization, specifications} = options
369-
370-
const store = await storeContext({
371-
appContextResult: {
372-
app,
373-
remoteApp,
374-
developerPlatformClient,
375-
organization,
376-
specifications,
377-
},
378-
forceReselectStore: false,
379-
})
356+
const {remoteApp, store} = options
380357

381358
const appSecrets = remoteApp.apiSecretKeys.map((secret) => secret.secret)
382359
const appSecret = appSecrets[0]

packages/cli/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [`shopify app build`](#shopify-app-build)
44
* [`shopify app config link`](#shopify-app-config-link)
55
* [`shopify app config use [config] [flags]`](#shopify-app-config-use-config-flags)
6+
* [`shopify app data import-definitions`](#shopify-app-data-import-definitions)
67
* [`shopify app deploy`](#shopify-app-deploy)
78
* [`shopify app dev`](#shopify-app-dev)
89
* [`shopify app dev clean`](#shopify-app-dev-clean)
@@ -167,6 +168,31 @@ DESCRIPTION
167168
be prompted to choose from the configuration files in your project.
168169
```
169170

171+
## `shopify app data import-definitions`
172+
173+
Import metafield and metaobject definitions.
174+
175+
```
176+
USAGE
177+
$ shopify app data import-definitions [--client-id <value> | -c <value>] [--no-color] [--path <value>] [--reset | ] [-s
178+
<value>] [--verbose]
179+
180+
FLAGS
181+
-c, --config=<value> The name of the app configuration.
182+
-s, --store=<value> Store URL. Must be an existing development or Shopify Plus sandbox store.
183+
--client-id=<value> The Client ID of your app.
184+
--no-color Disable color output.
185+
--path=<value> The path to your app directory.
186+
--reset Reset all your settings.
187+
--verbose Increase the verbosity of the output.
188+
189+
DESCRIPTION
190+
Import metafield and metaobject definitions.
191+
192+
Import metafield and metaobject definitions from your development store. "Read more about declarative custom data
193+
definitions" (https://shopify.dev/docs/apps/build/custom-data/declarative-custom-data-definitions).
194+
```
195+
170196
## `shopify app deploy`
171197

172198
Deploy your Shopify app.

0 commit comments

Comments
 (0)