diff --git a/messages/webapp.generate.md b/messages/webapp.generate.md index 8aaa4db..920cd48 100644 --- a/messages/webapp.generate.md +++ b/messages/webapp.generate.md @@ -26,11 +26,11 @@ Run in interactive wizard mode - Create an empty web app: - <%= config.bin %> <%= command.id %> --name "myWebApp" --label "My first Web App" + <%= config.bin %> <%= command.id %> --name "myWebApp" --label "My first Web App -- Create a web app with a specific template: +- Create a web app using the vibe-coding-starter template: - <%= config.bin %> <%= command.id %> --name "myWebApp" --label "My Web App" --template "React app starter" + <%= config.bin %> <%= command.id %> --name "myWebApp" --label "My Web App" --template "vibe-coding-starter" - Create a web app using the wizard: diff --git a/src/commands/webapp/generate.ts b/src/commands/webapp/generate.ts index e0801c2..9e0f928 100644 --- a/src/commands/webapp/generate.ts +++ b/src/commands/webapp/generate.ts @@ -14,8 +14,11 @@ * limitations under the License. */ -import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; +import { execSync } from 'node:child_process'; +import { existsSync } from 'node:fs'; +import { resolve } from 'node:path'; import { Messages } from '@salesforce/core'; +import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const messages = Messages.loadMessages('@salesforce/plugin-webapp', 'webapp.generate'); @@ -64,20 +67,47 @@ export default class WebappGenerate extends SfCommand { this.log(`Template: ${flags.template}`); this.log(`Wizard mode: ${flags.wizard}`); - // TODO: Implement web app generation logic - // This would typically involve: - // 1. Creating webapp.json configuration - // 2. Setting up SFDX project structure - // 3. Generating metadata files - // 4. Creating necessary bundle structure + const template = flags.template ?? 'empty'; + + // Clone vibe-coding-starter repository if template is specified + if (template === 'vibe-coding-starter') { + const repoUrl = 'https://github.com/salesforce-experience-platform-emu/vibe-coding-starter'; + const directory = resolve(flags.name); + this.cloneRepository(repoUrl, directory); + } else { + // TODO: Implement web app generation logic for other templates + // This would typically involve: + // 1. Creating webapp.json configuration + // 2. Setting up SFDX project structure + // 3. Generating metadata files + // 4. Creating necessary bundle structure + } this.log('Your Web App has been created, have fun!'); return { name: flags.name, label: flags.label, - template: flags.template ?? 'empty', + template, wizard: flags.wizard, }; } + + protected cloneRepository(repoUrl: string, directory: string): void { + if (existsSync(directory)) { + throw new Error(`Directory ${directory} already exists. Please choose a different name.`); + } + + const templateRepo = `git clone ${repoUrl}`; + this.log(`Cloning ${repoUrl} into ${directory}...`); + try { + execSync(`${templateRepo} "${directory}"`, { + stdio: 'inherit', + cwd: process.cwd(), + }); + this.log(`Successfully cloned ${repoUrl} into ${directory}`); + } catch (error) { + throw new Error(`Failed to clone repository: ${error instanceof Error ? error.message : String(error)}`); + } + } } diff --git a/test/commands/webapp/generate.nut.ts b/test/commands/webapp/generate.nut.ts index e639f74..af85935 100644 --- a/test/commands/webapp/generate.nut.ts +++ b/test/commands/webapp/generate.nut.ts @@ -35,4 +35,14 @@ describe('webapp generate NUTs', () => { expect(output).to.contain(name); expect(output).to.contain(label); }); + + it('should clone vibe-coding-starter repository', () => { + const name = `test-vibe-${Date.now()}`; + const label = 'Test Vibe App'; + const command = `webapp generate --name ${name} --label "${label}" --template vibe-coding-starter`; + const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout; + expect(output).to.contain(name); + expect(output).to.contain('Cloning'); + expect(output).to.contain('vibe-coding-starter'); + }); }); diff --git a/test/commands/webapp/generate.test.ts b/test/commands/webapp/generate.test.ts index 835a8ef..e20ce5a 100644 --- a/test/commands/webapp/generate.test.ts +++ b/test/commands/webapp/generate.test.ts @@ -67,4 +67,28 @@ describe('webapp generate', () => { expect(output).to.include('Generating your web app'); expect(output).to.include('Your Web App has been created'); }); + + describe('vibe-coding-starter template', () => { + it('sets template to vibe-coding-starter when specified', async () => { + const uniqueName = `testVibeApp-${Date.now()}`; + const result = await WebappGenerate.run([ + '--name', + uniqueName, + '--label', + 'Test Vibe App', + '--template', + 'vibe-coding-starter', + ]); + + expect(result.template).to.equal('vibe-coding-starter'); + expect(result.name).to.equal(uniqueName); + }); + + it('sets template to vibe when vibe alias is used', async () => { + const uniqueName = `testVibeApp-${Date.now()}-vibe`; + const result = await WebappGenerate.run(['--name', uniqueName, '--label', 'Test Vibe App', '--template', 'vibe']); + + expect(result.template).to.equal('vibe'); + }); + }); });