2024-11-12 13:21:37 +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 { spawn } from "node:child_process";
|
|
|
|
|
import fs from "node:fs/promises";
|
|
|
|
|
import path from "node:path";
|
|
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
|
|
|
|
|
const IS_WATCH = process.argv.includes("--watch");
|
|
|
|
|
const TSC =
|
|
|
|
|
process.platform === "win32"
|
|
|
|
|
? path.join(__dirname, "..", "node_modules", ".bin", "tsc.cmd")
|
|
|
|
|
: path.join(__dirname, "..", "node_modules", ".bin", "tsc");
|
|
|
|
|
|
2025-10-08 08:42:00 +05:00
|
|
|
const TSCGO =
|
|
|
|
|
process.platform === "win32"
|
|
|
|
|
? path.join(__dirname, "..", "node_modules", ".bin", "tsgo.cmd")
|
|
|
|
|
: path.join(__dirname, "..", "node_modules", ".bin", "tsgo");
|
|
|
|
|
|
2024-11-12 13:21:37 +05:00
|
|
|
const esmPackageJson = {
|
|
|
|
|
type: "module"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
cmd(
|
|
|
|
|
TSC,
|
|
|
|
|
"--noCheck",
|
|
|
|
|
"--declaration",
|
|
|
|
|
"false",
|
|
|
|
|
"--module",
|
|
|
|
|
"commonjs",
|
2024-11-15 12:31:50 +05:00
|
|
|
"--moduleResolution",
|
|
|
|
|
"node",
|
2024-11-12 13:21:37 +05:00
|
|
|
"--outDir",
|
|
|
|
|
"dist/cjs",
|
|
|
|
|
IS_WATCH ? "--watch" : ""
|
|
|
|
|
),
|
|
|
|
|
cmd(
|
|
|
|
|
TSC,
|
|
|
|
|
"--noCheck",
|
|
|
|
|
"--declaration",
|
|
|
|
|
"false",
|
|
|
|
|
"--module",
|
|
|
|
|
"esnext",
|
2024-11-15 12:31:50 +05:00
|
|
|
"--moduleResolution",
|
|
|
|
|
"Bundler",
|
2024-11-12 13:21:37 +05:00
|
|
|
"--outDir",
|
|
|
|
|
"dist/esm",
|
|
|
|
|
IS_WATCH ? "--watch" : ""
|
|
|
|
|
),
|
|
|
|
|
cmd(
|
2025-10-08 08:42:00 +05:00
|
|
|
TSCGO,
|
2024-11-12 13:21:37 +05:00
|
|
|
"--emitDeclarationOnly",
|
|
|
|
|
"--outDir",
|
|
|
|
|
"dist/types",
|
|
|
|
|
IS_WATCH ? "--watch" : ""
|
|
|
|
|
),
|
|
|
|
|
fs
|
|
|
|
|
.mkdir("dist/esm", { recursive: true })
|
|
|
|
|
.then(() =>
|
|
|
|
|
fs.writeFile(
|
|
|
|
|
"dist/esm/package.json",
|
|
|
|
|
JSON.stringify(esmPackageJson, null, 2)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
]);
|
|
|
|
|
|
2025-10-08 08:42:00 +05:00
|
|
|
async function cmd(...command) {
|
2024-11-12 13:21:37 +05:00
|
|
|
let p = spawn(command[0], command.slice(1), { shell: true });
|
2025-10-08 08:42:00 +05:00
|
|
|
console.time(command.join(" "));
|
|
|
|
|
await new Promise((resolveFunc) => {
|
2024-11-12 13:21:37 +05:00
|
|
|
p.stdout.on("data", (x) => {
|
|
|
|
|
process.stdout.write(x.toString());
|
|
|
|
|
});
|
|
|
|
|
p.stderr.on("data", (x) => {
|
|
|
|
|
process.stderr.write(x.toString());
|
|
|
|
|
});
|
|
|
|
|
p.on("exit", (code) => {
|
2025-10-08 08:42:00 +05:00
|
|
|
// console.log(command.join(" "), "exited with code", code);
|
2024-11-12 13:21:37 +05:00
|
|
|
resolveFunc(code);
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-10-08 08:42:00 +05:00
|
|
|
console.timeEnd(command.join(" "));
|
2024-11-12 13:21:37 +05:00
|
|
|
}
|