mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
setup: add build script
This commit is contained in:
committed by
Abdullah Atta
parent
fc01103353
commit
e2bbc1425b
91
scripts/build.mjs
Normal file
91
scripts/build.mjs
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
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");
|
||||
|
||||
const esmPackageJson = {
|
||||
type: "module"
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
cmd(
|
||||
TSC,
|
||||
"--noCheck",
|
||||
"--declaration",
|
||||
"false",
|
||||
"--module",
|
||||
"commonjs",
|
||||
"--outDir",
|
||||
"dist/cjs",
|
||||
IS_WATCH ? "--watch" : ""
|
||||
),
|
||||
cmd(
|
||||
TSC,
|
||||
"--noCheck",
|
||||
"--declaration",
|
||||
"false",
|
||||
"--module",
|
||||
"esnext",
|
||||
"--outDir",
|
||||
"dist/esm",
|
||||
IS_WATCH ? "--watch" : ""
|
||||
),
|
||||
cmd(
|
||||
TSC,
|
||||
"--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)
|
||||
)
|
||||
)
|
||||
]);
|
||||
|
||||
function cmd(...command) {
|
||||
let p = spawn(command[0], command.slice(1), { shell: true });
|
||||
return new Promise((resolveFunc) => {
|
||||
p.stdout.on("data", (x) => {
|
||||
process.stdout.write(x.toString());
|
||||
});
|
||||
p.stderr.on("data", (x) => {
|
||||
process.stderr.write(x.toString());
|
||||
});
|
||||
p.on("exit", (code) => {
|
||||
console.log(command.join(" "), "exited with code", code);
|
||||
resolveFunc(code);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user