Skip to content

Commit 9e26d69

Browse files
committed
Cleaned up features 💖 <a href=https://mayank-chaudhari.vercel.app target=_blank>Mayank Kumar Chaudhari</a> [skip ci]
1 parent 45f58a7 commit 9e26d69

19 files changed

+418
-3161
lines changed

‎lib/vitest.config.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineConfig({
1111
setupFiles: [],
1212
coverage: {
1313
include: ["src/**"],
14-
exclude: ["src/**/index.ts", "src/**/*.test.*", "src/**/declaration.d.ts"],
14+
exclude: ["src/**/*.test.*", "src/**/declaration.d.ts"],
1515
reporter: ["text", "json", "clover", "html"],
1616
},
1717
},

‎package.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"sync": "turborepo-template-upgrade",
1313
"test": "turbo test",
1414
"typecheck": "turbo typecheck",
15-
"preinstall": "node scripts/update-pm.js",
16-
"rebrand": "node scripts/rebrand.js"
15+
"preinstall": "node scripts/update-pm.js"
1716
},
1817
"pre-commit": [
1918
"lint:fix",
@@ -23,8 +22,6 @@
2322
"@changesets/cli": "^2.29.6",
2423
"@repo/typescript-config": "workspace:*",
2524
"@types/node": "^24.3.0",
26-
"enquirer": "^2.4.1",
27-
"plop": "^4.0.1",
2825
"pre-commit": "^1.2.2",
2926
"prettier": "^3.6.2",
3027
"turbo": "^2.5.6",

‎plopfile.js‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎pnpm-lock.yaml‎

Lines changed: 200 additions & 1987 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/hook.js‎

Lines changed: 0 additions & 62 deletions
This file was deleted.

‎scripts/lite.js‎

Lines changed: 0 additions & 29 deletions
This file was deleted.

‎scripts/manual-publish.js‎

Lines changed: 123 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,123 @@
1-
/**
2-
* allow only patch changes from release branches.
3-
* Major and minor changes allowed only from main branch.
4-
* pre-release only from branch containing dev or alpha in the branchname
5-
*/
6-
7-
/** Let the following error be thrown by npm. There are situations where publish could have failed for different reasons. */
8-
// throws an exception if process.env.oldv === process.env.v The library version is not up to date, error(" Not able to release to the same version.
9-
10-
const { execSync } = require("child_process");
11-
const fs = require("fs");
12-
const path = require("path");
13-
14-
const BRANCH = process.env.BRANCH;
15-
const DEFAULT_BRANCH = process.env.DEFAULT_BRANCH;
16-
17-
const isLatestRelease = BRANCH === DEFAULT_BRANCH || BRANCH.includes("release-");
18-
let tag = "";
19-
20-
const { version: OLD_VERSION, name } = require("../lib/package.json");
21-
if (!isLatestRelease) {
22-
/** pre-release branch name should be the tag name (e.g., beta, canery, etc.) or tag name followed by a '-' and version or other specifiers. e.g. beta-2.0 */
23-
tag = BRANCH.split("-")[0];
24-
try {
25-
execSync(`pnpm changeset pre enter ${tag}`);
26-
} catch (e) {
27-
console.log({ e });
28-
}
29-
}
30-
/** Apply changeset */
31-
execSync("pnpm changeset version");
32-
33-
// exit pre mode -- to avoid collision with full releases
34-
try {
35-
execSync("pnpm changeset pre exit");
36-
} catch {
37-
// empty
38-
}
39-
40-
/** not requiring as require is cached by npm/node */
41-
const NEW_VERSION = JSON.parse(
42-
fs.readFileSync(path.resolve(__dirname, "..", "lib", "package.json")),
43-
).version;
44-
45-
const [newMajor, newMinor] = NEW_VERSION.split(".");
46-
const [oldMajor, oldMinor] = OLD_VERSION.split(".");
47-
48-
const isNotPatch = newMajor !== oldMajor || newMinor !== oldMinor;
49-
50-
const pushCmd = `git add . && git commit -m "Apply changesets and update CHANGELOG" && git push origin ${BRANCH}`;
51-
52-
if (isNotPatch && BRANCH === DEFAULT_BRANCH) {
53-
try {
54-
execSync(pushCmd);
55-
} catch (e) {
56-
console.log({ e });
57-
}
58-
require("./update-security-md")(`${newMajor}.${newMinor}`, `${oldMajor}.${oldMinor}`);
59-
/** Create new release branch for every Major or Minor release */
60-
const releaseBranch = `release-${newMajor}.${newMinor}`;
61-
execSync(`git checkout -b ${releaseBranch} && git push origin ${releaseBranch}`);
62-
} else if (isLatestRelease) {
63-
/** New version must be valid SEMVER version. No pre-release (beta/alpha etc.) */
64-
if (!/^\d+\.\d+.\d+$/.test(NEW_VERSION)) throw new Error("Invalid version");
65-
66-
if (isNotPatch)
67-
throw new Error("Major or Minor changes can be published only from the default branch.");
68-
69-
// Push changes back to the repo
70-
try {
71-
execSync(pushCmd);
72-
} catch (e) {
73-
console.log({ e });
74-
}
75-
} else {
76-
try {
77-
execSync(pushCmd);
78-
} catch (e) {
79-
console.log({ e });
80-
}
81-
}
82-
83-
const { visibility } = JSON.parse(execSync("gh repo view --json visibility").toString());
84-
const provenance = visibility.toLowerCase() === "public" ? "--provenance" : "";
85-
86-
let LATEST_VERSION = "0.0.-1";
87-
88-
try {
89-
LATEST_VERSION = execSync(`npm view ${name} version`).toString().trim() ?? "0.0.-1";
90-
} catch {
91-
// empty
92-
}
93-
94-
const latest = LATEST_VERSION.split(".").map(parseInt);
95-
const current = NEW_VERSION.split(".").map(parseInt);
96-
97-
let isLatest = false;
98-
99-
if (latest[0] < current[0]) {
100-
isLatest = true;
101-
} else if (latest[0] === current[0] && latest[1] < current[1]) {
102-
isLatest = true;
103-
} else if (latest[0] === current[0] && latest[1] === current[1] && latest[2] < current[2]) {
104-
isLatest = true;
105-
}
106-
107-
const reTag = isLatest ? "" : ` && npm dist-tag add ${name}@${LATEST_VERSION} latest`;
108-
/** Create release */
109-
const publishCmd = `cd lib && pnpm build && npm publish ${provenance} --access public${tag && ` --tag ${tag}`}`;
110-
execSync(publishCmd + reTag);
111-
112-
/** Create GitHub release */
113-
execSync(
114-
`gh release create ${NEW_VERSION} --generate-notes${isLatestRelease ? " --latest" : ""} -n "$(sed '1,/^## /d;/^## /,$d' lib/CHANGELOG.md)" --title "Release v${NEW_VERSION}"`,
115-
);
116-
117-
try {
118-
// Publish canonical packages
119-
execSync("node scripts/publish-canonical.js");
120-
} catch {
121-
console.error("Failed to publish canonical packages");
122-
}
123-
124-
execSync("node ./scripts/lite.js");
125-
execSync(publishCmd + reTag.replace("@", "-lite@"));
1+
/**
2+
* allow only patch changes from release branches.
3+
* Major and minor changes allowed only from main branch.
4+
* pre-release only from branch containing dev or alpha in the branchname
5+
*/
6+
7+
/** Let the following error be thrown by npm. There are situations where publish could have failed for different reasons. */
8+
// throws an exception if process.env.oldv === process.env.v The library version is not up to date, error(" Not able to release to the same version.
9+
10+
const { execSync } = require("child_process");
11+
const fs = require("fs");
12+
const path = require("path");
13+
14+
const BRANCH = process.env.BRANCH;
15+
const DEFAULT_BRANCH = process.env.DEFAULT_BRANCH;
16+
17+
const isLatestRelease = BRANCH === DEFAULT_BRANCH || BRANCH.includes("release-");
18+
let tag = "";
19+
20+
const { version: OLD_VERSION, name } = require("../lib/package.json");
21+
if (!isLatestRelease) {
22+
/** pre-release branch name should be the tag name (e.g., beta, canery, etc.) or tag name followed by a '-' and version or other specifiers. e.g. beta-2.0 */
23+
tag = BRANCH.split("-")[0];
24+
try {
25+
execSync(`pnpm changeset pre enter ${tag}`);
26+
} catch (e) {
27+
console.log({ e });
28+
}
29+
}
30+
/** Apply changeset */
31+
execSync("pnpm changeset version");
32+
33+
// exit pre mode -- to avoid collision with full releases
34+
try {
35+
execSync("pnpm changeset pre exit");
36+
} catch {
37+
// empty
38+
}
39+
40+
/** not requiring as require is cached by npm/node */
41+
const NEW_VERSION = JSON.parse(
42+
fs.readFileSync(path.resolve(__dirname, "..", "lib", "package.json")),
43+
).version;
44+
45+
const [newMajor, newMinor] = NEW_VERSION.split(".");
46+
const [oldMajor, oldMinor] = OLD_VERSION.split(".");
47+
48+
const isNotPatch = newMajor !== oldMajor || newMinor !== oldMinor;
49+
50+
const pushCmd = `git add . && git commit -m "Apply changesets and update CHANGELOG" && git push origin ${BRANCH}`;
51+
52+
if (isNotPatch && BRANCH === DEFAULT_BRANCH) {
53+
try {
54+
execSync(pushCmd);
55+
} catch (e) {
56+
console.log({ e });
57+
}
58+
require("./update-security-md")(`${newMajor}.${newMinor}`, `${oldMajor}.${oldMinor}`);
59+
/** Create new release branch for every Major or Minor release */
60+
const releaseBranch = `release-${newMajor}.${newMinor}`;
61+
execSync(`git checkout -b ${releaseBranch} && git push origin ${releaseBranch}`);
62+
} else if (isLatestRelease) {
63+
/** New version must be valid SEMVER version. No pre-release (beta/alpha etc.) */
64+
if (!/^\d+\.\d+.\d+$/.test(NEW_VERSION)) throw new Error("Invalid version");
65+
66+
if (isNotPatch)
67+
throw new Error("Major or Minor changes can be published only from the default branch.");
68+
69+
// Push changes back to the repo
70+
try {
71+
execSync(pushCmd);
72+
} catch (e) {
73+
console.log({ e });
74+
}
75+
} else {
76+
try {
77+
execSync(pushCmd);
78+
} catch (e) {
79+
console.log({ e });
80+
}
81+
}
82+
83+
const { visibility } = JSON.parse(execSync("gh repo view --json visibility").toString());
84+
const provenance = visibility.toLowerCase() === "public" ? "--provenance" : "";
85+
86+
let LATEST_VERSION = "0.0.-1";
87+
88+
try {
89+
LATEST_VERSION = execSync(`npm view ${name} version`).toString().trim() ?? "0.0.-1";
90+
} catch {
91+
// empty
92+
}
93+
94+
const latest = LATEST_VERSION.split(".").map(parseInt);
95+
const current = NEW_VERSION.split(".").map(parseInt);
96+
97+
let isLatest = false;
98+
99+
if (latest[0] < current[0]) {
100+
isLatest = true;
101+
} else if (latest[0] === current[0] && latest[1] < current[1]) {
102+
isLatest = true;
103+
} else if (latest[0] === current[0] && latest[1] === current[1] && latest[2] < current[2]) {
104+
isLatest = true;
105+
}
106+
107+
const reTag = isLatest ? "" : ` && npm dist-tag add ${name}@${LATEST_VERSION} latest`;
108+
/** Create release */
109+
const publishCmd = `cd lib && pnpm build && npm publish ${provenance} --access public${tag && ` --tag ${tag}`}`;
110+
execSync(publishCmd + reTag);
111+
112+
/** Create GitHub release */
113+
execSync(
114+
`gh release create ${NEW_VERSION} --generate-notes${isLatestRelease ? " --latest" : ""} -n "$(sed '1,/^## /d;/^## /,$d' lib/CHANGELOG.md)" --title "Release v${NEW_VERSION}"`,
115+
);
116+
117+
try {
118+
// Publish canonical packages
119+
execSync("node scripts/publish-canonical.js");
120+
} catch {
121+
console.error("Failed to publish canonical packages");
122+
}
123+

0 commit comments

Comments
 (0)