-
Notifications
You must be signed in to change notification settings - Fork 8
/
publish.ts
54 lines (42 loc) · 1.41 KB
/
publish.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable no-console */
import { $, semver } from 'bun'
import { z } from 'zod'
const packagesToConsider = [
'packages/eslint-config',
'packages/vue-use-tippy',
'packages/yoco',
]
const packageJsonSchema = z.object({ name: z.string(), version: z.string() })
const getRemoteVersion = async (name: string): Promise<string | null> => {
try {
return (await $`npm view ${name} version`.text()).trim()
} catch {
return null
}
}
const toPublish: string[] = []
for (const path of packagesToConsider) {
const { name, version } = packageJsonSchema.parse(
await Bun.file(`./${path}/package.json`).json(),
)
const remoteVersion = await getRemoteVersion(name)
console.info(
`${path}: found package “${name}@${version}”, remote is ${remoteVersion ?? 'LIKELY UNPUBLISHED'}`,
)
const shouldPublish =
remoteVersion === null || semver.order(version, remoteVersion) === 1
if (!shouldPublish) {
console.info(`${path}: already up-to-date, skipping`)
continue
}
console.info(`${path}: scheduled for publishing`)
toPublish.push(name)
}
if (toPublish.length === 0) {
console.warn(`nothing to publish, exiting.`)
process.exit(0)
}
console.info(`attempting to publish ${toPublish.join(', ')}`)
// eslint-disable-next-line sonarjs/no-nested-template-literals
await $`yarn run turbo run publish-package --continue ${toPublish.map((packageName) => `--filter=${packageName}`).join(' ')}`
/* eslint-enable no-console */