Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Last active August 18, 2016 21:10
Show Gist options
  • Save jashkenas/c71021bba8ee580ded92 to your computer and use it in GitHub Desktop.
Save jashkenas/c71021bba8ee580ded92 to your computer and use it in GitHub Desktop.
A little script to publish a "semantic" version of any npm package that uses real version numbers.
#!/usr/bin/env coffee
fs = require 'fs'
sh = require 'execSync'
config = JSON.parse fs.readFileSync 'package.json'
fs.renameSync 'package.json', 'package.json.real'
name = config.name = "#{config.name}-semver"
version = config.version = config.version.replace(/\./g, '') + '.0.0'
fs.writeFileSync 'package.json', JSON.stringify config, null, 2
sh.run 'npm publish .'
sh.run "npm tag #{name}@#{version} stable"
fs.unlinkSync 'package.json'
fs.renameSync 'package.json.real', 'package.json'
@asyncanup
Copy link

May want to move the fs operations closer together (as here: https://gist.github.com/asyncanup/efdc57d85ee233df5579 )

And throw in a try/catch for the case when npm publish fails?

@hypesystem
Copy link

@kballenegger no. Should be LPAD. Otherwise, 1.10.0 and 1.1.0 are the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment