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.
|
|
|
|
|
*/
|
2022-12-27 15:37:40 +01:00
|
|
|
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))
|
|
|
|
|
|
2021-11-29 17:58:08 +01:00
|
|
|
/*
|
|
|
|
|
* 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-12-27 15:37:40 +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" },
|
2023-01-30 16:44:35 +01:00
|
|
|
"../node_modules/luxon/build/es6/luxon.js",
|
2022-12-27 15:37:40 +01:00
|
|
|
{ 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) {
|
2021-11-29 17:58:08 +01:00
|
|
|
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)
|
|
|
|
|
}
|
2022-12-27 15:37:40 +01:00
|
|
|
await fs.copy(path.join(__dirname, srcFile), path.join(__dirname, "../libs/", targetName))
|
2021-03-30 11:50:45 +02:00
|
|
|
}
|
2021-11-29 17:58:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Will bundle starting at {@param src} into a single file at {@param target}. */
|
|
|
|
|
async function roll(src, target) {
|
2022-12-27 15:37:40 +01:00
|
|
|
const bundle = await rollup({ input: path.join(__dirname, src) })
|
|
|
|
|
await bundle.write({ file: path.join(__dirname, "../libs", target) })
|
2021-11-29 17:58:08 +01:00
|
|
|
}
|