Allow excluding lockdown at build time (#11937)

This adds an `--omit-lockdown` flag to our build script, which will cause SES `lockdown` to be omitted from the resulting bundle. Useful for development when we don't want the environment to be locked down.

Thanks to @kumavis for the suggestion.
feature/default_network_editable
Erik Marks 3 years ago committed by GitHub
parent 48c5c07ded
commit 290fcbf89e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      development/build/index.js
  2. 160
      development/build/static.js

@ -28,12 +28,17 @@ require('@babel/preset-react');
require('@babel/core'); require('@babel/core');
const browserPlatforms = ['firefox', 'chrome', 'brave', 'opera']; const browserPlatforms = ['firefox', 'chrome', 'brave', 'opera'];
const shouldIncludeLockdown = !process.argv.includes('--omit-lockdown');
defineAllTasks(); defineAllTasks();
detectAndRunEntryTask(); detectAndRunEntryTask();
function defineAllTasks() { function defineAllTasks() {
const staticTasks = createStaticAssetTasks({ livereload, browserPlatforms }); const staticTasks = createStaticAssetTasks({
livereload,
browserPlatforms,
shouldIncludeLockdown,
});
const manifestTasks = createManifestTasks({ browserPlatforms }); const manifestTasks = createManifestTasks({ browserPlatforms });
const styleTasks = createStyleTasks({ livereload }); const styleTasks = createStyleTasks({ livereload });
const scriptTasks = createScriptTasks({ livereload, browserPlatforms }); const scriptTasks = createScriptTasks({ livereload, browserPlatforms });

@ -7,9 +7,82 @@ const locales = require('../../app/_locales/index.json');
const { createTask, composeSeries } = require('./task'); const { createTask, composeSeries } = require('./task');
module.exports = createStaticAssetTasks; const EMPTY_JS_FILE = './development/empty.js';
const copyTargets = [ module.exports = function createStaticAssetTasks({
livereload,
browserPlatforms,
shouldIncludeLockdown = true,
}) {
const [copyTargetsProd, copyTargetsDev] = getCopyTargets(
shouldIncludeLockdown,
);
const prod = createTask(
'static:prod',
composeSeries(
...copyTargetsProd.map((target) => {
return async function copyStaticAssets() {
await performCopy(target);
};
}),
),
);
const dev = createTask(
'static:dev',
composeSeries(
...copyTargetsDev.map((target) => {
return async function copyStaticAssets() {
await setupLiveCopy(target);
};
}),
),
);
return { dev, prod };
async function setupLiveCopy(target) {
const pattern = target.pattern || '/**/*';
watch(target.src + pattern, (event) => {
livereload.changed(event.path);
performCopy(target);
});
await performCopy(target);
}
async function performCopy(target) {
await Promise.all(
browserPlatforms.map(async (platform) => {
if (target.pattern) {
await copyGlob(
target.src,
`${target.src}${target.pattern}`,
`./dist/${platform}/${target.dest}`,
);
} else {
await copyGlob(
target.src,
`${target.src}`,
`./dist/${platform}/${target.dest}`,
);
}
}),
);
}
async function copyGlob(baseDir, srcGlob, dest) {
const sources = await glob(srcGlob, { onlyFiles: false });
await Promise.all(
sources.map(async (src) => {
const relativePath = path.relative(baseDir, src);
await fs.copy(src, `${dest}${relativePath}`);
}),
);
}
};
function getCopyTargets(shouldIncludeLockdown) {
const allCopyTargets = [
{ {
src: `./app/_locales/`, src: `./app/_locales/`,
dest: `_locales`, dest: `_locales`,
@ -48,11 +121,15 @@ const copyTargets = [
dest: `globalthis.js`, dest: `globalthis.js`,
}, },
{ {
src: `./node_modules/ses/dist/lockdown.umd.min.js`, src: shouldIncludeLockdown
? `./node_modules/ses/dist/lockdown.umd.min.js`
: EMPTY_JS_FILE,
dest: `lockdown-install.js`, dest: `lockdown-install.js`,
}, },
{ {
src: `./app/scripts/lockdown-run.js`, src: shouldIncludeLockdown
? `./app/scripts/lockdown-run.js`
: EMPTY_JS_FILE,
dest: `lockdown-run.js`, dest: `lockdown-run.js`,
}, },
{ {
@ -70,14 +147,14 @@ for (const locale of locales) {
} }
for (const tag of languageTags) { for (const tag of languageTags) {
copyTargets.push({ allCopyTargets.push({
src: `./node_modules/@formatjs/intl-relativetimeformat/dist/locale-data/${tag}.json`, src: `./node_modules/@formatjs/intl-relativetimeformat/dist/locale-data/${tag}.json`,
dest: `intl/${tag}/relative-time-format-data.json`, dest: `intl/${tag}/relative-time-format-data.json`,
}); });
} }
const copyTargetsDev = [ const copyTargetsDev = [
...copyTargets, ...allCopyTargets,
{ {
src: './development', src: './development',
pattern: '/chromereload.js', pattern: '/chromereload.js',
@ -85,84 +162,23 @@ const copyTargetsDev = [
}, },
// empty files to suppress missing file errors // empty files to suppress missing file errors
{ {
src: './development/empty.js', src: EMPTY_JS_FILE,
dest: `bg-libs.js`, dest: `bg-libs.js`,
}, },
{ {
src: './development/empty.js', src: EMPTY_JS_FILE,
dest: `ui-libs.js`, dest: `ui-libs.js`,
}, },
]; ];
const copyTargetsProd = [ const copyTargetsProd = [
...copyTargets, ...allCopyTargets,
// empty files to suppress missing file errors // empty files to suppress missing file errors
{ {
src: './development/empty.js', src: EMPTY_JS_FILE,
dest: `chromereload.js`, dest: `chromereload.js`,
}, },
]; ];
function createStaticAssetTasks({ livereload, browserPlatforms }) { return [copyTargetsProd, copyTargetsDev];
const prod = createTask(
'static:prod',
composeSeries(
...copyTargetsProd.map((target) => {
return async function copyStaticAssets() {
await performCopy(target);
};
}),
),
);
const dev = createTask(
'static:dev',
composeSeries(
...copyTargetsDev.map((target) => {
return async function copyStaticAssets() {
await setupLiveCopy(target);
};
}),
),
);
return { dev, prod };
async function setupLiveCopy(target) {
const pattern = target.pattern || '/**/*';
watch(target.src + pattern, (event) => {
livereload.changed(event.path);
performCopy(target);
});
await performCopy(target);
}
async function performCopy(target) {
await Promise.all(
browserPlatforms.map(async (platform) => {
if (target.pattern) {
await copyGlob(
target.src,
`${target.src}${target.pattern}`,
`./dist/${platform}/${target.dest}`,
);
} else {
await copyGlob(
target.src,
`${target.src}`,
`./dist/${platform}/${target.dest}`,
);
}
}),
);
}
async function copyGlob(baseDir, srcGlob, dest) {
const sources = await glob(srcGlob, { onlyFiles: false });
await Promise.all(
sources.map(async (src) => {
const relativePath = path.relative(baseDir, src);
await fs.copy(src, `${dest}${relativePath}`);
}),
);
}
} }

Loading…
Cancel
Save