iteratr 0.0.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.
Files changed (3) hide show
  1. package/bin/iteratr +21 -0
  2. package/install.js +153 -0
  3. package/package.json +41 -0
package/bin/iteratr ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawnSync } = require("child_process");
4
+ const path = require("path");
5
+
6
+ const binDir = __dirname;
7
+ const isWindows = process.platform === "win32";
8
+ const binaryName = isWindows ? "iteratr.exe" : "iteratr-bin";
9
+ const binaryPath = path.join(binDir, binaryName);
10
+
11
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
12
+ stdio: "inherit",
13
+ shell: false,
14
+ });
15
+
16
+ if (result.error) {
17
+ console.error(`Failed to run iteratr: ${result.error.message}`);
18
+ process.exit(1);
19
+ }
20
+
21
+ process.exit(result.status ?? 1);
package/install.js ADDED
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync, spawnSync } = require("child_process");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const https = require("https");
7
+ const { createWriteStream, mkdirSync, chmodSync, unlinkSync } = fs;
8
+
9
+ const REPO = "mark3labs/iteratr";
10
+ const BINARY = "iteratr";
11
+
12
+ // Get version from package.json
13
+ const packageJson = require("./package.json");
14
+ const VERSION = packageJson.version;
15
+
16
+ // Platform mapping
17
+ const PLATFORM_MAP = {
18
+ darwin: "darwin",
19
+ linux: "linux",
20
+ win32: "windows",
21
+ };
22
+
23
+ // Arch mapping
24
+ const ARCH_MAP = {
25
+ x64: "amd64",
26
+ arm64: "arm64",
27
+ };
28
+
29
+ function getPlatform() {
30
+ const platform = PLATFORM_MAP[process.platform];
31
+ if (!platform) {
32
+ throw new Error(`Unsupported platform: ${process.platform}`);
33
+ }
34
+ return platform;
35
+ }
36
+
37
+ function getArch() {
38
+ const arch = ARCH_MAP[process.arch];
39
+ if (!arch) {
40
+ throw new Error(`Unsupported architecture: ${process.arch}`);
41
+ }
42
+ return arch;
43
+ }
44
+
45
+ function getExtension(platform) {
46
+ return platform === "windows" ? "zip" : "tar.gz";
47
+ }
48
+
49
+ function getBinaryName(platform) {
50
+ // Use different name to avoid conflict with JS wrapper on Unix
51
+ return platform === "windows" ? `${BINARY}.exe` : `${BINARY}-bin`;
52
+ }
53
+
54
+ function download(url, dest) {
55
+ return new Promise((resolve, reject) => {
56
+ const follow = (url, redirects = 0) => {
57
+ if (redirects > 10) {
58
+ reject(new Error("Too many redirects"));
59
+ return;
60
+ }
61
+
62
+ https
63
+ .get(url, (response) => {
64
+ if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
65
+ follow(response.headers.location, redirects + 1);
66
+ return;
67
+ }
68
+
69
+ if (response.statusCode !== 200) {
70
+ reject(new Error(`Failed to download: ${response.statusCode}`));
71
+ return;
72
+ }
73
+
74
+ const file = createWriteStream(dest);
75
+ response.pipe(file);
76
+ file.on("finish", () => {
77
+ file.close();
78
+ resolve();
79
+ });
80
+ file.on("error", (err) => {
81
+ unlinkSync(dest);
82
+ reject(err);
83
+ });
84
+ })
85
+ .on("error", reject);
86
+ };
87
+
88
+ follow(url);
89
+ });
90
+ }
91
+
92
+ function extract(archivePath, destDir, platform) {
93
+ if (platform === "windows") {
94
+ // Use PowerShell to extract zip on Windows
95
+ spawnSync("powershell", [
96
+ "-Command",
97
+ `Expand-Archive -Path "${archivePath}" -DestinationPath "${destDir}" -Force`,
98
+ ]);
99
+ } else {
100
+ // Use tar for Unix systems
101
+ spawnSync("tar", ["-xzf", archivePath, "-C", destDir]);
102
+ }
103
+ }
104
+
105
+ async function main() {
106
+ const platform = getPlatform();
107
+ const arch = getArch();
108
+ const ext = getExtension(platform);
109
+ const binaryName = getBinaryName(platform);
110
+
111
+ const filename = `${BINARY}_${VERSION}_${platform}_${arch}.${ext}`;
112
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${filename}`;
113
+
114
+ const binDir = path.join(__dirname, "bin");
115
+ const archivePath = path.join(__dirname, filename);
116
+ const binaryPath = path.join(binDir, binaryName);
117
+
118
+ console.log(`Installing ${BINARY} v${VERSION} (${platform}/${arch})...`);
119
+ console.log(`Downloading from ${url}...`);
120
+
121
+ try {
122
+ // Ensure bin directory exists
123
+ mkdirSync(binDir, { recursive: true });
124
+
125
+ // Download archive
126
+ await download(url, archivePath);
127
+
128
+ // Extract
129
+ extract(archivePath, binDir, platform);
130
+
131
+ // Rename binary (archive contains "iteratr", we want "iteratr-bin" on Unix)
132
+ const extractedName = platform === "windows" ? `${BINARY}.exe` : BINARY;
133
+ const extractedPath = path.join(binDir, extractedName);
134
+ if (extractedPath !== binaryPath && fs.existsSync(extractedPath)) {
135
+ fs.renameSync(extractedPath, binaryPath);
136
+ }
137
+
138
+ // Make executable on Unix
139
+ if (platform !== "windows") {
140
+ chmodSync(binaryPath, 0o755);
141
+ }
142
+
143
+ // Clean up archive
144
+ unlinkSync(archivePath);
145
+
146
+ console.log(`Successfully installed ${BINARY} to ${binaryPath}`);
147
+ } catch (err) {
148
+ console.error(`Failed to install ${BINARY}: ${err.message}`);
149
+ process.exit(1);
150
+ }
151
+ }
152
+
153
+ main();
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "iteratr",
3
+ "version": "0.0.0",
4
+ "description": "AI-powered CLI tool",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/mark3labs/iteratr.git"
8
+ },
9
+ "homepage": "https://github.com/mark3labs/iteratr",
10
+ "bugs": {
11
+ "url": "https://github.com/mark3labs/iteratr/issues"
12
+ },
13
+ "license": "MIT",
14
+ "bin": {
15
+ "iteratr": "bin/iteratr"
16
+ },
17
+ "scripts": {
18
+ "postinstall": "node install.js"
19
+ },
20
+ "files": [
21
+ "bin",
22
+ "install.js"
23
+ ],
24
+ "engines": {
25
+ "node": ">=16"
26
+ },
27
+ "os": [
28
+ "darwin",
29
+ "linux",
30
+ "win32"
31
+ ],
32
+ "cpu": [
33
+ "x64",
34
+ "arm64"
35
+ ],
36
+ "keywords": [
37
+ "cli",
38
+ "iteratr",
39
+ "ai"
40
+ ]
41
+ }