Skip to content

Commit

Permalink
adding in templatePath option
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredwray committed Dec 10, 2023
1 parent 76dc8a8 commit 74400de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
21 changes: 15 additions & 6 deletions src/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export class WritrConsole {
console.log(' version Print the version');
console.log();
console.log(' Arguments Build:');
console.log(' -w, --watch watch for changes and rebuild');
console.log(' -s, --site Set the path where site files are located');
console.log(' -o, --output Set the output directory. Default is ./site/dist');
console.log(' -w, --watch watch for changes and rebuild');
console.log(' -s, --site Set the path where site files are located');
console.log(' -o, --outputPath Set the output directory. Default is ./site/dist');
console.log(' -t, --templatePath Set the custom template to use');
console.log();
console.log(' Arguments serve:');
console.log(' -p, --port Set the port number used with serve');
Expand Down Expand Up @@ -79,7 +80,8 @@ export class WritrConsole {

public getArguments(argv: string[]): WritrConsoleArguments {
const args = {
site: '',
sitePath: '',
templatePath: '',
output: '',
watch: false,
port: 3000,
Expand Down Expand Up @@ -112,7 +114,13 @@ export class WritrConsole {

case '-s':
case '--site': {
args.site = argv[i + 1];
args.sitePath = argv[i + 1];
break;
}

case '-t':
case '--templatePath': {
args.templatePath = argv[i + 1];
break;
}
}
Expand All @@ -129,7 +137,8 @@ type WritrConsoleProcess = {
};

type WritrConsoleArguments = {
site: string | undefined;
sitePath: string | undefined;
templatePath: string | undefined;
output: string | undefined;
watch: boolean;
port: number;
Expand Down
4 changes: 2 additions & 2 deletions src/writr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export default class Writr {
const consoleProcess = this._console.parseProcessArgv(process.argv);

// Update options
if (consoleProcess.args.site) {
this.options.sitePath = consoleProcess.args.site;
if (consoleProcess.args.sitePath) {
this.options.sitePath = consoleProcess.args.sitePath;
}

if (consoleProcess.args.output) {
Expand Down
15 changes: 11 additions & 4 deletions test/console.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,27 @@ describe('WritrConsole', () => {

const c = new WritrConsole();
c.printHelp();
expect(messages.length).toEqual(18);
expect(messages.length).toEqual(19);

console.log = consoleLog;
});
it('should be able to parse process argv', () => {
const c = new WritrConsole();
const result = c.parseProcessArgv(['node', 'writr', 'build', '-w', '-s', './site', '-o', './site/dist', '-p', '8080']);
expect(result.argv.length).toEqual(10);
const result = c.parseProcessArgv(['node', 'writr', 'build', '-w', '-s', './site', '-o', './site/dist', '-p', '8080', '-t', './site/template']);
expect(result.argv.length).toEqual(12);
expect(result.command).toEqual('build');
expect(result.args.watch).toEqual(true);
expect(result.args.site).toEqual('./site');
expect(result.args.templatePath).toEqual('./site/template');
expect(result.args.sitePath).toEqual('./site');
expect(result.args.output).toEqual('./site/dist');
expect(result.args.port).toEqual(8080);
});
it('should be able to parse process templatePath', () => {
const c = new WritrConsole();
const result = c.parseProcessArgv(['node', 'writr', 'build', '--templatePath', './site/dist', '-p', '8080']);
expect(result.command).toEqual('build');
expect(result.args.templatePath).toEqual('./site/dist');
});
it('should be able to parse serve', () => {
const c = new WritrConsole();
const commands = ['serve', 'build', 'help', 'version', 'init'];
Expand Down

0 comments on commit 74400de

Please sign in to comment.