@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 ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package",
3
+ "name": "@nikcli-ai/script",
4
+ "license": "MIT",
5
+ "devDependencies": {
6
+ "@types/bun": "1.3.7"
7
+ },
8
+ "exports": {
9
+ ".": "./src/index.ts"
10
+ },
11
+ "version": "0.0.6"
12
+ }
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
@@ -0,0 +1,10 @@
1
+ /* This file is auto-generated by SST. Do not edit. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /* deno-fmt-ignore-file */
5
+ /* biome-ignore-all lint: auto-generated */
6
+
7
+ /// <reference path="../../sst-env.d.ts" />
8
+
9
+ import "sst"
10
+ export {}
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "@tsconfig/bun/tsconfig.json",
4
+ "compilerOptions": {
5
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
6
+ "noUncheckedIndexedAccess": false
7
+ }
8
+ }