forked from SocketDev/socket-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepublish-socketbin.mts
More file actions
75 lines (65 loc) · 2.17 KB
/
Copy pathprepublish-socketbin.mts
File metadata and controls
75 lines (65 loc) · 2.17 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
/**
* @fileoverview Prepares @socketbin/* binary packages for publishing.
* Updates package.json with version and buildMethod, removes private field.
* Binary is already in place from SEA build (following biome convention).
*/
import { existsSync } from 'node:fs'
import { parseArgs } from '@socketsecurity/lib/argv/parse'
import { getDefaultLogger } from '@socketsecurity/lib/logger'
import {
getSocketbinBinaryPath,
getSocketbinPackageDir,
} from 'package-builder/scripts/paths.mts'
import { preparePackageForPublish } from 'package-builder/scripts/utils/prepare-package.mts'
const logger = getDefaultLogger()
const { values } = parseArgs({
options: {
arch: { type: 'string' },
dev: { type: 'boolean' },
libc: { type: 'string' },
method: { default: 'sea', type: 'string' },
platform: { type: 'string' },
prod: { type: 'boolean' },
version: { type: 'string' },
},
})
const {
arch,
libc,
method: buildMethod,
platform,
version: providedVersion,
} = values
if (!platform || !arch) {
logger.error(
'Usage: prepublish-socketbin.mts --platform=darwin --arch=arm64 --version=2.1.0 [--method=sea]',
)
process.exitCode = 1
} else if (!providedVersion) {
logger.error('--version is required')
process.exitCode = 1
} else {
// Get package directory from centralized paths.
const packageDir = getSocketbinPackageDir(platform, arch, libc)
// Verify binary exists (should be built by SEA build).
const binaryPath = getSocketbinBinaryPath(platform, arch, libc)
if (!existsSync(binaryPath)) {
logger.error(`Binary not found at ${binaryPath}`)
logger.error('Run SEA build first: pnpm run build:sea')
process.exitCode = 1
} else {
const version = providedVersion.replace(/^v/, '')
// Prepare package for publishing.
const { name } = preparePackageForPublish(packageDir, {
buildMethod,
version,
})
logger.log(` Version: ${version}`)
logger.log(` Build method: ${buildMethod}`)
logger.log(` Binary: ${binaryPath}`)
logger.log(`\nPackage ready for publishing at: ${packageDir}`)
logger.log(
`\nTo publish:\n cd ${packageDir}\n npm publish --provenance --access public`,
)
}
}