forked from SocketDev/socket-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.mjs
More file actions
executable file
·86 lines (73 loc) · 2.26 KB
/
Copy pathpublish.mjs
File metadata and controls
executable file
·86 lines (73 loc) · 2.26 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Unified publish script router.
* Routes publish commands to appropriate packages based on --target flag.
*/
import process from 'node:process'
import { WIN32 } from '@socketsecurity/lib/constants/platform'
import { getDefaultLogger } from '@socketsecurity/lib/logger'
import { spawn } from '@socketsecurity/lib/spawn'
const logger = getDefaultLogger()
const TARGET_PACKAGES = {
__proto__: null,
all: './packages/**',
cli: '@socketsecurity/cli',
'cli-sentry': '@socketsecurity/cli-with-sentry',
'darwin-arm64': '@socketbin/cli-darwin-arm64',
'darwin-x64': '@socketbin/cli-darwin-x64',
'linux-arm64': '@socketbin/cli-linux-arm64',
'linux-arm64-musl': '@socketbin/cli-linux-arm64-musl',
'linux-x64': '@socketbin/cli-linux-x64',
'linux-x64-musl': '@socketbin/cli-linux-x64-musl',
node: '@socketbin/node-smol-builder-builder',
sea: '@socketbin/node-sea-builder-builder',
socket: 'socket',
'win32-arm64': '@socketbin/cli-win32-arm64',
'win32-x64': '@socketbin/cli-win32-x64',
}
const args = process.argv.slice(2)
let target = 'cli'
const publishArgs = []
for (let i = 0; i < args.length; i++) {
const arg = args[i]
if (arg === '--target' && i + 1 < args.length) {
target = args[++i]
} else {
publishArgs.push(arg)
}
}
async function main() {
const packageFilter = TARGET_PACKAGES[target]
if (!packageFilter) {
logger.error(`Unknown publish target: ${target}`)
logger.error(
`Available targets: ${Object.keys(TARGET_PACKAGES).join(', ')}`,
)
process.exitCode = 1
return
}
// Special handling for 'all' target.
if (target === 'all') {
logger.log('Publishing all packages...')
logger.log('Note: Packages are published in dependency order by pnpm')
}
const pnpmArgs = ['--filter', packageFilter, 'publish', ...publishArgs]
logger.log(`Publishing ${target}...`)
logger.log(`Command: pnpm ${pnpmArgs.join(' ')}`)
logger.log('')
const result = await spawn('pnpm', pnpmArgs, {
shell: WIN32,
stdio: 'inherit',
})
if (result.code === 0) {
logger.log('')
logger.success(`Successfully published ${target}`)
} else {
logger.log('')
logger.error(`Failed to publish ${target}`)
}
process.exitCode = result.code ?? 1
}
main().catch(e => {
logger.error(e)
process.exitCode = 1
})