Skip to content

Commit

Permalink
feat(build): Add release-packages.js script for updating sub-package
Browse files Browse the repository at this point in the history
package.json files during the release stage

chore: Update package.json
  • Loading branch information
yuexiaoliang committed Aug 1, 2024
1 parent aff4fef commit e4a1c10
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
34 changes: 1 addition & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,14 @@
"type": "module",
"version": "0.0.0",
"packageManager": "[email protected]",
"description": "_description_",
"author": "Anthony Fu <[email protected]>",
"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",
"docs:dev": "pnpm --filter docs dev",
"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 ."
},
Expand Down
60 changes: 60 additions & 0 deletions scripts/release-packages.js
Original file line number Diff line number Diff line change
@@ -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: '岳晓亮 <https://github.com/yuexiaoliang>',
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))
}

0 comments on commit e4a1c10

Please sign in to comment.