Files
notesnook/apps/desktop/scripts/build.mjs

77 lines
2.2 KiB
JavaScript
Raw Normal View History

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";
import fs from "fs/promises";
2023-06-20 20:16:48 +05:00
import { existsSync } from "fs";
import yargs from "yargs-parser";
import os from "os";
2023-06-20 20:16:48 +05:00
import * as childProcess from "child_process";
import { fileURLToPath } from "url";
2023-06-20 20:16:48 +05:00
const args = yargs(process.argv);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
2023-06-20 20:21:14 +05:00
const webAppPath = path.resolve(path.join(__dirname, "..", "..", "web"));
2023-06-09 17:57:12 +05:00
await fs.rm("./build/", { force: true, recursive: true });
2023-06-09 17:57:12 +05:00
if (args.rebuild || !existsSync(path.join(webAppPath, "build"))) {
await exec(`cd ${webAppPath} && npm run build:desktop`);
2023-06-10 09:47:49 +05:00
}
if (os.platform() === "win32")
await exec(
"npx prebuildify --arch=arm64 --strip",
path.join(__dirname, "..", "node_modules", "sodium-native")
);
await fs.cp(path.join(webAppPath, "build"), "build", {
recursive: true,
force: true
});
if (args.variant === "mas") {
2023-06-20 20:16:48 +05:00
await exec(`npm run bundle:mas`);
2023-06-10 09:47:49 +05:00
} else {
2023-06-20 20:16:48 +05:00
await exec(`npm run bundle`);
2023-06-10 09:47:49 +05:00
}
2023-06-09 17:57:12 +05:00
2023-06-20 20:16:48 +05:00
await exec(`npx tsc`);
2023-06-09 17:57:12 +05:00
if (args.run) {
await exec(`npx electron-builder --dir --x64`);
2023-06-20 20:16:48 +05:00
if (process.platform === "win32") {
await exec(`.\\output\\win-unpacked\\Notesnook.exe`);
} else if (process.platform === "darwin") {
await exec(`./output/darwin-unpacked/Notesnook`);
2023-06-20 20:16:48 +05:00
} else {
await exec(`./output/linux-unpacked/Notesnook`);
2023-06-20 20:16:48 +05:00
}
}
2023-06-09 17:57:12 +05:00
async function exec(cmd, cwd) {
2023-06-20 20:16:48 +05:00
return childProcess.execSync(cmd, {
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
}