@napisani/scute 0.0.1 → 0.0.2

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/dist/scute CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napisani/scute",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "AI-powered shell assistant",
5
5
  "module": "index.ts",
6
6
  "type": "module",
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import { createHash } from "node:crypto";
4
+ import { readFile, writeFile } from "node:fs/promises";
5
+ import { resolve } from "node:path";
6
+
7
+ interface ReleaseAsset {
8
+ id: number;
9
+ name: string;
10
+ browser_download_url: string;
11
+ }
12
+
13
+ interface ReleaseInfo {
14
+ tag_name: string;
15
+ assets: ReleaseAsset[];
16
+ }
17
+
18
+ const REPO = "napisani/scute";
19
+ const FORMULA_PATH = resolve(import.meta.dir, "..", "Formula", "scute.rb");
20
+
21
+ async function main() {
22
+ const [, , versionArg] = process.argv;
23
+ if (!versionArg) {
24
+ console.error("Usage: bun scripts/update-brew.ts <version>|latest");
25
+ process.exit(1);
26
+ }
27
+
28
+ const release = await fetchRelease(versionArg);
29
+ const version = release.tag_name.replace(/^v/, "");
30
+ const macAsset = findAsset(release.assets, "macos");
31
+ const linuxAsset = findAsset(release.assets, "linux");
32
+
33
+ if (!macAsset || !linuxAsset) {
34
+ const missing = [!macAsset ? "macos" : null, !linuxAsset ? "linux" : null]
35
+ .filter(Boolean)
36
+ .join(", ");
37
+ throw new Error(`Missing release assets for: ${missing}`);
38
+ }
39
+
40
+ console.log(`Downloading assets for ${release.tag_name}…`);
41
+ const [macSha, linuxSha] = await Promise.all([
42
+ computeSha256(macAsset),
43
+ computeSha256(linuxAsset),
44
+ ]);
45
+
46
+ await updateFormula({
47
+ version,
48
+ macSha,
49
+ linuxSha,
50
+ });
51
+ console.log(
52
+ `Updated Formula/scute.rb -> version ${version}, macOS sha ${macSha}, linux sha ${linuxSha}`,
53
+ );
54
+ }
55
+
56
+ async function fetchRelease(versionArg: string): Promise<ReleaseInfo> {
57
+ const endpoint =
58
+ versionArg === "latest"
59
+ ? `https://api.github.com/repos/${REPO}/releases/latest`
60
+ : `https://api.github.com/repos/${REPO}/releases/tags/${ensureTag(versionArg)}`;
61
+ const response = await fetch(endpoint, {
62
+ headers: {
63
+ Accept: "application/vnd.github+json",
64
+ "User-Agent": "scute-update-brew",
65
+ },
66
+ });
67
+ if (!response.ok) {
68
+ throw new Error(
69
+ `Failed to fetch release info (${response.status} ${response.statusText})`,
70
+ );
71
+ }
72
+ return (await response.json()) as ReleaseInfo;
73
+ }
74
+
75
+ function ensureTag(version: string): string {
76
+ return version.startsWith("v") ? version : `v${version}`;
77
+ }
78
+
79
+ function findAsset(
80
+ assets: ReleaseAsset[],
81
+ platform: "macos" | "linux",
82
+ ): string | null {
83
+ const candidate = assets.find((asset) => {
84
+ const lower = asset.name.toLowerCase();
85
+ return lower.includes(platform) && lower.endsWith(".tar.gz");
86
+ });
87
+ if (!candidate) {
88
+ return null;
89
+ }
90
+ return candidate.browser_download_url;
91
+ }
92
+
93
+ async function computeSha256(url: string): Promise<string> {
94
+ const response = await fetch(url);
95
+ if (!response.ok) {
96
+ throw new Error(
97
+ `Failed to download asset ${url} (${response.status} ${response.statusText})`,
98
+ );
99
+ }
100
+ const arrayBuffer = await response.arrayBuffer();
101
+ const hash = createHash("sha256");
102
+ hash.update(Buffer.from(arrayBuffer));
103
+ return hash.digest("hex");
104
+ }
105
+
106
+ async function updateFormula(params: {
107
+ version: string;
108
+ macSha: string;
109
+ linuxSha: string;
110
+ }) {
111
+ const formula = await readFile(FORMULA_PATH, "utf8");
112
+ let updated = formula;
113
+ updated = replaceOne(
114
+ updated,
115
+ /version "[^"]+"/,
116
+ `version "${params.version}"`,
117
+ );
118
+ updated = replaceOne(
119
+ updated,
120
+ /(on_macos do\s+url "[^"]+"\s+sha256 ")[^"]+("\s+)/,
121
+ `$1${params.macSha}$2`,
122
+ );
123
+ updated = replaceOne(
124
+ updated,
125
+ /(on_linux do\s+url "[^"]+"\s+sha256 ")[^"]+("\s+)/,
126
+ `$1${params.linuxSha}$2`,
127
+ );
128
+ await writeFile(FORMULA_PATH, updated, "utf8");
129
+ }
130
+
131
+ function replaceOne(
132
+ source: string,
133
+ pattern: RegExp,
134
+ replacement: string,
135
+ ): string {
136
+ if (!pattern.test(source)) {
137
+ throw new Error(`Pattern ${pattern} not found in formula`);
138
+ }
139
+ return source.replace(pattern, replacement);
140
+ }
141
+
142
+ main().catch((error) => {
143
+ console.error(`[update-brew] ${error.message}`);
144
+ process.exit(1);
145
+ });
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -euo pipefail
4
-
5
- if [ $# -ne 1 ]; then
6
- echo "Usage: $0 <version>" >&2
7
- exit 1
8
- fi
9
-
10
- VERSION="$1"
11
- case "$VERSION" in
12
- v*) TAG="$VERSION" ;;
13
- *) TAG="v$VERSION" ;;
14
- esac
15
-
16
- if ! command -v curl >/dev/null 2>&1; then
17
- echo "curl is required" >&2
18
- exit 1
19
- fi
20
-
21
- if ! command -v sha256sum >/dev/null 2>&1; then
22
- if command -v shasum >/dev/null 2>&1; then
23
- sha256sum() { shasum -a 256 "$@"; }
24
- else
25
- echo "sha256sum or shasum is required" >&2
26
- exit 1
27
- fi
28
- fi
29
-
30
- REPO="napisani/scute"
31
-
32
- download_and_sha() {
33
- local platform="$1"
34
- local arch="x86_64"
35
- local url="https://github.com/${REPO}/releases/download/${TAG}/scute-${TAG}-${platform}-${arch}.tar.gz"
36
- local tmp
37
- tmp=$(mktemp)
38
- curl -fsSL "$url" -o "$tmp"
39
- local sum
40
- sum=$(sha256sum "$tmp" | awk '{print $1}')
41
- rm -f "$tmp"
42
- echo "$sum"
43
- }
44
-
45
- MAC_SHA=$(download_and_sha macos)
46
- LINUX_SHA=$(download_and_sha linux)
47
-
48
- FORMULA="Formula/scute.rb"
49
-
50
- perl -0pi -e 's/version "[^"]+"/version "'"${TAG#v}"'"/' "$FORMULA"
51
- perl -0pi -e 's/(on_macos do\n\s+url ".*"\n\s+sha256 ")[^"]+("/\1'"$MAC_SHA"'\2/' "$FORMULA"
52
- perl -0pi -e 's/(on_linux do\n\s+url ".*"\n\s+sha256 ")[^"]+("/\1'"$LINUX_SHA"'\2/' "$FORMULA"
53
-
54
- echo "Updated $FORMULA with version ${TAG#v}"