Skip to content

Instantly share code, notes, and snippets.

@captainsafia
Last active September 16, 2017 11:06
Show Gist options
  • Save captainsafia/360f95bb028b8203909fa6b5ac245049 to your computer and use it in GitHub Desktop.
Save captainsafia/360f95bb028b8203909fa6b5ac245049 to your computer and use it in GitHub Desktop.
A quick Node script to allow multi-environment deploys with now
#! /usr/bin/env node
'use strict';
const program = require('commander');
const fs = require('fs');
const { spawn } = require('child_process');
program
.version('1.0.0')
.option('-e, --environment <environment>', 'Environment to deploy to')
.parse(process.argv);
const file = `now.${program.environment}.json`;
fs.createReadStream(file).pipe(fs.createWriteStream('now.json'));
const deploy = spawn('now && now alias', { shell: true, stdio: 'inherit' });
deploy.on('close', () => fs.unlink('now.json', (error) => { if (error) throw error }));
{
"devDependencies": {
"commander": "latest"
}
}

Usage

This assumes that you have created now.${environment}.json configurations in your current directory.

$ node deploy.js -e production
$ node deploy.js -e staging
@9andresc
Copy link

Simple and so useful. Thanks!

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