no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / tools / ts / build_services.js
blob397eff7074219d323ffd5d84a88bb5690a612047
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 "use strict";
6 /**
7  * Build: <objdir>/dist/@types/lib.gecko.services.d.ts,
8  *
9  * from:  <objdir>/xpcom/components/services.json,
10  *        generated by a previous build step.
11  */
13 const fs = require("fs");
15 const HEADER = `/**
16  * NOTE: Do not modify this file by hand.
17  * Content was generated from services.json.
18  */
21 const SERVICES = {
22   cpmm: ["ContentProcessMessageManager"],
23   mm: ["ChromeMessageBroadcaster"],
24   ppmm: ["ParentProcessMessageManager"],
27 function main(lib_dts, services_json) {
28   let interfaces = JSON.parse(fs.readFileSync(services_json, "utf8"));
30   for (let [iface, svc] of Object.entries(interfaces)) {
31     SERVICES[svc] = SERVICES[svc] ?? [];
32     SERVICES[svc].push(iface);
33   }
35   let lines = [HEADER];
36   lines.push("interface JSServices {");
37   for (let [svc, ifaces] of Object.entries(SERVICES).sort()) {
38     lines.push(`  ${svc}: ${ifaces.join(" & ")};`);
39   }
40   lines.push("}\n");
42   let dts = lines.join("\n");
43   console.log(`[INFO] ${lib_dts} (${dts.length.toLocaleString()} bytes)`);
44   fs.writeFileSync(lib_dts, dts);
47 main(...process.argv.slice(2));