Skip to content

Commit 30421ab

Browse files
committed
Add new channel spec
1 parent c5eb8a5 commit 30421ab

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

packages/app/src/cli/models/extensions/load-specifications.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import themeSpec from './specifications/theme.js'
2525
import uiExtensionSpec from './specifications/ui_extension.js'
2626
import webPixelSpec from './specifications/web_pixel_extension.js'
2727
import editorExtensionCollectionSpecification from './specifications/editor_extension_collection.js'
28+
import channelSpecificationSpec from './specifications/channel.js'
2829

2930
const SORTED_CONFIGURATION_SPEC_IDENTIFIERS = [
3031
BrandingSpecIdentifier,
@@ -73,6 +74,7 @@ function loadSpecifications() {
7374
uiExtensionSpec,
7475
webPixelSpec,
7576
editorExtensionCollectionSpecification,
77+
channelSpecificationSpec,
7678
]
7779

7880
return [...configModuleSpecs, ...moduleSpecs] as ExtensionSpecification[]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {createExtensionSpecification} from '../specification.js'
2+
import {BaseSchemaWithHandle} from '../schemas.js'
3+
import {zod} from '@shopify/cli-kit/node/schema'
4+
import {glob} from '@shopify/cli-kit/node/fs'
5+
import {joinPath, relativePath} from '@shopify/cli-kit/node/path'
6+
7+
const ChannelSpecificationSchema = BaseSchemaWithHandle.extend({
8+
type: zod.literal('channel_config'),
9+
name: zod.string().optional(),
10+
channel_requirements: zod.any(),
11+
})
12+
13+
const SUBDIRECTORY_NAME = 'specifications'
14+
const FILE_EXTENSIONS = ['json', 'toml', 'yaml', 'yml']
15+
16+
// Generate glob patterns for all supported file types
17+
const getGlobPatterns = () => FILE_EXTENSIONS.map((ext) => joinPath(SUBDIRECTORY_NAME, '**', `*.${ext}`))
18+
19+
async function getSpecificationFiles(directory: string): Promise<string[]> {
20+
const patterns = getGlobPatterns()
21+
22+
const files = await glob(patterns, {
23+
absolute: true,
24+
cwd: directory,
25+
})
26+
27+
return files.map((file) => relativePath(directory, file))
28+
}
29+
30+
const channelSpecificationSpec = createExtensionSpecification({
31+
identifier: 'channel_config',
32+
schema: ChannelSpecificationSchema,
33+
buildConfig: {mode: 'copy_files', filePatterns: getGlobPatterns()},
34+
appModuleFeatures: () => [],
35+
deployConfig: async (config, directory) => {
36+
const specifications = await getSpecificationFiles(directory)
37+
return {
38+
handle: config.handle,
39+
name: config.name,
40+
specifications,
41+
channel_requirements: config.channel_requirements,
42+
}
43+
},
44+
})
45+
46+
export default channelSpecificationSpec

0 commit comments

Comments
 (0)