2024-07-14 13:03:06 +03:00
|
|
|
import fs from "fs-extra";
|
|
|
|
import path from "path";
|
2024-05-01 00:05:24 +02:00
|
|
|
|
2025-03-09 08:29:03 +01:00
|
|
|
const DEST_DIR = "./build";
|
2024-05-01 00:05:24 +02:00
|
|
|
|
2024-07-27 16:42:47 +03:00
|
|
|
const VERBOSE = process.env.VERBOSE;
|
|
|
|
|
2025-02-15 13:08:13 +01:00
|
|
|
function log(...args: any[]) {
|
2025-01-09 18:07:02 +02:00
|
|
|
if (VERBOSE) {
|
2025-02-15 13:08:13 +01:00
|
|
|
console.log(...args);
|
2025-01-09 18:07:02 +02:00
|
|
|
}
|
2024-07-27 16:42:47 +03:00
|
|
|
}
|
|
|
|
|
2025-04-18 18:31:41 +03:00
|
|
|
import { fileURLToPath } from "url";
|
|
|
|
import { dirname } from "path";
|
|
|
|
|
|
|
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
|
|
const rootDir = path.resolve(scriptDir, "..", "..", "..");
|
|
|
|
const clientDir = path.join(rootDir, "apps", "client");
|
|
|
|
const serverDir = path.join(rootDir, "apps", "server");
|
|
|
|
|
|
|
|
function copyAssets(baseDir: string, destDir: string, files: string[]) {
|
|
|
|
for (const file of files) {
|
|
|
|
const src = path.join(baseDir, file);
|
|
|
|
const dest = path.join(destDir, file);
|
|
|
|
log(`${src} -> ${dest}`);
|
|
|
|
fs.copySync(src, dest);
|
|
|
|
}
|
|
|
|
}
|
2025-02-27 09:10:27 +01:00
|
|
|
|
2025-04-18 21:52:50 +03:00
|
|
|
/**
|
|
|
|
* Copies the dependencies from the node_modules directory to the build directory.
|
|
|
|
* We cannot copy the node_modules directory directly because we are in a monorepo and all the packages are gathered at root level.
|
|
|
|
*
|
|
|
|
* @param packageJsonPath
|
|
|
|
*/
|
|
|
|
function copyNodeModules(packageJsonPath: string) {
|
|
|
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
|
|
const dependencies = packageJson.dependencies || {};
|
|
|
|
|
|
|
|
for (const dependency of Object.keys(dependencies)) {
|
|
|
|
if (dependency.startsWith("@triliumnext/")) {
|
|
|
|
// Skip copying @triliumnext dependencies since they are symlinked in the monorepo.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const src = path.join(rootDir, "node_modules", dependency);
|
|
|
|
const dest = path.join(DEST_DIR, "node_modules", dependency);
|
|
|
|
log(`${src} -> ${dest}`);
|
|
|
|
fs.copySync(src, dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-18 18:14:40 +03:00
|
|
|
try {
|
2025-04-18 18:31:41 +03:00
|
|
|
const clientAssets = [
|
|
|
|
"./libraries",
|
|
|
|
`./stylesheets`
|
|
|
|
];
|
|
|
|
|
|
|
|
const serverAssets = [
|
2025-03-16 01:17:46 +01:00
|
|
|
// copy node_module, to avoid downloading packages a 2nd time during pruning
|
2025-03-23 22:47:59 +02:00
|
|
|
"./node_modules",
|
2025-04-18 19:41:09 +03:00
|
|
|
"./assets",
|
2025-02-27 08:01:07 +01:00
|
|
|
"./translations",
|
|
|
|
"./db",
|
|
|
|
"./config-sample.ini",
|
2025-03-05 09:01:21 +01:00
|
|
|
"./package.json",
|
2025-02-26 21:24:00 +01:00
|
|
|
"./src/public/icon.png",
|
|
|
|
"./src/public/manifest.webmanifest",
|
2025-02-27 08:01:07 +01:00
|
|
|
"./src/public/robots.txt",
|
|
|
|
"./src/public/fonts",
|
2025-03-19 19:23:43 +02:00
|
|
|
"./src/public/translations",
|
2025-04-18 18:31:41 +03:00
|
|
|
`./tpl/`,
|
|
|
|
"./scripts/cleanupNodeModules.ts",
|
|
|
|
"./src/views/",
|
|
|
|
"./src/etapi/etapi.openapi.yaml",
|
|
|
|
"./src/routes/api/openapi.json",
|
|
|
|
];
|
2025-02-27 08:01:07 +01:00
|
|
|
|
2025-04-18 18:31:41 +03:00
|
|
|
const rootAssets = [
|
|
|
|
"LICENSE",
|
|
|
|
"README.md"
|
|
|
|
];
|
|
|
|
|
2025-04-18 21:52:50 +03:00
|
|
|
copyNodeModules(path.join(serverDir, "package.json"));
|
2025-04-18 18:31:41 +03:00
|
|
|
copyAssets(clientDir, path.join(DEST_DIR, "src", "public"), clientAssets);
|
|
|
|
copyAssets(serverDir, path.join(DEST_DIR), serverAssets);
|
|
|
|
copyAssets(rootDir, path.join(DEST_DIR), rootAssets);
|
2024-05-01 00:05:24 +02:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
/**
|
|
|
|
* 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) {
|
2025-04-18 18:14:40 +03:00
|
|
|
fs.copySync(dir, path.normalize(path.join(PUBLIC_DIR, path.basename(dir))));
|
2025-01-09 18:07:02 +02:00
|
|
|
}
|
2024-11-02 16:11:59 +02:00
|
|
|
|
2025-04-18 19:55:30 +03:00
|
|
|
fs.copySync(path.join(clientDir, "build"), path.join(DEST_DIR, "src", "public", "app-dist"));
|
2025-04-18 18:31:41 +03:00
|
|
|
fs.copySync(path.join(rootDir, "packages", "turndown-plugin-gfm", "src"), path.join(DEST_DIR, "src", "public", "app-dist", "turndown-plugin-gfm"));
|
|
|
|
|
2025-02-27 09:10:27 +01:00
|
|
|
console.log("Copying complete!")
|
2024-05-01 00:05:24 +02:00
|
|
|
|
2025-02-27 09:10:27 +01:00
|
|
|
} catch(err) {
|
2025-04-18 18:14:40 +03:00
|
|
|
console.error("Error during copy:", err.message)
|
2025-03-12 09:52:42 +01:00
|
|
|
process.exit(1)
|
2025-03-11 23:03:13 +02:00
|
|
|
}
|
2025-03-16 01:50:59 +01:00
|
|
|
|