|
| 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