UNPKG

1.09 kBJavaScriptView Raw
1'use strict';
2
3const Bluebird = require(`bluebird`);
4const debug = require(`debug`)(`npm-publish-git-tag`);
5const latestSemverTag = Bluebird.promisify(require(`git-latest-semver-tag`));
6const readPkg = require(`read-pkg`);
7const setNpmAuthTokenForCI = require(`set-npm-auth-token-for-ci`);
8const shell = require(`shelljs`);
9const writePkg = require(`write-pkg`);
10
11module.exports = npmPublishGitTag(shell);
12module.exports.npmPublishGitTag = npmPublishGitTag;
13
14function npmPublishGitTag(shell) {
15 return options =>
16 latestSemverTag()
17 .then(latestTag => readPkg().then(pkg => writePkg(Object.assign(pkg, {version: latestTag}))))
18 .then(() => options.skipToken || setNpmAuthTokenForCI())
19 .then(() => publish({access: options.access}));
20
21 function publish(options) {
22 let command = `npm publish`;
23
24 if (typeof options.access === `string`) {
25 debug(`publishing package with the following access level`, options.access);
26 command += ` --access ${options.access}`;
27 }
28
29 debug(`executing publish command`, command);
30 return shell.exec(command);
31 }
32}