Browse Source

Replace `copy-paste` with `clipboardy`

This closes #457
master
Leo Lamprecht 8 years ago
parent
commit
c1ba650ec4
  1. 52
      bin/now-deploy.js
  2. 91
      lib/alias.js
  3. 16
      lib/copy.js
  4. 2
      package.json

52
bin/now-deploy.js

@ -13,9 +13,9 @@ const ms = require('ms');
const flatten = require('arr-flatten'); const flatten = require('arr-flatten');
const dotenv = require('dotenv'); const dotenv = require('dotenv');
const { eraseLines } = require('ansi-escapes'); const { eraseLines } = require('ansi-escapes');
const { write: copy } = require('clipboardy');
// Ours // Ours
const copy = require('../lib/copy');
const login = require('../lib/login'); const login = require('../lib/login');
const cfg = require('../lib/cfg'); const cfg = require('../lib/cfg');
const { version } = require('../lib/pkg'); const { version } = require('../lib/pkg');
@ -225,24 +225,29 @@ Promise.resolve().then(async () => {
console.log('> Logged in successfully. Token saved in ~/.now.json'); console.log('> Logged in successfully. Token saved in ~/.now.json');
process.exit(0); process.exit(0);
} else { } else {
sync({token, config}).catch(err => { sync({ token, config }).catch(err => {
error(`Unknown error: ${err}\n${err.stack}`); error(`Unknown error: ${err}\n${err.stack}`);
process.exit(1); process.exit(1);
}); });
} }
} else { } else {
sync({token: argv.token || config.token, config}).catch(err => { sync({ token: argv.token || config.token, config }).catch(err => {
error(`Unknown error: ${err}\n${err.stack}`); error(`Unknown error: ${err}\n${err.stack}`);
process.exit(1); process.exit(1);
}); });
} }
}); });
async function sync({token, config: {currentTeam, user}}) { async function sync({ token, config: { currentTeam, user } }) {
const start = Date.now(); const start = Date.now();
const rawPath = argv._[0]; const rawPath = argv._[0];
const planPromise = new NowPlans({apiUrl, token, debug, currentTeam }).getCurrent(); const planPromise = new NowPlans({
apiUrl,
token,
debug,
currentTeam
}).getCurrent();
const stopDeployment = msg => { const stopDeployment = msg => {
error(msg); error(msg);
@ -260,14 +265,9 @@ async function sync({token, config: {currentTeam, user}}) {
const gitParts = gitPathParts(rawPath); const gitParts = gitPathParts(rawPath);
Object.assign(gitRepo, gitParts); Object.assign(gitRepo, gitParts);
const searchMessage = setTimeout( const searchMessage = setTimeout(() => {
() => { console.log(`> Didn't find directory. Searching on ${gitRepo.type}...`);
console.log( }, 500);
`> Didn't find directory. Searching on ${gitRepo.type}...`
);
},
500
);
try { try {
repo = await fromGit(rawPath, debug); repo = await fromGit(rawPath, debug);
@ -309,18 +309,12 @@ async function sync({token, config: {currentTeam, user}}) {
if (gitRepo.main) { if (gitRepo.main) {
const gitRef = gitRepo.ref ? ` at "${chalk.bold(gitRepo.ref)}" ` : ''; const gitRef = gitRepo.ref ? ` at "${chalk.bold(gitRepo.ref)}" ` : '';
console.log( console.log(
`> Deploying ${gitRepo.type} repository "${chalk.bold(gitRepo.main)}" ${gitRef} under ${ `> Deploying ${gitRepo.type} repository "${chalk.bold(gitRepo.main)}" ${gitRef} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`
chalk.bold(
(currentTeam && currentTeam.slug) || user.username || user.email
)
}`
); );
} else { } else {
console.log(`> Deploying ${chalk.bold(toHumanPath(path))} under ${ console.log(
chalk.bold( `> Deploying ${chalk.bold(toHumanPath(path))} under ${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)}`
(currentTeam && currentTeam.slug) || user.username || user.email );
)
}`);
} }
} }
@ -435,7 +429,7 @@ async function sync({token, config: {currentTeam, user}}) {
quiet: true quiet: true
}); });
const now = new Now({apiUrl, token, debug, currentTeam }); const now = new Now({ apiUrl, token, debug, currentTeam });
let dotenvConfig; let dotenvConfig;
let dotenvOption; let dotenvOption;
@ -622,11 +616,7 @@ async function sync({token, config: {currentTeam, user}}) {
if (plan.id === 'oss') { if (plan.id === 'oss') {
if (isTTY) { if (isTTY) {
info( info(
`${ `${chalk.bold((currentTeam && `${currentTeam.slug} is`) || `You (${user.username || user.email}) are`)} on the OSS plan. Your code will be made ${chalk.bold('public')}.`
chalk.bold(
(currentTeam && `${currentTeam.slug} is`) || `You (${user.username || user.email}) are`
)
} on the OSS plan. Your code will be made ${chalk.bold('public')}.`
); );
let proceed; let proceed;
@ -731,7 +721,9 @@ function printLogs(host, token, currentTeam) {
const assignments = []; const assignments = [];
for (const alias of aliasList) { for (const alias of aliasList) {
assignments.push(assignAlias(alias, token, host, apiUrl, debug, currentTeam)); assignments.push(
assignAlias(alias, token, host, apiUrl, debug, currentTeam)
);
} }
await Promise.all(assignments); await Promise.all(assignments);

91
lib/alias.js

@ -4,6 +4,7 @@ const publicSuffixList = require('psl');
const minimist = require('minimist'); const minimist = require('minimist');
const ms = require('ms'); const ms = require('ms');
const chalk = require('chalk'); const chalk = require('chalk');
const { write: copy } = require('clipboardy');
// Ours // Ours
const promptBool = require('../lib/utils/input/prompt-bool'); const promptBool = require('../lib/utils/input/prompt-bool');
@ -22,7 +23,6 @@ const isZeitWorld = require('./is-zeit-world');
const resolve4 = require('./dns'); const resolve4 = require('./dns');
const toHost = require('./to-host'); const toHost = require('./to-host');
const exit = require('./utils/exit'); const exit = require('./utils/exit');
const copy = require('./copy');
const Now = require('./'); const Now = require('./');
const argv = minimist(process.argv.slice(2), { const argv = minimist(process.argv.slice(2), {
@ -538,8 +538,8 @@ module.exports = class Alias extends Now {
let stopSpinner = wait('Fetching domain info'); let stopSpinner = wait('Fetching domain info');
let elapsed = stamp() let elapsed = stamp();
const parsed = publicSuffixList.parse(alias) const parsed = publicSuffixList.parse(alias);
const pricePromise = domains.price(parsed.domain); const pricePromise = domains.price(parsed.domain);
const canBePurchased = await domains.status(parsed.domain); const canBePurchased = await domains.status(parsed.domain);
const aliasParam = param(parsed.domain); const aliasParam = param(parsed.domain);
@ -552,18 +552,14 @@ module.exports = class Alias extends Now {
`The domain ${aliasParam} is ${chalk.bold('available for purchase')}! ${elapsed()}` `The domain ${aliasParam} is ${chalk.bold('available for purchase')}! ${elapsed()}`
); );
const confirmation = await promptBool( const confirmation = await promptBool(
`Buy now for ${chalk.bold(`$${price}`)} (${ `Buy now for ${chalk.bold(`$${price}`)} (${chalk.bold((currentTeam && currentTeam.slug) || user.username || user.email)})?`
chalk.bold( );
(currentTeam && currentTeam.slug) || user.username || user.email
)
})?`
)
eraseLines(1); eraseLines(1);
if (!confirmation) { if (!confirmation) {
info('Aborted'); info('Aborted');
gracefulExit(); gracefulExit();
} }
elapsed = stamp() elapsed = stamp();
stopSpinner = wait('Purchasing'); stopSpinner = wait('Purchasing');
let domain; let domain;
try { try {
@ -749,52 +745,55 @@ module.exports = class Alias extends Now {
} }
verifyOwnership(domain) { verifyOwnership(domain) {
return this.retry(async bail => { return this.retry(
const targets = await resolve4('alias.zeit.co'); async bail => {
const targets = await resolve4('alias.zeit.co');
if (targets.length <= 0) { if (targets.length <= 0) {
return bail(new Error('Unable to resolve alias.zeit.co')); return bail(new Error('Unable to resolve alias.zeit.co'));
} }
let ips = []; let ips = [];
try { try {
ips = await resolve4(domain); ips = await resolve4(domain);
} catch (err) { } catch (err) {
if ( if (
err.code === 'ENODATA' || err.code === 'ENODATA' ||
err.code === 'ESERVFAIL' || err.code === 'ESERVFAIL' ||
err.code === 'ENOTFOUND' err.code === 'ENOTFOUND'
) { ) {
// Not errors per se, just absence of records // Not errors per se, just absence of records
if (this._debug) { if (this._debug) {
console.log(`> [debug] No records found for "${domain}"`); console.log(`> [debug] No records found for "${domain}"`);
}
const err = new Error(DOMAIN_VERIFICATION_ERROR);
err.userError = true;
return bail(err);
} }
throw err;
}
if (ips.length <= 0) {
const err = new Error(DOMAIN_VERIFICATION_ERROR); const err = new Error(DOMAIN_VERIFICATION_ERROR);
err.userError = true; err.userError = true;
return bail(err); return bail(err);
} }
throw err;
}
if (ips.length <= 0) { for (const ip of ips) {
const err = new Error(DOMAIN_VERIFICATION_ERROR); if (targets.indexOf(ip) === -1) {
err.userError = true; const err = new Error(
return bail(err); `The domain ${domain} has an A record ${chalk.bold(ip)} that doesn't resolve to ${chalk.bold(chalk.underline('alias.zeit.co'))}.\n> ` +
} DOMAIN_VERIFICATION_ERROR
);
for (const ip of ips) { err.ip = ip;
if (targets.indexOf(ip) === -1) { err.userError = true;
const err = new Error( return bail(err);
`The domain ${domain} has an A record ${chalk.bold(ip)} that doesn't resolve to ${chalk.bold(chalk.underline('alias.zeit.co'))}.\n> ` + }
DOMAIN_VERIFICATION_ERROR
);
err.ip = ip;
err.userError = true;
return bail(err);
} }
} },
}, { retries: 5 }); { retries: 5 }
);
} }
}; };

16
lib/copy.js

@ -1,16 +0,0 @@
// Packages
const { copy: _copy } = require('copy-paste');
function copy(text) {
return new Promise((resolve, reject) => {
_copy(text, err => {
if (err) {
return reject(err);
}
resolve();
});
});
}
module.exports = copy;

2
package.json

@ -57,7 +57,7 @@
"async-to-gen": "1.3.3", "async-to-gen": "1.3.3",
"bytes": "2.5.0", "bytes": "2.5.0",
"chalk": "1.1.3", "chalk": "1.1.3",
"copy-paste": "1.3.0", "clipboardy": "1.1.1",
"credit-card": "3.0.1", "credit-card": "3.0.1",
"cross-spawn": "5.1.0", "cross-spawn": "5.1.0",
"dateformat": "2.0.0", "dateformat": "2.0.0",

Loading…
Cancel
Save