From 74400de558de703a0b2412ca5e14595f8df6d351 Mon Sep 17 00:00:00 2001 From: Jared Wray Date: Sun, 10 Dec 2023 09:51:46 -0800 Subject: [PATCH] adding in templatePath option --- src/console.ts | 21 +++++++++++++++------ src/writr.ts | 4 ++-- test/console.test.ts | 15 +++++++++++---- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/console.ts b/src/console.ts index e62b322..69eb42c 100644 --- a/src/console.ts +++ b/src/console.ts @@ -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'); @@ -79,7 +80,8 @@ export class WritrConsole { public getArguments(argv: string[]): WritrConsoleArguments { const args = { - site: '', + sitePath: '', + templatePath: '', output: '', watch: false, port: 3000, @@ -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; } } @@ -129,7 +137,8 @@ type WritrConsoleProcess = { }; type WritrConsoleArguments = { - site: string | undefined; + sitePath: string | undefined; + templatePath: string | undefined; output: string | undefined; watch: boolean; port: number; diff --git a/src/writr.ts b/src/writr.ts index 08ef49b..70a2e7f 100644 --- a/src/writr.ts +++ b/src/writr.ts @@ -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) { diff --git a/test/console.test.ts b/test/console.test.ts index e76c4f0..b8bedb6 100644 --- a/test/console.test.ts +++ b/test/console.test.ts @@ -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'];