Skip to content

Commit

Permalink
Merge pull request #237 from jaredwray/handing-build-output-path
Browse files Browse the repository at this point in the history
handing build output path
  • Loading branch information
jaredwray committed Jan 10, 2024
2 parents 5525220 + dc74fc8 commit a8d0991
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 36 deletions.
5 changes: 2 additions & 3 deletions src/writr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export default class Writr {
this.options.outputPath = consoleProcess.args.output;
}

console.log(consoleProcess);

switch (consoleProcess.command) {
case 'init': {
const isTypescript = fs.existsSync('./tsconfig.json') ?? false;
Expand All @@ -88,7 +86,8 @@ export default class Writr {
}

default: {
const builder = new WritrBuilder();
console.log(this.options);
const builder = new WritrBuilder(this.options);
await builder.build();
break;
}
Expand Down
54 changes: 21 additions & 33 deletions test/writr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ describe('writr', () => {
const writrHelpers = new WritrHelpers();
expect(writrHelpers.createDoc).toBeDefined();
});
it('if no parameters then it should build', async () => {
const writr = new Writr(defaultOptions);

const outputPath = './test/noparam-custom-site';
process.argv = ['node', 'writr', '-o', outputPath];
await writr.execute(process);
});
it('is a single page site or not', () => {
const writr = new Writr(defaultOptions);
const singlePageSite = 'test/fixtures/single-page-site';
Expand Down Expand Up @@ -149,20 +142,31 @@ describe('writr', () => {

describe('writr execute', () => {
it('should be able to execute with no parameters', async () => {
const writr = new Writr(defaultOptions);
const consoleLog = console.log;
let consoleMessage = '';
const buildOptions = new WritrOptions();
buildOptions.sitePath = 'test/fixtures/single-page-site';
buildOptions.outputPath = 'test/fixtures/single-page-site/dist';
buildOptions.templatePath = 'test/fixtures/template-example/';
const writr = new Writr(buildOptions);
process.argv = ['node', 'writr'];
await writr.execute(process);

console.log = message => {
if (typeof message === 'string' && message.includes('Build')) {
consoleMessage = message;
}
};
expect(fs.existsSync(buildOptions.outputPath)).toEqual(true);

fs.rmdirSync(buildOptions.outputPath, {recursive: true});
});
it('should be able to execute with output parameter', async () => {
const buildOptions = new WritrOptions();
buildOptions.sitePath = 'test/fixtures/single-page-site';
buildOptions.outputPath = 'test/fixtures/single-page-site/dist-foo';
buildOptions.templatePath = 'test/fixtures/template-example/';
const realOutputPath = 'test/fixtures/single-page-site/dist1';
const writr = new Writr(buildOptions);
process.argv = ['node', 'writr', '-o', realOutputPath];
await writr.execute(process);

expect(consoleMessage).toContain('Build');
console.log = consoleLog;
expect(fs.existsSync(realOutputPath)).toEqual(true);

fs.rmdirSync(realOutputPath, {recursive: true});
});
it('should init based on the init command', async () => {
const writr = new Writr(defaultOptions);
Expand All @@ -185,22 +189,6 @@ describe('writr execute', () => {
console.log = consoleLog;
}
});
it('should build based on the build command', async () => {
const writr = new Writr(defaultOptions);
const outputPath = './custom-site/dist';
const consoleLog = console.log;
let consoleMessage = '';
process.argv = ['node', 'writr', 'build', '-o', outputPath];
console.log = message => {
if (typeof message === 'string' && message.includes('Build')) {
consoleMessage = message;
}
};

await writr.execute(process);
expect(consoleMessage).toContain('Build');
console.log = consoleLog;
});
it('should print help command', async () => {
const writr = new Writr(defaultOptions);
const consoleLog = console.log;
Expand Down

0 comments on commit a8d0991

Please sign in to comment.