Browse Source

Replace `copy-paste` with `clipboardy`

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

44
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');
@ -242,7 +242,12 @@ 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 );
)
}`);
} }
} }
@ -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);

23
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,7 +745,8 @@ module.exports = class Alias extends Now {
} }
verifyOwnership(domain) { verifyOwnership(domain) {
return this.retry(async bail => { return this.retry(
async bail => {
const targets = await resolve4('alias.zeit.co'); const targets = await resolve4('alias.zeit.co');
if (targets.length <= 0) { if (targets.length <= 0) {
@ -795,6 +792,8 @@ module.exports = class Alias extends Now {
return bail(err); 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