Skip to content

Commit 0bd26ef

Browse files
committed
fix(release): publish sdk and plugin packages
1 parent c35834c commit 0bd26ef

5 files changed

Lines changed: 44 additions & 12 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ jobs:
1919
test "v$version" = "$GITHUB_REF_NAME"
2020
- name: Set release version
2121
run: echo "MIAOPAN_CODE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
22+
- name: Build SDK
23+
run: bun ./packages/sdk/js/script/build.ts
24+
env:
25+
MIAOPAN_CODE_CHANNEL: latest
26+
- name: Publish SDK
27+
run: bun ./packages/sdk/js/script/publish.ts
28+
env:
29+
MIAOPAN_CODE_CHANNEL: latest
30+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
31+
- name: Publish plugin
32+
run: bun ./packages/plugin/script/publish.ts
33+
env:
34+
MIAOPAN_CODE_CHANNEL: latest
35+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
2236
- name: Build CLI
2337
run: bun run --cwd packages/miaopan-code build
2438
env:

‎packages/miaopan-code/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://json.schemastore.org/package.json",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"name": "miaopan-code",
55
"type": "module",
66
"license": "MIT",

‎packages/plugin/script/publish.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const language = resolveLanguage(process.env.MIAOPAN_CODE_LANGUAGE)
88

99
const dir = fileURLToPath(new URL("..", import.meta.url))
1010
process.chdir(dir)
11+
const dryRun = process.argv.includes("--dry-run")
1112

1213
async function published(name: string, version: string) {
1314
return (await $`npm view ${name}@${version} version`.nothrow()).exitCode === 0
@@ -18,23 +19,32 @@ const originalText = await Bun.file("package.json").text()
1819
const pkg = JSON.parse(originalText) as {
1920
name: string
2021
version: string
21-
exports: Record<string, string>
22+
exports: Record<string, string | { import: string; types: string }>
23+
dependencies: Record<string, string>
2224
}
23-
if (await published(pkg.name, pkg.version)) {
24-
console.log(t(language, "publish_already_published", { name: pkg.name, version: pkg.version }))
25+
const version = Script.version
26+
if (await published(pkg.name, version)) {
27+
console.log(t(language, "publish_already_published", { name: pkg.name, version }))
2528
} else {
29+
pkg.version = version
30+
pkg.dependencies["@miaopan-code/sdk"] = version
2631
for (const [key, value] of Object.entries(pkg.exports)) {
32+
if (typeof value !== "string") continue
2733
const file = value.replace("./src/", "./dist/").replace(".ts", "")
28-
// @ts-ignore
2934
pkg.exports[key] = {
3035
import: file + ".js",
3136
types: file + ".d.ts",
3237
}
3338
}
3439
await Bun.write("package.json", JSON.stringify(pkg, null, 2))
3540
try {
41+
await $`find . -maxdepth 1 -type f -name '*.tgz' -delete`
3642
await $`bun pm pack`
37-
await $`npm publish *.tgz --tag ${Script.channel} --access public`
43+
if (dryRun) {
44+
await $`npm publish *.tgz --tag ${Script.channel} --access public --dry-run`
45+
} else {
46+
await $`npm publish *.tgz --tag ${Script.channel} --access public`
47+
}
3848
} finally {
3949
await Bun.write("package.json", originalText)
4050
}

‎packages/sdk/js/script/publish.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const language = resolveLanguage(process.env.MIAOPAN_CODE_LANGUAGE)
99

1010
const dir = fileURLToPath(new URL("..", import.meta.url))
1111
process.chdir(dir)
12+
const dryRun = process.argv.includes("--dry-run")
1213

1314
async function published(name: string, version: string) {
1415
return (await $`npm view ${name}@${version} version`.nothrow()).exitCode === 0
@@ -20,6 +21,7 @@ const pkg = JSON.parse(originalText) as {
2021
version: string
2122
exports: Record<string, unknown>
2223
}
24+
const version = Script.version
2325
function transformExports(exports: Record<string, unknown>) {
2426
return Object.fromEntries(
2527
Object.entries(exports).map(([key, value]) => {
@@ -34,14 +36,20 @@ function transformExports(exports: Record<string, unknown>) {
3436
}),
3537
)
3638
}
37-
if (await published(pkg.name, pkg.version)) {
38-
console.log(t(language, "publish_already_published", { name: pkg.name, version: pkg.version }))
39+
if (await published(pkg.name, version)) {
40+
console.log(t(language, "publish_already_published", { name: pkg.name, version }))
3941
} else {
42+
pkg.version = version
4043
pkg.exports = transformExports(pkg.exports)
4144
await Bun.write("package.json", JSON.stringify(pkg, null, 2))
4245
try {
46+
await $`find . -maxdepth 1 -type f -name '*.tgz' -delete`
4347
await $`bun pm pack`
44-
await $`npm publish *.tgz --tag ${Script.channel} --access public`
48+
if (dryRun) {
49+
await $`npm publish *.tgz --tag ${Script.channel} --access public --dry-run`
50+
} else {
51+
await $`npm publish *.tgz --tag ${Script.channel} --access public`
52+
}
4553
} finally {
4654
await Bun.write("package.json", originalText)
4755
}

‎script/publish.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ if (Script.release && !Script.preview) {
3535

3636
await prepareReleaseFiles()
3737

38-
console.log("\n=== cli ===\n")
39-
await $`bun ./packages/miaopan-code/script/publish.ts`
40-
4138
console.log("\n=== sdk ===\n")
4239
await $`bun ./packages/sdk/js/script/publish.ts`
4340

4441
console.log("\n=== plugin ===\n")
4542
await $`bun ./packages/plugin/script/publish.ts`
4643

44+
console.log("\n=== cli ===\n")
45+
await $`bun ./packages/miaopan-code/script/publish.ts`
46+
4747
if (Script.release && !Script.preview) {
4848
await $`git commit -am "release: ${tag}"`
4949
await $`git tag -d ${tag}`.nothrow()

0 commit comments

Comments
 (0)