update readme

This commit is contained in:
Alexander Wang 2025-03-21 11:53:16 -06:00
parent 05f4923d70
commit b46fbb6270
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
5 changed files with 71 additions and 9 deletions

View file

@ -51,7 +51,7 @@ jobs:
- name: Publish nightly version to NPM
if: steps.check_changes.outputs.has_changes == 'true'
run: COLOR=1 ./make.sh --version=nightly js
run: COLOR=1 NPM_VERSION=nightly ./make.sh js
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets._GITHUB_TOKEN }}

View file

@ -9,6 +9,8 @@
[![ci](https://github.com/terrastruct/d2/actions/workflows/ci.yml/badge.svg)](https://github.com/terrastruct/d2/actions/workflows/ci.yml)
[![daily](https://github.com/terrastruct/d2/actions/workflows/daily.yml/badge.svg)](https://github.com/terrastruct/d2/actions/workflows/daily.yml)
[![release](https://img.shields.io/github/v/release/terrastruct/d2)](https://github.com/terrastruct/d2/releases)
[![changelog](https://img.shields.io/badge/changelog-read-blue)](./CHANGELOG.md)
[![npm version](https://img.shields.io/npm/v/@terrastruct/d2)](https://www.npmjs.com/package/@terrastruct/d2)
[![discord](https://img.shields.io/discord/1039184639652265985?label=discord)](https://discord.gg/NF6X8K4eDq)
[![twitter](https://img.shields.io/twitter/follow/terrastruct?style=social)](https://twitter.com/terrastruct)
[![license](https://img.shields.io/github/license/terrastruct/d2?color=9cf)](./LICENSE.txt)

39
ci/release/release-js.sh Executable file
View file

@ -0,0 +1,39 @@
#!/bin/sh
set -eu
cd -- "$(dirname "$0")/../.."
. "./ci/sub/lib.sh"
VERSION=""
help() {
cat <<EOF
usage: $0 --version=<version>
Publishes the d2.js to NPM.
Flags:
--version Version to publish (e.g., "0.1.2" or "nightly"). Note this is the js version, not related to the d2 version. A non-nightly version will publish to latest.
EOF
}
for arg in "$@"; do
case "$arg" in
--help|-h)
help
exit 0
;;
--version=*)
VERSION="${arg#*=}"
;;
esac
done
if [ -z "$VERSION" ]; then
flag_errusage "--version is required"
fi
FGCOLOR=6 header "Publishing JavaScript package to NPM (version: $VERSION)"
sh_c "NPM_VERSION=$VERSION ./make.sh js"
FGCOLOR=2 header 'NPM publish completed'

View file

@ -1,5 +1,26 @@
#!/bin/sh
set -eu
cd -- "$(dirname "$0")/../.."
. "./ci/sub/lib.sh"
NPM_VERSION=""
for arg in "$@"; do
case "$arg" in
--npm-version=*)
NPM_VERSION="${arg#*=}"
;;
esac
done
if [ -z "$NPM_VERSION" ]; then
flag_errusage "--npm-version is required"
fi
./ci/sub/release/release.sh "$@"
if [ -n "$NPM_VERSION" ]; then
./ci/release/release-js.sh --version="$NPM_VERSION"
fi

View file

@ -18,11 +18,11 @@ fi
cd d2js/js
sh_c bun build.js
if [ -n "$VERSION" ]; then
if [ -n "$NPM_VERSION" ]; then
cp package.json package.json.bak
trap 'rm -f .npmrc; mv package.json.bak package.json' EXIT
if [ "$VERSION" = "nightly" ]; then
if [ "$NPM_VERSION" = "nightly" ]; then
echo "Publishing nightly version to npm..."
DATE_TAG=$(date +'%Y%m%d')
@ -33,8 +33,8 @@ if [ -n "$VERSION" ]; then
echo "Updating package version to ${PUBLISH_VERSION}"
else
echo "Publishing official version ${VERSION} to npm..."
PUBLISH_VERSION="$VERSION"
echo "Publishing official version ${NPM_VERSION} to npm..."
PUBLISH_VERSION="$NPM_VERSION"
NPM_TAG="latest"
echo "Setting package version to ${PUBLISH_VERSION}"
@ -52,14 +52,14 @@ if [ -n "$VERSION" ]; then
echo "Successfully published @terrastruct/d2@${PUBLISH_VERSION} to npm with tag '${NPM_TAG}'"
# For official releases, bump the patch version
if [ "$VERSION" != "nightly" ]; then
if [ "$NPM_VERSION" != "nightly" ]; then
# Restore original package.json first
mv package.json.bak package.json
echo "Bumping version to ${VERSION}"
npm version "${VERSION}" --no-git-tag-version
echo "Bumping version to ${NPM_VERSION}"
npm version "${NPM_VERSION}" --no-git-tag-version
git add package.json
git commit -m "Bump version to ${VERSION} [skip ci]"
git commit -m "Bump version to ${NPM_VERSION} [skip ci]"
# Cancel the trap since we manually restored and don't want it to execute on exit
trap - EXIT