1 | 'use strict';
|
2 |
|
3 | const Bluebird = require(`bluebird`);
|
4 | const debug = require(`debug`)(`npm-publish-git-tag`);
|
5 | const latestSemverTag = Bluebird.promisify(require(`git-latest-semver-tag`));
|
6 | const readPkg = require(`read-pkg`);
|
7 | const setNpmAuthTokenForCI = require(`set-npm-auth-token-for-ci`);
|
8 | const shell = require(`shelljs`);
|
9 | const writePkg = require(`write-pkg`);
|
10 |
|
11 | module.exports = npmPublishGitTag(shell);
|
12 | module.exports.npmPublishGitTag = npmPublishGitTag;
|
13 |
|
14 | function 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 | }
|