<commit_before>/*
 * Copyright 2012, Mozilla Foundation and contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var copy = require('dryice').copy;
var path = require('path');
var fs = require('fs');
var main = require('../../../gcli');
var gcli = main.require('gcli/index');

// TODO: When the memory of node 0.6 has faded, expunge path.existsSync
var existsSync = fs.existsSync || path.existsSync;

/**
 * Registration and de-registration.
 */
exports.startup = function() {
  gcli.addCommand(firefoxCmdSpc);
};

exports.shutdown = function() {
  gcli.removeCommand(firefoxCmdSpc);
};

/**
 * 'firefox' build command
 */
var firefoxCmdSpc = {
  name: 'firefox',
  description: 'Build the firefox-GCLI target',
  params: [
    {
      name: 'location',
      type: 'string',
      defaultValue: '../devtools',
      description: 'The location of the mozilla-central checkout'
    }
  ],
  returnType: 'terminal',
  exec: function(args, context) {
    return exports.buildFirefox(args.location);
  }
};

/**
 * Build the Javascript JSM files for Firefox
 * Consists of: gcli.jsm, gclichrome.jsm, browser_gcli_web.js and gcli.properties
 */
exports.buildFirefox = function(destDir) {
  if (!destDir && process.env.FIREFOX_HOME) {
    destDir = process.env.FIREFOX_HOME;
  }
  var log = 'Building Firefox outputs to ' + (destDir || 'built/ff') + '.\n\n';

  if (!destDir) {
    copy.mkdirSync(main.gcliHome + '/built/ff', 0755);
  }

  var jsmDir = '/browser/devtools/commandline';
  var testDir = '/browser/devtools/commandline/test';
  var propsDir = '/browser/locales/en-US/chrome/browser/devtools';

  if (destDir) {
    if (!existsSync(destDir + jsmDir)) {
      throw new Error('Missing path for JSM: ' + destDir + jsmDir);
    }
    if (!existsSync(destDir + testDir)) {
      throw new Error('Missing path for tests: ' + destDir + testDir);
    }
    if (!existsSync(destDir + propsDir)) {
      throw new Error('Missing path for l10n string: ' + destDir + propsDir);
    }
  }

  var project = copy.createCommonJsProject({
    roots: [ main.gcliHome + '/mozilla', main.gcliHome + '/lib' ]
  });

  // Package Gcli.jsm
  copy({
    source: [<commit_msg>nodetest-786658: Remove existsSync hack<commit_after>/*
 * Copyright 2012, Mozilla Foundation and contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var copy = require('dryice').copy;
var fs = require('fs');
var main = require('../../../gcli');
var gcli = main.require('gcli/index');

/**
 * Registration and de-registration.
 */
exports.startup = function() {
  gcli.addCommand(firefoxCmdSpc);
};

exports.shutdown = function() {
  gcli.removeCommand(firefoxCmdSpc);
};

/**
 * 'firefox' build command
 */
var firefoxCmdSpc = {
  name: 'firefox',
  description: 'Build the firefox-GCLI target',
  params: [
    {
      name: 'location',
      type: 'string',
      defaultValue: '../devtools',
      description: 'The location of the mozilla-central checkout'
    }
  ],
  returnType: 'terminal',
  exec: function(args, context) {
    return exports.buildFirefox(args.location);
  }
};

/**
 * Build the Javascript JSM files for Firefox
 * Consists of: gcli.jsm, gclichrome.jsm, browser_gcli_web.js and gcli.properties
 */
exports.buildFirefox = function(destDir) {
  if (!destDir && process.env.FIREFOX_HOME) {
    destDir = process.env.FIREFOX_HOME;
  }
  var log = 'Building Firefox outputs to ' + (destDir || 'built/ff') + '.\n\n';

  if (!destDir) {
    copy.mkdirSync(main.gcliHome + '/built/ff', 0755);
  }

  var jsmDir = '/browser/devtools/commandline';
  var testDir = '/browser/devtools/commandline/test';
  var propsDir = '/browser/locales/en-US/chrome/browser/devtools';

  if (destDir) {
    if (!fs.existsSync(destDir + jsmDir)) {
      throw new Error('Missing path for JSM: ' + destDir + jsmDir);
    }
    if (!fs.existsSync(destDir + testDir)) {
      throw new Error('Missing path for tests: ' + destDir + testDir);
    }
    if (!fs.existsSync(destDir + propsDir)) {
      throw new Error('Missing path for l10n string: ' + destDir + propsDir);
    }
  }

  var project = copy.createCommonJsProject({
    roots: [ main.gcliHome + '/mozilla', main.gcliHome + '/lib' ]
  });

  // Package Gcli.jsm
  copy({
    source: [
{'fraction_non_alphanumeric': 0.13571292231341858, 'fraction_numerical': 0.006871540370299675, 'mean_word_length': 3.4294167371090447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7295497', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1637, 'n_words': 483}