Last active
August 18, 2016 21:10
-
-
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.
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
#!/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' |
May want test case for roll from 1.10.0 to 2.0.0.
@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.
And just a while ago, all was well in the npm land....
sigh.
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?
@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
Regardless of the seriousness of the discussion, I had a genuine laugh out loud when I saw underscore-semver's approach :-) Bravo.