Skip to content

Commit

Permalink
quick POC of an extension workflow registry
Browse files Browse the repository at this point in the history
  • Loading branch information
nickwesselman committed Dec 11, 2024
1 parent 3d8ce6a commit 85d8f54
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/app/src/cli/services/generate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {fetchExtensionTemplates} from './generate/fetch-template-specifications.js'
import {workflowRegistry} from './generate/workflows/registry.js'
import {DeveloperPlatformClient} from '../utilities/developer-platform-client.js'
import {AppInterface, AppLinkedInterface} from '../models/app/app.js'
import generateExtensionPrompts, {
Expand All @@ -23,7 +24,7 @@ import {AbortError} from '@shopify/cli-kit/node/error'
import {formatPackageManagerCommand} from '@shopify/cli-kit/node/output'
import {groupBy} from '@shopify/cli-kit/common/collection'

interface GenerateOptions {
export interface GenerateOptions {
app: AppLinkedInterface
specifications: RemoteAwareExtensionSpecification[]
remoteApp: OrganizationApp
Expand All @@ -50,6 +51,12 @@ async function generate(options: GenerateOptions) {
const generateExtensionOptions = buildGenerateOptions(promptAnswers, app, options, developerPlatformClient)
const generatedExtension = await generateExtensionTemplate(generateExtensionOptions)

const workflow = workflowRegistry[generatedExtension.extensionTemplate.identifier]
await workflow?.afterGenerate({
generateOptions: options,
extensionTemplateOptions: generateExtensionOptions,
})

renderSuccessMessage(generatedExtension, app.packageManager)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Workflow} from './registry.js'

export const editorExtensionCollection: Workflow = {
afterGenerate: async (options) => {

Check failure on line 4 in packages/app/src/cli/services/generate/workflows/editor-extension-collection.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/generate/workflows/editor-extension-collection.ts#L4

[@typescript-eslint/no-unused-vars] 'options' is defined but never used. Allowed unused args must match /^_/u.
console.log('hello world')

Check failure on line 5 in packages/app/src/cli/services/generate/workflows/editor-extension-collection.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/generate/workflows/editor-extension-collection.ts#L5

[no-console] Unexpected console statement.
},
}
20 changes: 20 additions & 0 deletions packages/app/src/cli/services/generate/workflows/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {editorExtensionCollection} from './editor-extension-collection.js'
import {GenerateOptions} from '../../generate.js'
import {GenerateExtensionTemplateOptions} from '../../generate/extension.js'

interface AfterGenerateOptions {
generateOptions: GenerateOptions
extensionTemplateOptions: GenerateExtensionTemplateOptions
}

export interface Workflow {
afterGenerate: (options: AfterGenerateOptions) => Promise<void>
}

interface WorkflowRegistry {
[key: string]: Workflow
}

export const workflowRegistry: WorkflowRegistry = {
editor_extension_collection: editorExtensionCollection,
}

0 comments on commit 85d8f54

Please sign in to comment.