Skip to content

Commit

Permalink
simplify release script
Browse files Browse the repository at this point in the history
  • Loading branch information
uenoB committed Jul 22, 2024
1 parent cceef2d commit 9a7c3da
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"typescript": "^5.5.3",
"typescript-eslint": "^7.16.1",
"vite": "^5.3.4",
"vitest": "^2.0.3",
"yaml": "^2.4.5"
"vitest": "^2.0.3"
}
}
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion release/git.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as childProcess from 'node:child_process'

export const gitLsFiles = files => {
export const gitLsFiles = (...files) => {
const r = childProcess.spawnSync('git', ['ls-files', '-z', ...files])
if (r.error != null) throw r.error
const lines = r.stdout.toString('utf8')
Expand Down
28 changes: 13 additions & 15 deletions release/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import * as fs from 'node:fs'
import * as path from 'node:path'
import * as url from 'node:url'
import * as YAML from 'yaml'
import semanticRelease from 'semantic-release'
import * as commitAnalyzer from '@semantic-release/commit-analyzer'
import * as notesGenerator from '@semantic-release/release-notes-generator'
Expand All @@ -16,11 +13,12 @@ import { packages } from './package-list.js'
const rootDir = url.fileURLToPath(new URL('..', import.meta.url))
process.chdir(rootDir)

const packageJsonGlobList = YAML.parse(
fs.readFileSync('pnpm-workspace.yaml').toString('utf8')
).packages.map(i => path.join(i, 'package.json'))

const packageJsonList = gitLsFiles(packageJsonGlobList)
const packageJsonList = {
packages: gitLsFiles('packages/*/package.json'),
example: gitLsFiles('example/*/package.json'),
template: gitLsFiles('template/*/package.json')
}
packageJsonList.all = Object.values(packageJsonList).flat()

// iterate for each directory under packages.
for (const pkg of packages) {
Expand All @@ -36,25 +34,25 @@ for (const pkg of packages) {
hookPlugin(npm, { ...pkg, name: null }),
[
hookPlugin(updateDependencies, pkg),
{ ...pkg, packageJsonList, major: false }
{ ...pkg, packageJsonList: packageJsonList.all }
],
[
hookPlugin(git, { ...pkg, cwd: rootDir, name: null }),
{
assets: packageJsonList,
assets: [
...packageJsonList.example,
...packageJsonList.template,
`packages/${pkg.name}/package.json`
],
message: `chore(release): ${pkg.name} <%=
nextRelease.version %> [skip ci]\n\n<%=
nextRelease.notes %>`
}
],
[
hookPlugin(updateDependencies, pkg),
{ ...pkg, packageJsonList, major: true }
],
[
hookPlugin(git, { ...pkg, cwd: rootDir, name: null }),
{
assets: packageJsonList,
assets: packageJsonList.packages,
message: `fix: update ${pkg.name} to version <%=
nextRelease.version %>\n\n[skip ci]`
}
Expand Down
1 change: 0 additions & 1 deletion release/update-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const prepare = (pluginConfig, { nextRelease }) => {
// nothing to do if this is a prerelease.
if (nextRelease.channel != null) return
if (nextRelease.type.startsWith('pre')) return
if ((nextRelease.type === 'major') !== (pluginConfig.major === true)) return

const packageJsonList = pluginConfig.packageJsonList
const packageName = pluginConfig.json.name
Expand Down

0 comments on commit 9a7c3da

Please sign in to comment.