tulingcode-script 0.1.0

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,19 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package",
3
+ "name": "tulingcode-script",
4
+ "version": "0.1.0",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "dependencies": {
10
+ "semver": "^7.6.3"
11
+ },
12
+ "devDependencies": {
13
+ "@types/bun": "1.3.11",
14
+ "@types/semver": "^7.5.8"
15
+ },
16
+ "exports": {
17
+ ".": "./src/index.ts"
18
+ }
19
+ }
package/src/index.ts ADDED
@@ -0,0 +1,62 @@
1
+ import { $ } from "bun"
2
+ import semver from "semver"
3
+ import path from "path"
4
+
5
+ const rootPkgPath = path.resolve(import.meta.dir, "../../../package.json")
6
+ const rootPkg = await Bun.file(rootPkgPath).json()
7
+ const expectedBunVersion = rootPkg.packageManager?.split("@")[1]
8
+
9
+ if (!expectedBunVersion) {
10
+ throw new Error("packageManager field not found in root package.json")
11
+ }
12
+
13
+ // relax version requirement
14
+ const expectedBunVersionRange = `^${expectedBunVersion}`
15
+
16
+ if (!semver.satisfies(process.versions.bun, expectedBunVersionRange)) {
17
+ throw new Error(`This script requires bun@${expectedBunVersionRange}, but you are using bun@${process.versions.bun}`)
18
+ }
19
+
20
+ const env = {
21
+ OPENCODE_CHANNEL: process.env["OPENCODE_CHANNEL"],
22
+ OPENCODE_BUMP: process.env["OPENCODE_BUMP"],
23
+ OPENCODE_VERSION: process.env["OPENCODE_VERSION"],
24
+ OPENCODE_RELEASE: process.env["OPENCODE_RELEASE"],
25
+ }
26
+ const CHANNEL = await (async () => {
27
+ if (env.OPENCODE_CHANNEL) return env.OPENCODE_CHANNEL
28
+ if (env.OPENCODE_BUMP) return "latest"
29
+ if (env.OPENCODE_VERSION && !env.OPENCODE_VERSION.startsWith("0.0.0-")) return "latest"
30
+ return await $`git branch --show-current`.text().then((x) => x.trim()) || "latest"
31
+ })()
32
+ const IS_PREVIEW = CHANNEL !== "latest"
33
+
34
+ const VERSION = await (async () => {
35
+ if (env.OPENCODE_VERSION) return env.OPENCODE_VERSION
36
+ if (IS_PREVIEW) return `0.0.0-${CHANNEL}-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
37
+ const version = await Bun.file(path.resolve(import.meta.dir, "../../tulingcode/package.json"))
38
+ .json()
39
+ .then((data: any) => data.version)
40
+ const t = env.OPENCODE_BUMP?.toLowerCase()
41
+ if (!t) return version
42
+ const [major, minor, patch] = version.split(".").map((x: string) => Number(x) || 0)
43
+ if (t === "major") return `${major + 1}.0.0`
44
+ if (t === "minor") return `${major}.${minor + 1}.0`
45
+ return `${major}.${minor}.${patch + 1}`
46
+ })()
47
+
48
+ export const Script = {
49
+ get channel() {
50
+ return CHANNEL
51
+ },
52
+ get version() {
53
+ return VERSION
54
+ },
55
+ get preview() {
56
+ return IS_PREVIEW
57
+ },
58
+ get release(): boolean {
59
+ return !!env.OPENCODE_RELEASE
60
+ },
61
+ }
62
+ console.log(`opencode 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
+ }