Comparing version
#!/usr/bin/env node | ||
const ghpages = require('../lib/index.js'); | ||
const program = require('commander'); | ||
const {Command} = require('commander'); | ||
const path = require('path'); | ||
@@ -9,5 +9,5 @@ const pkg = require('../package.json'); | ||
function publish(config) { | ||
function publish(dist, config) { | ||
return new Promise((resolve, reject) => { | ||
const basePath = path.resolve(process.cwd(), program.dist); | ||
const basePath = path.resolve(process.cwd(), dist); | ||
ghpages.publish(basePath, config, (err) => { | ||
@@ -24,5 +24,8 @@ if (err) { | ||
return Promise.resolve().then(() => { | ||
program | ||
const program = new Command() | ||
.version(pkg.version) | ||
.option('-d, --dist <dist>', 'Base directory for all source files') | ||
.requiredOption( | ||
'-d, --dist <dist>', | ||
'Base directory for all source files' | ||
) | ||
.option( | ||
@@ -53,2 +56,7 @@ '-s, --src <src>', | ||
.option('-t, --dotfiles', 'Include dotfiles') | ||
.option('--nojekyll', 'Add a .nojekyll file to disable Jekyll') | ||
.option( | ||
'--cname <CNAME>', | ||
'Add a CNAME file with the name of your custom domain' | ||
) | ||
.option('-r, --repo <repo>', 'URL of the repository you are pushing to') | ||
@@ -82,8 +90,10 @@ .option('-p, --depth <depth>', 'depth for clone', ghpages.defaults.depth) | ||
const options = program.opts(); | ||
let user; | ||
if (program.user) { | ||
const parts = addr.parseOneAddress(program.user); | ||
if (options.user) { | ||
const parts = addr.parseOneAddress(options.user); | ||
if (!parts) { | ||
throw new Error( | ||
`Could not parse name and email from user option "${program.user}" ` + | ||
`Could not parse name and email from user option "${options.user}" ` + | ||
'(format should be "Your Name <email@example.com>")' | ||
@@ -95,4 +105,4 @@ ); | ||
let beforeAdd; | ||
if (program.beforeAdd) { | ||
const m = require(require.resolve(program.beforeAdd, { | ||
if (options.beforeAdd) { | ||
const m = require(require.resolve(options.beforeAdd, { | ||
paths: [process.cwd()], | ||
@@ -108,3 +118,3 @@ })); | ||
`Could not find function to execute before adding files in ` + | ||
`"${program.beforeAdd}".\n ` | ||
`"${options.beforeAdd}".\n ` | ||
); | ||
@@ -115,17 +125,19 @@ } | ||
const config = { | ||
repo: program.repo, | ||
silent: !!program.silent, | ||
branch: program.branch, | ||
src: program.src, | ||
dest: program.dest, | ||
message: program.message, | ||
tag: program.tag, | ||
git: program.git, | ||
depth: program.depth, | ||
dotfiles: !!program.dotfiles, | ||
add: !!program.add, | ||
remove: program.remove, | ||
remote: program.remote, | ||
push: !!program.push, | ||
history: !!program.history, | ||
repo: options.repo, | ||
silent: !!options.silent, | ||
branch: options.branch, | ||
src: options.src, | ||
dest: options.dest, | ||
message: options.message, | ||
tag: options.tag, | ||
git: options.git, | ||
depth: options.depth, | ||
dotfiles: !!options.dotfiles, | ||
nojekyll: !!options.nojekyll, | ||
cname: options.cname, | ||
add: !!options.add, | ||
remove: options.remove, | ||
remote: options.remote, | ||
push: !!options.push, | ||
history: !!options.history, | ||
user: user, | ||
@@ -135,3 +147,3 @@ beforeAdd: beforeAdd, | ||
return publish(config); | ||
return publish(options.dist, config); | ||
}); | ||
@@ -146,3 +158,3 @@ } | ||
.catch((err) => { | ||
process.stderr.write(`${err.message}\n`, () => process.exit(1)); | ||
process.stderr.write(`${err.stack}\n`, () => process.exit(1)); | ||
}); | ||
@@ -149,0 +161,0 @@ } |
@@ -186,2 +186,10 @@ const findCacheDir = require('find-cache-dir'); | ||
.then((git) => { | ||
if (options.nojekyll) { | ||
log('Creating .nojekyll'); | ||
fs.createFileSync(path.join(git.cwd, '.nojekyll')); | ||
} | ||
if (options.cname) { | ||
log('Creating CNAME for %s', options.cname); | ||
fs.writeFileSync(path.join(git.cwd, 'CNAME'), options.cname); | ||
} | ||
log('Copying files'); | ||
@@ -188,0 +196,0 @@ return copy(files, basePath, path.join(git.cwd, options.dest)).then( |
{ | ||
"name": "gh-pages", | ||
"version": "5.0.0", | ||
"version": "6.1.1", | ||
"description": "Publish to a gh-pages branch on GitHub (or any other branch on any other remote)", | ||
@@ -38,7 +38,7 @@ "keywords": [ | ||
"async": "^3.2.4", | ||
"commander": "^2.18.0", | ||
"commander": "^11.0.0", | ||
"email-addresses": "^5.0.0", | ||
"filenamify": "^4.3.0", | ||
"find-cache-dir": "^3.3.1", | ||
"fs-extra": "^8.1.0", | ||
"fs-extra": "^11.1.1", | ||
"globby": "^6.1.0" | ||
@@ -52,3 +52,3 @@ }, | ||
"mocha": "^10.2.0", | ||
"sinon": "^15.0.1", | ||
"sinon": "^17.0.1", | ||
"tmp": "^0.2.1" | ||
@@ -55,0 +55,0 @@ }, |
@@ -12,3 +12,3 @@ | ||
This module requires Git >= 1.9 and Node >= 12. | ||
This module requires Git >= 1.9 and Node > 14. | ||
@@ -68,3 +68,3 @@ ## Basic Usage | ||
The default options work for simple cases. The options described below let you push to alternate branches, customize your commit messages, and more. | ||
The default options work for simple cases. The options described below let you push to alternate branches, customize your commit messages and more. | ||
@@ -76,3 +76,3 @@ | ||
The [minimatch](https://github.com/isaacs/minimatch) pattern or array of patterns used to select which files should be published. | ||
The [minimatch](https://github.com/isaacs/minimatch) pattern or array of patterns is used to select which files should be published. | ||
@@ -134,3 +134,32 @@ | ||
#### <a id="optionsnojekyll">options.nojekyll</a> | ||
* type: `boolean` | ||
* default: `false` | ||
Write out a `.nojekyll` file to [bypass Jekyll on GitHub Pages](https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/). | ||
Example use of the `nojekyll` option: | ||
```js | ||
/** | ||
* The usage below will add a `.nojekyll` file to the output. | ||
*/ | ||
ghpages.publish('dist', {nojekyll: true}, callback); | ||
``` | ||
#### <a id="optionscname">options.cname</a> | ||
* type: `string` | ||
Write out a `CNAME` file with a custom domain name. | ||
Example use of the `cname` option: | ||
```js | ||
/** | ||
* The usage below will add a `CNAME` file to the output. | ||
*/ | ||
ghpages.publish('dist', {cname: 'custom-domain.com'}, callback); | ||
``` | ||
#### <a id="optionsadd">options.add</a> | ||
@@ -409,6 +438,6 @@ * type: `boolean` | ||
Modify the deployment line to your deploy script if you use custom domain. This will prevent the deployment from removing the domain settings in GitHub. | ||
Use the `--cname` option to create a `CNAME` file with the name of your custom domain. See [the GitHub docs](https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site) for more detail. | ||
``` | ||
echo your_cutom_domain.online > ./build/CNAME && gh-pages -d build" | ||
gh-pages -d build --cname custom-domain.com" | ||
``` | ||
@@ -415,0 +444,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
39923
3.74%826
2.35%479
6.44%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated
Updated