Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message when --dist is not specified. #504

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 protected]>")',
},
{
args: ['.'],
error:
'No base directory specified. The `--dist` option must be specified.',
},
];

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