@nikcli-ai/script 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -0
- package/src/index.ts +64 -0
- package/sst-env.d.ts +10 -0
- package/tsconfig.json +8 -0
package/package.json
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { $, semver } from "bun"
|
|
2
|
+
import path from "path"
|
|
3
|
+
|
|
4
|
+
const rootPkgPath = path.resolve(import.meta.dir, "../../../package.json")
|
|
5
|
+
const rootPkg = await Bun.file(rootPkgPath).json()
|
|
6
|
+
const expectedBunVersion = rootPkg.packageManager?.split("@")[1]
|
|
7
|
+
const pkgPath = path.resolve(import.meta.dir, "../../nikcli/package.json")
|
|
8
|
+
const pkg = await Bun.file(pkgPath).json()
|
|
9
|
+
const pkgver = pkg.version
|
|
10
|
+
|
|
11
|
+
if (!expectedBunVersion) {
|
|
12
|
+
throw new Error("packageManager field not found in root package.json")
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!pkgver) {
|
|
16
|
+
throw new Error("version field not found in packages/nikcli/package.json")
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// relax version requirement
|
|
20
|
+
const expectedBunVersionRange = `^${expectedBunVersion}`
|
|
21
|
+
|
|
22
|
+
if (!semver.satisfies(process.versions.bun, expectedBunVersionRange)) {
|
|
23
|
+
throw new Error(`This script requires bun@${expectedBunVersionRange}, but you are using bun@${process.versions.bun}`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const env = {
|
|
27
|
+
NIKCLI_CHANNEL: process.env["NIKCLI_CHANNEL"],
|
|
28
|
+
NIKCLI_BUMP: process.env["NIKCLI_BUMP"],
|
|
29
|
+
NIKCLI_VERSION: process.env["NIKCLI_VERSION"],
|
|
30
|
+
}
|
|
31
|
+
const CHANNEL = await (async () => {
|
|
32
|
+
if (env.NIKCLI_CHANNEL) return env.NIKCLI_CHANNEL
|
|
33
|
+
if (env.NIKCLI_BUMP) return "latest"
|
|
34
|
+
if (env.NIKCLI_VERSION && !env.NIKCLI_VERSION.startsWith("0.0.0-")) return "latest"
|
|
35
|
+
return await $`git branch --show-current`.text().then((x) => x.trim())
|
|
36
|
+
})()
|
|
37
|
+
const IS_PREVIEW = CHANNEL !== "latest"
|
|
38
|
+
|
|
39
|
+
const VERSION = await (async () => {
|
|
40
|
+
if (env.NIKCLI_VERSION) return env.NIKCLI_VERSION
|
|
41
|
+
if (IS_PREVIEW) return pkgver
|
|
42
|
+
const res = await fetch("https://registry.npmjs.org/nikcli-ai/latest")
|
|
43
|
+
const version = res.ok
|
|
44
|
+
? await res.json().then((data: any) => data.version)
|
|
45
|
+
: pkgver
|
|
46
|
+
const [major, minor, patch] = version.split(".").map((x: string) => Number(x) || 0)
|
|
47
|
+
const t = env.NIKCLI_BUMP?.toLowerCase()
|
|
48
|
+
if (t === "major") return `${major + 1}.0.0`
|
|
49
|
+
if (t === "minor") return `${major}.${minor + 1}.0`
|
|
50
|
+
return `${major}.${minor}.${patch + 1}`
|
|
51
|
+
})()
|
|
52
|
+
|
|
53
|
+
export const Script = {
|
|
54
|
+
get channel() {
|
|
55
|
+
return CHANNEL
|
|
56
|
+
},
|
|
57
|
+
get version() {
|
|
58
|
+
return VERSION
|
|
59
|
+
},
|
|
60
|
+
get preview() {
|
|
61
|
+
return IS_PREVIEW
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
console.log(`nikcli script`, JSON.stringify(Script, null, 2))
|
package/sst-env.d.ts
ADDED