Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
add files for publishing to npm
Browse files Browse the repository at this point in the history
  • Loading branch information
stazrad committed Mar 25, 2020
1 parent ee9e945 commit 52cd10b
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 5 deletions.
32 changes: 32 additions & 0 deletions .npmignore
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
158 changes: 154 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bayer/ol-kit",
"version": "0.0.0-1",
"version": "0.0.0-2",
"license": "BSD",
"description": "Mapping components & utils built with openlayers + react",
"contributors": [
Expand Down Expand Up @@ -32,6 +32,8 @@
"docs": "jsdoc -r -c jsdoc.json && cp static/index.html static/docs.html static/bayer-logo.png docs/",
"lint": "eslint src/*.js",
"lint:fix": "npm run lint -- --fix",
"prepublishOnly": "run preventPublish",
"ship": "run ship",
"test": "jest --notify --config=jest.config.js",
"test:coverage": "jest --config=jest.config.js --coverage",
"test:watch": "jest --notify --config=jest.config.js --watch --coverage"
Expand Down Expand Up @@ -63,6 +65,7 @@
"babel-plugin-inline-react-svg": "~1.1.0",
"babel-plugin-module-resolver": "~3.2.0",
"better-docs": "~1.4.7",
"child_process": "^1.0.2",
"enzyme": "~3.10.0",
"enzyme-adapter-react-16": "~1.15.1",
"enzyme-to-json": "~3.4.3",
Expand All @@ -82,6 +85,8 @@
"ol": "4.6.5",
"react": "~16.11.0",
"react-dom": "~16.11.0",
"runjs": "^4.4.2",
"semver": "^7.1.3",
"styled-components": "~5.0.0"
},
"peerDependencies": {
Expand Down
45 changes: 45 additions & 0 deletions runfile.js
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
}

0 comments on commit 52cd10b

Please sign in to comment.