Skip to content

Commit 2c3d73f

Browse files
authored
Merge pull request #6658 from Shopify/shauns/11-24-shopify_app_data_import-definitions
shopify app import-custom-data-definitions
2 parents 3fda5d4 + 2f3ae6c commit 2c3d73f

File tree

10 files changed

+393
-0
lines changed

10 files changed

+393
-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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
* Include existing declared definitions in the output.
17+
* @environment SHOPIFY_FLAG_INCLUDE_EXISTING
18+
*/
19+
'--include-existing'?: ''
20+
21+
/**
22+
* Disable color output.
23+
* @environment SHOPIFY_FLAG_NO_COLOR
24+
*/
25+
'--no-color'?: ''
26+
27+
/**
28+
* The path to your app directory.
29+
* @environment SHOPIFY_FLAG_PATH
30+
*/
31+
'--path <value>'?: string
32+
33+
/**
34+
* Reset all your settings.
35+
* @environment SHOPIFY_FLAG_RESET
36+
*/
37+
'--reset'?: ''
38+
39+
/**
40+
* Store URL. Must be an existing development or Shopify Plus sandbox store.
41+
* @environment SHOPIFY_FLAG_STORE
42+
*/
43+
'-s, --store <value>'?: string
44+
45+
/**
46+
* Increase the verbosity of the output.
47+
* @environment SHOPIFY_FLAG_VERBOSE
48+
*/
49+
'--verbose'?: ''
50+
}

docs-shopify.dev/generated/generated_docs_data.json

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,116 @@
17501750
"category": "app",
17511751
"related": []
17521752
},
1753+
{
1754+
"name": "app import-custom-data-definitions",
1755+
"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).",
1756+
"overviewPreviewDescription": "Import metafield and metaobject definitions.",
1757+
"type": "command",
1758+
"isVisualComponent": false,
1759+
"defaultExample": {
1760+
"codeblock": {
1761+
"tabs": [
1762+
{
1763+
"title": "app import-custom-data-definitions",
1764+
"code": "shopify app import-custom-data-definitions [flags]",
1765+
"language": "bash"
1766+
}
1767+
],
1768+
"title": "app import-custom-data-definitions"
1769+
}
1770+
},
1771+
"definitions": [
1772+
{
1773+
"title": "Flags",
1774+
"description": "The following flags are available for the `app import-custom-data-definitions` command:",
1775+
"type": "appimportcustomdatadefinitions",
1776+
"typeDefinitions": {
1777+
"appimportcustomdatadefinitions": {
1778+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1779+
"name": "appimportcustomdatadefinitions",
1780+
"description": "",
1781+
"members": [
1782+
{
1783+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1784+
"syntaxKind": "PropertySignature",
1785+
"name": "--client-id <value>",
1786+
"value": "string",
1787+
"description": "The Client ID of your app.",
1788+
"isOptional": true,
1789+
"environmentValue": "SHOPIFY_FLAG_CLIENT_ID"
1790+
},
1791+
{
1792+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1793+
"syntaxKind": "PropertySignature",
1794+
"name": "--include-existing",
1795+
"value": "\"\"",
1796+
"description": "Include existing declared definitions in the output.",
1797+
"isOptional": true,
1798+
"environmentValue": "SHOPIFY_FLAG_INCLUDE_EXISTING"
1799+
},
1800+
{
1801+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1802+
"syntaxKind": "PropertySignature",
1803+
"name": "--no-color",
1804+
"value": "\"\"",
1805+
"description": "Disable color output.",
1806+
"isOptional": true,
1807+
"environmentValue": "SHOPIFY_FLAG_NO_COLOR"
1808+
},
1809+
{
1810+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1811+
"syntaxKind": "PropertySignature",
1812+
"name": "--path <value>",
1813+
"value": "string",
1814+
"description": "The path to your app directory.",
1815+
"isOptional": true,
1816+
"environmentValue": "SHOPIFY_FLAG_PATH"
1817+
},
1818+
{
1819+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1820+
"syntaxKind": "PropertySignature",
1821+
"name": "--reset",
1822+
"value": "\"\"",
1823+
"description": "Reset all your settings.",
1824+
"isOptional": true,
1825+
"environmentValue": "SHOPIFY_FLAG_RESET"
1826+
},
1827+
{
1828+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1829+
"syntaxKind": "PropertySignature",
1830+
"name": "--verbose",
1831+
"value": "\"\"",
1832+
"description": "Increase the verbosity of the output.",
1833+
"isOptional": true,
1834+
"environmentValue": "SHOPIFY_FLAG_VERBOSE"
1835+
},
1836+
{
1837+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1838+
"syntaxKind": "PropertySignature",
1839+
"name": "-c, --config <value>",
1840+
"value": "string",
1841+
"description": "The name of the app configuration.",
1842+
"isOptional": true,
1843+
"environmentValue": "SHOPIFY_FLAG_APP_CONFIG"
1844+
},
1845+
{
1846+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1847+
"syntaxKind": "PropertySignature",
1848+
"name": "-s, --store <value>",
1849+
"value": "string",
1850+
"description": "Store URL. Must be an existing development or Shopify Plus sandbox store.",
1851+
"isOptional": true,
1852+
"environmentValue": "SHOPIFY_FLAG_STORE"
1853+
}
1854+
],
1855+
"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 * Include existing declared definitions in the output.\n * @environment SHOPIFY_FLAG_INCLUDE_EXISTING\n */\n '--include-existing'?: ''\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}"
1856+
}
1857+
}
1858+
}
1859+
],
1860+
"category": "app",
1861+
"related": []
1862+
},
17531863
{
17541864
"name": "app import-extensions",
17551865
"description": "Import dashboard-managed extensions into your app.",
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
'include-existing': Flags.boolean({
30+
description: 'Include existing declared definitions in the output.',
31+
default: false,
32+
env: 'SHOPIFY_FLAG_INCLUDE_EXISTING',
33+
}),
34+
}
35+
36+
public async run(): Promise<AppLinkedCommandOutput> {
37+
const {appContextResult, ...options} = await renderSingleTask({
38+
title: outputContent`Loading application`,
39+
task: async () => {
40+
const {flags} = await this.parse(ImportCustomDataDefinitions)
41+
42+
await checkFolderIsValidApp(flags.path)
43+
44+
const appContextResult = await linkedAppContext({
45+
directory: flags.path,
46+
clientId: flags['client-id'],
47+
forceRelink: flags.reset,
48+
userProvidedConfigName: flags.config,
49+
})
50+
const store = await storeContext({
51+
appContextResult,
52+
storeFqdn: flags.store,
53+
forceReselectStore: flags.reset,
54+
})
55+
56+
return {
57+
appContextResult,
58+
appConfiguration: appContextResult.app.configuration,
59+
remoteApp: appContextResult.remoteApp,
60+
store,
61+
includeExistingDeclaredDefinitions: flags['include-existing'],
62+
}
63+
},
64+
})
65+
await importDeclarativeDefinitions(options)
66+
67+
return {app: appContextResult.app}
68+
}
69+
}

packages/app/src/cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import AppLinkedCommand from './utilities/app-linked-command.js'
3333
import DevClean from './commands/app/dev/clean.js'
3434
import AppUnlinkedCommand from './utilities/app-unlinked-command.js'
3535
import FunctionInfo from './commands/app/function/info.js'
36+
import ImportCustomDataDefinitions from './commands/app/import-custom-data-definitions.js'
3637

3738
/**
3839
* All app commands should extend AppCommand.
@@ -45,6 +46,7 @@ export const commands: {[key: string]: typeof AppLinkedCommand | typeof AppUnlin
4546
'app:dev:clean': DevClean,
4647
'app:logs': Logs,
4748
'app:logs:sources': Sources,
49+
'app:import-custom-data-definitions': ImportCustomDataDefinitions,
4850
'app:import-extensions': ImportExtensions,
4951
'app:info': AppInfo,
5052
'app:init': Init,

packages/cli/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [`shopify app function schema`](#shopify-app-function-schema)
1717
* [`shopify app function typegen`](#shopify-app-function-typegen)
1818
* [`shopify app generate extension`](#shopify-app-generate-extension)
19+
* [`shopify app import-custom-data-definitions`](#shopify-app-import-custom-data-definitions)
1920
* [`shopify app import-extensions`](#shopify-app-import-extensions)
2021
* [`shopify app info`](#shopify-app-info)
2122
* [`shopify app init`](#shopify-app-init)
@@ -548,6 +549,32 @@ DESCRIPTION
548549
refer to "App structure" (https://shopify.dev/docs/apps/tools/cli/structure) and the documentation for your extension.
549550
```
550551

552+
## `shopify app import-custom-data-definitions`
553+
554+
Import metafield and metaobject definitions.
555+
556+
```
557+
USAGE
558+
$ shopify app import-custom-data-definitions [--client-id <value> | -c <value>] [--include-existing] [--no-color] [--path <value>]
559+
[--reset | ] [-s <value>] [--verbose]
560+
561+
FLAGS
562+
-c, --config=<value> The name of the app configuration.
563+
-s, --store=<value> Store URL. Must be an existing development or Shopify Plus sandbox store.
564+
--client-id=<value> The Client ID of your app.
565+
--include-existing Include existing declared definitions in the output.
566+
--no-color Disable color output.
567+
--path=<value> The path to your app directory.
568+
--reset Reset all your settings.
569+
--verbose Increase the verbosity of the output.
570+
571+
DESCRIPTION
572+
Import metafield and metaobject definitions.
573+
574+
Import metafield and metaobject definitions from your development store. "Read more about declarative custom data
575+
definitions" (https://shopify.dev/docs/apps/build/custom-data/declarative-custom-data-definitions).
576+
```
577+
551578
## `shopify app import-extensions`
552579

553580
Import dashboard-managed extensions into your app.

0 commit comments

Comments
 (0)