Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
393ad86
tests(next): reuse existing tests but with different imports
dragidavid Jan 21, 2025
3a27a10
build(next): Simplify test setup (#112)
thien-remote Jan 22, 2025
3e2dfe8
chore: apply changes based on review
dragidavid Jan 22, 2025
da31ee7
build(next): add release script based on existing ones
dragidavid Jan 22, 2025
5cc66de
build(next): add release:next scripts
dragidavid Jan 22, 2025
17e6257
chore: make changes based on review
dragidavid Jan 23, 2025
b33dcd7
build(next): adjust release script
dragidavid Jan 23, 2025
d14f2f0
Release next 1.0.0-alpha.1
dragidavid Jan 23, 2025
5b659cb
build(next): change release script
dragidavid Jan 24, 2025
d8968ff
build(next): add new scripts
dragidavid Jan 24, 2025
932c400
build(next): do not update package.json with dev versions
dragidavid Jan 24, 2025
00ad987
build(next): adjust script to always use the current version
dragidavid Jan 24, 2025
e3bf095
Release v1-beta 1.0.0-beta.1
dragidavid Jan 24, 2025
f90466c
build(next): add `files` to package.json
dragidavid Jan 24, 2025
f90b799
build(next): correct main entry
dragidavid Jan 24, 2025
65a62c3
Release v1-beta 1.0.0-beta.2
dragidavid Jan 24, 2025
4e653d1
build(next): release rules
dragidavid Jan 31, 2025
a0bdf45
build(next): simplify `bumpVersion`
dragidavid Jan 31, 2025
00e467a
build(next): generate changelog for beta releases
dragidavid Jan 31, 2025
40a045f
fix: versioning bug
dragidavid Jan 31, 2025
9259d8d
build(next): check dev version restriction
dragidavid Jan 31, 2025
d11dc67
build(next): correcting version check
dragidavid Jan 31, 2025
cad063d
chore: reset version
dragidavid Jan 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ jobs:
run: npm run lint
- run: npm run prettier:check
- run: npm run check:pr-version
- run: npm run check:pr-next-version
16 changes: 12 additions & 4 deletions next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remoteoss/json-schema-form",
"version": "1.0.0-alpha.1",
"version": "1.0.0-beta.0",
"packageManager": "[email protected]",
"description": "WIP V2 – Headless UI form powered by JSON Schemas",
"author": "Remote.com <[email protected]> (https://remote.com/)",
Expand All @@ -16,16 +16,23 @@
"json-schema",
"form"
],
"main": "index.js",
"main": "dist/index.mjs",
"module": "dist/index.mjs",
"files": [
"README.md",
"dist"
],
"engines": {
"node": "22.13.1"
"node": ">=18.14.0"
},
"scripts": {
"build": "tsup",
"test": "jest",
"test:watch": "jest --watchAll",
"test:file": "jest --runTestsByPath",
"lint": "eslint --max-warnings 0 .",
"build": "tsup"
"release:dev": "cd .. && npm run release:v1:dev",
"release:beta": "cd .. && npm run release:v1:beta"
},
"devDependencies": {
"@antfu/eslint-config": "^3.14.0",
Expand All @@ -35,6 +42,7 @@
"@jest/globals": "^29.7.0",
"babel-jest": "^29.7.0",
"eslint": "^9.18.0",
"generate-changelog": "^1.8.0",
"jest": "^29.7.0",
"json-schema-typed": "^8.0.1",
"tsup": "^8.3.5",
Expand Down
28 changes: 28 additions & 0 deletions next/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@
"format:prettier": "prettier --write \"src/**/*.{js,ts}\"",
"prettier:check": "prettier --check \"src/**/*.{js,ts}\"",
"check:pr-version": "node scripts/pr_dev_version",
"check:pr-next-version": "node scripts/pr_next_dev_version",
"release:local": "node scripts/release_local",
"release:dev:patch": "node scripts/release_dev patch",
"release:dev:minor": "node scripts/release_dev minor",
"release:main:patch": "node scripts/release_main patch",
"release:main:minor": "node scripts/release_main minor",
"release:v1:dev": "node scripts/release_v1 dev",
"release:v1:beta": "node scripts/release_v1 beta",
"version_as_main": "node scripts/version_as_main.js",
"psrepublishOnly": "if [[ ! $PWD =~ scripts$ ]]; then npm run publish:nopublish; fi",
"psublish:nopublish": "echo 'Use `npm release:*` script instead && exit 1"
Expand Down
29 changes: 29 additions & 0 deletions scripts/pr_next_dev_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const fs = require('fs');
const path = require('path');

function init() {
const packageJson = fs.readFileSync(path.resolve(__dirname, '../next/package.json'), 'utf8');
const { version } = JSON.parse(packageJson);

if (version.includes('-dev')) {
console.log(
`🟠 This PR cannot be merged because the next/package.json version ${version} contains "-dev".` +
'\n The version in next/package.json should be a beta version (e.g., 1.0.0-beta.0).'
);
process.exit(1);
}

if (!version.includes('-beta.')) {
console.log(
`🟠 This PR cannot be merged because the next/package.json version ${version} is not a beta version.` +
'\n The version in next/package.json should be in format X.X.X-beta.Y (e.g., 1.0.0-beta.0).'
);
process.exit(1);
}

console.log(
`The package version in next/package.json is ${version} and seems valid. Continuing...`
);
}

init();
178 changes: 178 additions & 0 deletions scripts/release_v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
const path = require('path');

const semver = require('semver');

const {
askForConfirmation,
askForText,
checkGitStatus,
checkNpmAuth,
runExec,
revertCommit,
revertChanges,
getDateYYYYMMDDHHMMSS,
} = require('./release.helpers');

const packageJsonPath = path.resolve(__dirname, '../next/package.json');
const packageJson = require(packageJsonPath);

async function checkGitBranchAndStatus() {
const releaseType = process.argv[2];
console.log(`Checking your branch for ${releaseType} release...`);

const resultBranch = await runExec('git branch --show-current', {
silent: true,
});
const branchName = resultBranch.stdout.toString().trim();

if (releaseType === 'dev') {
// For dev releases, cannot be on main branch
if (branchName === 'main') {
console.error(`🟠 You are at "main". Dev versions cannot be released from main branch.`);
process.exit(1);
}
} else if (releaseType === 'beta') {
// For beta releases, must be on main branch and up to date
if (branchName !== 'main') {
console.error(
`🟠 You are at "${branchName}" instead of "main" branch. Beta versions must be released from main.`
);
process.exit(1);
}

// Check if local main is up to date
await runExec('git remote update', { silent: true });
const resultStatus = await runExec('git status -uno', { silent: true });
const mainStatus = resultStatus.stdout.toString().trim();

if (!mainStatus.includes("Your branch is up to date with 'origin/main'.")) {
console.error(`🟠 Please make sure your branch is up to date with the git repo.`);
process.exit(1);
}
}

await checkGitStatus();
}

async function getNewVersion() {
const releaseType = process.argv[2];
if (!['dev', 'beta'].includes(releaseType)) {
console.error('🟠 Invalid release type. Use dev or beta');
process.exit(1);
}

const currentVersion = packageJson.version;

if (releaseType === 'dev') {
const timestamp = getDateYYYYMMDDHHMMSS();
console.log('Creating new dev version...');
return `1.0.0-dev.${timestamp}`;
}

// For beta releases
console.log('Creating new beta version...');
if (currentVersion.includes('-beta.')) {
return semver.inc(currentVersion, 'prerelease', 'beta');
}

console.error(
`🟠 Cannot create beta version: Current version "${currentVersion}" is not a beta version.\n` +
' The package.json version should be in the format "1.0.0-beta.X"'
);
process.exit(1);
}

async function bumpVersion({ newVersion }) {
const cmd = `cd next && npm version --no-git-tag-version ${newVersion}`;
await runExec(cmd);
}

async function build() {
console.log('Building next version...');
const cmd = 'cd next && npm run build';
await runExec(cmd);
}

async function updateChangelog() {
console.log('Updating changelog...');
const cmd = 'cd next && npx generate-changelog';
await runExec(cmd);
}

async function gitCommit({ newVersion, releaseType }) {
console.log('Committing published version...');
const prefix = `v1-${releaseType}`;

let cmd;
if (releaseType === 'beta') {
// For beta, we commit package.json changes and changelog
cmd = `git add next/package.json next/CHANGELOG.md && git commit -m "Release ${prefix} ${newVersion}" && git tag ${prefix}-${newVersion} && git push && git push origin --tags`;
} else {
// For dev, we only create a tag
cmd = `git tag ${prefix}-${newVersion} && git push origin --tags`;
}

await runExec(cmd);
}

async function publish({ newVersion, releaseType, otp }) {
console.log('Publishing new version...');
const npmTag = `v1-${releaseType}`;
const originalVersion = packageJson.version;

try {
// Publish with the dev/beta version
const cmd = `cd next && npm publish --access=public --tag=${npmTag} --otp=${otp}`;
await runExec(cmd);

// For dev releases, revert package.json back to original version
if (releaseType === 'dev') {
const revertCmd = `cd next && npm version --no-git-tag-version ${originalVersion}`;
await runExec(revertCmd);
}

console.log(`🎉 ${npmTag} version ${newVersion} published!`);
console.log(`Install with: npm i @remoteoss/json-schema-form@${npmTag}`);
} catch {
console.log('🚨 Publish failed! Perhaps the OTP is wrong.');
await revertCommit({ newVersion });
}
}

async function init() {
const releaseType = process.argv[2];
await checkGitBranchAndStatus();
const newVersion = await getNewVersion();

console.log(':: Current version:', packageJson.version);
console.log(`:::::: New version (${releaseType}):`, newVersion);

const answer = await askForConfirmation('Ready to commit and publish it?');

if (answer === 'no') {
process.exit(1);
}

await checkNpmAuth();

await bumpVersion({ newVersion });

// Only update changelog for beta releases
if (releaseType === 'beta') {
await updateChangelog();
const answerChangelog = await askForConfirmation(
'Changelog is updated. You may tweak it as needed. Once ready, press Y to continue.'
);
if (answerChangelog === 'no') {
await revertChanges();
}
}

await build();
const otp = await askForText('🔐 What is the NPM Auth OTP? (Check 1PW) ');

await gitCommit({ newVersion, releaseType });
await publish({ newVersion, releaseType, otp });
}

init();