tutanota/buildSrc/updateLibs.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-03-30 11:50:45 +02:00
/**
* Copies all currently used libraries from node_modules into libs.
*
* We do this to be able to audit changes in the libraries and not rely on npm for checksums.
*/
import fs from "fs-extra";
import path, {dirname} from "path";
import {fileURLToPath} from "url";
import {rollup} from "rollup"
2021-03-30 11:50:45 +02:00
const __dirname = dirname(fileURLToPath(import.meta.url))
/*
* Each entry is one of:
* - string: will be copied from specified to libs preserving the file name
* - object with:
* - src: path to file
* - target: resulting file name
* - rollup: if truthy will use src as input for rollup, otherwise just copy
*/
2021-03-30 11:50:45 +02:00
const clientDependencies = [
"../node_modules/systemjs/dist/s.js",
"../node_modules/mithril/mithril.js",
"../node_modules/mithril/stream/stream.js",
"../node_modules/squire-rte/build/squire-raw.js",
"../node_modules/dompurify/dist/purify.js",
2022-01-19 15:17:38 +01:00
{src: "../node_modules/linkifyjs/dist/linkify.module.js", target: "linkify.js"},
{src: "../node_modules/linkifyjs/dist/linkify-html.module.js", target: "linkify-html.js"},
2021-03-30 11:50:45 +02:00
"../node_modules/luxon/build/cjs-browser/luxon.js",
{src: "../node_modules/cborg/esm/cborg.js", target: "cborg.js", rollup: true},
2021-03-30 11:50:45 +02:00
]
run()
async function run() {
await copyToLibs(clientDependencies)
}
async function copyToLibs(files) {
for (let srcFile of files) {
let targetName = ""
if (srcFile instanceof Object) {
if (srcFile.rollup) {
await roll(srcFile.src, srcFile.target)
continue
} else {
targetName = srcFile.target
srcFile = srcFile.src
}
2021-03-30 11:50:45 +02:00
} else {
targetName = path.basename(srcFile)
}
await fs.copy(path.join(__dirname, srcFile), path.join(__dirname, '../libs/', targetName))
}
}
/** Will bundle starting at {@param src} into a single file at {@param target}. */
async function roll(src, target) {
const bundle = await rollup({input: path.join(__dirname, src)})
await bundle.write({file: path.join(__dirname, "../libs", target)})
}