Skip to content

Commit bb7fdfd

Browse files
authored
Merge pull request #262 from alibaba/feat/rich_message
Add rich React message interpolation and TypeScript build for react-intl-universal
2 parents 83b465c + ca92772 commit bb7fdfd

90 files changed

Lines changed: 28852 additions & 6830 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Deploy Next.js example to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-22.04
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 24
26+
cache: npm
27+
cache-dependency-path: |
28+
packages/react-intl-universal/package-lock.json
29+
packages/react-intl-universal/examples/nextjs-example/package-lock.json
30+
31+
- name: Use npm public registry
32+
run: npm config set registry https://registry.npmjs.org/
33+
34+
- name: Install package dependencies
35+
working-directory: packages/react-intl-universal
36+
run: npm ci
37+
38+
- name: Build react-intl-universal
39+
working-directory: packages/react-intl-universal
40+
run: npm run build
41+
42+
- name: Install example dependencies
43+
working-directory: packages/react-intl-universal/examples/nextjs-example
44+
run: npm ci
45+
46+
- name: Build static example
47+
working-directory: packages/react-intl-universal/examples/nextjs-example
48+
env:
49+
GITHUB_PAGES: true
50+
run: |
51+
npm run build
52+
touch out/.nojekyll
53+
test -d out
54+
find out -maxdepth 2 -type f | head -50
55+
56+
- name: Upload Pages artifact
57+
uses: actions/upload-pages-artifact@v5
58+
with:
59+
name: github-pages
60+
path: packages/react-intl-universal/examples/nextjs-example/out
61+
62+
deploy:
63+
runs-on: ubuntu-22.04
64+
needs: build
65+
environment:
66+
name: github-pages
67+
url: ${{ steps.deployment.outputs.page_url }}
68+
69+
steps:
70+
- name: Deploy to GitHub Pages
71+
id: deployment
72+
uses: actions/deploy-pages@v4
73+
with:
74+
artifact_name: github-pages

.github/workflows/publish.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Publish react-intl-universal
2+
3+
on:
4+
push:
5+
branches:
6+
- beta
7+
- master
8+
9+
permissions:
10+
contents: read
11+
id-token: write
12+
13+
concurrency:
14+
group: npm-publish-${{ github.ref_name }}
15+
cancel-in-progress: false
16+
17+
jobs:
18+
publish:
19+
runs-on: ubuntu-latest
20+
21+
defaults:
22+
run:
23+
working-directory: packages/react-intl-universal
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: 24
33+
registry-url: https://registry.npmjs.org/
34+
cache: npm
35+
cache-dependency-path: packages/react-intl-universal/package-lock.json
36+
37+
- name: Use npm version with trusted publishing support
38+
run: |
39+
npm install --global npm@latest
40+
node --version
41+
npm --version
42+
43+
- name: Install dependencies
44+
run: npm ci
45+
46+
# Release rules:
47+
# - beta branch publishes <package.json version>-beta.N with the npm "beta" dist-tag.
48+
# - master branch publishes package.json version unchanged with the npm "latest" dist-tag.
49+
# Keep package.json version as the stable base version, for example 2.14.0.
50+
- name: Prepare release version
51+
id: release
52+
run: |
53+
set -euo pipefail
54+
55+
PACKAGE_NAME="$(node -p "require('./package.json').name")"
56+
SOURCE_VERSION="$(node -p "require('./package.json').version")"
57+
BRANCH_NAME="${GITHUB_REF_NAME}"
58+
59+
if [[ ! "${SOURCE_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
60+
echo "package.json should keep the stable base version, but it has ${SOURCE_VERSION}."
61+
exit 1
62+
fi
63+
64+
if [[ "${BRANCH_NAME}" == "beta" ]]; then
65+
DIST_TAG="beta"
66+
BASE_VERSION="${SOURCE_VERSION}"
67+
68+
if npm view "${PACKAGE_NAME}@${BASE_VERSION}" version >/dev/null 2>&1; then
69+
echo "${PACKAGE_NAME}@${BASE_VERSION} is already published as a stable version. Bump package.json before publishing a new beta."
70+
exit 1
71+
fi
72+
73+
PUBLISHED_VERSIONS_JSON="$(npm view "${PACKAGE_NAME}" versions --json)"
74+
NEXT_BETA_NUMBER="$(
75+
PUBLISHED_VERSIONS_JSON="${PUBLISHED_VERSIONS_JSON}" BASE_VERSION="${BASE_VERSION}" node <<'NODE'
76+
const versions = JSON.parse(process.env.PUBLISHED_VERSIONS_JSON || '[]');
77+
const baseVersion = process.env.BASE_VERSION;
78+
const escapedBaseVersion = baseVersion.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
79+
const betaPattern = new RegExp(`^${escapedBaseVersion}-beta\\.(\\d+)$`);
80+
let maxBetaNumber = -1;
81+
82+
for (const version of versions) {
83+
const match = betaPattern.exec(version);
84+
if (match) {
85+
maxBetaNumber = Math.max(maxBetaNumber, Number(match[1]));
86+
}
87+
}
88+
89+
process.stdout.write(String(maxBetaNumber + 1));
90+
NODE
91+
)"
92+
PACKAGE_VERSION="${BASE_VERSION}-beta.${NEXT_BETA_NUMBER}"
93+
elif [[ "${BRANCH_NAME}" == "master" ]]; then
94+
DIST_TAG="latest"
95+
PACKAGE_VERSION="${SOURCE_VERSION}"
96+
else
97+
echo "Unsupported release branch: ${BRANCH_NAME}"
98+
exit 1
99+
fi
100+
101+
if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version >/dev/null 2>&1; then
102+
echo "${PACKAGE_NAME}@${PACKAGE_VERSION} already exists on npm."
103+
exit 1
104+
fi
105+
106+
PACKAGE_VERSION="${PACKAGE_VERSION}" node <<'NODE'
107+
const fs = require('fs');
108+
const packagePath = './package.json';
109+
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
110+
pkg.version = process.env.PACKAGE_VERSION;
111+
fs.writeFileSync(packagePath, `${JSON.stringify(pkg, null, 2)}\n`);
112+
NODE
113+
114+
echo "Prepared ${PACKAGE_NAME}@${PACKAGE_VERSION} for ${DIST_TAG} release."
115+
echo "package-name=${PACKAGE_NAME}" >> "${GITHUB_OUTPUT}"
116+
echo "package-version=${PACKAGE_VERSION}" >> "${GITHUB_OUTPUT}"
117+
echo "dist-tag=${DIST_TAG}" >> "${GITHUB_OUTPUT}"
118+
119+
- name: Test
120+
run: npm test -- --runInBand
121+
122+
- name: Build
123+
run: npm run build
124+
125+
- name: Type test
126+
run: npm run test:types
127+
128+
- name: Publish beta package to npm
129+
if: github.ref_name == 'beta'
130+
run: npm publish --tag "${{ steps.release.outputs.dist-tag }}"
131+
132+
- name: Stage publish package to npm
133+
if: github.ref_name == 'master'
134+
run: npm stage publish

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.specify/
2+
.idea
3+
tmp
4+
todo.txt

0 commit comments

Comments
 (0)