Browse Source

Merge pull request #103 from zeit/nowenv

Add an environment variable to change .now.json location
master
Tony Kovanen 9 years ago
committed by GitHub
parent
commit
638b5700b4
  1. 10
      bin/now-alias
  2. 10
      bin/now-deploy
  3. 10
      bin/now-domains
  4. 11
      bin/now-list
  5. 11
      bin/now-remove
  6. 10
      bin/now-secrets
  7. 6
      lib/cfg.js

10
bin/now-alias

@ -10,10 +10,13 @@ import { error } from '../lib/error';
import toHost from '../lib/to-host'; import toHost from '../lib/to-host';
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
string: ['config', 'token'],
boolean: ['help', 'debug'], boolean: ['help', 'debug'],
alias: { alias: {
help: 'h', help: 'h',
debug: 'd' config: 'c',
debug: 'd',
token: 't'
} }
}); });
const subcommand = argv._[0]; const subcommand = argv._[0];
@ -26,7 +29,9 @@ const help = () => {
${chalk.dim('Options:')} ${chalk.dim('Options:')}
-h, --help output usage information -h, --help output usage information
-c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file
-d, --debug debug mode [off] -d, --debug debug mode [off]
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token
${chalk.dim('Examples:')} ${chalk.dim('Examples:')}
@ -66,6 +71,7 @@ const help = () => {
// options // options
const debug = argv.debug; const debug = argv.debug;
const apiUrl = argv.url || 'https://api.zeit.co'; const apiUrl = argv.url || 'https://api.zeit.co';
if (argv.config) cfg.setConfigFile(argv.config);
const exit = (code) => { const exit = (code) => {
// we give stdout some time to flush out // we give stdout some time to flush out
@ -81,7 +87,7 @@ if (argv.help || !subcommand) {
} else { } else {
const config = cfg.read(); const config = cfg.read();
Promise.resolve(config.token || login(apiUrl)) Promise.resolve(argv.token || config.token || login(apiUrl))
.then(async (token) => { .then(async (token) => {
try { try {
await run(token); await run(token);

10
bin/now-deploy

@ -17,12 +17,15 @@ import ms from 'ms';
import { handleError, error } from '../lib/error'; import { handleError, error } from '../lib/error';
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
string: ['config', 'token'],
boolean: ['help', 'version', 'debug', 'force', 'login', 'no-clipboard', 'forward-npm', 'docker', 'npm'], boolean: ['help', 'version', 'debug', 'force', 'login', 'no-clipboard', 'forward-npm', 'docker', 'npm'],
alias: { alias: {
help: 'h', help: 'h',
config: 'c',
debug: 'd', debug: 'd',
version: 'v', version: 'v',
force: 'f', force: 'f',
token: 't',
forceSync: 'F', forceSync: 'F',
login: 'L', login: 'L',
public: 'p', public: 'p',
@ -49,8 +52,10 @@ const help = () => {
-h, --help output usage information -h, --help output usage information
-v, --version output the version number -v, --version output the version number
-c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file
-d, --debug debug mode [off] -d, --debug debug mode [off]
-f, --force force a new deployment even if nothing has changed -f, --force force a new deployment even if nothing has changed
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token
-L, --login configure login -L, --login configure login
-p, --public deployment is public (\`/_src\` is exposed) [on for oss, off for premium] -p, --public deployment is public (\`/_src\` is exposed) [on for oss, off for premium]
-C, --no-clipboard do not attempt to copy URL to clipboard -C, --no-clipboard do not attempt to copy URL to clipboard
@ -109,6 +114,7 @@ const wantsPublic = argv.public;
const apiUrl = argv.url || 'https://api.zeit.co'; const apiUrl = argv.url || 'https://api.zeit.co';
const isTTY = process.stdout.isTTY; const isTTY = process.stdout.isTTY;
const quiet = !isTTY; const quiet = !isTTY;
if (argv.config) cfg.setConfigFile(argv.config);
const config = cfg.read(); const config = cfg.read();
const alwaysForwardNpm = config.forwardNpm; const alwaysForwardNpm = config.forwardNpm;
@ -118,7 +124,7 @@ if (argv.h || argv.help) {
} else if (argv.v || argv.version) { } else if (argv.v || argv.version) {
console.log(chalk.bold('𝚫 now'), version); console.log(chalk.bold('𝚫 now'), version);
process.exit(0); process.exit(0);
} else if (!config.token || shouldLogin) { } else if (!(argv.token || config.token) || shouldLogin) {
login(apiUrl) login(apiUrl)
.then((token) => { .then((token) => {
if (shouldLogin) { if (shouldLogin) {
@ -136,7 +142,7 @@ if (argv.h || argv.help) {
process.exit(1); process.exit(1);
}); });
} else { } else {
sync(config.token).catch((err) => { sync(argv.token || config.token).catch((err) => {
error(`Unknown error: ${err.stack}`); error(`Unknown error: ${err.stack}`);
process.exit(1); process.exit(1);
}); });

10
bin/now-domains

@ -10,10 +10,13 @@ import toHost from '../lib/to-host';
import NowDomains from '../lib/domains'; import NowDomains from '../lib/domains';
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
string: ['config', 'token'],
boolean: ['help', 'debug'], boolean: ['help', 'debug'],
alias: { alias: {
help: 'h', help: 'h',
debug: 'd' config: 'c',
debug: 'd',
token: 't'
} }
}); });
const subcommand = argv._[0]; const subcommand = argv._[0];
@ -26,7 +29,9 @@ const help = () => {
${chalk.dim('Options:')} ${chalk.dim('Options:')}
-h, --help output usage information -h, --help output usage information
-c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file
-d, --debug debug mode [off] -d, --debug debug mode [off]
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token
${chalk.dim('Examples:')} ${chalk.dim('Examples:')}
@ -71,6 +76,7 @@ const help = () => {
// options // options
const debug = argv.debug; const debug = argv.debug;
const apiUrl = argv.url || 'https://api.zeit.co'; const apiUrl = argv.url || 'https://api.zeit.co';
if (argv.config) cfg.setConfigFile(argv.config);
const exit = (code) => { const exit = (code) => {
// we give stdout some time to flush out // we give stdout some time to flush out
@ -86,7 +92,7 @@ if (argv.help || !subcommand) {
} else { } else {
const config = cfg.read(); const config = cfg.read();
Promise.resolve(config.token || login(apiUrl)) Promise.resolve(argv.token || config.token || login(apiUrl))
.then(async (token) => { .then(async (token) => {
try { try {
await run(token); await run(token);

11
bin/now-list

@ -11,10 +11,13 @@ import * as cfg from '../lib/cfg';
import { handleError, error } from '../lib/error'; import { handleError, error } from '../lib/error';
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
string: ['config', 'token'],
boolean: ['help', 'debug'], boolean: ['help', 'debug'],
alias: { alias: {
help: 'h', help: 'h',
debug: 'd' config: 'c',
debug: 'd',
token: 't'
} }
}); });
@ -25,7 +28,9 @@ const help = () => {
${chalk.dim('Options:')} ${chalk.dim('Options:')}
-h, --help output usage information -h, --help output usage information
-c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file
-d, --debug debug mode [off] -d, --debug debug mode [off]
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token
${chalk.dim('Examples:')} ${chalk.dim('Examples:')}
@ -51,10 +56,10 @@ const app = argv._[0];
// options // options
const debug = argv.debug; const debug = argv.debug;
const apiUrl = argv.url || 'https://api.zeit.co'; const apiUrl = argv.url || 'https://api.zeit.co';
if (argv.config) cfg.setConfigFile(argv.config);
const config = cfg.read(); const config = cfg.read();
Promise.resolve(config.token || login(apiUrl)) Promise.resolve(argv.token || config.token || login(apiUrl))
.then(async (token) => { .then(async (token) => {
try { try {
await list(token); await list(token);

11
bin/now-remove

@ -10,10 +10,13 @@ import * as cfg from '../lib/cfg';
import { handleError, error } from '../lib/error'; import { handleError, error } from '../lib/error';
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
string: ['config', 'token'],
boolean: ['help', 'debug', 'hard'], boolean: ['help', 'debug', 'hard'],
alias: { alias: {
help: 'h', help: 'h',
debug: 'd' config: 'c',
debug: 'd',
token: 't'
} }
}); });
@ -27,7 +30,9 @@ const help = () => {
${chalk.dim('Options:')} ${chalk.dim('Options:')}
-h, --help output usage information -h, --help output usage information
-c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file
-d, --debug debug mode [off] -d, --debug debug mode [off]
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token
${chalk.dim('Examples:')} ${chalk.dim('Examples:')}
@ -48,7 +53,7 @@ if (argv.help || !deploymentId) {
const debug = argv.debug; const debug = argv.debug;
const apiUrl = argv.url || 'https://api.zeit.co'; const apiUrl = argv.url || 'https://api.zeit.co';
const hard = argv.hard || false; const hard = argv.hard || false;
if (argv.config) cfg.setConfigFile(argv.config);
const config = cfg.read(); const config = cfg.read();
function readConfirmation (depl, aliases) { function readConfirmation (depl, aliases) {
@ -77,7 +82,7 @@ function readConfirmation (depl, aliases) {
}); });
} }
Promise.resolve(config.token || login(apiUrl)) Promise.resolve(argv.token || config.token || login(apiUrl))
.then(async (token) => { .then(async (token) => {
try { try {
await remove(token); await remove(token);

10
bin/now-secrets

@ -8,11 +8,14 @@ import NowSecrets from '../lib/secrets';
import ms from 'ms'; import ms from 'ms';
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
string: ['config', 'token'],
boolean: ['help', 'debug', 'base64'], boolean: ['help', 'debug', 'base64'],
alias: { alias: {
help: 'h', help: 'h',
config: 'c',
debug: 'd', debug: 'd',
base64: 'b' base64: 'b',
token: 't'
} }
}); });
const subcommand = argv._[0]; const subcommand = argv._[0];
@ -26,7 +29,9 @@ const help = () => {
-h, --help output usage information -h, --help output usage information
-b, --base64 treat value as base64-encoded -b, --base64 treat value as base64-encoded
-c ${chalk.bold.underline('FILE')}, --config=${chalk.bold.underline('FILE')} config file
-d, --debug debug mode [off] -d, --debug debug mode [off]
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline('TOKEN')} login token
${chalk.dim('Examples:')} ${chalk.dim('Examples:')}
@ -61,6 +66,7 @@ const help = () => {
// options // options
const debug = argv.debug; const debug = argv.debug;
const apiUrl = argv.url || 'https://api.zeit.co'; const apiUrl = argv.url || 'https://api.zeit.co';
if (argv.config) cfg.setConfigFile(argv.config);
const exit = (code) => { const exit = (code) => {
// we give stdout some time to flush out // we give stdout some time to flush out
@ -76,7 +82,7 @@ if (argv.help || !subcommand) {
} else { } else {
const config = cfg.read(); const config = cfg.read();
Promise.resolve(config.token || login(apiUrl)) Promise.resolve(argv.token || config.token || login(apiUrl))
.then(async (token) => { .then(async (token) => {
try { try {
await run(token); await run(token);

6
lib/cfg.js

@ -2,7 +2,11 @@ import path from 'path';
import fs from 'fs-promise'; import fs from 'fs-promise';
import { homedir } from 'os'; import { homedir } from 'os';
const file = path.resolve(homedir(), '.now.json'); let file = process.env.NOW_JSON ? path.resolve(process.env.NOW_JSON) : path.resolve(homedir(), '.now.json');
export function setConfigFile (nowjson) {
file = path.resolve(nowjson);
}
export function read () { export function read () {
let existing = null; let existing = null;

Loading…
Cancel
Save