From a49a0334084fadf539bb5b5fa2b492998f92dbbb Mon Sep 17 00:00:00 2001 From: Leo Lamprecht Date: Sun, 19 Mar 2017 22:17:54 +0100 Subject: [PATCH] Upgraded instance of `serve` --- lib/read-metadata.js | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/read-metadata.js b/lib/read-metadata.js index 71593dc..d84d118 100644 --- a/lib/read-metadata.js +++ b/lib/read-metadata.js @@ -1,14 +1,14 @@ -const { basename, resolve: resolvePath } = require("path"); -const chalk = require("chalk"); -const { readFile, exists } = require("fs-promise"); -const { parse: parseDockerfile } = require("docker-file-parser"); +const { basename, resolve: resolvePath } = require('path'); +const chalk = require('chalk'); +const { readFile, exists } = require('fs-promise'); +const { parse: parseDockerfile } = require('docker-file-parser'); const listPackage = { scripts: { start: `NODE_ENV='production' serve ./content` }, dependencies: { - serve: "4.0.1" + serve: '5.0.4' } }; @@ -17,7 +17,7 @@ module.exports = readMetaData; async function readMetaData( path, { - deploymentType = "npm", + deploymentType = 'npm', deploymentName, quiet = false, strict = true, @@ -32,11 +32,11 @@ async function readMetaData( let description; try { - nowConfig = JSON.parse(await readFile(resolvePath(path, "now.json"))); + nowConfig = JSON.parse(await readFile(resolvePath(path, 'now.json'))); hasNowJson = true; } catch (err) { // if the file doesn't exist then that's fine; any other error bubbles up - if (err.code !== "ENOENT") { + if (err.code !== 'ENOENT') { const e = Error(`Failed to read JSON in "${path}/now.json"`); e.userError = true; throw e; @@ -50,26 +50,26 @@ async function readMetaData( deploymentType = nowConfig.type; } else if ( nowConfig.type === undefined && - !await exists(resolvePath(path, "package.json")) + !await exists(resolvePath(path, 'package.json')) ) { - deploymentType = "static"; + deploymentType = 'static'; } if (nowConfig.name) { deploymentName = nowConfig.name; } } - if (deploymentType === "static") { + if (deploymentType === 'static') { isStatic = true; - deploymentType = "npm"; + deploymentType = 'npm'; } - if (deploymentType === "npm") { + if (deploymentType === 'npm') { if (isStatic) { pkg = listPackage; } else { try { - pkg = JSON.parse(await readFile(resolvePath(path, "package.json"))); + pkg = JSON.parse(await readFile(resolvePath(path, 'package.json'))); } catch (err) { const e = Error(`Failed to read JSON in "${path}/package.json"`); e.userError = true; @@ -79,18 +79,18 @@ async function readMetaData( if ( strict && - (!pkg.scripts || (!pkg.scripts.start && !pkg.scripts["now-start"])) + (!pkg.scripts || (!pkg.scripts.start && !pkg.scripts['now-start'])) ) { const e = Error( - "Missing `start` (or `now-start`) script in `package.json`. " + - "See: https://docs.npmjs.com/cli/start." + 'Missing `start` (or `now-start`) script in `package.json`. ' + + 'See: https://docs.npmjs.com/cli/start.' ); e.userError = true; throw e; } if (!deploymentName) { - if (typeof pkg.name === "string") { + if (typeof pkg.name === 'string') { name = pkg.name; } else { name = basename(path); @@ -104,12 +104,12 @@ async function readMetaData( } description = pkg.description; - } else if (deploymentType === "docker") { + } else if (deploymentType === 'docker') { let docker; try { const dockerfile = await readFile( - resolvePath(path, "Dockerfile"), - "utf8" + resolvePath(path, 'Dockerfile'), + 'utf8' ); docker = parseDockerfile(dockerfile, { includeComments: true }); } catch (err) { @@ -119,13 +119,13 @@ async function readMetaData( } if (strict && docker.length <= 0) { - const e = Error("No commands found in `Dockerfile`"); + const e = Error('No commands found in `Dockerfile`'); e.userError = true; throw e; } const labels = {}; - docker.filter(cmd => cmd.name === "LABEL").forEach(({ args }) => { + docker.filter(cmd => cmd.name === 'LABEL').forEach(({ args }) => { for (const key in args) { if (!{}.hasOwnProperty.call(args, key)) { continue; @@ -179,8 +179,8 @@ async function readMetaData( // other if (hasNowJson) { const e = new Error( - "You have a `now` configuration field" + - "inside `package.json`, but configuration is also present" + + 'You have a `now` configuration field' + + 'inside `package.json`, but configuration is also present' + "in `now.json`! Please ensure there's a single source of configuration by removing one" ); e.userError = true;