<commit_before>var fs = require('fs');
var path = require('path');
var shell = require('shelljs');
var util = require('../util');
var config_parser = require('../config_parser');
var config = require('../config');

module.exports = function firefoxos_parser(project) {
    this.path = project;
};

module.exports.check_requirements = function(project_root, callback) {
    callback(false);
};

module.exports.prototype = {
    update_from_config: function(config, callback) {
        if (!(config instanceof config_parser)) {
            var err = new Error('update_from_config requires a config_parser object');
            if (callback) {
                callback(err);
                return;
            }
            else {
                throw err;
            }
        }

        var name = config.name();
        var pkg = config.packageName();
        var version = config.version();

        var manifestPath = path.join(this.www_dir(), 'manifest.webapp');
        var manifest;

        if(fs.existsSync(manifestPath)) {
            manifest = JSON.parse(fs.readFileSync(manifestPath));
        }
        else {
            manifest = {
                launch_path: "/index.html",
                installs_allowed_from: ["*"]
            };
        }

        manifest.version = version;
        manifest.name = name;
        manifest.pkgName = pkg;
        fs.writeFileSync(manifestPath, JSON.stringify(manifest));

        if(callback) {
            callback();
        }
    },

    www_dir: function() {
        return path.join(this.path, 'www');
    },

    update_www: function() {
        var projectRoot = util.isCordova(this.path);
        var projectWww = util.projectWww(projectRoot);
        var platformWww = this.www_dir();

        shell.rm('-rf', platformWww);
        shell.cp('-rf', projectWww, this.path);

        var customPath = config.has_custom_path(projectRoot, 'firefoxos');
        var libPath = (customPath ?
                       customPath :
                       path.join(util.libDirectory, 'firefoxos', 'cordova',
                                 require('../../platforms').ios.version));
        shell.cp('-f',
                 path.join(libPath, 'cordova-lib', 'cordova.js'),
                 path.join(platformWww, 'cordova.js'));
    },

    update_overrides: function() {
        var projectRoot = util.isCordova(this.path);
        var mergesPath = path.join(util.appDir(projectRoot), 'merges', 'firefoxos');
        if(fs.existsSync(mergesPath)) {
            var overrides = path.join(mergesPath, '*');
            shell.cp('-rf', overrides, this.www_dir());
        }
    },

    update_staging: function() {
        var projectRoot = util.isCordova(this.path);
        var stagingDir = path.join(this.path, '.staging', 'www');

        if(fs.existsSync(stagingDir)) {
            shell.cp('-rf',
                     path.join(stagingDir, '*'),<commit_msg>CB-4657: added staging_dir function to ff parser<commit_after>var fs = require('fs');
var path = require('path');
var shell = require('shelljs');
var util = require('../util');
var config_parser = require('../config_parser');
var config = require('../config');

module.exports = function firefoxos_parser(project) {
    this.path = project;
};

module.exports.check_requirements = function(project_root, callback) {
    callback(false);
};

module.exports.prototype = {
    update_from_config: function(config, callback) {
        if (!(config instanceof config_parser)) {
            var err = new Error('update_from_config requires a config_parser object');
            if (callback) {
                callback(err);
                return;
            }
            else {
                throw err;
            }
        }

        var name = config.name();
        var pkg = config.packageName();
        var version = config.version();

        var manifestPath = path.join(this.www_dir(), 'manifest.webapp');
        var manifest;

        if(fs.existsSync(manifestPath)) {
            manifest = JSON.parse(fs.readFileSync(manifestPath));
        }
        else {
            manifest = {
                launch_path: "/index.html",
                installs_allowed_from: ["*"]
            };
        }

        manifest.version = version;
        manifest.name = name;
        manifest.pkgName = pkg;
        fs.writeFileSync(manifestPath, JSON.stringify(manifest));

        if(callback) {
            callback();
        }
    },

    www_dir: function() {
        return path.join(this.path, 'www');
    },

    update_www: function() {
        var projectRoot = util.isCordova(this.path);
        var projectWww = util.projectWww(projectRoot);
        var platformWww = this.www_dir();

        shell.rm('-rf', platformWww);
        shell.cp('-rf', projectWww, this.path);

        var customPath = config.has_custom_path(projectRoot, 'firefoxos');
        var libPath = (customPath ?
                       customPath :
                       path.join(util.libDirectory, 'firefoxos', 'cordova',
                                 require('../../platforms').ios.version));
        shell.cp('-f',
                 path.join(libPath, 'cordova-lib', 'cordova.js'),
                 path.join(platformWww, 'cordova.js'));
    },

    update_overrides: function() {
        var projectRoot = util.isCordova(this.path);
        var mergesPath = path.join(util.appDir(projectRoot), 'merges', 'firefoxos');
        if(fs.existsSync(mergesPath)) {
            var overrides = path.join(mergesPath, '*');
            shell.cp('-rf', overrides, this.www_dir());
        }
    },
    staging_dir: function() {
        return path.join(this.path, '.staging', 'www');
    },
    update_staging: function() {
        var projectRoot = util.isCordova(this.path);
        var stagingDir = path.join(this.path, '.staging', 'www');

        if(fs.existsSync(stagingDir)) {
            shell.cp('-rf',
                     path.join(stagingDir, '*'),
{'fraction_non_alphanumeric': 0.13933187846231324, 'fraction_numerical': 0.0006714789323484975, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 15, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5878654', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1671, 'n_words': 316}