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

91
lib/alias.js

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

Loading…
Cancel
Save