mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-12-03 10:00:31 +03:00
* fix: Undeclared dependencies Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * chore: Rationalize package versions Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * chore: Remove old react app remnants Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * feat: Conversion to pnpm Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Circular deps #0 Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: common package circular dependencies Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * chore: Move history and undo/redo to excalidraw/excalidraw Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * feat: AppState broken up across package boundaries Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: renderElement and binding type racionalization Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Refactor linearElementEditor to not use types outside the package Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * chore: Do not import self barrel file Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: All circular dependencies except core Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * feat: Bump pnpm to 11 Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: SASS deprecation warnings Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Polynomial regular expression used on uncontrolled data Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Vercel deploy Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * feat: excalidraw/history package Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Polynomial regex in SVG payload decoding Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: emit the internal packages' types from the editor again The editor advertises ./common/*, ./element/*, ./history/*, ./math/* and ./utils/* type subpaths, but without the path aliases tsc treats those packages as external libraries and no longer emits them. Include their sources in the editor's type build, and drop the relative cross-package import that made element/ come out half-emitted. * feat: export the history classes of the editor's API from the entry onIncrement hands out StoreIncrement subclasses and applyDeltas takes StoreDelta, so export them next to CaptureUpdateAction. Hosts then need no dependency of their own on @excalidraw/history. * chore: refuse to publish packages with npm or yarn Only pnpm publish rewrites workspace:* dependencies and applies publishConfig.exports, so a package published with another client can't be installed. --------- Signed-off-by: Mark Tolmacs <mark@lazycat.hu> Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
241 lines
7.1 KiB
JavaScript
241 lines
7.1 KiB
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const { execSync } = require("child_process");
|
|
|
|
const updateChangelog = require("./updateChangelog");
|
|
|
|
// skipping utils for now, as it has independent release process
|
|
const PACKAGES = [
|
|
"common",
|
|
"fractional-indexing",
|
|
"math",
|
|
"element",
|
|
"history",
|
|
"excalidraw",
|
|
];
|
|
const PACKAGES_DIR = path.resolve(__dirname, "../packages");
|
|
|
|
/**
|
|
* Returns the arguments for the release script.
|
|
*
|
|
* Usage examples:
|
|
* - pnpm release --help -> prints this help message
|
|
* - pnpm release -> publishes `@excalidraw` packages with "test" tag and "-[hash]" version suffix
|
|
* - pnpm release --tag=test -> same as above
|
|
* - pnpm release --tag=next -> publishes `@excalidraw` packages with "next" tag and version "-[hash]" suffix
|
|
* - pnpm release --tag=next --non-interactive -> skips interactive prompts (runs on CI/CD), otherwise same as above
|
|
* - pnpm release --tag=latest --version=0.19.0 -> publishes `@excalidraw` packages with "latest" tag and version "0.19.0" & prepares changelog for the release
|
|
*
|
|
* @returns [tag, version, nonInteractive]
|
|
*/
|
|
const getArguments = () => {
|
|
let tag = "test";
|
|
let version = "";
|
|
let nonInteractive = false;
|
|
|
|
for (const argument of process.argv.slice(2)) {
|
|
if (/--help/.test(argument)) {
|
|
console.info(`Available arguments:
|
|
--tag=<tag> -> (optional) "test" (default), "next" for auto release, "latest" for stable release
|
|
--version=<version> -> (optional) for "next" and "test", (required) for "latest" i.e. "0.19.0"
|
|
--non-interactive -> (optional) disables interactive prompts`);
|
|
|
|
console.info(`\nUsage examples:
|
|
- pnpm release -> publishes \`@excalidraw\` packages with "test" tag and "-[hash]" version suffix
|
|
- pnpm release --tag=test -> same as above
|
|
- pnpm release --tag=next -> publishes \`@excalidraw\` packages with "next" tag and version "-[hash]" suffix
|
|
- pnpm release --tag=next --non-interactive -> skips interactive prompts (runs on CI/CD), otherwise same as above
|
|
- pnpm release --tag=latest --version=0.19.0 -> publishes \`@excalidraw\` packages with "latest" tag and version "0.19.0" & prepares changelog for the release`);
|
|
|
|
process.exit(0);
|
|
}
|
|
|
|
if (/--tag=/.test(argument)) {
|
|
tag = argument.split("=")[1];
|
|
}
|
|
|
|
if (/--version=/.test(argument)) {
|
|
version = argument.split("=")[1];
|
|
}
|
|
|
|
if (/--non-interactive/.test(argument)) {
|
|
nonInteractive = true;
|
|
}
|
|
}
|
|
|
|
if (tag !== "latest" && tag !== "next" && tag !== "test") {
|
|
console.error(`Unsupported tag "${tag}", use "latest", "next" or "test".`);
|
|
process.exit(1);
|
|
}
|
|
|
|
if (tag === "latest" && !version) {
|
|
console.error("Pass the version to make the latest stable release!");
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!version) {
|
|
// set the next version based on the excalidraw package version + commit hash
|
|
const excalidrawPackageVersion = require(getPackageJsonPath(
|
|
"excalidraw",
|
|
)).version;
|
|
|
|
const hash = getShortCommitHash();
|
|
|
|
if (!excalidrawPackageVersion.includes(hash)) {
|
|
version = `${excalidrawPackageVersion}-${hash}`;
|
|
} else {
|
|
// ensuring idempotency
|
|
version = excalidrawPackageVersion;
|
|
}
|
|
}
|
|
|
|
console.info(`Running with tag "${tag}" and version "${version}"...`);
|
|
|
|
return [tag, version, nonInteractive];
|
|
};
|
|
|
|
const validatePackageName = (packageName) => {
|
|
if (!PACKAGES.includes(packageName)) {
|
|
console.error(`Package "${packageName}" not found!`);
|
|
process.exit(1);
|
|
}
|
|
};
|
|
|
|
const getPackageJsonPath = (packageName) => {
|
|
validatePackageName(packageName);
|
|
return path.resolve(PACKAGES_DIR, packageName, "package.json");
|
|
};
|
|
|
|
const updatePackageJsons = (nextVersion) => {
|
|
const packageJsons = new Map();
|
|
|
|
for (const packageName of PACKAGES) {
|
|
const pkg = require(getPackageJsonPath(packageName));
|
|
|
|
// internal dependencies use the `workspace:*` protocol, which
|
|
// `pnpm publish` replaces with the version bumped here
|
|
pkg.version = nextVersion;
|
|
|
|
packageJsons.set(packageName, `${JSON.stringify(pkg, null, 2)}\n`);
|
|
}
|
|
|
|
// modify once, to avoid inconsistent state
|
|
for (const packageName of PACKAGES) {
|
|
const content = packageJsons.get(packageName);
|
|
fs.writeFileSync(getPackageJsonPath(packageName), content, "utf-8");
|
|
}
|
|
};
|
|
|
|
const getShortCommitHash = () => {
|
|
return execSync("git rev-parse --short HEAD").toString().trim();
|
|
};
|
|
|
|
const askToCommit = (tag, nextVersion) => {
|
|
if (tag !== "latest") {
|
|
return Promise.resolve();
|
|
}
|
|
|
|
return new Promise((resolve) => {
|
|
const rl = require("readline").createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout,
|
|
});
|
|
|
|
rl.question(
|
|
"Would you like to commit these changes to git? (Y/n): ",
|
|
(answer) => {
|
|
rl.close();
|
|
|
|
if (answer.toLowerCase() === "y") {
|
|
execSync(`git add -u`);
|
|
execSync(
|
|
`git commit -m "chore: release @excalidraw/excalidraw@${nextVersion} 🎉"`,
|
|
);
|
|
} else {
|
|
console.warn(
|
|
"Skipping commit. Don't forget to commit manually later!",
|
|
);
|
|
}
|
|
|
|
resolve();
|
|
},
|
|
);
|
|
});
|
|
};
|
|
|
|
const buildPackages = () => {
|
|
console.info("Running pnpm install...");
|
|
execSync(`pnpm install --frozen-lockfile`, { stdio: "inherit" });
|
|
|
|
console.info("Removing existing build artifacts...");
|
|
execSync(`pnpm rm:build`, { stdio: "inherit" });
|
|
|
|
for (const packageName of PACKAGES) {
|
|
console.info(`Building "@excalidraw/${packageName}"...`);
|
|
execSync(`pnpm run build:esm`, {
|
|
cwd: path.resolve(PACKAGES_DIR, packageName),
|
|
stdio: "inherit",
|
|
});
|
|
}
|
|
};
|
|
|
|
const askToPublish = (tag, version) => {
|
|
return new Promise((resolve) => {
|
|
const rl = require("readline").createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout,
|
|
});
|
|
|
|
rl.question(
|
|
"Would you like to publish these changes to npm? (Y/n): ",
|
|
(answer) => {
|
|
rl.close();
|
|
|
|
if (answer.toLowerCase() === "y") {
|
|
publishPackages(tag, version);
|
|
} else {
|
|
console.info("Skipping publish.");
|
|
}
|
|
|
|
resolve();
|
|
},
|
|
);
|
|
});
|
|
};
|
|
|
|
const publishPackages = (tag, version) => {
|
|
for (const packageName of PACKAGES) {
|
|
// --no-git-checks: the version bumps above stay uncommitted for "test"
|
|
// and "next" releases, which pnpm's clean-tree check would reject
|
|
execSync(`pnpm publish --tag ${tag} --no-git-checks`, {
|
|
cwd: path.resolve(PACKAGES_DIR, packageName),
|
|
stdio: "inherit",
|
|
});
|
|
|
|
console.info(
|
|
`Published "@excalidraw/${packageName}@${tag}" with version "${version}"! 🎉`,
|
|
);
|
|
}
|
|
};
|
|
|
|
/** main */
|
|
(async () => {
|
|
const [tag, version, nonInteractive] = getArguments();
|
|
|
|
buildPackages();
|
|
|
|
if (tag === "latest") {
|
|
await updateChangelog(version);
|
|
}
|
|
|
|
updatePackageJsons(version);
|
|
|
|
if (nonInteractive) {
|
|
publishPackages(tag, version);
|
|
} else {
|
|
await askToCommit(tag, version);
|
|
await askToPublish(tag, version);
|
|
}
|
|
})();
|