From dd3b1c50f085607e165c599728e8e3f9ea304a6d Mon Sep 17 00:00:00 2001 From: Nick Wesselman <27013789+nickwesselman@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:58:11 -0500 Subject: [PATCH] extension collection workflow working --- .../workflows/editor-extension-collection.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/app/src/cli/services/generate/workflows/editor-extension-collection.ts b/packages/app/src/cli/services/generate/workflows/editor-extension-collection.ts index 035ef42b3fb..a026e09af19 100644 --- a/packages/app/src/cli/services/generate/workflows/editor-extension-collection.ts +++ b/packages/app/src/cli/services/generate/workflows/editor-extension-collection.ts @@ -1,7 +1,8 @@ import {Workflow} from './registry.js' -import {patchAppConfigurationFile} from '../../app/patch-app-configuration-file.js' import {joinPath} from '@shopify/cli-kit/node/path' import {renderTextPrompt} from '@shopify/cli-kit/node/ui' +import {readFile, writeFile} from '@shopify/cli-kit/node/fs' +import {decodeToml, encodeToml} from '@shopify/cli-kit/node/toml' export const editorExtensionCollection: Workflow = { afterGenerate: async (options) => { @@ -13,14 +14,15 @@ export const editorExtensionCollection: Workflow = { const extensions = await renderTextPrompt({ message: `The extension handles to include in the collection, comma separated. Options: ${availableExtensions}`, }) - await patchAppConfigurationFile({ - path: joinPath(options.generatedExtension.directory, 'shopify.extension.toml'), - patch: { - extensions: { - includes: extensions.split(',').map((handle) => handle.trim()), - }, - }, - schema: options.generateOptions.app.configSchema, - }) + const tomlPath = joinPath(options.generatedExtension.directory, 'shopify.extension.toml') + const tomlContents = await readFile(tomlPath) + const configuration = decodeToml(tomlContents) + if (configuration.extensions && Array.isArray(configuration.extensions) && configuration.extensions.length > 0) { + ;(configuration.extensions[0] as {includes: string[]}).includes = extensions + .split(',') + .map((handle) => handle.trim()) + } + const encodedString = encodeToml(configuration) + await writeFile(tomlPath, encodedString) }, }