From e4a1c106941517ec59aeab03358d62e3c4eeaff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B2=B3=E6=99=93=E4=BA=AE?= <2220124666@qq.com> Date: Thu, 1 Aug 2024 18:29:40 +0800 Subject: [PATCH] feat(build): Add release-packages.js script for updating sub-package package.json files during the release stage chore: Update package.json --- package.json | 34 +-------------------- scripts/release-packages.js | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 33 deletions(-) create mode 100644 scripts/release-packages.js diff --git a/package.json b/package.json index 1aa5c94..2f60eda 100644 --- a/package.json +++ b/package.json @@ -2,39 +2,6 @@ "type": "module", "version": "0.0.0", "packageManager": "pnpm@9.4.0", - "description": "_description_", - "author": "Anthony Fu ", - "license": "MIT", - "funding": "https://github.com/sponsors/wuxian-space", - "homepage": "https://github.com/wuxian-space/wuxianx-charts#readme", - "repository": { - "type": "git", - "url": "git+https://github.com/wuxian-space/wuxianx-charts.git" - }, - "bugs": "https://github.com/wuxian-space/wuxianx-charts/issues", - "keywords": [], - "sideEffects": false, - "exports": { - ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" - } - }, - "main": "./dist/index.mjs", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", - "typesVersions": { - "*": { - "*": [ - "./dist/*", - "./dist/index.d.ts" - ] - } - }, - "files": [ - "dist" - ], "scripts": { "prepare": "simple-git-hooks", "prepublishOnly": "nr build", @@ -42,6 +9,7 @@ "test": "vitest", "build": "node scripts/build.js", "release": "bumpp && npm publish", + "release-packages": "node scripts/release-packages.js", "typecheck": "tsc --noEmit && pnpm -r typecheck", "lint": "eslint ." }, diff --git a/scripts/release-packages.js b/scripts/release-packages.js new file mode 100644 index 0000000..3f74e7f --- /dev/null +++ b/scripts/release-packages.js @@ -0,0 +1,60 @@ +import { existsSync, readdirSync, statSync } from 'node:fs' +import { writeFile } from 'node:fs/promises' +import { createRequire } from 'node:module' +import path from 'node:path' + +const require = createRequire(import.meta.url) + +run() + +async function run() { + const pkgs = readdirSync('packages') + + await Promise.all(pkgs.map(updatePkg)) +} + +async function updatePkg(name) { + const isPkg = statSync(`packages/${name}`).isDirectory() && existsSync(`packages/${name}/package.json`) + + if (!isPkg) + return + + const file = path.resolve(`./packages/${name}/package.json`) + + const pkg = require(`../packages/${name}/package.json`) + if (pkg.private) + return false + + const rest = { + ...pkg, + main: `dist/${name}.cjs.js`, + module: `dist/${name}.esm-bundler.js`, + types: `dist/${name}.d.ts`, + files: [ + 'dist', + ], + exports: { + '.': { + types: `./dist/${name}.d.ts`, + node: `./dist/${name}.cjs.js`, + module: `./dist/${name}.esm-bundler.js`, + import: `./dist/${name}.esm-bundler.js`, + require: `./dist/${name}.cjs.js`, + }, + './*': './*', + }, + author: '岳晓亮 ', + license: 'MIT', + homepage: 'https://github.com/wuxian-space/wuxianx-charts#readme', + repository: { + type: 'git', + url: 'git+https://github.com/wuxian-space/wuxianx-charts.git', + directory: `packages/${name}`, + }, + bugs: { + url: 'https://github.com/wuxian-space/wuxianx-charts/issues', + }, + } + + await writeFile(file, JSON.stringify(rest, null, 2)) +}