Skip to content

Instantly share code, notes, and snippets.

@remy
Last active September 6, 2016 11:38
Show Gist options
  • Save remy/078c364486f57ac21af4b8564160594d to your computer and use it in GitHub Desktop.
Save remy/078c364486f57ac21af4b8564160594d to your computer and use it in GitHub Desktop.
Quick `now` re-alias script, if run inside the current project dir
#!/usr/bin/env node
const Now = require('now-client');
const now = Now(); // this looks like it detect the token from ~/.now.json or the env automatically
const pkg = require(process.cwd() + '/package.json');
now.getDeployments().then(res => {
const [latest, prev, ...rest] = res.filter(_ => _.name === pkg.name).sort((a, b) => b.created - a.created);
console.log(`getting alias for ${prev.uid} (${prev.url})`);
return now.getAliases(prev.uid).then(res => {
const first = res.shift(); // expecting a single alias - otherwise ¯\_(ツ)_/¯
console.log(`aliasing to ${first.alias}...`);
return now.createAlias(latest.uid, first.alias);
});
})
.then(() => console.log('done'))
.catch(e => console.error(e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment