-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
npmPublish
and tarballDir
options
`npmPublish` can be set to `false` to skip the publishing on npm registry If `tarballDir` is set the npm tarball (`npm pack`) will be generated in the configured directory
- Loading branch information
Showing
7 changed files
with
165 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
const path = require('path'); | ||
const {move} = require('fs-extra'); | ||
const execa = require('execa'); | ||
const getRegistry = require('./get-registry'); | ||
const updatePackageVersion = require('./update-package-version'); | ||
|
||
module.exports = async ({publishConfig, name}, version, logger) => { | ||
module.exports = async ({npmPublish, tarballDir}, {publishConfig, name}, version, logger) => { | ||
const registry = await getRegistry(publishConfig, name); | ||
await updatePackageVersion(version, logger); | ||
|
||
logger.log('Publishing version %s to npm registry', version); | ||
const shell = await execa('npm', ['publish', '--registry', registry]); | ||
process.stdout.write(shell.stdout); | ||
if (tarballDir) { | ||
logger.log('Creating npm package version %s', version); | ||
const tarball = await execa.stdout('npm', ['pack']); | ||
await move(tarball, path.join(tarballDir.trim(), tarball)); | ||
} | ||
|
||
if (npmPublish !== false) { | ||
logger.log('Publishing version %s to npm registry', version); | ||
const shell = await execa('npm', ['publish', '--registry', registry]); | ||
process.stdout.write(shell.stdout); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import test from 'ava'; | ||
import {stub} from 'sinon'; | ||
import verify from '../lib/verify'; | ||
|
||
test.beforeEach(t => { | ||
// Stub the logger functions | ||
t.context.log = stub(); | ||
t.context.logger = {log: t.context.log}; | ||
}); | ||
|
||
test('Throw SemanticReleaseError if "npmPublish" option is not a Boolean', async t => { | ||
const npmPublish = 42; | ||
const error = await t.throws(verify({npmPublish}, {}, t.context.logger)); | ||
|
||
t.is(error.name, 'SemanticReleaseError'); | ||
t.is(error.code, 'EINVALIDNPMPUBLISH'); | ||
}); | ||
|
||
test('Throw SemanticReleaseError if "tarballDir" option is not a String', async t => { | ||
const tarballDir = 42; | ||
const error = await t.throws(verify({tarballDir}, {}, t.context.logger)); | ||
|
||
t.is(error.name, 'SemanticReleaseError'); | ||
t.is(error.code, 'EINVALIDTARBALLDIR'); | ||
}); |