Browse Source

activate quiet mode when piping

master
Guillermo Rauch 9 years ago
parent
commit
396bd8713f
  1. 31
      bin/now-deploy
  2. 4
      lib/build-logger.js

31
bin/now-deploy

@ -100,7 +100,8 @@ const forceNew = argv.force;
const forceSync = argv.forceSync; const forceSync = argv.forceSync;
const shouldLogin = argv.login; const shouldLogin = argv.login;
const apiUrl = argv.url || 'https://api.zeit.co'; const apiUrl = argv.url || 'https://api.zeit.co';
const isTTY = process.stdout.isTTY;
const quiet = !isTTY;
const config = cfg.read(); const config = cfg.read();
if (argv.h || argv.help) { if (argv.h || argv.help) {
@ -133,12 +134,12 @@ if (argv.h || argv.help) {
}); });
} }
const isTTY = process.stdout.isTTY;
async function sync (token) { async function sync (token) {
const start = Date.now(); const start = Date.now();
console.log(`> Deploying "${path}"`); if (!quiet) {
console.log(`> Deploying "${path}"`);
}
const now = new Now(apiUrl, token, { debug }); const now = new Now(apiUrl, token, { debug });
@ -147,7 +148,7 @@ async function sync (token) {
forceNew, forceNew,
forceSync, forceSync,
forwardNpm, forwardNpm,
quiet: !isTTY quiet
}); });
} catch (err) { } catch (err) {
handleError(err); handleError(err);
@ -169,14 +170,16 @@ async function sync (token) {
console.log(`> ${url} [${elapsed}]`); console.log(`> ${url} [${elapsed}]`);
} }
} else { } else {
system.stdout.write(url); process.stdout.write(url);
} }
const start_u = new Date(); const start_u = new Date();
const complete = () => { const complete = () => {
const elapsed_u = ms(new Date() - start_u); if (!quiet) {
console.log(`> Sync complete (${bytes(now.syncAmount)}) [${elapsed_u}] `); const elapsed_u = ms(new Date() - start_u);
console.log('> Initializing…'); console.log(`> Sync complete (${bytes(now.syncAmount)}) [${elapsed_u}] `);
console.log('> Initializing…');
}
// close http2 agent // close http2 agent
now.close(); now.close();
@ -211,7 +214,9 @@ async function sync (token) {
process.exit(1); process.exit(1);
}); });
} else { } else {
console.log(`> Initializing…`); if (!quiet) {
console.log(`> Initializing…`);
}
// close http2 agent // close http2 agent
now.close(); now.close();
@ -223,12 +228,14 @@ async function sync (token) {
function printLogs (host) { function printLogs (host) {
// log build // log build
const logger = new Logger(host, { debug, quiet: !isTTY }); const logger = new Logger(host, { debug, quiet });
logger.on('error', () => { logger.on('error', () => {
process.exit(1); process.exit(1);
}); });
logger.on('close', () => { logger.on('close', () => {
console.log(`${chalk.cyan('> Deployment complete!')}`); if (!quiet) {
console.log(`${chalk.cyan('> Deployment complete!')}`);
}
process.exit(0); process.exit(0);
}); });
} }

4
lib/build-logger.js

@ -47,7 +47,9 @@ export default class Logger extends EventEmitter {
onLog (log) { onLog (log) {
if (!this.building) { if (!this.building) {
console.log('> Building'); if (!this.quiet) {
console.log('> Building');
}
this.building = true; this.building = true;
} }

Loading…
Cancel
Save