diff --git a/gulpfile.js b/gulpfile.js index 552168825b12d..fdbdd0d2aa56c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -770,32 +770,52 @@ function buildDefaultPreferences(defines, dir) { const bundleDefines = builder.merge(defines, { LIB: true, - SKIP_BABEL: false, - BUNDLE_VERSION: 0, // Dummy version - BUNDLE_BUILD: 0, // Dummy build TESTING: defines.TESTING ?? process.env.TESTING === "true", }); - const inputStream = merge([ - gulp.src(["web/app_options.js"], { - base: ".", - }), - ]); - - return buildLibHelper( + const defaultPreferencesConfig = createWebpackConfig( bundleDefines, - inputStream, - DEFAULT_PREFERENCES_DIR + dir + { + filename: "app_options.mjs", + library: { + type: "module", + }, + }, + { + disableVersionInfo: true, + } ); + return gulp + .src("web/app_options.js") + .pipe(webpack2Stream(defaultPreferencesConfig)) + .pipe(gulp.dest(DEFAULT_PREFERENCES_DIR + dir)); } -function getDefaultPreferences(dir) { - const { AppOptions, OptionKind } = require("./" + - DEFAULT_PREFERENCES_DIR + - dir + - "web/app_options.js"); +async function parseDefaultPreferences(dir) { + console.log(); + console.log("### Parsing default preferences"); + + // eslint-disable-next-line no-unsanitized/method + const { AppOptions, OptionKind } = await import( + "./" + DEFAULT_PREFERENCES_DIR + dir + "app_options.mjs" + ); + + const prefs = AppOptions.getAll(OptionKind.PREFERENCE); + if (Object.keys(prefs).length === 0) { + throw new Error("No default preferences found."); + } - return AppOptions.getAll(OptionKind.PREFERENCE); + fs.writeFileSync( + DEFAULT_PREFERENCES_DIR + dir + "default_preferences.json", + JSON.stringify(prefs) + ); +} + +function getDefaultPreferences(dir) { + const str = fs + .readFileSync(DEFAULT_PREFERENCES_DIR + dir + "default_preferences.json") + .toString(); + return JSON.parse(str); } gulp.task("locale", function () { @@ -948,6 +968,9 @@ gulp.task( createTemporaryScriptingBundle(defines), ]); }, + async function prefsGeneric() { + await parseDefaultPreferences("generic/"); + }, function createGeneric() { console.log(); console.log("### Creating generic viewer"); @@ -975,6 +998,9 @@ gulp.task( createTemporaryScriptingBundle(defines), ]); }, + async function prefsGenericLegacy() { + await parseDefaultPreferences("generic-legacy/"); + }, function createGenericLegacy() { console.log(); console.log("### Creating generic (legacy) viewer"); @@ -1186,6 +1212,9 @@ gulp.task( createTemporaryScriptingBundle(defines), ]); }, + async function prefsMinified() { + await parseDefaultPreferences("minified/"); + }, function createMinified() { console.log(); console.log("### Creating minified viewer"); @@ -1216,6 +1245,9 @@ gulp.task( createTemporaryScriptingBundle(defines), ]); }, + async function prefsMinifiedLegacy() { + await parseDefaultPreferences("minified-legacy/"); + }, function createMinifiedLegacy() { console.log(); console.log("### Creating minified (legacy) viewer"); @@ -1268,6 +1300,9 @@ gulp.task( const defines = builder.merge(DEFINES, { MOZCENTRAL: true }); return buildDefaultPreferences(defines, "mozcentral/"); }, + async function prefsMozcentral() { + await parseDefaultPreferences("mozcentral/"); + }, function createMozcentral() { console.log(); console.log("### Building mozilla-central extension"); @@ -1365,6 +1400,9 @@ gulp.task( createTemporaryScriptingBundle(defines), ]); }, + async function prefsChromium() { + await parseDefaultPreferences("chromium/"); + }, function createChromium() { console.log(); console.log("### Building Chromium extension"); @@ -1589,6 +1627,9 @@ gulp.task( createTemporaryScriptingBundle(defines), ]); }, + async function prefsLib() { + await parseDefaultPreferences("lib/"); + }, function createLib() { const defines = builder.merge(DEFINES, { GENERIC: true, LIB: true }); @@ -1615,6 +1656,9 @@ gulp.task( createTemporaryScriptingBundle(defines), ]); }, + async function prefsLibLegacy() { + await parseDefaultPreferences("lib-legacy/"); + }, function createLibLegacy() { const defines = builder.merge(DEFINES, { GENERIC: true, @@ -1927,6 +1971,9 @@ gulp.task( }); return buildDefaultPreferences(defines, "lint-chromium/"); }, + async function prefsLintChromium() { + await parseDefaultPreferences("lint-chromium/"); + }, function runLintChromium(done) { console.log(); console.log("### Checking supplemental Chromium files");