Skip to content

Instantly share code, notes, and snippets.

@asyncanup
Forked from jashkenas/npm-publish-semver.coffee
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asyncanup/efdc57d85ee233df5579 to your computer and use it in GitHub Desktop.
Save asyncanup/efdc57d85ee233df5579 to your computer and use it in GitHub Desktop.
#!/usr/bin/env coffee
fs = require 'fs'
sh = require 'execSync'
config = require './package.json'
name = config.name = "#{config.name}-semver"
version = config.version = config.version.replace(/\./g, '') + '.0.0'
fs.renameSync 'package.json', 'package.json.real'
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
Author

Moved fs actions closer together so you don't have corrupted state in case the script fails.

TODO: config.version.replace is unsafe without a try/catch (what if config.version is undefined)

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