Skip to content

Commit 2f3ae6c

Browse files
committed
shopify app import-custom-data-definitions
1 parent b44cf4a commit 2f3ae6c

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
@@ -1887,6 +1887,116 @@
18871887
"category": "app",
18881888
"related": []
18891889
},
1890+
{
1891+
"name": "app import-custom-data-definitions",
1892+
"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).",
1893+
"overviewPreviewDescription": "Import metafield and metaobject definitions.",
1894+
"type": "command",
1895+
"isVisualComponent": false,
1896+
"defaultExample": {
1897+
"codeblock": {
1898+
"tabs": [
1899+
{
1900+
"title": "app import-custom-data-definitions",
1901+
"code": "shopify app import-custom-data-definitions [flags]",
1902+
"language": "bash"
1903+
}
1904+
],
1905+
"title": "app import-custom-data-definitions"
1906+
}
1907+
},
1908+
"definitions": [
1909+
{
1910+
"title": "Flags",
1911+
"description": "The following flags are available for the `app import-custom-data-definitions` command:",
1912+
"type": "appimportcustomdatadefinitions",
1913+
"typeDefinitions": {
1914+
"appimportcustomdatadefinitions": {
1915+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1916+
"name": "appimportcustomdatadefinitions",
1917+
"description": "",
1918+
"members": [
1919+
{
1920+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1921+
"syntaxKind": "PropertySignature",
1922+
"name": "--client-id <value>",
1923+
"value": "string",
1924+
"description": "The Client ID of your app.",
1925+
"isOptional": true,
1926+
"environmentValue": "SHOPIFY_FLAG_CLIENT_ID"
1927+
},
1928+
{
1929+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1930+
"syntaxKind": "PropertySignature",
1931+
"name": "--include-existing",
1932+
"value": "\"\"",
1933+
"description": "Include existing declared definitions in the output.",
1934+
"isOptional": true,
1935+
"environmentValue": "SHOPIFY_FLAG_INCLUDE_EXISTING"
1936+
},
1937+
{
1938+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1939+
"syntaxKind": "PropertySignature",
1940+
"name": "--no-color",
1941+
"value": "\"\"",
1942+
"description": "Disable color output.",
1943+
"isOptional": true,
1944+
"environmentValue": "SHOPIFY_FLAG_NO_COLOR"
1945+
},
1946+
{
1947+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1948+
"syntaxKind": "PropertySignature",
1949+
"name": "--path <value>",
1950+
"value": "string",
1951+
"description": "The path to your app directory.",
1952+
"isOptional": true,
1953+
"environmentValue": "SHOPIFY_FLAG_PATH"
1954+
},
1955+
{
1956+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1957+
"syntaxKind": "PropertySignature",
1958+
"name": "--reset",
1959+
"value": "\"\"",
1960+
"description": "Reset all your settings.",
1961+
"isOptional": true,
1962+
"environmentValue": "SHOPIFY_FLAG_RESET"
1963+
},
1964+
{
1965+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1966+
"syntaxKind": "PropertySignature",
1967+
"name": "--verbose",
1968+
"value": "\"\"",
1969+
"description": "Increase the verbosity of the output.",
1970+
"isOptional": true,
1971+
"environmentValue": "SHOPIFY_FLAG_VERBOSE"
1972+
},
1973+
{
1974+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1975+
"syntaxKind": "PropertySignature",
1976+
"name": "-c, --config <value>",
1977+
"value": "string",
1978+
"description": "The name of the app configuration.",
1979+
"isOptional": true,
1980+
"environmentValue": "SHOPIFY_FLAG_APP_CONFIG"
1981+
},
1982+
{
1983+
"filePath": "docs-shopify.dev/commands/interfaces/app-import-custom-data-definitions.interface.ts",
1984+
"syntaxKind": "PropertySignature",
1985+
"name": "-s, --store <value>",
1986+
"value": "string",
1987+
"description": "Store URL. Must be an existing development or Shopify Plus sandbox store.",
1988+
"isOptional": true,
1989+
"environmentValue": "SHOPIFY_FLAG_STORE"
1990+
}
1991+
],
1992+
"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}"
1993+
}
1994+
}
1995+
}
1996+
],
1997+
"category": "app",
1998+
"related": []
1999+
},
18902000
{
18912001
"name": "app import-extensions",
18922002
"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
@@ -17,6 +17,7 @@
1717
* [`shopify app function schema`](#shopify-app-function-schema)
1818
* [`shopify app function typegen`](#shopify-app-function-typegen)
1919
* [`shopify app generate extension`](#shopify-app-generate-extension)
20+
* [`shopify app import-custom-data-definitions`](#shopify-app-import-custom-data-definitions)
2021
* [`shopify app import-extensions`](#shopify-app-import-extensions)
2122
* [`shopify app info`](#shopify-app-info)
2223
* [`shopify app init`](#shopify-app-init)
@@ -578,6 +579,32 @@ DESCRIPTION
578579
refer to "App structure" (https://shopify.dev/docs/apps/tools/cli/structure) and the documentation for your extension.
579580
```
580581

582+
## `shopify app import-custom-data-definitions`
583+
584+
Import metafield and metaobject definitions.
585+
586+
```
587+
USAGE
588+
$ shopify app import-custom-data-definitions [--client-id <value> | -c <value>] [--include-existing] [--no-color] [--path <value>]
589+
[--reset | ] [-s <value>] [--verbose]
590+
591+
FLAGS
592+
-c, --config=<value> The name of the app configuration.
593+
-s, --store=<value> Store URL. Must be an existing development or Shopify Plus sandbox store.
594+
--client-id=<value> The Client ID of your app.
595+
--include-existing Include existing declared definitions in the output.
596+
--no-color Disable color output.
597+
--path=<value> The path to your app directory.
598+
--reset Reset all your settings.
599+
--verbose Increase the verbosity of the output.
600+
601+
DESCRIPTION
602+
Import metafield and metaobject definitions.
603+
604+
Import metafield and metaobject definitions from your development store. "Read more about declarative custom data
605+
definitions" (https://shopify.dev/docs/apps/build/custom-data/declarative-custom-data-definitions).
606+
```
607+
581608
## `shopify app import-extensions`
582609

583610
Import dashboard-managed extensions into your app.

0 commit comments

Comments
 (0)