Skip to content

Commit 1a20071

Browse files
committed
shopify app import-custom-data-definitions
1 parent ac99e52 commit 1a20071

File tree

10 files changed

+363
-0
lines changed

10 files changed

+363
-0
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 import-custom-data-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 import-custom-data-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 import-custom-data-definitions',
15+
code: './examples/app-import-custom-data-definitions.example.sh',
16+
language: 'bash',
17+
},
18+
],
19+
title: 'app import-custom-data-definitions',
20+
},
21+
},
22+
definitions: [
23+
{
24+
title: 'Flags',
25+
description: 'The following flags are available for the `app import-custom-data-definitions` command:',
26+
type: 'appimportcustomdatadefinitions',
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 import-custom-data-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 appimportcustomdatadefinitions {
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
@@ -1658,6 +1658,107 @@
16581658
"category": "app",
16591659
"related": []
16601660
},
1661+
{
1662+
"name": "app import-custom-data-definitions",
1663+
"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).",
1664+
"overviewPreviewDescription": "Import metafield and metaobject definitions.",
1665+
"type": "command",
1666+
"isVisualComponent": false,
1667+
"defaultExample": {
1668+
"codeblock": {
1669+
"tabs": [
1670+
{
1671+
"title": "app import-custom-data-definitions",
1672+
"code": "shopify app import-custom-data-definitions [flags]",
1673+
"language": "bash"
1674+
}
1675+
],
1676+
"title": "app import-custom-data-definitions"
1677+
}
1678+
},
1679+
"definitions": [
1680+
{
1681+
"title": "Flags",
1682+
"description": "The following flags are available for the `app import-custom-data-definitions` command:",
1683+
"type": "appimportcustomdatadefinitions",
1684+
"typeDefinitions": {
1685+
"appimportcustomdatadefinitions": {
1686+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1687+
"name": "appimportcustomdatadefinitions",
1688+
"description": "",
1689+
"members": [
1690+
{
1691+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1692+
"syntaxKind": "PropertySignature",
1693+
"name": "--client-id <value>",
1694+
"value": "string",
1695+
"description": "The Client ID of your app.",
1696+
"isOptional": true,
1697+
"environmentValue": "SHOPIFY_FLAG_CLIENT_ID"
1698+
},
1699+
{
1700+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1701+
"syntaxKind": "PropertySignature",
1702+
"name": "--no-color",
1703+
"value": "\"\"",
1704+
"description": "Disable color output.",
1705+
"isOptional": true,
1706+
"environmentValue": "SHOPIFY_FLAG_NO_COLOR"
1707+
},
1708+
{
1709+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1710+
"syntaxKind": "PropertySignature",
1711+
"name": "--path <value>",
1712+
"value": "string",
1713+
"description": "The path to your app directory.",
1714+
"isOptional": true,
1715+
"environmentValue": "SHOPIFY_FLAG_PATH"
1716+
},
1717+
{
1718+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1719+
"syntaxKind": "PropertySignature",
1720+
"name": "--reset",
1721+
"value": "\"\"",
1722+
"description": "Reset all your settings.",
1723+
"isOptional": true,
1724+
"environmentValue": "SHOPIFY_FLAG_RESET"
1725+
},
1726+
{
1727+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1728+
"syntaxKind": "PropertySignature",
1729+
"name": "--verbose",
1730+
"value": "\"\"",
1731+
"description": "Increase the verbosity of the output.",
1732+
"isOptional": true,
1733+
"environmentValue": "SHOPIFY_FLAG_VERBOSE"
1734+
},
1735+
{
1736+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1737+
"syntaxKind": "PropertySignature",
1738+
"name": "-c, --config <value>",
1739+
"value": "string",
1740+
"description": "The name of the app configuration.",
1741+
"isOptional": true,
1742+
"environmentValue": "SHOPIFY_FLAG_APP_CONFIG"
1743+
},
1744+
{
1745+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1746+
"syntaxKind": "PropertySignature",
1747+
"name": "-s, --store <value>",
1748+
"value": "string",
1749+
"description": "Store URL. Must be an existing development or Shopify Plus sandbox store.",
1750+
"isOptional": true,
1751+
"environmentValue": "SHOPIFY_FLAG_STORE"
1752+
}
1753+
],
1754+
"value": "export interface appimportcustomdatadefinitions {\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}"
1755+
}
1756+
}
1757+
}
1758+
],
1759+
"category": "app",
1760+
"related": []
1761+
},
16611762
{
16621763
"name": "app import-extensions",
16631764
"description": "Import dashboard-managed extensions into your app.",
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 ImportCustomDataDefinitions 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(ImportCustomDataDefinitions)
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 ImportCustomDataDefinitions from './commands/app/import-custom-data-definitions.js'
3334

3435
/**
3536
* All app commands should extend AppCommand.
@@ -41,6 +42,7 @@ export const commands: {[key: string]: typeof AppLinkedCommand | typeof AppUnlin
4142
'app:dev:clean': DevClean,
4243
'app:logs': Logs,
4344
'app:logs:sources': Sources,
45+
'app:import-custom-data-definitions': ImportCustomDataDefinitions,
4446
'app:import-extensions': ImportExtensions,
4547
'app:info': AppInfo,
4648
'app:init': Init,

packages/cli/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [`shopify app function schema`](#shopify-app-function-schema)
1616
* [`shopify app function typegen`](#shopify-app-function-typegen)
1717
* [`shopify app generate extension`](#shopify-app-generate-extension)
18+
* [`shopify app import-custom-data-definitions`](#shopify-app-import-custom-data-definitions)
1819
* [`shopify app import-extensions`](#shopify-app-import-extensions)
1920
* [`shopify app info`](#shopify-app-info)
2021
* [`shopify app init`](#shopify-app-init)
@@ -522,6 +523,31 @@ DESCRIPTION
522523
refer to "App structure" (https://shopify.dev/docs/apps/tools/cli/structure) and the documentation for your extension.
523524
```
524525

526+
## `shopify app import-custom-data-definitions`
527+
528+
Import metafield and metaobject definitions.
529+
530+
```
531+
USAGE
532+
$ shopify app import-custom-data-definitions [--client-id <value> | -c <value>] [--no-color] [--path <value>] [--reset | ] [-s
533+
<value>] [--verbose]
534+
535+
FLAGS
536+
-c, --config=<value> The name of the app configuration.
537+
-s, --store=<value> Store URL. Must be an existing development or Shopify Plus sandbox store.
538+
--client-id=<value> The Client ID of your app.
539+
--no-color Disable color output.
540+
--path=<value> The path to your app directory.
541+
--reset Reset all your settings.
542+
--verbose Increase the verbosity of the output.
543+
544+
DESCRIPTION
545+
Import metafield and metaobject definitions.
546+
547+
Import metafield and metaobject definitions from your development store. "Read more about declarative custom data
548+
definitions" (https://shopify.dev/docs/apps/build/custom-data/declarative-custom-data-definitions).
549+
```
550+
525551
## `shopify app import-extensions`
526552

527553
Import dashboard-managed extensions into your app.

0 commit comments

Comments
 (0)