Skip to content

Commit

Permalink
feat: add nut template
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 7, 2022
1 parent 863f0f3 commit 78a993c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/generators/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,24 @@ export default class Command extends Generator {
public writing(): void {
this.writeCmdFile();
this.writeMessageFile();
// TODO: this.writeNutFile();
this.writeNutFile();
}

private getMessageFileName(): string {
return this.options.name.replace(/:/g, '.');
}

private writeCmdFile(): void {
const cmdPath = this.options.name.split(':').join('/');
this.sourceRoot(path.join(__dirname, '../../templates'));
const cmdPath = this.options.name.split(':').join('/');
const commandPath = this.destinationPath(`src/commands/${cmdPath}.ts`);
const className = pascalCase(this.options.name);
const year = new Date().getFullYear();
const opts = {
...this.options,
className,
returnType: `${className}Result`,
commandPath,
year,
year: new Date().getFullYear(),
pluginName: this.pjson.name,
messageFile: this.getMessageFileName(),
};
Expand All @@ -65,4 +64,17 @@ export default class Command extends Generator {
const messagePath = this.destinationPath(`messages/${filename}.md`);
this.fs.copyTpl(this.templatePath('messages/message.md.ejs'), messagePath, this.options);
}

private writeNutFile(): void {
this.sourceRoot(path.join(__dirname, '../../templates'));
const cmdPath = this.options.name.split(':').join('/');
const nutPah = this.destinationPath(`test/commands/${cmdPath}.nut.ts`);
const opts = {
cmd: this.options.name.split(':').join(' '),
year: new Date().getFullYear(),
pluginName: this.pjson.name,
messageFile: this.getMessageFileName(),
};
this.fs.copyTpl(this.templatePath('test/command.nut.ts.ejs'), nutPah, opts);
}
}
31 changes: 31 additions & 0 deletions templates/test/command.nut.ts.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) <%- year %>, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as path from 'path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { env } from '@salesforce/kit';
import { expect } from 'chai';

describe('<%- cmd %> NUTs', () => {
let session: TestSession;

before(async () => {
env.setString('TESTKIT_EXECUTABLE_PATH', path.join(process.cwd(), 'bin', 'dev'));
session = await TestSession.create({});
});

after(async () => {
await session?.clean();
});

it('should display provided name', () => {
const name = 'World';
const command = `<%- cmd %> --name ${name}`;
const output = execCmd(command, { ensureExitCode: 0, cli: 'sf' }).shellOutput.stdout;
expect(output).to.contain(name);
});
});

0 comments on commit 78a993c

Please sign in to comment.