Browse Source

Added 'downloading' and 'interrupted' state (#570)

* move placeholder population to index.js

* detect ctrl+c and put 'please reinstall' to placeholder
master
Igor Klopov 8 years ago
committed by Leo Lamprecht
parent
commit
ff5d38644c
  1. 13
      download/placeholder.js
  2. 21
      download/src/index.js
  3. 3
      package.json

13
download/placeholder.js

@ -1,13 +0,0 @@
/* eslint-disable no-var */
// Native
var path = require('path')
var fs = require('fs')
var now = path.join(__dirname, 'dist', 'now')
fs.writeFileSync(
now,
'#!/usr/bin/env node\n' +
'console.log("\'Now\' binary downloading was interrupted. Please reinstall!")\n'
)

21
download/src/index.js

@ -1,8 +1,11 @@
/* eslint-disable unicorn/no-process-exit */
// Native
import fs from 'fs'
import path from 'path'
// Packages
import onDeath from 'death'
import fetch from 'node-fetch'
// Utilities
@ -24,6 +27,22 @@ const platformToName = {
}
async function main() {
fs.writeFileSync(
now,
'#!/usr/bin/env node\n' +
'console.log("Please wait until \'now\' installation completes!")\n'
)
onDeath(() => {
fs.writeFileSync(
now,
'#!/usr/bin/env node\n' +
'console.log("The \'now\' installation did not complete successfully.")\n' +
'console.log("Please run \'npm i -g now\' to reinstall!")\n'
)
process.exit();
})
info('Retrieving the latest CLI version...')
const downloadURL = `https://api.github.com/repos/zeit/now-cli/releases/tags/${packageJSON.version}`
@ -94,7 +113,5 @@ async function main() {
main().catch(err => {
console.error(err)
// eslint-disable-next-line unicorn/no-process-exit
process.exit(2)
})

3
package.json

@ -6,7 +6,7 @@
"scripts": {
"postinstall": "node download/postinstall.js",
"precommit": "xo --quiet && lint-staged",
"prepublish": "in-install || (npm run webpack && node download/placeholder.js)",
"prepublish": "in-install || (npm run webpack && cp /dev/null download/dist/now)",
"lint": "xo --quiet",
"test": "npm run lint && ava",
"pack": "pkg bin/now.js -c package.json -o packed/now",
@ -70,6 +70,7 @@
"credit-card": "3.0.1",
"cross-spawn": "5.1.0",
"dateformat": "2.0.0",
"death": "1.1.0",
"docker-file-parser": "1.0.2",
"dotenv": "4.0.0",
"download": "6.1.0",

Loading…
Cancel
Save