This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
237 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Project | ||
__tests__ | ||
docs/ | ||
.jest | ||
.huskyrc | ||
.babelrc | ||
.eslintrc | ||
.gitignore | ||
jest.config.js | ||
jest.setup.js | ||
|
||
# OS X | ||
.DS_Store* | ||
._* | ||
|
||
# NPM | ||
node_modules | ||
*.log | ||
*.gz | ||
|
||
# Test Coverage | ||
coverage | ||
|
||
# Benchmarking | ||
benchmarks/graphs | ||
|
||
# IDEs | ||
/.idea | ||
.idea | ||
/.idea_modules | ||
*.iml | ||
*.tgz |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
const { run } = require('runjs') | ||
const semver = require('semver') | ||
const child_process = require('child_process') | ||
const packageJson = require('./package.json') | ||
|
||
const packageName = packageJson.name | ||
|
||
function ship () { | ||
const tag = packageJson.version.includes('-') ? 'next' : 'latest' | ||
const latestVersion = child_process.execSync(`npm view ${packageName}@latest version`).toString() | ||
|
||
// publish with a `shipping` tag so we can control the latest/next tags manually since NPM defaults to latest if no tag is provided | ||
run(`export SHIP=true && npm run build && npm publish -f --tag shipping`) | ||
// remove the temporary shipping tag | ||
run(`npm dist-tags remove ${packageName} shipping || true`) | ||
|
||
// only if the latest is less than the current version do we tag it (this ignores support branches) | ||
if (semver.gt(packageJson.version, latestVersion)) { | ||
// add the appropriate next or latest tag manually to the version just published | ||
run(`npm dist-tags add ${packageName}@${packageJson.version} ${tag}`) | ||
} | ||
} | ||
|
||
function preventPublish () { | ||
if (process.env.SHIP !== 'true') { | ||
run(` | ||
printf "\\033[0;31m | ||
==========================================================\n | ||
'npm publish' is not allowed -- use 'npm run ship' instead\n | ||
==========================================================\n\n\n" && exit 1;` | ||
) | ||
} else { | ||
run(` | ||
printf "\\033[0;32m | ||
===============================\n | ||
thanks for using 'npm run ship'\n | ||
===============================\n\n\n" && exit 0;` | ||
) | ||
} | ||
} | ||
|
||
module.exports = { | ||
preventPublish, | ||
ship | ||
} |