Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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'
@peterc

This comment has been minimized.

Copy link

commented Aug 29, 2014

Regardless of the seriousness of the discussion, I had a genuine laugh out loud when I saw underscore-semver's approach :-) Bravo.

@gojomo

This comment has been minimized.

Copy link

commented Aug 29, 2014

May want test case for roll from 1.10.0 to 2.0.0.

@kballenegger

This comment has been minimized.

Copy link

commented Aug 30, 2014

@gojomo a simple fix for this would be to rpad all numbers to 3 characters. e.g. 1.10.0 would be 100100000.0.0 and 2.0.0 would be 200000000.0.0. Now, it might break for an upgrade from 1.1000.0 to 2.0.0, but that's a little rarer than versions numbered 10.

@asyncanup

This comment has been minimized.

Copy link

commented Aug 31, 2014

And just a while ago, all was well in the npm land....
sigh.

@asyncanup

This comment has been minimized.

Copy link

commented Aug 31, 2014

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

This comment has been minimized.

Copy link

commented Jan 1, 2015

@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
You can’t perform that action at this time.