UNPKG

@qiwi/semantic-release-gh-pages-plugin

Version:
68 lines (67 loc) 1.56 kB
/** @module semantic-release-gh-pages-plugin */ import execa from 'execa'; import { clean, publish as ghpagePublish } from 'gh-pages'; import { queuefy } from 'queuefy'; /** * @private */ export const OK = { status: 'OK' }; /** * @private */ export const pullTags = (opts) => { if (opts.pullTagsBranch === '') { return Promise.resolve(); } const repo = '' + opts.repo; const pullTagsBranch = '' + opts.pullTagsBranch; const execaOpts = { env: opts.env, cwd: opts.cwd }; return execa('git', [ 'pull', '--tags', '--force', repo, pullTagsBranch ], execaOpts) .catch(console.log); }; /** * @private */ export const pushPages = (opts) => new Promise((resolve, reject) => { const { src, logger, repo, docsBranch, dst, message, add, dotfiles } = opts; const ghpagesOpts = { repo, branch: docsBranch, dest: dst, message, add, dotfiles, }; ghpagePublish(src, ghpagesOpts, (err) => { if (err) { logger.error('Publish docs failure', err); reject(err); } else { logger.log(`Docs published successfully, branch=${ghpagesOpts.branch}, src=${src}, dst=${ghpagesOpts.dest}`); resolve(OK); } }); }); /** * @private */ export const _publish = (opts) => pullTags(opts) .then(() => pushPages(opts)) .then(res => { clean(); return res; }); /** * @private */ export const publish = queuefy(_publish);