Leo Lamprecht
8 years ago
85 changed files with 3813 additions and 3876 deletions
@ -1,64 +1,64 @@ |
|||
const { italic, bold } = require('chalk'); |
|||
const { italic, bold } = require('chalk') |
|||
|
|||
const error = require('../../lib/utils/output/error'); |
|||
const wait = require('../../lib/utils/output/wait'); |
|||
const cmd = require('../../lib/utils/output/cmd'); |
|||
const param = require('../../lib/utils/output/param'); |
|||
const info = require('../../lib/utils/output/info'); |
|||
const uid = require('../../lib/utils/output/uid'); |
|||
const success = require('../../lib/utils/output/success'); |
|||
const stamp = require('../../lib/utils/output/stamp'); |
|||
const promptBool = require('../../lib/utils/input/prompt-bool'); |
|||
const eraseLines = require('../../lib/utils/output/erase-lines'); |
|||
const treatBuyError = require('../../lib/utils/domains/treat-buy-error'); |
|||
const error = require('../../lib/utils/output/error') |
|||
const wait = require('../../lib/utils/output/wait') |
|||
const cmd = require('../../lib/utils/output/cmd') |
|||
const param = require('../../lib/utils/output/param') |
|||
const info = require('../../lib/utils/output/info') |
|||
const uid = require('../../lib/utils/output/uid') |
|||
const success = require('../../lib/utils/output/success') |
|||
const stamp = require('../../lib/utils/output/stamp') |
|||
const promptBool = require('../../lib/utils/input/prompt-bool') |
|||
const eraseLines = require('../../lib/utils/output/erase-lines') |
|||
const treatBuyError = require('../../lib/utils/domains/treat-buy-error') |
|||
|
|||
module.exports = async function({domains, args, currentTeam, user}) { |
|||
const name = args[0]; |
|||
module.exports = async function({ domains, args, currentTeam, user }) { |
|||
const name = args[0] |
|||
let elapsed |
|||
|
|||
if (!name) { |
|||
return error(`Missing domain name. Run ${cmd('now domains help')}`); |
|||
return error(`Missing domain name. Run ${cmd('now domains help')}`) |
|||
} |
|||
|
|||
const nameParam = param(name); |
|||
const nameParam = param(name) |
|||
elapsed = stamp() |
|||
let stopSpinner = wait(`Checking availability for ${nameParam}`); |
|||
let stopSpinner = wait(`Checking availability for ${nameParam}`) |
|||
|
|||
const price = await domains.price(name); |
|||
const available = await domains.status(name); |
|||
const price = await domains.price(name) |
|||
const available = await domains.status(name) |
|||
|
|||
stopSpinner(); |
|||
stopSpinner() |
|||
|
|||
if (! available) { |
|||
return error(`The domain ${nameParam} is ${italic('unavailable')}! ${elapsed()}`); |
|||
if (!available) { |
|||
return error( |
|||
`The domain ${nameParam} is ${italic('unavailable')}! ${elapsed()}` |
|||
) |
|||
} |
|||
|
|||
info(`The domain ${nameParam} is ${italic('available')}! ${elapsed()}`); |
|||
const confirmation = await promptBool(`Buy now for ${bold(`$${price}`)} (${ |
|||
bold( |
|||
(currentTeam && currentTeam.slug) || user.username || user.email |
|||
) |
|||
})?`);
|
|||
info(`The domain ${nameParam} is ${italic('available')}! ${elapsed()}`) |
|||
const confirmation = await promptBool( |
|||
`Buy now for ${bold(`$${price}`)} (${bold((currentTeam && currentTeam.slug) || user.username || user.email)})?` |
|||
) |
|||
|
|||
eraseLines(1); |
|||
eraseLines(1) |
|||
if (!confirmation) { |
|||
return info('Aborted'); |
|||
return info('Aborted') |
|||
} |
|||
|
|||
stopSpinner = wait('Purchasing'); |
|||
stopSpinner = wait('Purchasing') |
|||
elapsed = stamp() |
|||
let domain; |
|||
let domain |
|||
try { |
|||
domain = await domains.buy(name); |
|||
domain = await domains.buy(name) |
|||
} catch (err) { |
|||
stopSpinner(); |
|||
return treatBuyError(err); |
|||
stopSpinner() |
|||
return treatBuyError(err) |
|||
} |
|||
|
|||
stopSpinner(); |
|||
stopSpinner() |
|||
|
|||
success(`Domain purchased and created ${uid(domain.uid)} ${elapsed()}`); |
|||
success(`Domain purchased and created ${uid(domain.uid)} ${elapsed()}`) |
|||
info( |
|||
`You may now use your domain as an alias to your deployments. Run ${cmd('now alias help')}` |
|||
); |
|||
}; |
|||
) |
|||
} |
|||
|
File diff suppressed because it is too large
@ -1,133 +1,133 @@ |
|||
// Native
|
|||
const EventEmitter = require('events'); |
|||
const EventEmitter = require('events') |
|||
|
|||
// Packages
|
|||
const io = require('socket.io-client'); |
|||
const chalk = require('chalk'); |
|||
const io = require('socket.io-client') |
|||
const chalk = require('chalk') |
|||
|
|||
const { compare, deserialize } = require('./logs'); |
|||
const { compare, deserialize } = require('./logs') |
|||
|
|||
module.exports = class Logger extends EventEmitter { |
|||
constructor(host, token, { debug = false, quiet = false } = {}) { |
|||
super(); |
|||
this.host = host; |
|||
this.token = token; |
|||
this.debug = debug; |
|||
this.quiet = quiet; |
|||
super() |
|||
this.host = host |
|||
this.token = token |
|||
this.debug = debug |
|||
this.quiet = quiet |
|||
|
|||
// ReadyState
|
|||
this.building = false; |
|||
this.building = false |
|||
|
|||
this.socket = io(`https://io.now.sh/states?host=${host}&v=2`); |
|||
this.socket.once('error', this.onSocketError.bind(this)); |
|||
this.socket.on('auth', this.onAuth.bind(this)); |
|||
this.socket.on('state', this.onState.bind(this)); |
|||
this.socket.on('logs', this.onLog.bind(this)); |
|||
this.socket.on('backend', this.onComplete.bind(this)); |
|||
this.socket = io(`https://io.now.sh/states?host=${host}&v=2`) |
|||
this.socket.once('error', this.onSocketError.bind(this)) |
|||
this.socket.on('auth', this.onAuth.bind(this)) |
|||
this.socket.on('state', this.onState.bind(this)) |
|||
this.socket.on('logs', this.onLog.bind(this)) |
|||
this.socket.on('backend', this.onComplete.bind(this)) |
|||
|
|||
// Log buffer
|
|||
this.buf = []; |
|||
this.buf = [] |
|||
} |
|||
|
|||
onAuth(callback) { |
|||
if (this.debug) { |
|||
console.log('> [debug] authenticate'); |
|||
console.log('> [debug] authenticate') |
|||
} |
|||
callback(this.token); |
|||
callback(this.token) |
|||
} |
|||
|
|||
onState(state) { |
|||
// Console.log(state)
|
|||
if (!state.id) { |
|||
console.error('> Deployment not found'); |
|||
this.emit('error'); |
|||
return; |
|||
console.error('> Deployment not found') |
|||
this.emit('error') |
|||
return |
|||
} |
|||
|
|||
if (state.error) { |
|||
this.emit('error', state); |
|||
return; |
|||
this.emit('error', state) |
|||
return |
|||
} |
|||
|
|||
if (state.backend) { |
|||
this.onComplete(); |
|||
return; |
|||
this.onComplete() |
|||
return |
|||
} |
|||
|
|||
if (state.logs) { |
|||
state.logs.forEach(this.onLog, this); |
|||
state.logs.forEach(this.onLog, this) |
|||
} |
|||
} |
|||
|
|||
onLog(log) { |
|||
if (!this.building) { |
|||
if (!this.quiet) { |
|||
console.log('> Building'); |
|||
console.log('> Building') |
|||
} |
|||
this.building = true; |
|||
this.building = true |
|||
} |
|||
|
|||
if (this.quiet) { |
|||
return; |
|||
return |
|||
} |
|||
|
|||
log = deserialize(log); |
|||
log = deserialize(log) |
|||
|
|||
const timer = setTimeout(() => { |
|||
this.buf.sort((a, b) => compare(a.log, b.log)); |
|||
const idx = this.buf.findIndex(b => b.log.id === log.id) + 1; |
|||
this.buf.sort((a, b) => compare(a.log, b.log)) |
|||
const idx = this.buf.findIndex(b => b.log.id === log.id) + 1 |
|||
for (const b of this.buf.slice(0, idx)) { |
|||
clearTimeout(b.timer); |
|||
this.printLog(b.log); |
|||
clearTimeout(b.timer) |
|||
this.printLog(b.log) |
|||
} |
|||
this.buf = this.buf.slice(idx); |
|||
}, 300); |
|||
this.buf = this.buf.slice(idx) |
|||
}, 300) |
|||
|
|||
this.buf.push({ log, timer }); |
|||
this.buf.push({ log, timer }) |
|||
} |
|||
|
|||
onComplete() { |
|||
this.socket.disconnect(); |
|||
this.socket.disconnect() |
|||
|
|||
if (this.building) { |
|||
this.building = false; |
|||
this.building = false |
|||
} |
|||
|
|||
this.buf.sort((a, b) => compare(a.log, b.log)); |
|||
this.buf.sort((a, b) => compare(a.log, b.log)) |
|||
|
|||
// Flush all buffer
|
|||
for (const b of this.buf) { |
|||
clearTimeout(b.timer); |
|||
this.printLog(b.log); |
|||
clearTimeout(b.timer) |
|||
this.printLog(b.log) |
|||
} |
|||
this.buf = []; |
|||
this.buf = [] |
|||
|
|||
this.emit('close'); |
|||
this.emit('close') |
|||
} |
|||
|
|||
onSocketError(err) { |
|||
if (this.debug) { |
|||
console.log(`> [debug] Socket error ${err}\n${err.stack}`); |
|||
console.log(`> [debug] Socket error ${err}\n${err.stack}`) |
|||
} |
|||
} |
|||
|
|||
printLog(log) { |
|||
const data = log.object ? JSON.stringify(log.object) : log.text; |
|||
const data = log.object ? JSON.stringify(log.object) : log.text |
|||
|
|||
if (log.type === 'command') { |
|||
console.log(`${chalk.gray('>')} ▲ ${data}`); |
|||
console.log(`${chalk.gray('>')} ▲ ${data}`) |
|||
} else if (log.type === 'stderr') { |
|||
data.split('\n').forEach(v => { |
|||
if (v.length > 0) { |
|||
console.error(chalk.gray(`> ${v}`)); |
|||
console.error(chalk.gray(`> ${v}`)) |
|||
} |
|||
}); |
|||
}) |
|||
} else if (log.type === 'stdout') { |
|||
data.split('\n').forEach(v => { |
|||
if (v.length > 0) { |
|||
console.log(`${chalk.gray('>')} ${v}`); |
|||
console.log(`${chalk.gray('>')} ${v}`) |
|||
} |
|||
}); |
|||
}) |
|||
} |
|||
} |
|||
}; |
|||
} |
|||
|
@ -1,15 +1,15 @@ |
|||
// Packages
|
|||
const dns = require('dns'); |
|||
const dns = require('dns') |
|||
|
|||
function resolve4(host) { |
|||
return new Promise((resolve, reject) => { |
|||
return dns.resolve4(host, (err, answer) => { |
|||
if (err) { |
|||
return reject(err); |
|||
return reject(err) |
|||
} |
|||
|
|||
resolve(answer); |
|||
}); |
|||
}); |
|||
resolve(answer) |
|||
}) |
|||
}) |
|||
} |
|||
module.exports = resolve4; |
|||
module.exports = resolve4 |
|||
|
@ -1,150 +1,148 @@ |
|||
// Ours
|
|||
const Now = require('../lib'); |
|||
const Now = require('../lib') |
|||
|
|||
module.exports = class DomainRecords extends Now { |
|||
async getRecord(id) { |
|||
const all = (await this.ls()).entries(); |
|||
const all = (await this.ls()).entries() |
|||
for (const [domain, records] of all) { |
|||
for (const record of records) { |
|||
if (record.id === id) { |
|||
record.domain = domain; |
|||
return record; |
|||
record.domain = domain |
|||
return record |
|||
} |
|||
} |
|||
} |
|||
return null; |
|||
return null |
|||
} |
|||
|
|||
async ls(dom) { |
|||
let domains; |
|||
let domains |
|||
|
|||
if (dom) { |
|||
domains = [dom]; |
|||
domains = [dom] |
|||
} else { |
|||
const ret = await this.listDomains(); |
|||
const ret = await this.listDomains() |
|||
domains = ret |
|||
.filter(x => !x.isExternal) |
|||
.map(x => x.name) |
|||
.sort((a, b) => a.localeCompare(b)); |
|||
.sort((a, b) => a.localeCompare(b)) |
|||
} |
|||
|
|||
const records = new Map(); |
|||
const bodies = []; |
|||
const records = new Map() |
|||
const bodies = [] |
|||
|
|||
for (const domain of domains) { |
|||
bodies.push( |
|||
this.retry(async (bail, attempt) => { |
|||
const url = `/domains/${domain}/records`; |
|||
const url = `/domains/${domain}/records` |
|||
if (this._debug) { |
|||
console.time(`> [debug] #${attempt} GET ${url}`); |
|||
console.time(`> [debug] #${attempt} GET ${url}`) |
|||
} |
|||
const res = await this._fetch(url); |
|||
const res = await this._fetch(url) |
|||
if (this._debug) { |
|||
console.timeEnd(`> [debug] #${attempt} GET ${url}`); |
|||
console.timeEnd(`> [debug] #${attempt} GET ${url}`) |
|||
} |
|||
const body = await res.json(); |
|||
const body = await res.json() |
|||
|
|||
if (res.status === 404 && body.code === 'not_found') { |
|||
return bail(new Error(body.message)); |
|||
return bail(new Error(body.message)) |
|||
} else if (res.status !== 200) { |
|||
throw new Error(`Failed to get DNS records for domain "${domain}"`); |
|||
throw new Error(`Failed to get DNS records for domain "${domain}"`) |
|||
} |
|||
|
|||
return body; |
|||
return body |
|||
}) |
|||
); |
|||
) |
|||
} |
|||
|
|||
const domainList = await Promise.all(bodies); |
|||
const domainList = await Promise.all(bodies) |
|||
|
|||
for (const body of domainList) { |
|||
const index = domainList.indexOf(body); |
|||
const index = domainList.indexOf(body) |
|||
|
|||
records.set( |
|||
domains[index], |
|||
body.records.sort((a, b) => a.slug.localeCompare(b.slug)) |
|||
); |
|||
) |
|||
} |
|||
|
|||
return records; |
|||
return records |
|||
} |
|||
|
|||
create(domain, data) { |
|||
const url = `/domains/${domain}/records`; |
|||
const url = `/domains/${domain}/records` |
|||
|
|||
return this.retry(async (bail, attempt) => { |
|||
if (this._debug) { |
|||
console.time(`> [debug] #${attempt} POST ${url}`); |
|||
console.time(`> [debug] #${attempt} POST ${url}`) |
|||
} |
|||
const res = await this._fetch(url, { |
|||
method: 'POST', |
|||
body: data |
|||
}); |
|||
}) |
|||
if (this._debug) { |
|||
console.timeEnd(`> [debug] #${attempt} POST ${url}`); |
|||
console.timeEnd(`> [debug] #${attempt} POST ${url}`) |
|||
} |
|||
|
|||
const body = await res.json(); |
|||
const body = await res.json() |
|||
if (res.status === 400) { |
|||
return bail( |
|||
new Error(body.error ? body.error.message : 'Unknown error') |
|||
); |
|||
) |
|||
} else if (res.status === 403) { |
|||
const err = new Error( |
|||
`Not authorized to access the domain "${domain}"` |
|||
); |
|||
err.userError = true; |
|||
return bail(err); |
|||
const err = new Error(`Not authorized to access the domain "${domain}"`) |
|||
err.userError = true |
|||
return bail(err) |
|||
} else if (res.status === 404) { |
|||
let err; |
|||
let err |
|||
|
|||
if (body.error.code === 'not_found') { |
|||
err = new Error(`The domain "${domain}" was not found`); |
|||
err.userError = true; |
|||
return bail(err); |
|||
err = new Error(`The domain "${domain}" was not found`) |
|||
err.userError = true |
|||
return bail(err) |
|||
} |
|||
} |
|||
|
|||
if (res.status !== 200) { |
|||
throw new Error(body.error ? body.error.message : 'Unknown error'); |
|||
throw new Error(body.error ? body.error.message : 'Unknown error') |
|||
} |
|||
|
|||
return body; |
|||
}); |
|||
return body |
|||
}) |
|||
} |
|||
|
|||
delete(domain, recordId) { |
|||
const url = `/domains/${domain}/records/${recordId}`; |
|||
const url = `/domains/${domain}/records/${recordId}` |
|||
|
|||
return this.retry(async (bail, attempt) => { |
|||
if (this._debug) { |
|||
console.time(`> [debug] #${attempt} DELETE ${url}`); |
|||
console.time(`> [debug] #${attempt} DELETE ${url}`) |
|||
} |
|||
const res = await this._fetch(url, { method: 'DELETE' }); |
|||
const res = await this._fetch(url, { method: 'DELETE' }) |
|||
if (this._debug) { |
|||
console.timeEnd(`> [debug] #${attempt} DELETE ${url}`); |
|||
console.timeEnd(`> [debug] #${attempt} DELETE ${url}`) |
|||
} |
|||
|
|||
const body = await res.json(); |
|||
const body = await res.json() |
|||
if (res.status === 403) { |
|||
const err = new Error(`Not authorized to access domain ${domain}`); |
|||
err.userError = true; |
|||
return bail(err); |
|||
const err = new Error(`Not authorized to access domain ${domain}`) |
|||
err.userError = true |
|||
return bail(err) |
|||
} else if (res.status === 404) { |
|||
let err; |
|||
let err |
|||
|
|||
if (body.error.code === 'not_found') { |
|||
err = new Error(body.error.message); |
|||
err.userError = true; |
|||
return bail(err); |
|||
err = new Error(body.error.message) |
|||
err.userError = true |
|||
return bail(err) |
|||
} |
|||
} |
|||
|
|||
if (res.status !== 200) { |
|||
throw new Error(body.error ? body.error.message : 'Unkown error'); |
|||
throw new Error(body.error ? body.error.message : 'Unkown error') |
|||
} |
|||
|
|||
return body; |
|||
}); |
|||
return body |
|||
}) |
|||
} |
|||
}; |
|||
} |
|||
|
@ -1,37 +1,37 @@ |
|||
// Packages
|
|||
const ms = require('ms'); |
|||
const chalk = require('chalk'); |
|||
const ms = require('ms') |
|||
const chalk = require('chalk') |
|||
|
|||
const error = require('./utils/output/error'); |
|||
const error = require('./utils/output/error') |
|||
|
|||
function handleError(err) { |
|||
if (err.status === 403) { |
|||
error( |
|||
'Authentication error. Run `now -L` or `now --login` to log-in again.' |
|||
); |
|||
) |
|||
} else if (err.status === 429) { |
|||
if (err.retryAfter === 'never') { |
|||
error(err.message); |
|||
error(err.message) |
|||
} else if (err.retryAfter === null) { |
|||
error('Rate limit exceeded error. Please try later.'); |
|||
error('Rate limit exceeded error. Please try later.') |
|||
} else { |
|||
error( |
|||
'Rate limit exceeded error. Try again in ' + |
|||
ms(err.retryAfter * 1000, { long: true }) + |
|||
', or upgrade your account by runnung ' + |
|||
`${chalk.gray('`')}${chalk.cyan('now upgrade')}${chalk.gray('`')}` |
|||
); |
|||
) |
|||
} |
|||
} else if (err.userError) { |
|||
error(err.message); |
|||
error(err.message) |
|||
} else if (err.status === 500) { |
|||
error('Unexpected server error. Please retry.'); |
|||
error('Unexpected server error. Please retry.') |
|||
} else { |
|||
error(`Unexpected error. Please try later. (${err.message})`); |
|||
error(`Unexpected error. Please try later. (${err.message})`) |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
handleError, |
|||
error |
|||
}; |
|||
} |
|||
|
@ -1,17 +1,18 @@ |
|||
// Packages
|
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
const DNS_VERIFICATION_ERROR = `Please make sure that your nameservers point to ${chalk.underline('zeit.world')}.
|
|||
> Examples: (full list at ${chalk.underline('https://zeit.world')}) |
|||
> ${chalk.gray('-')} ${chalk.underline('california.zeit.world')} ${chalk.dim('173.255.215.107')} |
|||
> ${chalk.gray('-')} ${chalk.underline('newark.zeit.world')} ${chalk.dim('173.255.231.87')} |
|||
> ${chalk.gray('-')} ${chalk.underline('london.zeit.world')} ${chalk.dim('178.62.47.76')} |
|||
> ${chalk.gray('-')} ${chalk.underline('singapore.zeit.world')} ${chalk.dim('119.81.97.170')}`;
|
|||
> ${chalk.gray('-')} ${chalk.underline('singapore.zeit.world')} ${chalk.dim('119.81.97.170')}` |
|||
|
|||
const DOMAIN_VERIFICATION_ERROR = DNS_VERIFICATION_ERROR + |
|||
`\n> Alternatively, ensure it resolves to ${chalk.underline('alias.zeit.co')} via ${chalk.dim('CNAME')} / ${chalk.dim('ALIAS')}.`; |
|||
const DOMAIN_VERIFICATION_ERROR = |
|||
DNS_VERIFICATION_ERROR + |
|||
`\n> Alternatively, ensure it resolves to ${chalk.underline('alias.zeit.co')} via ${chalk.dim('CNAME')} / ${chalk.dim('ALIAS')}.` |
|||
|
|||
module.exports = { |
|||
DNS_VERIFICATION_ERROR, |
|||
DOMAIN_VERIFICATION_ERROR |
|||
}; |
|||
} |
|||
|
@ -1,211 +1,210 @@ |
|||
// Native
|
|||
const path = require('path'); |
|||
const url = require('url'); |
|||
const childProcess = require('child_process'); |
|||
const path = require('path') |
|||
const url = require('url') |
|||
const childProcess = require('child_process') |
|||
|
|||
// Packages
|
|||
const fs = require('fs-promise'); |
|||
const download = require('download'); |
|||
const tmp = require('tmp-promise'); |
|||
const isURL = require('is-url'); |
|||
const fs = require('fs-promise') |
|||
const download = require('download') |
|||
const tmp = require('tmp-promise') |
|||
const isURL = require('is-url') |
|||
|
|||
const cloneRepo = (parts, tmpDir) => |
|||
new Promise((resolve, reject) => { |
|||
let host; |
|||
let host |
|||
|
|||
switch (parts.type) { |
|||
case 'GitLab': |
|||
host = `gitlab.com`; |
|||
break; |
|||
host = `gitlab.com` |
|||
break |
|||
case 'Bitbucket': |
|||
host = `bitbucket.org`; |
|||
break; |
|||
host = `bitbucket.org` |
|||
break |
|||
default: |
|||
host = `github.com`; |
|||
host = `github.com` |
|||
} |
|||
|
|||
const url = `https://${host}/${parts.main}`; |
|||
const ref = parts.ref || |
|||
(parts.type === 'Bitbucket' ? 'default' : 'master'); |
|||
const cmd = `git clone ${url} --single-branch ${ref}`; |
|||
const url = `https://${host}/${parts.main}` |
|||
const ref = parts.ref || (parts.type === 'Bitbucket' ? 'default' : 'master') |
|||
const cmd = `git clone ${url} --single-branch ${ref}` |
|||
|
|||
childProcess.exec(cmd, { cwd: tmpDir.path }, (err, stdout) => { |
|||
if (err) { |
|||
reject(err); |
|||
reject(err) |
|||
} |
|||
|
|||
resolve(stdout); |
|||
}); |
|||
}); |
|||
resolve(stdout) |
|||
}) |
|||
}) |
|||
|
|||
const renameRepoDir = async (pathParts, tmpDir) => { |
|||
const tmpContents = await fs.readdir(tmpDir.path); |
|||
const tmpContents = await fs.readdir(tmpDir.path) |
|||
|
|||
const oldTemp = path.join(tmpDir.path, tmpContents[0]); |
|||
const newTemp = path.join(tmpDir.path, pathParts.main.replace('/', '-')); |
|||
const oldTemp = path.join(tmpDir.path, tmpContents[0]) |
|||
const newTemp = path.join(tmpDir.path, pathParts.main.replace('/', '-')) |
|||
|
|||
await fs.rename(oldTemp, newTemp); |
|||
tmpDir.path = newTemp; |
|||
await fs.rename(oldTemp, newTemp) |
|||
tmpDir.path = newTemp |
|||
|
|||
return tmpDir; |
|||
}; |
|||
return tmpDir |
|||
} |
|||
|
|||
const capitalizePlatform = name => { |
|||
const names = { |
|||
github: 'GitHub', |
|||
gitlab: 'GitLab', |
|||
bitbucket: 'Bitbucket' |
|||
}; |
|||
} |
|||
|
|||
return names[name]; |
|||
}; |
|||
return names[name] |
|||
} |
|||
|
|||
const splittedURL = fullURL => { |
|||
const parsedURL = url.parse(fullURL); |
|||
const pathParts = parsedURL.path.split('/'); |
|||
const parsedURL = url.parse(fullURL) |
|||
const pathParts = parsedURL.path.split('/') |
|||
|
|||
pathParts.shift(); |
|||
pathParts.shift() |
|||
|
|||
// Set path to repo...
|
|||
const main = pathParts[0] + '/' + pathParts[1]; |
|||
const main = pathParts[0] + '/' + pathParts[1] |
|||
|
|||
// ...and then remove it from the parts
|
|||
pathParts.splice(0, 2); |
|||
pathParts.splice(0, 2) |
|||
|
|||
// Assign Git reference
|
|||
let ref = pathParts.length >= 2 ? pathParts[1] : ''; |
|||
let ref = pathParts.length >= 2 ? pathParts[1] : '' |
|||
|
|||
// Firstly be sure that we haven know the ref type
|
|||
if (pathParts[0]) { |
|||
// Then shorten the SHA of the commit
|
|||
if (pathParts[0] === 'commit' || pathParts[0] === 'commits') { |
|||
ref = ref.substring(0, 7); |
|||
ref = ref.substring(0, 7) |
|||
} |
|||
} |
|||
|
|||
// We're deploying master by default,
|
|||
// so there's no need to indicate it explicitly
|
|||
if (ref === 'master') { |
|||
ref = ''; |
|||
ref = '' |
|||
} |
|||
|
|||
return { |
|||
main, |
|||
ref, |
|||
type: capitalizePlatform(parsedURL.host.split('.')[0]) |
|||
}; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
const gitPathParts = main => { |
|||
let ref = ''; |
|||
let ref = '' |
|||
|
|||
if (isURL(main)) { |
|||
return splittedURL(main); |
|||
return splittedURL(main) |
|||
} |
|||
|
|||
if (main.split('/')[1].includes('#')) { |
|||
const parts = main.split('#'); |
|||
const parts = main.split('#') |
|||
|
|||
ref = parts[1]; |
|||
main = parts[0]; |
|||
ref = parts[1] |
|||
main = parts[0] |
|||
} |
|||
|
|||
return { |
|||
main, |
|||
ref, |
|||
type: capitalizePlatform('github') |
|||
}; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
const downloadRepo = async repoPath => { |
|||
const pathParts = gitPathParts(repoPath); |
|||
const pathParts = gitPathParts(repoPath) |
|||
|
|||
const tmpDir = await tmp.dir({ |
|||
// We'll remove it manually once deployment is done
|
|||
keep: true, |
|||
// Recursively remove directory when calling respective method
|
|||
unsafeCleanup: true |
|||
}); |
|||
}) |
|||
|
|||
let gitInstalled = true; |
|||
let gitInstalled = true |
|||
|
|||
try { |
|||
await cloneRepo(pathParts, tmpDir); |
|||
await cloneRepo(pathParts, tmpDir) |
|||
} catch (err) { |
|||
gitInstalled = false; |
|||
gitInstalled = false |
|||
} |
|||
|
|||
if (gitInstalled) { |
|||
const renaming = await renameRepoDir(pathParts, tmpDir); |
|||
return renaming; |
|||
const renaming = await renameRepoDir(pathParts, tmpDir) |
|||
return renaming |
|||
} |
|||
|
|||
let url; |
|||
let url |
|||
|
|||
switch (pathParts.type) { |
|||
case 'GitLab': { |
|||
const ref = pathParts.ref ? `?ref=${pathParts.ref}` : ''; |
|||
url = `https://gitlab.com/${pathParts.main}/repository/archive.tar` + ref; |
|||
break; |
|||
const ref = pathParts.ref ? `?ref=${pathParts.ref}` : '' |
|||
url = `https://gitlab.com/${pathParts.main}/repository/archive.tar` + ref |
|||
break |
|||
} |
|||
case 'Bitbucket': |
|||
url = `https://bitbucket.org/${pathParts.main}/get/${pathParts.ref || 'default'}.zip`; |
|||
break; |
|||
url = `https://bitbucket.org/${pathParts.main}/get/${pathParts.ref || 'default'}.zip` |
|||
break |
|||
default: |
|||
url = `https://api.github.com/repos/${pathParts.main}/tarball/${pathParts.ref}`; |
|||
url = `https://api.github.com/repos/${pathParts.main}/tarball/${pathParts.ref}` |
|||
} |
|||
|
|||
try { |
|||
await download(url, tmpDir.path, { |
|||
extract: true |
|||
}); |
|||
}) |
|||
} catch (err) { |
|||
tmpDir.cleanup(); |
|||
return false; |
|||
tmpDir.cleanup() |
|||
return false |
|||
} |
|||
|
|||
const renaming = await renameRepoDir(pathParts, tmpDir); |
|||
return renaming; |
|||
}; |
|||
const renaming = await renameRepoDir(pathParts, tmpDir) |
|||
return renaming |
|||
} |
|||
|
|||
const isRepoPath = path => { |
|||
if (!path) { |
|||
return false; |
|||
return false |
|||
} |
|||
|
|||
const allowedHosts = ['github.com', 'gitlab.com', 'bitbucket.org']; |
|||
const allowedHosts = ['github.com', 'gitlab.com', 'bitbucket.org'] |
|||
|
|||
if (isURL(path)) { |
|||
const urlParts = url.parse(path); |
|||
const slashSplitted = urlParts.path.split('/').filter(n => n); |
|||
const notBare = slashSplitted.length >= 2; |
|||
const urlParts = url.parse(path) |
|||
const slashSplitted = urlParts.path.split('/').filter(n => n) |
|||
const notBare = slashSplitted.length >= 2 |
|||
|
|||
if (allowedHosts.includes(urlParts.host) && notBare) { |
|||
return true; |
|||
return true |
|||
} |
|||
|
|||
return 'no-valid-url'; |
|||
return 'no-valid-url' |
|||
} |
|||
|
|||
return /[^\s\\]\/[^\s\\]/g.test(path); |
|||
}; |
|||
return /[^\s\\]\/[^\s\\]/g.test(path) |
|||
} |
|||
|
|||
const fromGit = async (path, debug) => { |
|||
let tmpDir = false; |
|||
let tmpDir = false |
|||
|
|||
try { |
|||
tmpDir = await downloadRepo(path); |
|||
tmpDir = await downloadRepo(path) |
|||
} catch (err) { |
|||
if (debug) { |
|||
console.log(`Could not download "${path}" repo from GitHub`); |
|||
console.log(`Could not download "${path}" repo from GitHub`) |
|||
} |
|||
} |
|||
|
|||
return tmpDir; |
|||
}; |
|||
return tmpDir |
|||
} |
|||
|
|||
module.exports = { |
|||
gitPathParts, |
|||
isRepoPath, |
|||
fromGit |
|||
}; |
|||
} |
|||
|
@ -1,5 +1,5 @@ |
|||
function indent(text, n) { |
|||
return text.split('\n').map(l => ' '.repeat(n) + l).join('\n'); |
|||
return text.split('\n').map(l => ' '.repeat(n) + l).join('\n') |
|||
} |
|||
|
|||
module.exports = indent; |
|||
module.exports = indent |
|||
|
File diff suppressed because it is too large
@ -1,12 +1,14 @@ |
|||
exports.compare = function(a, b) { |
|||
return a.serial.localeCompare(b.serial) || |
|||
return ( |
|||
a.serial.localeCompare(b.serial) || |
|||
// For the case serials are a same value on old logs
|
|||
a.created.getTime() - b.created.getTime(); |
|||
}; |
|||
a.created.getTime() - b.created.getTime() |
|||
) |
|||
} |
|||
|
|||
exports.deserialize = function(log) { |
|||
return Object.assign({}, log, { |
|||
date: new Date(log.date), |
|||
created: new Date(log.created) |
|||
}); |
|||
}; |
|||
}) |
|||
} |
|||
|
@ -1,10 +1,10 @@ |
|||
/* eslint-disable import/no-unresolved */ |
|||
|
|||
let pkg; |
|||
let pkg |
|||
try { |
|||
pkg = require('../package.json'); |
|||
pkg = require('../package.json') |
|||
} catch (err) { |
|||
pkg = require('../../package.json'); |
|||
pkg = require('../../package.json') |
|||
} |
|||
|
|||
module.exports = pkg; |
|||
module.exports = pkg |
|||
|
@ -1,43 +1,40 @@ |
|||
// Ours
|
|||
const Now = require('../lib'); |
|||
const Now = require('../lib') |
|||
|
|||
module.exports = class Scale extends Now { |
|||
|
|||
getInstances(id) { |
|||
return this.retry(async (bail, attempt) => { |
|||
if (this._debug) { |
|||
console.time( |
|||
`> [debug] #${attempt} GET /deployments/${id}/instances` |
|||
); |
|||
console.time(`> [debug] #${attempt} GET /deployments/${id}/instances`) |
|||
} |
|||
|
|||
const res = await this._fetch(`/now/deployments/${id}/instances`, { |
|||
method: 'GET' |
|||
}); |
|||
}) |
|||
|
|||
if (this._debug) { |
|||
console.timeEnd( |
|||
`> [debug] #${attempt} GET /deployments/${id}/instances` |
|||
); |
|||
) |
|||
} |
|||
|
|||
if (res.status === 403) { |
|||
return bail(new Error('Unauthorized')); |
|||
return bail(new Error('Unauthorized')) |
|||
} |
|||
|
|||
const body = await res.json(); |
|||
const body = await res.json() |
|||
|
|||
if (res.status !== 200) { |
|||
if (res.status === 404 || res.status === 400) { |
|||
const err = new Error(body.error.message); |
|||
err.userError = true; |
|||
return bail(err); |
|||
const err = new Error(body.error.message) |
|||
err.userError = true |
|||
return bail(err) |
|||
} |
|||
|
|||
throw new Error(body.error.message); |
|||
throw new Error(body.error.message) |
|||
} |
|||
|
|||
return body; |
|||
}); |
|||
return body |
|||
}) |
|||
} |
|||
}; |
|||
} |
|||
|
@ -1,5 +1,5 @@ |
|||
function strlen(str) { |
|||
return str.replace(/\u001b[^m]*m/g, '').length; |
|||
return str.replace(/\u001b[^m]*m/g, '').length |
|||
} |
|||
|
|||
module.exports = strlen; |
|||
module.exports = strlen |
|||
|
@ -1,22 +1,22 @@ |
|||
// Native
|
|||
const { resolve } = require('path'); |
|||
const { resolve } = require('path') |
|||
|
|||
// Ours
|
|||
const { npm: getFiles } = require('./get-files'); |
|||
const { npm: getFiles } = require('./get-files') |
|||
|
|||
getFiles(resolve('../mng-test/files-in-package')) |
|||
.then(files => { |
|||
console.log(files); |
|||
console.log(files) |
|||
|
|||
getFiles(resolve('../mng-test/files-in-package-ignore')) |
|||
.then(files2 => { |
|||
console.log('ignored: '); |
|||
console.log(files2); |
|||
console.log('ignored: ') |
|||
console.log(files2) |
|||
}) |
|||
.catch(err => { |
|||
console.log(err.stack); |
|||
}); |
|||
console.log(err.stack) |
|||
}) |
|||
}) |
|||
.catch(err => { |
|||
console.log(err.stack); |
|||
}); |
|||
console.log(err.stack) |
|||
}) |
|||
|
@ -1,7 +1,7 @@ |
|||
// Native
|
|||
const os = require('os'); |
|||
const os = require('os') |
|||
|
|||
// Ours
|
|||
const { version } = require('./pkg'); |
|||
const { version } = require('./pkg') |
|||
|
|||
module.exports = `now ${version} node-${process.version} ${os.platform()} (${os.arch()})`; |
|||
module.exports = `now ${version} node-${process.version} ${os.platform()} (${os.arch()})` |
|||
|
@ -1,33 +1,33 @@ |
|||
// Packages
|
|||
const gMaps = require('@google/maps'); |
|||
const gMaps = require('@google/maps') |
|||
|
|||
const MAPS_API_KEY = 'AIzaSyALfKTQ6AiIoJ8WGDXR3E7IBOwlHoTPfYY'; |
|||
const MAPS_API_KEY = 'AIzaSyALfKTQ6AiIoJ8WGDXR3E7IBOwlHoTPfYY' |
|||
|
|||
// eslint-disable-next-line camelcase
|
|||
module.exports = function({ country, zipCode: postal_code }) { |
|||
return new Promise(resolve => { |
|||
const maps = gMaps.createClient({ key: MAPS_API_KEY }); |
|||
const maps = gMaps.createClient({ key: MAPS_API_KEY }) |
|||
maps.geocode( |
|||
{ |
|||
address: `${postal_code} ${country}` // eslint-disable-line camelcase
|
|||
}, |
|||
(err, res) => { |
|||
if (err || res.json.results.length === 0) { |
|||
resolve(); |
|||
resolve() |
|||
} |
|||
|
|||
const data = res.json.results[0]; |
|||
const components = {}; |
|||
const data = res.json.results[0] |
|||
const components = {} |
|||
data.address_components.forEach(c => { |
|||
components[c.types[0]] = c; |
|||
}); |
|||
const state = components.administrative_area_level_1; |
|||
const city = components.locality; |
|||
components[c.types[0]] = c |
|||
}) |
|||
const state = components.administrative_area_level_1 |
|||
const city = components.locality |
|||
resolve({ |
|||
state: state && state.long_name, |
|||
city: city && city.long_name |
|||
}); |
|||
}) |
|||
} |
|||
); |
|||
}); |
|||
}; |
|||
) |
|||
}) |
|||
} |
|||
|
@ -1,49 +1,49 @@ |
|||
// Native
|
|||
const os = require('os'); |
|||
const path = require('path'); |
|||
const os = require('os') |
|||
const path = require('path') |
|||
|
|||
const checkPath = async dir => { |
|||
if (!dir) { |
|||
return; |
|||
return |
|||
} |
|||
|
|||
const home = os.homedir(); |
|||
let location; |
|||
const home = os.homedir() |
|||
let location |
|||
|
|||
const paths = { |
|||
home, |
|||
desktop: path.join(home, 'Desktop'), |
|||
downloads: path.join(home, 'Downloads') |
|||
}; |
|||
} |
|||
|
|||
for (const locationPath in paths) { |
|||
if (!{}.hasOwnProperty.call(paths, locationPath)) { |
|||
continue; |
|||
continue |
|||
} |
|||
|
|||
if (dir === paths[locationPath]) { |
|||
location = locationPath; |
|||
location = locationPath |
|||
} |
|||
} |
|||
|
|||
if (!location) { |
|||
return; |
|||
return |
|||
} |
|||
|
|||
let locationName; |
|||
let locationName |
|||
|
|||
switch (location) { |
|||
case 'home': |
|||
locationName = 'user directory'; |
|||
break; |
|||
locationName = 'user directory' |
|||
break |
|||
case 'downloads': |
|||
locationName = 'downloads directory'; |
|||
break; |
|||
locationName = 'downloads directory' |
|||
break |
|||
default: |
|||
locationName = location; |
|||
locationName = location |
|||
} |
|||
|
|||
throw new Error(`You're trying to deploy your ${locationName}.`); |
|||
}; |
|||
throw new Error(`You're trying to deploy your ${locationName}.`) |
|||
} |
|||
|
|||
module.exports = checkPath; |
|||
module.exports = checkPath |
|||
|
@ -1,7 +1,7 @@ |
|||
const error = require('./output/error'); |
|||
const exit = require('./exit'); |
|||
const error = require('./output/error') |
|||
const exit = require('./exit') |
|||
|
|||
module.exports = (msg, code = 1) => { |
|||
error(msg); |
|||
exit(code); |
|||
}; |
|||
error(msg) |
|||
exit(code) |
|||
} |
|||
|
@ -1,92 +1,90 @@ |
|||
const chalk = require('chalk'); |
|||
const inquirer = require('inquirer'); |
|||
const stripAnsi = require('strip-ansi'); |
|||
const chalk = require('chalk') |
|||
const inquirer = require('inquirer') |
|||
const stripAnsi = require('strip-ansi') |
|||
|
|||
/* eslint-disable no-multiple-empty-lines, no-var, no-undef, no-eq-null, eqeqeq, semi */ |
|||
inquirer.prompt.prompts.list.prototype.getQuestion = function() { |
|||
var message = chalk.bold('> ' + this.opt.message) + ' '; |
|||
var message = chalk.bold('> ' + this.opt.message) + ' ' |
|||
|
|||
// Append the default if available, and if question isn't answered
|
|||
if (this.opt.default != null && this.status !== 'answered') { |
|||
message += chalk.dim('(' + this.opt.default + ') '); |
|||
message += chalk.dim('(' + this.opt.default + ') ') |
|||
} |
|||
|
|||
return message; |
|||
}; |
|||
return message |
|||
} |
|||
/* eslint-enable */ |
|||
|
|||
function getLength(string) { |
|||
let biggestLength = 0; |
|||
let biggestLength = 0 |
|||
string.split('\n').map(str => { |
|||
str = stripAnsi(str); |
|||
str = stripAnsi(str) |
|||
if (str.length > biggestLength) { |
|||
biggestLength = str.length; |
|||
biggestLength = str.length |
|||
} |
|||
return undefined; |
|||
}); |
|||
return biggestLength; |
|||
return undefined |
|||
}) |
|||
return biggestLength |
|||
} |
|||
|
|||
module.exports = async function( |
|||
{ |
|||
message = 'the question', |
|||
// eslint-disable-line no-unused-vars
|
|||
choices = [ |
|||
{ |
|||
name: 'something\ndescription\ndetails\netc', |
|||
value: 'something unique', |
|||
short: 'generally the first line of `name`' |
|||
} |
|||
], |
|||
pageSize = 15, // Show 15 lines without scrolling (~4 credit cards)
|
|||
separator = true, // Puts a blank separator between each choice
|
|||
abort = 'end' // Wether the `abort` option will be at the `start` or the `end`
|
|||
} |
|||
) { |
|||
let biggestLength = 0; |
|||
module.exports = async function({ |
|||
message = 'the question', |
|||
// eslint-disable-line no-unused-vars
|
|||
choices = [ |
|||
{ |
|||
name: 'something\ndescription\ndetails\netc', |
|||
value: 'something unique', |
|||
short: 'generally the first line of `name`' |
|||
} |
|||
], |
|||
pageSize = 15, // Show 15 lines without scrolling (~4 credit cards)
|
|||
separator = true, // Puts a blank separator between each choice
|
|||
abort = 'end' // Wether the `abort` option will be at the `start` or the `end`
|
|||
}) { |
|||
let biggestLength = 0 |
|||
|
|||
choices = choices.map(choice => { |
|||
if (choice.name) { |
|||
const length = getLength(choice.name); |
|||
const length = getLength(choice.name) |
|||
if (length > biggestLength) { |
|||
biggestLength = length; |
|||
biggestLength = length |
|||
} |
|||
return choice; |
|||
return choice |
|||
} |
|||
throw new Error('Invalid choice'); |
|||
}); |
|||
throw new Error('Invalid choice') |
|||
}) |
|||
|
|||
if (separator === true) { |
|||
choices = choices.reduce( |
|||
(prev, curr) => prev.concat(new inquirer.Separator(' '), curr), |
|||
[] |
|||
); |
|||
) |
|||
} |
|||
|
|||
const abortSeparator = new inquirer.Separator('─'.repeat(biggestLength)); |
|||
const abortSeparator = new inquirer.Separator('─'.repeat(biggestLength)) |
|||
const _abort = { |
|||
name: 'Abort', |
|||
value: undefined |
|||
}; |
|||
} |
|||
|
|||
if (abort === 'start') { |
|||
const blankSep = choices.shift(); |
|||
choices.unshift(abortSeparator); |
|||
choices.unshift(_abort); |
|||
choices.unshift(blankSep); |
|||
const blankSep = choices.shift() |
|||
choices.unshift(abortSeparator) |
|||
choices.unshift(_abort) |
|||
choices.unshift(blankSep) |
|||
} else { |
|||
choices.push(abortSeparator); |
|||
choices.push(_abort); |
|||
choices.push(abortSeparator) |
|||
choices.push(_abort) |
|||
} |
|||
|
|||
const nonce = Date.now(); |
|||
const nonce = Date.now() |
|||
const answer = await inquirer.prompt({ |
|||
name: nonce, |
|||
type: 'list', |
|||
message, |
|||
choices, |
|||
pageSize |
|||
}); |
|||
}) |
|||
|
|||
return answer[nonce]; |
|||
}; |
|||
return answer[nonce] |
|||
} |
|||
|
@ -1,3 +1,3 @@ |
|||
module.exports = { |
|||
email: /.+@.+\..+$/ |
|||
}; |
|||
} |
|||
|
@ -1,3 +1,3 @@ |
|||
module.exports = { |
|||
tick: '✓' |
|||
}; |
|||
} |
|||
|
@ -1,7 +1,6 @@ |
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
// The equivalent of <code>, for embedding a cmd
|
|||
// eg: Please run ${cmd(woot)}
|
|||
|
|||
module.exports = cmd => |
|||
`${chalk.gray('`')}${chalk.cyan(cmd)}${chalk.gray('`')}`; |
|||
module.exports = cmd => `${chalk.gray('`')}${chalk.cyan(cmd)}${chalk.gray('`')}` |
|||
|
@ -1,7 +1,6 @@ |
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
// The equivalent of <code>, for embedding anything
|
|||
// you may want to take a look at ./cmd.js
|
|||
|
|||
module.exports = cmd => |
|||
`${chalk.gray('`')}${chalk.bold(cmd)}${chalk.gray('`')}`; |
|||
module.exports = cmd => `${chalk.gray('`')}${chalk.bold(cmd)}${chalk.gray('`')}` |
|||
|
@ -1,3 +1,3 @@ |
|||
const ansiEscapes = require('ansi-escapes'); |
|||
const ansiEscapes = require('ansi-escapes') |
|||
|
|||
module.exports = n => process.stdout.write(ansiEscapes.eraseLines(n)); |
|||
module.exports = n => process.stdout.write(ansiEscapes.eraseLines(n)) |
|||
|
@ -1,10 +1,10 @@ |
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
// Prints an error message
|
|||
module.exports = msg => { |
|||
if (msg instanceof Error) { |
|||
msg = msg.message; |
|||
msg = msg.message |
|||
} |
|||
|
|||
console.error(`${chalk.red('> Error!')} ${msg}`); |
|||
}; |
|||
console.error(`${chalk.red('> Error!')} ${msg}`) |
|||
} |
|||
|
@ -1,6 +1,6 @@ |
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
// Prints an informational message
|
|||
module.exports = msg => { |
|||
console.log(`${chalk.gray('>')} ${msg}`); |
|||
}; |
|||
console.log(`${chalk.gray('>')} ${msg}`) |
|||
} |
|||
|
@ -1 +1 @@ |
|||
module.exports = process.platform === 'win32' ? 'Δ' : '𝚫'; |
|||
module.exports = process.platform === 'win32' ? 'Δ' : '𝚫' |
|||
|
@ -1,6 +1,6 @@ |
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
// Prints a note
|
|||
module.exports = msg => { |
|||
console.log(`${chalk.yellow('> NOTE:')} ${msg}`); |
|||
}; |
|||
console.log(`${chalk.yellow('> NOTE:')} ${msg}`) |
|||
} |
|||
|
@ -1,7 +1,7 @@ |
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
// Returns a user param in a nice formatting
|
|||
// e.g.: google.com -> "google.com" (in bold)
|
|||
|
|||
module.exports = param => |
|||
chalk.bold(`${chalk.gray('"')}${chalk.bold(param)}${chalk.gray('"')}`); |
|||
chalk.bold(`${chalk.gray('"')}${chalk.bold(param)}${chalk.gray('"')}`) |
|||
|
@ -1,4 +1,4 @@ |
|||
module.exports = (string, n = 0) => { |
|||
n -= string.length; |
|||
return string + ' '.repeat(n > -1 ? n : 0); |
|||
}; |
|||
n -= string.length |
|||
return string + ' '.repeat(n > -1 ? n : 0) |
|||
} |
|||
|
@ -1,10 +1,10 @@ |
|||
const ms = require('ms'); |
|||
const chalk = require('chalk'); |
|||
const ms = require('ms') |
|||
const chalk = require('chalk') |
|||
|
|||
// Returns a time delta with the right color
|
|||
// example: `[103ms]`
|
|||
|
|||
module.exports = () => { |
|||
const start = new Date(); |
|||
return () => chalk.gray(`[${ms(new Date() - start)}]`); |
|||
}; |
|||
const start = new Date() |
|||
return () => chalk.gray(`[${ms(new Date() - start)}]`) |
|||
} |
|||
|
@ -1,6 +1,6 @@ |
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
// Prints a success message
|
|||
module.exports = msg => { |
|||
console.log(`${chalk.cyan('> Success!')} ${msg}`); |
|||
}; |
|||
console.log(`${chalk.cyan('> Success!')} ${msg}`) |
|||
} |
|||
|
@ -1,5 +1,5 @@ |
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
// Used for including uids in the output
|
|||
// example: `(dom_ji13dj2fih4fi2hf)`
|
|||
module.exports = id => chalk.gray(`(${id})`); |
|||
module.exports = id => chalk.gray(`(${id})`) |
|||
|
@ -1,15 +1,15 @@ |
|||
const ora = require('ora'); |
|||
const chalk = require('chalk'); |
|||
const { eraseLine } = require('ansi-escapes'); |
|||
const ora = require('ora') |
|||
const chalk = require('chalk') |
|||
const { eraseLine } = require('ansi-escapes') |
|||
|
|||
// Prints a spinner followed by the given text
|
|||
module.exports = msg => { |
|||
const spinner = ora(chalk.gray(msg)); |
|||
spinner.color = 'gray'; |
|||
spinner.start(); |
|||
const spinner = ora(chalk.gray(msg)) |
|||
spinner.color = 'gray' |
|||
spinner.start() |
|||
|
|||
return () => { |
|||
spinner.stop(); |
|||
process.stdout.write(eraseLine); |
|||
}; |
|||
}; |
|||
spinner.stop() |
|||
process.stdout.write(eraseLine) |
|||
} |
|||
} |
|||
|
@ -1,35 +1,35 @@ |
|||
// Packages
|
|||
const chalk = require('chalk'); |
|||
const chalk = require('chalk') |
|||
|
|||
module.exports = function(opts) { |
|||
return new Promise((resolve, reject) => { |
|||
opts.forEach(([, text], i) => { |
|||
console.log(`${chalk.gray('>')} [${chalk.bold(i + 1)}] ${text}`); |
|||
}); |
|||
console.log(`${chalk.gray('>')} [${chalk.bold(i + 1)}] ${text}`) |
|||
}) |
|||
|
|||
const ondata = v => { |
|||
const s = v.toString(); |
|||
const s = v.toString() |
|||
|
|||
const cleanup = () => { |
|||
process.stdin.setRawMode(false); |
|||
process.stdin.removeListener('data', ondata); |
|||
}; |
|||
process.stdin.setRawMode(false) |
|||
process.stdin.removeListener('data', ondata) |
|||
} |
|||
|
|||
if (s === '\u0003') { |
|||
cleanup(); |
|||
reject(new Error('Aborted')); |
|||
return; |
|||
cleanup() |
|||
reject(new Error('Aborted')) |
|||
return |
|||
} |
|||
|
|||
const n = Number(s); |
|||
const n = Number(s) |
|||
if (opts[n - 1]) { |
|||
cleanup(); |
|||
resolve(opts[n - 1][0]); |
|||
cleanup() |
|||
resolve(opts[n - 1][0]) |
|||
} |
|||
}; |
|||
} |
|||
|
|||
process.stdin.setRawMode(true); |
|||
process.stdin.resume(); |
|||
process.stdin.on('data', ondata); |
|||
}); |
|||
}; |
|||
process.stdin.setRawMode(true) |
|||
process.stdin.resume() |
|||
process.stdin.on('data', ondata) |
|||
}) |
|||
} |
|||
|
@ -1,21 +1,21 @@ |
|||
exports.maybeURL = id => { |
|||
// E.g, "appname-asdf"
|
|||
return id.includes('-'); |
|||
}; |
|||
return id.includes('-') |
|||
} |
|||
|
|||
exports.normalizeURL = u => { |
|||
// Normalize URL by removing slash from the end
|
|||
if (u.slice(-1) === '/') { |
|||
u = u.slice(0, -1); |
|||
u = u.slice(0, -1) |
|||
} |
|||
|
|||
// `url` should match the hostname of the deployment
|
|||
u = u.replace(/^https:\/\//i, ''); |
|||
u = u.replace(/^https:\/\//i, '') |
|||
|
|||
if (!u.includes('.')) { |
|||
// `.now.sh` domain is implied if just the subdomain is given
|
|||
u += '.now.sh'; |
|||
u += '.now.sh' |
|||
} |
|||
|
|||
return u; |
|||
}; |
|||
return u |
|||
} |
|||
|
@ -1,214 +1,214 @@ |
|||
// Native
|
|||
const { join, resolve } = require('path'); |
|||
const { join, resolve } = require('path') |
|||
|
|||
// Packages
|
|||
const test = require('ava'); |
|||
const { asc: alpha } = require('alpha-sort'); |
|||
const test = require('ava') |
|||
const { asc: alpha } = require('alpha-sort') |
|||
|
|||
// Ours
|
|||
const hash = require('../build/lib/hash'); |
|||
const readMetadata = require('../build/lib/read-metadata'); |
|||
const hash = require('../build/lib/hash') |
|||
const readMetadata = require('../build/lib/read-metadata') |
|||
const { |
|||
npm: getNpmFiles_, |
|||
docker: getDockerFiles |
|||
} = require('../build/lib/get-files'); |
|||
} = require('../build/lib/get-files') |
|||
|
|||
const prefix = join(__dirname, '_fixtures') + '/'; |
|||
const base = path => path.replace(prefix, ''); |
|||
const fixture = name => resolve(`./test/_fixtures/${name}`); |
|||
const prefix = join(__dirname, '_fixtures') + '/' |
|||
const base = path => path.replace(prefix, '') |
|||
const fixture = name => resolve(`./test/_fixtures/${name}`) |
|||
|
|||
// Overload to force debugging
|
|||
const getNpmFiles = async dir => { |
|||
const { pkg, nowConfig, hasNowJson } = await readMetadata(dir, { |
|||
quiet: true, |
|||
strict: false |
|||
}); |
|||
return getNpmFiles_(dir, pkg, nowConfig, { hasNowJson }); |
|||
}; |
|||
}) |
|||
return getNpmFiles_(dir, pkg, nowConfig, { hasNowJson }) |
|||
} |
|||
|
|||
test('`files`', async t => { |
|||
let files = await getNpmFiles(fixture('files-in-package')); |
|||
t.is(files.length, 3); |
|||
files = files.sort(alpha); |
|||
t.is(base(files[0]), 'files-in-package/build/a/b/c/d.js'); |
|||
t.is(base(files[1]), 'files-in-package/build/a/e.js'); |
|||
t.is(base(files[2]), 'files-in-package/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('files-in-package')) |
|||
t.is(files.length, 3) |
|||
files = files.sort(alpha) |
|||
t.is(base(files[0]), 'files-in-package/build/a/b/c/d.js') |
|||
t.is(base(files[1]), 'files-in-package/build/a/e.js') |
|||
t.is(base(files[2]), 'files-in-package/package.json') |
|||
}) |
|||
|
|||
test('`files` + `.*.swp` + `.npmignore`', async t => { |
|||
let files = await getNpmFiles(fixture('files-in-package-ignore')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 3); |
|||
t.is(base(files[0]), 'files-in-package-ignore/build/a/b/c/d.js'); |
|||
t.is(base(files[1]), 'files-in-package-ignore/build/a/e.js'); |
|||
t.is(base(files[2]), 'files-in-package-ignore/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('files-in-package-ignore')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 3) |
|||
t.is(base(files[0]), 'files-in-package-ignore/build/a/b/c/d.js') |
|||
t.is(base(files[1]), 'files-in-package-ignore/build/a/e.js') |
|||
t.is(base(files[2]), 'files-in-package-ignore/package.json') |
|||
}) |
|||
|
|||
test('`files` overrides `.gitignore`', async t => { |
|||
let files = await getNpmFiles(fixture('files-overrides-gitignore')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 3); |
|||
t.is(base(files[0]), 'files-overrides-gitignore/package.json'); |
|||
t.is(base(files[1]), 'files-overrides-gitignore/test.js'); |
|||
t.is(base(files[2]), 'files-overrides-gitignore/test.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('files-overrides-gitignore')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 3) |
|||
t.is(base(files[0]), 'files-overrides-gitignore/package.json') |
|||
t.is(base(files[1]), 'files-overrides-gitignore/test.js') |
|||
t.is(base(files[2]), 'files-overrides-gitignore/test.json') |
|||
}) |
|||
|
|||
test('`now.files` overrides `.npmignore`', async t => { |
|||
let files = await getNpmFiles(fixture('now-files-overrides-npmignore')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 3); |
|||
t.is(base(files[0]), 'now-files-overrides-npmignore/package.json'); |
|||
t.is(base(files[1]), 'now-files-overrides-npmignore/test.js'); |
|||
t.is(base(files[2]), 'now-files-overrides-npmignore/test.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('now-files-overrides-npmignore')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 3) |
|||
t.is(base(files[0]), 'now-files-overrides-npmignore/package.json') |
|||
t.is(base(files[1]), 'now-files-overrides-npmignore/test.js') |
|||
t.is(base(files[2]), 'now-files-overrides-npmignore/test.json') |
|||
}) |
|||
|
|||
test('simple', async t => { |
|||
let files = await getNpmFiles(fixture('simple')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 5); |
|||
t.is(base(files[0]), 'simple/bin/test'); |
|||
t.is(base(files[1]), 'simple/index.js'); |
|||
t.is(base(files[2]), 'simple/lib/woot'); |
|||
t.is(base(files[3]), 'simple/lib/woot.jsx'); |
|||
t.is(base(files[4]), 'simple/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('simple')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 5) |
|||
t.is(base(files[0]), 'simple/bin/test') |
|||
t.is(base(files[1]), 'simple/index.js') |
|||
t.is(base(files[2]), 'simple/lib/woot') |
|||
t.is(base(files[3]), 'simple/lib/woot.jsx') |
|||
t.is(base(files[4]), 'simple/package.json') |
|||
}) |
|||
|
|||
test('simple with main', async t => { |
|||
let files = await getNpmFiles(fixture('simple-main')); |
|||
t.is(files.length, 3); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 3); |
|||
t.is(base(files[0]), 'simple-main/build/a.js'); |
|||
t.is(base(files[1]), 'simple-main/index.js'); |
|||
t.is(base(files[2]), 'simple-main/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('simple-main')) |
|||
t.is(files.length, 3) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 3) |
|||
t.is(base(files[0]), 'simple-main/build/a.js') |
|||
t.is(base(files[1]), 'simple-main/index.js') |
|||
t.is(base(files[2]), 'simple-main/package.json') |
|||
}) |
|||
|
|||
test('directory main', async t => { |
|||
let files = await getNpmFiles(fixture('directory-main')); |
|||
t.is(files.length, 3); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 3); |
|||
t.is(base(files[0]), 'directory-main/a/index.js'); |
|||
t.is(base(files[1]), 'directory-main/build/a.js'); |
|||
t.is(base(files[2]), 'directory-main/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('directory-main')) |
|||
t.is(files.length, 3) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 3) |
|||
t.is(base(files[0]), 'directory-main/a/index.js') |
|||
t.is(base(files[1]), 'directory-main/build/a.js') |
|||
t.is(base(files[2]), 'directory-main/package.json') |
|||
}) |
|||
|
|||
test('extensionless main', async t => { |
|||
let files = await getNpmFiles(fixture('extensionless-main')); |
|||
t.is(files.length, 3); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 3); |
|||
t.is(base(files[0]), 'extensionless-main/build/a.js'); |
|||
t.is(base(files[1]), 'extensionless-main/index.js'); |
|||
t.is(base(files[2]), 'extensionless-main/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('extensionless-main')) |
|||
t.is(files.length, 3) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 3) |
|||
t.is(base(files[0]), 'extensionless-main/build/a.js') |
|||
t.is(base(files[1]), 'extensionless-main/index.js') |
|||
t.is(base(files[2]), 'extensionless-main/package.json') |
|||
}) |
|||
|
|||
test('hashes', async t => { |
|||
const files = await getNpmFiles(fixture('hashes')); |
|||
const hashes = await hash(files); |
|||
t.is(hashes.size, 3); |
|||
const files = await getNpmFiles(fixture('hashes')) |
|||
const hashes = await hash(files) |
|||
t.is(hashes.size, 3) |
|||
const many = new Set( |
|||
hashes.get('277c55a2042910b9fe706ad00859e008c1b7d172').names |
|||
); |
|||
t.is(many.size, 2); |
|||
t.is(many.has(prefix + 'hashes/dei.png'), true); |
|||
t.is(many.has(prefix + 'hashes/duplicate/dei.png'), true); |
|||
) |
|||
t.is(many.size, 2) |
|||
t.is(many.has(prefix + 'hashes/dei.png'), true) |
|||
t.is(many.has(prefix + 'hashes/duplicate/dei.png'), true) |
|||
t.is( |
|||
hashes.get('56c00d0466fc6bdd41b13dac5fc920cc30a63b45').names[0], |
|||
prefix + 'hashes/index.js' |
|||
); |
|||
) |
|||
t.is( |
|||
hashes.get('706214f42ae940a01d2aa60c5e32408f4d2127dd').names[0], |
|||
prefix + 'hashes/package.json' |
|||
); |
|||
}); |
|||
) |
|||
}) |
|||
|
|||
test('ignore node_modules', async t => { |
|||
let files = await getNpmFiles(fixture('no-node_modules')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 2); |
|||
t.is(base(files[0]), 'no-node_modules/index.js'); |
|||
t.is(base(files[1]), 'no-node_modules/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('no-node_modules')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 2) |
|||
t.is(base(files[0]), 'no-node_modules/index.js') |
|||
t.is(base(files[1]), 'no-node_modules/package.json') |
|||
}) |
|||
|
|||
test('ignore nested `node_modules` with .npmignore **', async t => { |
|||
let files = await getNpmFiles(fixture('nested-node_modules')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 2); |
|||
t.is(base(files[0]), 'nested-node_modules/index.js'); |
|||
t.is(base(files[1]), 'nested-node_modules/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('nested-node_modules')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 2) |
|||
t.is(base(files[0]), 'nested-node_modules/index.js') |
|||
t.is(base(files[1]), 'nested-node_modules/package.json') |
|||
}) |
|||
|
|||
test('support whitelisting with .npmignore and !', async t => { |
|||
let files = await getNpmFiles(fixture('negation')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 2); |
|||
t.is(base(files[0]), 'negation/a.js'); |
|||
t.is(base(files[1]), 'negation/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('negation')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 2) |
|||
t.is(base(files[0]), 'negation/a.js') |
|||
t.is(base(files[1]), 'negation/package.json') |
|||
}) |
|||
|
|||
test('support `now.files`', async t => { |
|||
let files = await getNpmFiles(fixture('now-files')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 2); |
|||
t.is(base(files[0]), 'now-files/b.js'); |
|||
t.is(base(files[1]), 'now-files/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('now-files')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 2) |
|||
t.is(base(files[0]), 'now-files/b.js') |
|||
t.is(base(files[1]), 'now-files/package.json') |
|||
}) |
|||
|
|||
test('support docker', async t => { |
|||
let files = await getDockerFiles(fixture('dockerfile')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 2); |
|||
t.is(base(files[0]), 'dockerfile/Dockerfile'); |
|||
t.is(base(files[1]), 'dockerfile/a.js'); |
|||
}); |
|||
let files = await getDockerFiles(fixture('dockerfile')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 2) |
|||
t.is(base(files[0]), 'dockerfile/Dockerfile') |
|||
t.is(base(files[1]), 'dockerfile/a.js') |
|||
}) |
|||
|
|||
test('prefix regression', async t => { |
|||
let files = await getNpmFiles(fixture('prefix-regression')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 2); |
|||
t.is(base(files[0]), 'prefix-regression/package.json'); |
|||
t.is(base(files[1]), 'prefix-regression/woot.js'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('prefix-regression')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 2) |
|||
t.is(base(files[0]), 'prefix-regression/package.json') |
|||
t.is(base(files[1]), 'prefix-regression/woot.js') |
|||
}) |
|||
|
|||
test('support `now.json` files with package.json', async t => { |
|||
let files = await getNpmFiles(fixture('now-json')); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 3); |
|||
t.is(base(files[0]), 'now-json/b.js'); |
|||
t.is(base(files[1]), 'now-json/now.json'); |
|||
t.is(base(files[2]), 'now-json/package.json'); |
|||
}); |
|||
let files = await getNpmFiles(fixture('now-json')) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 3) |
|||
t.is(base(files[0]), 'now-json/b.js') |
|||
t.is(base(files[1]), 'now-json/now.json') |
|||
t.is(base(files[2]), 'now-json/package.json') |
|||
}) |
|||
|
|||
test('support `now.json` files with Dockerfile', async t => { |
|||
const f = fixture('now-json-docker'); |
|||
const f = fixture('now-json-docker') |
|||
const { deploymentType, nowConfig, hasNowJson } = await readMetadata(f, { |
|||
quiet: true, |
|||
strict: false |
|||
}); |
|||
t.is(deploymentType, 'docker'); |
|||
}) |
|||
t.is(deploymentType, 'docker') |
|||
|
|||
let files = await getDockerFiles(f, nowConfig, { hasNowJson }); |
|||
files = files.sort(alpha); |
|||
t.is(files.length, 3); |
|||
t.is(base(files[0]), 'now-json-docker/Dockerfile'); |
|||
t.is(base(files[1]), 'now-json-docker/b.js'); |
|||
t.is(base(files[2]), 'now-json-docker/now.json'); |
|||
}); |
|||
let files = await getDockerFiles(f, nowConfig, { hasNowJson }) |
|||
files = files.sort(alpha) |
|||
t.is(files.length, 3) |
|||
t.is(base(files[0]), 'now-json-docker/Dockerfile') |
|||
t.is(base(files[1]), 'now-json-docker/b.js') |
|||
t.is(base(files[2]), 'now-json-docker/now.json') |
|||
}) |
|||
|
|||
test('throws when both `now.json` and `package.json:now` exist', async t => { |
|||
let e; |
|||
let e |
|||
try { |
|||
await readMetadata(fixture('now-json-throws'), { |
|||
quiet: true, |
|||
strict: false |
|||
}); |
|||
}) |
|||
} catch (err) { |
|||
e = err; |
|||
e = err |
|||
} |
|||
t.is(e.name, 'Error'); |
|||
t.is(e.userError, true); |
|||
t.is(e.name, 'Error') |
|||
t.is(e.userError, true) |
|||
t.pass( |
|||
/please ensure there's a single source of configuration/i.test(e.message) |
|||
); |
|||
}); |
|||
) |
|||
}) |
|||
|
@ -1,58 +1,58 @@ |
|||
const path = require('path'); |
|||
const crossSpawn = require('cross-spawn'); |
|||
const test = require('ava'); |
|||
const path = require('path') |
|||
const crossSpawn = require('cross-spawn') |
|||
const test = require('ava') |
|||
|
|||
const logo = require('../lib/utils/output/logo'); |
|||
const logo = require('../lib/utils/output/logo') |
|||
|
|||
test.serial('make binary', async t => { |
|||
if (!process.env.CI) { |
|||
t.true(true); |
|||
return; |
|||
t.true(true) |
|||
return |
|||
} |
|||
const result = await spawn('npm', ['run', 'pack']); |
|||
t.is(result.code, 0); |
|||
}); |
|||
const result = await spawn('npm', ['run', 'pack']) |
|||
t.is(result.code, 0) |
|||
}) |
|||
|
|||
const binary = { |
|||
darwin: 'now-macos', |
|||
linux: 'now-linux', |
|||
win32: 'now-win.exe' |
|||
}[process.platform]; |
|||
}[process.platform] |
|||
|
|||
const binaryPath = path.resolve(__dirname, '../packed/' + binary); |
|||
const deployHelpMessage = `${logo} now [options] <command | path>`; |
|||
const binaryPath = path.resolve(__dirname, '../packed/' + binary) |
|||
const deployHelpMessage = `${logo} now [options] <command | path>` |
|||
|
|||
test.serial('packed "now help" prints deploy help message', async t => { |
|||
if (!process.env.CI) { |
|||
t.true(true); |
|||
return; |
|||
t.true(true) |
|||
return |
|||
} |
|||
const result = await spawn(binaryPath, ['help']); |
|||
const result = await spawn(binaryPath, ['help']) |
|||
|
|||
t.is(result.code, 0); |
|||
const stdout = result.stdout.split('\n'); |
|||
t.true(stdout.length > 1); |
|||
t.true(stdout[1].includes(deployHelpMessage)); |
|||
}); |
|||
t.is(result.code, 0) |
|||
const stdout = result.stdout.split('\n') |
|||
t.true(stdout.length > 1) |
|||
t.true(stdout[1].includes(deployHelpMessage)) |
|||
}) |
|||
|
|||
function spawn(command, args) { |
|||
return new Promise((resolve, reject) => { |
|||
const child = crossSpawn.spawn(command, args); |
|||
const child = crossSpawn.spawn(command, args) |
|||
|
|||
let stdout = ''; |
|||
let stdout = '' |
|||
child.stdout.on('data', data => { |
|||
stdout += data; |
|||
}); |
|||
stdout += data |
|||
}) |
|||
|
|||
child.on('error', err => { |
|||
reject(err); |
|||
}); |
|||
reject(err) |
|||
}) |
|||
|
|||
child.on('close', code => { |
|||
resolve({ |
|||
code, |
|||
stdout |
|||
}); |
|||
}); |
|||
}); |
|||
}) |
|||
}) |
|||
}) |
|||
} |
|||
|
@ -1,38 +1,35 @@ |
|||
const test = require('ava'); |
|||
const toHost = require('../build/lib/to-host'); |
|||
const test = require('ava') |
|||
const toHost = require('../build/lib/to-host') |
|||
|
|||
test('simple', t => { |
|||
t.is(toHost('zeit.co'), 'zeit.co'); |
|||
}); |
|||
t.is(toHost('zeit.co'), 'zeit.co') |
|||
}) |
|||
|
|||
test('leading //', t => { |
|||
t.is( |
|||
toHost('//zeit-logos-rnemgaicnc.now.sh'), |
|||
'zeit-logos-rnemgaicnc.now.sh' |
|||
); |
|||
}); |
|||
t.is(toHost('//zeit-logos-rnemgaicnc.now.sh'), 'zeit-logos-rnemgaicnc.now.sh') |
|||
}) |
|||
|
|||
test('leading http://', t => { |
|||
t.is( |
|||
toHost('http://zeit-logos-rnemgaicnc.now.sh'), |
|||
'zeit-logos-rnemgaicnc.now.sh' |
|||
); |
|||
}); |
|||
) |
|||
}) |
|||
|
|||
test('leading https://', t => { |
|||
t.is( |
|||
toHost('https://zeit-logos-rnemgaicnc.now.sh'), |
|||
'zeit-logos-rnemgaicnc.now.sh' |
|||
); |
|||
}); |
|||
) |
|||
}) |
|||
|
|||
test('leading https:// and path', t => { |
|||
t.is( |
|||
toHost('https://zeit-logos-rnemgaicnc.now.sh/path'), |
|||
'zeit-logos-rnemgaicnc.now.sh' |
|||
); |
|||
}); |
|||
) |
|||
}) |
|||
|
|||
test('simple and path', t => { |
|||
t.is(toHost('zeit.co/test'), 'zeit.co'); |
|||
}); |
|||
t.is(toHost('zeit.co/test'), 'zeit.co') |
|||
}) |
|||
|
Loading…
Reference in new issue