robojones/z1

View on GitHub
cli/lib/get-appname.js

Summary

Maintainability
A
0 mins
Test Coverage
B
84%
const path = require('path')
const assert = require('assert')

/**
 * Get the name of the app from the current cwd.
 * @returns string
 */
function getAppname() {
    log('no appname given')
    log('searching directory for package.json')
    try {
        const file = path.join(process.cwd(), 'package.json')
        const pack = require(file)
        assert(pack.name, 'name not specified in package.json')
        log(`found name "${pack.name}" in package.json`)
        return pack.name
    } catch (err) {
        console.error(`no package.json file found`)
        handle(new Error('missing argument `appname\''))
    }
}

module.exports = getAppname