Browse Source

Use implicit "start" script when `server.js` exists

Moves the verification step to the `create()` function,
instead of in `readMetaData()`.

Closes https://github.com/zeit/now-cli/issues/181.
master
Nathan Rajlich 8 years ago
committed by Leo Lamprecht
parent
commit
cc8e0b8e4a
  1. 24
      lib/index.js
  2. 13
      lib/read-metadata.js

24
lib/index.js

@ -23,6 +23,9 @@ const Agent = require('./agent');
const readMetaData = require('./read-metadata');
const toHost = require('./to-host');
// Helpers
const { error } = require('./error');
// How many concurrent HTTP/2 stream uploads
const MAX_CONCURRENT = 10;
@ -77,6 +80,18 @@ module.exports = class Now extends EventEmitter {
const opts = { debug: this._debug, hasNowJson };
if (deploymentType === 'npm') {
files = await getNpmFiles(path, pkg, nowConfig, opts);
// A `start` or `now-start` npm script, or a `server.js` file
// in the root directory of the deployment are required
if (!hasNpmStart(pkg) && !hasFile(path, files, 'server.js')) {
error(
'Missing `start` (or `now-start`) script in `package.json`. ' +
'See: https://docs.npmjs.com/cli/start.'
);
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
} else {
files = await getDockerFiles(path, nowConfig, opts);
}
@ -989,3 +1004,12 @@ async function responseError(res) {
return err;
}
function hasNpmStart(pkg) {
return pkg.scripts && (pkg.scripts.start || pkg.scripts['now-start']);
}
function hasFile(base, files, name) {
const relative = files.map(file => toRelative(file, base));
return relative.indexOf(name) !== -1;
}

13
lib/read-metadata.js

@ -84,19 +84,6 @@ async function readMetaData(
}
}
if (
strict &&
(!pkg.scripts || (!pkg.scripts.start && !pkg.scripts['now-start']))
) {
error(
'Missing `start` (or `now-start`) script in `package.json`. ' +
'See: https://docs.npmjs.com/cli/start.'
);
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
if (!deploymentName) {
if (typeof pkg.name === 'string' && pkg.name !== '') {
name = pkg.name;

Loading…
Cancel
Save