Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 34 additions & 39 deletions packages/pwa-kit-create-app/scripts/create-mobify-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,11 @@ const INITIAL_QUESTION = [

const askApplicationExtensibilityQuestions = (availableAppExtensions) => {
return [
{
name: 'project.useAppExtensibility',
message: 'Do you want to use Application Extensibility?',
type: 'confirm',
default: true
},
{
name: 'project.selectedAppExtensions',
message: 'Which Application Extensions do you want to install?',
type: 'checkbox',
choices: availableAppExtensions,
when: (answers) => answers.project.useAppExtensibility === true
choices: availableAppExtensions
},
{
name: 'project.extractAppExtensions',
Expand All @@ -161,8 +154,7 @@ const askApplicationExtensibilityQuestions = (availableAppExtensions) => {
'\n' +
'Do you want to proceed with extracting the Application Extensions code?',
type: 'confirm',
default: false,
when: (answers) => answers.project.useAppExtensibility === true
default: false
}
]
}
Expand Down Expand Up @@ -542,18 +534,6 @@ const PRESETS = [
}
]

const PRESET_QUESTIONS = [
{
name: 'general.presetId',
message: 'Choose a project preset to get started:',
type: 'list',
choices: PRESETS.filter(({private}) => !private).map(({shortDescription, id}) => ({
name: shortDescription,
value: id
}))
}
]

const ASSETS_TEMPLATES_DIR = p.join(__dirname, '..', 'assets', 'templates')

const PRIVATE_PRESET_NAMES = PRESETS.filter(({private}) => !!private).map(({id}) => id)
Expand Down Expand Up @@ -1112,8 +1092,17 @@ const main = async (opts) => {
if (initialAnswers.project.type === 'PWAKitAppExtensionProject') {
// Ask for extension name if Application Extension is selected
const extensionNameAnswers = await inquirer.prompt(APPLICATION_EXTENSION_QUESTIONS)
context.answers.project.name = extensionNameAnswers.project.extensionName
context.preset = PRESETS.find(({id}) => id === 'extension-starter')
const extensionName = extensionNameAnswers.project.extensionName

// Get the preset and set extension name in all required places
context.preset = {
...PRESETS.find(({id}) => id === 'extension-starter'),
answers: {
'project.type': 'PWAKitAppExtensionProject',
'project.name': extensionName,
'project.extensionName': extensionName
}
}
} else {
const availableAppExtensions = fetchAvailableAppExtensions()

Expand All @@ -1125,26 +1114,18 @@ const main = async (opts) => {
)
context = merge(context, {answers: expandObject(generationAnswers)})

if (context.answers.project.useAppExtensibility) {
// Add the 'typescript-minimal' preset for Application Extension
context.preset = PRESETS.find(({id}) => id === 'typescript-minimal')
}
// Default to 'typescript-minimal' preset when no preset is specified
context.preset = PRESETS.find(({id}) => id === 'typescript-minimal')
}
}

// If no preset is provided, prompt the user with available preset options
if (!presetId && !context.preset) {
context.answers = await prompt(PRESET_QUESTIONS)
// Set the preset based on presetId if provided
if (presetId && !context.preset) {
context.preset = PRESETS.find(({id}) => id === presetId)
}

// Set the preset to the selected preset or based on presetId
const selectedPreset =
context.preset ||
PRESETS.find(({id}) => id === (presetId || context.answers.general.presetId))
context.preset = selectedPreset

// Ask preset specific questions and merge into the current context.
const {questions = {}, answers = {}} = selectedPreset
const {questions = {}, answers = {}} = context.preset
if (questions) {
const projectAnswers = await prompt(questions, answers)

Expand All @@ -1154,7 +1135,21 @@ const main = async (opts) => {
}

if (!OUTPUT_DIR_FLAG_ACTIVE) {
outputDir = p.join(process.cwd(), context.answers.project.name || selectedPreset.id)
// For extension projects, use the extension name as the output directory
if (
context.answers.project.type === 'PWAKitAppExtensionProject' &&
context.answers.project.extensionName
) {
// Extract the package name part without the namespace for the directory name
const extensionName = context.answers.project.extensionName
const packageNamePart = extensionName.includes('/')
? extensionName.split('/')[1]
: extensionName

outputDir = p.join(process.cwd(), packageNamePart)
} else {
outputDir = p.join(process.cwd(), context.answers.project.name || context.preset.id)
}
}

if (context.answers.project.commerce?.instanceUrl) {
Expand Down
1 change: 0 additions & 1 deletion packages/pwa-kit-extension-sdk/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ npx @salesforce/pwa-kit-create-app
During the generation process, you'll be presented with several configuration options, answer the questions as follows:

* What type of PWA Kit project would you like to create? **PWA Kit Application**
* Do you want to use Application Extensibility? **Yes**
* Which Application Extensions do you want to install? *(use arrow key to navigate, space to select and enter to confirm)*
* **@salesforce/extension-chakra-storefront**
* **@salesforce/extension-chakra-store-locator**
Expand Down
Loading