tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

build.js (2599B)


      1 #!env node
      2 
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      6 
      7 const util = require("util");
      8 const fs = require("fs");
      9 const path = require("path");
     10 const webpack = require("webpack");
     11 
     12 const fixturesFolder = path.join(__dirname, "fixtures");
     13 
     14 const tests = fs
     15  .readdirSync(fixturesFolder)
     16  .map(name => {
     17    if (name[0] === ".") {
     18      return;
     19    }
     20 
     21    const inputTS = path.join(fixturesFolder, name, "input.ts");
     22    const inputJS = path.join(fixturesFolder, name, "input.js");
     23 
     24    return [name, fs.existsSync(inputTS) ? inputTS : inputJS];
     25  })
     26  .filter(Boolean);
     27 
     28 (async function() {
     29  const targets = [
     30    await require("./builds/parcel")(tests, __dirname),
     31    await require("./builds/webpack3")(tests, __dirname),
     32    await require("./builds/webpack3-babel6")(tests, __dirname),
     33    await require("./builds/webpack3-babel7")(tests, __dirname),
     34    await require("./builds/webpack4")(tests, __dirname),
     35    await require("./builds/webpack4-babel6")(tests, __dirname),
     36    await require("./builds/webpack4-babel7")(tests, __dirname),
     37    await require("./builds/rollup")(tests, __dirname),
     38    await require("./builds/rollup-babel6")(tests, __dirname),
     39    await require("./builds/rollup-babel7")(tests, __dirname)
     40  ];
     41 
     42  await util.promisify(webpack)({
     43    context: __dirname,
     44    entry: "babel-polyfill",
     45    output: {
     46      filename: "polyfill-bundle.js"
     47    },
     48    plugins: [new webpack.optimize.OccurrenceOrderPlugin(true)]
     49  });
     50 
     51  const examplesDir = path.join(__dirname, "..");
     52  const html = path.join(examplesDir, "doc-sourcemapped.html");
     53 
     54  fs.writeFileSync(
     55    html,
     56    fs.readFileSync(html, "utf8").replace(
     57      /\n\s*<!-- INJECTED-START[\s\S]*INJECTED-END -->/,
     58      `
     59    <!-- INJECTED-START -->
     60    <!--
     61      Content generated by examples/sourcemapped/build.js.
     62      Run "yarn build" to update.
     63    -->${targets
     64      .map(({ target, fixtures }) => {
     65        return `\n    <h2>${target}</h2>${fixtures
     66          .map(
     67            ({ name, testFnName, scriptPath }) =>
     68              `\n    <script src="${path.relative(
     69                examplesDir,
     70                scriptPath
     71              )}"></script>` +
     72              `\n    <button onclick="${testFnName}()">Run ${name}</button>`
     73          )
     74          .join("")}`;
     75      })
     76      .join("")}
     77    <!-- INJECTED-END -->`
     78    )
     79  );
     80 
     81  console.log("DONE - If node is still running, just hit Ctrl+C. Parcel leaves things running for some reason.")
     82 })();