All files / src/args getManifest.js

100% Statements 22/22
66.67% Branches 4/6
100% Functions 2/2
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 452x 2x   2x 2x 2x 2x   2x 2x 2x 2x       2x               2x 2x   2x 2x 1x 1x     1x       1x     1x 1x     2x  
const path = require('path')
const fs = require('fs-extra')
 
const log = require('../log')
const getArtifactsLocation = require('./getArtifactsLocation')
const { getArg } = require('./getArg')
const { MANIFEST } = require('./argOptions')
 
const getManifestLocation = () => {
  const artifactsLocation = getArtifactsLocation()
  const manifestArg = getArg(process.argv, MANIFEST)
  const manifestLocation = manifestArg
    ? path.resolve(manifestArg)
    : `${artifactsLocation}/interbit.manifest.json`
 
  return manifestLocation
}
 
/**
 * Gets the Interbit manifest file from disk based on the `--manifest`
 * command-line argument.
 * @returns {Object|undefined} The manifest file, if found, as a JSON object.
 */
const getManifest = () => {
  const manifestLocation = getManifestLocation()
 
  const doesManifestExist = fs.existsSync(manifestLocation)
  if (!doesManifestExist) {
    log.error(`Manifest file does not exist at location ${manifestLocation}`)
    return undefined
  }
 
  const manifestFilepath = fs.statSync(manifestLocation).isDirectory()
    ? `${manifestLocation}/interbit.manifest.json`
    : manifestLocation
 
  log.info(`Loading manifest at ${manifestFilepath}`)
 
  // eslint-disable-next-line
  const manifest = require(manifestFilepath)
  return manifest
}
 
module.exports = getManifest