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 authored and devisscher committed Dec 12, 2024
1 parent ff688bd commit 3b81c76
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
24 changes: 8 additions & 16 deletions 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 @@ -24,7 +25,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 Down Expand Up @@ -75,25 +76,16 @@ async function generate(options: GenerateOptions) {
console.log('PROMPT ANSWERS', promptAnswers)

Check failure on line 76 in packages/app/src/cli/services/generate.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/app/src/cli/services/generate.ts#L76

[no-console] Unexpected console statement.
// Call module related to that child extension
await saveAnalyticsMetadata(promptAnswers, template)
// Here we could check if the user wants to add a related extension
const addPromptConfirmation = await promptAddExtensionConfirmation()

// We can add an extra generated extension here.
const generateExtensionOptions = buildGenerateOptions(promptAnswers, app, options, developerPlatformClient)
const generatedExtension = await generateExtensionTemplate(generateExtensionOptions)

// 1. Generate ui extension
// 2. We check the identifier
// 3. If the identifier has related extensions then the team who owns can add logic to add related extensions
// 4. This allows new prompts
// 4.1. Generate function settings
// 4.2. Function settings is meant to be used with a discount function, would you like us to generate one for you?
// 4.3. What is the name of your function?
// Generates both extensions
if (addPromptConfirmation) {
// Generate related extensions
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 3b81c76

Please sign in to comment.