Notes/bin/copy-dist.ts
Panagiotis Papadopoulos 1ceaafa1e8 build: move cleanupNodeModules to its own file
this is necessary, since for Docker and electron-forge, we need to run this as an extra step after copy-dist

for electron-forge: after it is done with its own "pruning", as we otherwise would need to also take care of certain electron related pruning

for Docker: as a last step in the build stage
2025-03-26 08:12:48 +01:00

72 lines
2.0 KiB
TypeScript

import fs from "fs-extra";
import path from "path";
import { execSync } from "node:child_process";
const DEST_DIR = "./build";
const VERBOSE = process.env.VERBOSE;
function log(...args: any[]) {
if (VERBOSE) {
console.log(...args);
}
}
try {
const assetsToCopy = new Set([
// copy node_module, to avoid downloading packages a 2nd time during pruning
"./node_modules",
"./images",
"./libraries",
"./translations",
"./db",
"./config-sample.ini",
"./package-lock.json",
"./package.json",
"./LICENSE",
"./README.md",
"./forge.config.cjs",
"./bin/tpl/",
"./bin/cleanupNodeModules.ts",
"./bin/electron-forge/desktop.ejs",
"./bin/electron-forge/sign-windows.cjs",
"./src/views/",
"./src/etapi/etapi.openapi.yaml",
"./src/routes/api/openapi.json",
"./src/public/icon.png",
"./src/public/manifest.webmanifest",
"./src/public/robots.txt",
"./src/public/fonts",
"./src/public/stylesheets",
"./src/public/translations",
"./packages/turndown-plugin-gfm/src"
]);
for (const asset of assetsToCopy) {
log(`Copying ${asset}`);
fs.copySync(asset, path.join(DEST_DIR, asset));
}
/**
* Directories to be copied relative to the project root into <resource_dir>/src/public/app-dist.
*/
const publicDirsToCopy = ["./src/public/app/doc_notes"];
const PUBLIC_DIR = path.join(DEST_DIR, "src", "public", "app-dist");
for (const dir of publicDirsToCopy) {
fs.copySync(dir, path.join(PUBLIC_DIR, path.basename(dir)));
}
console.log("Copying complete!")
// TriliumNextTODO: for Docker this needs to run separately *after* build-stage
// Disable for now, because this messes with electron-forge as well
//console.log("Pruning npm packages...")
//execSync(`npm ci --omit=dev --prefix ${DEST_DIR}`);
} catch(err) {
console.error("Error during copy:", err)
process.exit(1)
}