summaryrefslogtreecommitdiffstats
path: root/tools/lint/eslint/eslint-plugin-mozilla/scripts/createExports.js
blob: 7f839edfbafb15f9954e032d00e0e1afd6442070 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 * @fileoverview A script to export the known globals to a file.
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
"use strict";

var fs = require("fs");
var path = require("path");
var helpers = require("../lib/helpers");

const eslintDir = path.join(helpers.rootDir, "tools", "lint", "eslint");

const globalsFile = path.join(
  eslintDir,
  "eslint-plugin-mozilla",
  "lib",
  "environments",
  "saved-globals.json"
);
const rulesFile = path.join(
  eslintDir,
  "eslint-plugin-mozilla",
  "lib",
  "rules",
  "saved-rules-data.json"
);

console.log("Copying services.json");

const env = helpers.getBuildEnvironment();

const servicesFile = path.join(
  env.topobjdir,
  "xpcom",
  "components",
  "services.json"
);
const shipServicesFile = path.join(
  eslintDir,
  "eslint-plugin-mozilla",
  "lib",
  "services.json"
);

fs.writeFileSync(shipServicesFile, fs.readFileSync(servicesFile));

console.log("Generating globals file");

// Export the environments.
let environmentGlobals = require("../lib/index.js").environments;

return fs.writeFile(
  globalsFile,
  JSON.stringify({ environments: environmentGlobals }),
  err => {
    if (err) {
      console.error(err);
      process.exit(1);
    }

    console.log("Globals file generation complete");

    console.log("Creating rules data file");
    let rulesData = {};

    return fs.writeFile(rulesFile, JSON.stringify({ rulesData }), err1 => {
      if (err1) {
        console.error(err1);
        process.exit(1);
      }

      console.log("Globals file generation complete");
    });
  }
);