Skip to content
Closed
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
6 changes: 3 additions & 3 deletions messages/webapp.generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
46 changes: 38 additions & 8 deletions src/commands/webapp/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -64,20 +67,47 @@ export default class WebappGenerate extends SfCommand<WebappGenerateResult> {
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)}`);
}
}
}
10 changes: 10 additions & 0 deletions test/commands/webapp/generate.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
24 changes: 24 additions & 0 deletions test/commands/webapp/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
Loading