Browse Source

Add support for `now alias domain.tld` (#467)

master
Steve Faulkner 8 years ago
committed by Leo Lamprecht
parent
commit
0c4f9dcd62
  1. 19
      bin/now-alias.js
  2. 2
      bin/now-deploy.js
  3. 53
      lib/re-alias.js

19
bin/now-alias.js

@ -315,7 +315,21 @@ async function run({token, config: {currentTeam, user}}) {
} }
default: { default: {
if (argv._.length === 0) { if (argv._.length === 0) {
await reAlias(token, null, help, exit, apiUrl, debug, alias); await reAlias(token, null, null, help, exit, apiUrl, debug, alias);
break;
}
if (argv._.length === 1) {
await reAlias(
token,
null,
String(argv._[0]),
help,
exit,
apiUrl,
debug,
alias
);
break; break;
} }
@ -354,7 +368,8 @@ async function confirmDeploymentRemoval(alias, _alias) {
{ align: ['l', 'r', 'l'], hsep: ' '.repeat(6) } { align: ['l', 'r', 'l'], hsep: ' '.repeat(6) }
); );
const msg = '> The following alias will be removed permanently\n' + const msg =
'> The following alias will be removed permanently\n' +
` ${tbl} \nAre you sure?`; ` ${tbl} \nAre you sure?`;
return promptBool(msg, { return promptBool(msg, {

2
bin/now-deploy.js

@ -728,7 +728,7 @@ function printLogs(host, token, currentTeam) {
await Promise.all(assignments); await Promise.all(assignments);
} else { } else {
await reAlias(token, host, help, exit, apiUrl, debug); await reAlias(token, host, null, help, exit, apiUrl, debug);
} }
} }

53
lib/re-alias.js

@ -20,7 +20,16 @@ exports.assignAlias = async (autoAlias, token, deployment, apiUrl, debug, curren
await aliases.set(String(deployment), String(autoAlias)); await aliases.set(String(deployment), String(autoAlias));
}; };
exports.reAlias = async (token, host, help, exit, apiUrl, debug, alias) => { exports.reAlias = async (
token,
host,
pointer,
help,
exit,
apiUrl,
debug,
alias
) => {
const path = process.cwd(); const path = process.cwd();
const configFiles = { const configFiles = {
@ -52,27 +61,33 @@ exports.reAlias = async (token, host, help, exit, apiUrl, debug, alias) => {
let pointers = []; let pointers = [];
if (nowConfig.alias) { if (pointer) {
const value = nowConfig.alias; pointers.push(pointer);
} else {
if (typeof value === 'string') { if (nowConfig.alias) {
pointers.push(value); const value = nowConfig.alias;
} else if (Array.isArray(value)) {
pointers = pointers.concat(nowConfig.alias); if (typeof value === 'string') {
} else { pointers.push(value);
error(`Property ${chalk.grey('aliases')} is not a valid array or string`); } else if (Array.isArray(value)) {
return exit(1); pointers = pointers.concat(nowConfig.alias);
} else {
error(
`Property ${chalk.grey('aliases')} is not a valid array or string`
);
return exit(1);
}
} }
}
if (nowConfig.aliases && Array.isArray(nowConfig.aliases)) { if (nowConfig.aliases && Array.isArray(nowConfig.aliases)) {
console.log( console.log(
`${chalk.red('Deprecated!')} The property ${chalk.grey('aliases')} will be ` + `${chalk.red('Deprecated!')} The property ${chalk.grey('aliases')} will be ` +
`removed from the config file soon.` `removed from the config file soon.`
); );
console.log('Read more about the new way here: http://bit.ly/2l2v5Fg\n'); console.log('Read more about the new way here: http://bit.ly/2l2v5Fg\n');
pointers = pointers.concat(nowConfig.aliases); pointers = pointers.concat(nowConfig.aliases);
}
} }
if (pointers.length === 0) { if (pointers.length === 0) {

Loading…
Cancel
Save