{"size": 1315, "ext": "js", "max_stars_repo_path": "lib/builtins/build-flows/nodejs-npm.js", "max_stars_repo_name": "CamdenFoucht/ask-cli", "max_stars_repo_stars_event_min_datetime": "2020-04-16T20:27:27.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-02T13:39:57.000Z", "max_issues_repo_path": "lib/builtins/build-flows/nodejs-npm.js", "max_issues_repo_name": "CamdenFoucht/ask-cli", "max_issues_repo_issues_event_min_datetime": "2020-04-07T00:27:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T06:32:44.000Z", "max_forks_repo_path": "lib/builtins/build-flows/nodejs-npm.js", "max_forks_repo_name": "CamdenFoucht/ask-cli", "max_forks_repo_forks_event_min_datetime": "2020-04-12T12:39:04.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-19T18:57:42.000Z"}
{"max_stars_count": 89, "max_issues_count": 210, "max_forks_count": 47, "avg_line_length": 29.8863636364, "max_line_length": 98, "alphanum_fraction": 0.6365019011}
const fs = require('fs-extra');
const path = require('path');

const AbstractBuildFlow = require('./abstract-build-flow');

class NodeJsNpmBuildFlow extends AbstractBuildFlow {
    /**
     * If this file exists than the build flow can handle build
     */
    static get manifest() { return 'package.json'; }

    /**
     * Returns true if the build flow can handle the build
     */
    static canHandle({ src }) {
        return fs.existsSync(path.join(src, NodeJsNpmBuildFlow.manifest));
    }

    /**
     * Constructor
     * @param {Object} options
     * @param {String} options.cwd working directory for build
     * @param {String} options.src source directory
     * @param {String} options.buildFile full path for zip file to generate
     * @param {Boolean} options.doDebug debug flag
     */
    constructor({ cwd, src, buildFile, doDebug }) {
        super({ cwd, src, buildFile, doDebug });
    }

    /**
     * Executes build
     * @param {Function} callback
     */
    execute(callback) {
        const quietFlag = this.doDebug ? '' : ' --quiet';
        this.debug(`Installing NodeJS dependencies based on the ${NodeJsNpmBuildFlow.manifest}.`);
        this.execCommand(`npm install --production${quietFlag}`);
        this.createZip(callback);
    }
}

module.exports = NodeJsNpmBuildFlow;
