diff --git a/PUBLISHING.md b/PUBLISHING.md new file mode 100644 index 0000000000..5f2b7f0302 --- /dev/null +++ b/PUBLISHING.md @@ -0,0 +1,15 @@ +# Stable Version + +Run + +``` +npm version major +npm version minor +npm version patch +``` + +commit and merge into `main`. The CI will publish the new version to npm automatically if `package.json` version is higher than the one in the registry. + +# Next Version + +Every `main` branch commit gets automatically published to npm with `next` tag and `0.0.0-next-df279c1e7` version where `df279c1e7` is the short commit hash. diff --git a/package.json b/package.json index 048ef86006..697d11e34e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "baseui", - "version": "13.0.0", + "version": "14.0.0", "description": "A React Component library implementing the Base design language", "keywords": [ "react", diff --git a/publish/publish-next.js b/publish/publish-next.js index 386df4cb10..2f7c88ffcf 100755 --- a/publish/publish-next.js +++ b/publish/publish-next.js @@ -2,19 +2,46 @@ const { execSync } = require("child_process"); const fs = require("fs"); +const pkgJson = JSON.parse(fs.readFileSync("./package.json")); -const shortHash = execSync("git rev-parse --short HEAD").toString().trim(); -const version = `0.0.0-next-${shortHash}`; +const publishNext = () => { + const shortHash = execSync("git rev-parse --short HEAD").toString().trim(); + const version = `0.0.0-next-${shortHash}`; + console.log(`Publishing baseui ${version}`); + pkgJson.version = version; + delete pkgJson.scripts.prepare; + fs.writeFileSync("./dist/package.json", JSON.stringify(pkgJson, null, 2)); -console.log(`Publishing baseui ${version}`); -const pkgJson = JSON.parse(fs.readFileSync("./package.json")); -pkgJson.version = version; -delete pkgJson.scripts.prepare; -fs.writeFileSync("./dist/package.json", JSON.stringify(pkgJson, null, 2)); + try { + execSync("cd dist && npm publish --tag next"); + } catch (e) { + console.log(e); + console.log("Next publish failed."); + } +}; -try { - execSync("cd dist && npm publish --tag next"); -} catch (e) { - console.log(e); - console.log("Publish failed."); -} +fetch(`https://registry.npmjs.org/baseui`) + .then((response) => response.json()) + .then((data) => { + const latest = data["dist-tags"].latest; + console.log(`Latest version of baseui is: ${latest}`); + if (latest !== pkgJson.version) { + console.log( + `The package.json version ${pkgJson.version} is different from the one that's published ${latest}.` + ); + console.log(`Publishing baseui@${pkgJson.version}...`); + delete pkgJson.scripts.prepare; + fs.writeFileSync("./dist/package.json", JSON.stringify(pkgJson, null, 2)); + try { + execSync("cd dist && npm publish"); + } catch (e) { + console.log(e); + console.log("Stable publish failed."); + } + } + publishNext(); + }) + .catch((error) => { + console.error("Error when fetching latest baseui version:", error); + publishNext(); + });