Skip to content

Commit

Permalink
extension collection workflow working
Browse files Browse the repository at this point in the history
  • Loading branch information
nickwesselman authored and devisscher committed Dec 12, 2024
1 parent 99f3a0f commit 7192936
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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)
},
}

0 comments on commit 7192936

Please sign in to comment.