2023-06-09 17:57:12 +05:00
|
|
|
/*
|
|
|
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2023 Streetwriters (Private) Limited
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import path from "path";
|
2024-11-24 22:01:28 +05:00
|
|
|
import fs from "fs/promises";
|
|
|
|
|
import { existsSync } from "fs";
|
2023-07-05 13:40:03 +05:00
|
|
|
import yargs from "yargs-parser";
|
|
|
|
|
import os from "os";
|
2023-06-20 20:16:48 +05:00
|
|
|
import * as childProcess from "child_process";
|
2023-07-05 13:40:03 +05:00
|
|
|
import { fileURLToPath } from "url";
|
2024-11-24 22:01:28 +05:00
|
|
|
import { patchBetterSQLite3 } from "./patch-better-sqlite3.mjs";
|
2023-06-20 20:16:48 +05:00
|
|
|
|
2023-07-05 13:40:03 +05:00
|
|
|
const args = yargs(process.argv);
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
const __dirname = path.dirname(__filename);
|
2025-02-28 12:00:31 +05:00
|
|
|
const root = args.root || path.join(__dirname, "..");
|
2025-02-28 12:40:46 +05:00
|
|
|
const skipTscBuild = args.skipTscBuild || false;
|
2024-02-07 13:26:45 +05:00
|
|
|
|
2023-06-20 20:21:14 +05:00
|
|
|
const webAppPath = path.resolve(path.join(__dirname, "..", "..", "web"));
|
2023-06-09 17:57:12 +05:00
|
|
|
|
2025-02-28 12:00:31 +05:00
|
|
|
await fs.rm(path.join(root, "build"), { force: true, recursive: true });
|
2023-06-09 17:57:12 +05:00
|
|
|
|
2023-07-06 10:02:38 +05:00
|
|
|
if (args.rebuild || !existsSync(path.join(webAppPath, "build"))) {
|
2024-04-29 11:15:43 +05:00
|
|
|
await exec(
|
2024-12-30 10:13:40 +05:00
|
|
|
"npx nx build:desktop @notesnook/web",
|
2024-04-29 11:15:43 +05:00
|
|
|
path.join(__dirname, "..", "..", "..")
|
|
|
|
|
);
|
2023-06-10 09:47:49 +05:00
|
|
|
}
|
|
|
|
|
|
2025-05-30 19:15:51 +05:00
|
|
|
await patchBetterSQLite3();
|
2024-02-10 13:30:45 +05:00
|
|
|
|
2025-02-28 12:00:31 +05:00
|
|
|
await fs.cp(path.join(webAppPath, "build"), path.join(root, "build"), {
|
2023-07-06 10:02:38 +05:00
|
|
|
recursive: true,
|
|
|
|
|
force: true
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-05 13:40:03 +05:00
|
|
|
if (args.variant === "mas") {
|
2025-02-28 12:00:31 +05:00
|
|
|
await exec(`yarn run bundle:mas --outdir=${path.join(root, "build")}`);
|
2023-06-10 09:47:49 +05:00
|
|
|
} else {
|
2025-02-28 12:00:31 +05:00
|
|
|
await exec(`yarn run bundle --outdir=${path.join(root, "build")}`);
|
2023-06-10 09:47:49 +05:00
|
|
|
}
|
2023-06-09 17:57:12 +05:00
|
|
|
|
2025-02-28 12:40:46 +05:00
|
|
|
if (!skipTscBuild) {
|
|
|
|
|
await exec(`yarn run build`);
|
|
|
|
|
}
|
2023-06-09 17:57:12 +05:00
|
|
|
|
2023-07-05 13:40:03 +05:00
|
|
|
if (args.run) {
|
2025-02-28 12:23:27 +05:00
|
|
|
await exec(
|
|
|
|
|
`yarn electron-builder --dir --${process.arch} --config=electron-builder.config.js`
|
|
|
|
|
);
|
2023-06-20 20:16:48 +05:00
|
|
|
if (process.platform === "win32") {
|
2023-07-03 06:50:05 +05:00
|
|
|
await exec(`.\\output\\win-unpacked\\Notesnook.exe`);
|
|
|
|
|
} else if (process.platform === "darwin") {
|
2024-12-30 10:13:40 +05:00
|
|
|
if (process.arch === "arm64")
|
|
|
|
|
await exec(`./output/mac-arm64/Notesnook.app/Contents/MacOS/Notesnook`);
|
|
|
|
|
else await exec(`./output/mac/Notesnook.app/Contents/MacOS/Notesnook`);
|
2023-06-20 20:16:48 +05:00
|
|
|
} else {
|
2023-07-03 06:50:05 +05:00
|
|
|
await exec(`./output/linux-unpacked/Notesnook`);
|
2023-06-20 20:16:48 +05:00
|
|
|
}
|
|
|
|
|
}
|
2023-06-09 17:57:12 +05:00
|
|
|
|
2024-02-07 13:26:45 +05:00
|
|
|
async function exec(cmd, cwd) {
|
2023-06-20 20:16:48 +05:00
|
|
|
return childProcess.execSync(cmd, {
|
2024-02-07 13:26:45 +05:00
|
|
|
env: { ...process.env, NOTESNOOK_STAGING: true },
|
|
|
|
|
stdio: "inherit",
|
|
|
|
|
cwd: cwd || process.cwd()
|
2023-06-20 20:16:48 +05:00
|
|
|
});
|
2023-06-09 17:57:12 +05:00
|
|
|
}
|