Skip to content

Commit

Permalink
Merge pull request #504 from domsleee/cli-add-dist-error-message
Browse files Browse the repository at this point in the history
Add error message when --dist is not specified.
  • Loading branch information
tschaub committed Aug 11, 2023
2 parents 7cbfcb3 + 6c1c6ad commit 0019a20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 11 additions & 4 deletions bin/gh-pages.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/usr/bin/env node

const ghpages = require('../lib/index.js');
const program = require('commander');
const {Command} = require('commander');
const path = require('path');
const pkg = require('../package.json');
const addr = require('email-addresses');

function publish(config) {
function publish(program, config) {
return new Promise((resolve, reject) => {
if (program.dist === undefined) {
return reject(
new Error(
'No base directory specified. The `--dist` option must be specified.'
)
);
}
const basePath = path.resolve(process.cwd(), program.dist);
ghpages.publish(basePath, config, (err) => {
if (err) {
Expand All @@ -20,7 +27,7 @@ function publish(config) {

function main(args) {
return Promise.resolve().then(() => {
program
const program = new Command()
.version(pkg.version)
.option('-d, --dist <dist>', 'Base directory for all source files')
.option(
Expand Down Expand Up @@ -125,7 +132,7 @@ function main(args) {
beforeAdd: beforeAdd,
};

return publish(config);
return publish(program, config);
});
}

Expand Down
5 changes: 5 additions & 0 deletions test/bin/gh-pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ describe('gh-pages', () => {
error:
'Could not parse name and email from user option "junk email" (format should be "Your Name <email@example.com>")',
},
{
args: ['.'],
error:
'No base directory specified. The `--dist` option must be specified.',
},
];

scenarios.forEach(({args, dist, config, error}) => {
Expand Down

0 comments on commit 0019a20

Please sign in to comment.