alurkerja-cli 0.0.1

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/index.js ADDED
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Alurkerja CLI - npx Wrapper
5
+ *
6
+ * This is a bootstrapper that downloads and executes the Go binary.
7
+ * As per PRD: npx wrapper should NOT contain business logic.
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ const https = require('https');
13
+ const { execSync, spawn } = require('child_process');
14
+ const os = require('os');
15
+
16
+ const REPO = 'alurkerja/alurkerja-cli';
17
+ const VERSION = 'v1.0.0.'; // Will be replaced during build
18
+ const INSTALL_DIR = path.join(os.homedir(), '.alurkerja', 'bin');
19
+ const BINARY_PATH = path.join(INSTALL_DIR, 'alurkerja');
20
+
21
+ /**
22
+ * Detect current platform
23
+ */
24
+ function detectPlatform() {
25
+ const platform = os.platform();
26
+ const arch = os.arch();
27
+
28
+ let osName;
29
+ switch (platform) {
30
+ case 'linux': osName = 'linux'; break;
31
+ case 'darwin': osName = 'darwin'; break;
32
+ case 'win32': osName = 'windows'; break;
33
+ default: throw new Error(`Unsupported platform: ${platform}`);
34
+ }
35
+
36
+ let archName;
37
+ switch (arch) {
38
+ case 'x64': archName = 'amd64'; break;
39
+ case 'arm64': archName = 'arm64'; break;
40
+ default: throw new Error(`Unsupported architecture: ${arch}`);
41
+ }
42
+
43
+ return { os: osName, arch: archName };
44
+ }
45
+
46
+ /**
47
+ * Get the latest version from GitHub if VERSION is 'latest'
48
+ */
49
+ async function getLatestVersion() {
50
+ if (VERSION !== 'latest' && VERSION !== 'v1.0.0.') {
51
+ return VERSION;
52
+ }
53
+
54
+ return new Promise((resolve, reject) => {
55
+ const options = {
56
+ hostname: 'api.github.com',
57
+ path: `/repos/${REPO}/releases/latest`,
58
+ headers: { 'User-Agent': 'alurkerja-cli-wrapper' }
59
+ };
60
+
61
+ const req = https.get(options, (res) => {
62
+ let data = '';
63
+ res.on('data', chunk => data += chunk);
64
+ res.on('end', () => {
65
+ try {
66
+ const release = JSON.parse(data);
67
+ resolve(release.tag_name);
68
+ } catch (err) {
69
+ reject(new Error('Failed to parse GitHub API response'));
70
+ }
71
+ });
72
+ });
73
+
74
+ req.on('error', reject);
75
+ req.setTimeout(10000, () => {
76
+ req.abort();
77
+ reject(new Error('GitHub API request timeout'));
78
+ });
79
+ });
80
+ }
81
+
82
+ /**
83
+ * Download binary from GitHub releases
84
+ */
85
+ async function downloadBinary(version, platform) {
86
+ const binaryName = `alurkerja-${platform.os}-${platform.arch}${platform.os === 'windows' ? '.exe' : ''}`;
87
+ const downloadUrl = `https://github.com/${REPO}/releases/download/${version}/${binaryName}`;
88
+
89
+ console.log(`📥 Downloading Alurkerja CLI ${version}...`);
90
+
91
+ // Ensure install directory exists
92
+ fs.mkdirSync(INSTALL_DIR, { recursive: true });
93
+
94
+ return new Promise((resolve, reject) => {
95
+ const file = fs.createWriteStream(BINARY_PATH);
96
+
97
+ const req = https.get(downloadUrl, (res) => {
98
+ if (res.statusCode === 302 || res.statusCode === 301) {
99
+ // Follow redirect
100
+ return https.get(res.headers.location, (redirectRes) => {
101
+ redirectRes.pipe(file);
102
+ redirectRes.on('end', resolve);
103
+ });
104
+ }
105
+
106
+ if (res.statusCode !== 200) {
107
+ reject(new Error(`Download failed with status ${res.statusCode}`));
108
+ return;
109
+ }
110
+
111
+ res.pipe(file);
112
+ res.on('end', resolve);
113
+ });
114
+
115
+ req.on('error', reject);
116
+ req.setTimeout(30000, () => {
117
+ req.abort();
118
+ reject(new Error('Download timeout'));
119
+ });
120
+
121
+ file.on('error', reject);
122
+ file.on('finish', () => {
123
+ file.close();
124
+ // Make executable on Unix systems
125
+ if (platform.os !== 'windows') {
126
+ fs.chmodSync(BINARY_PATH, '755');
127
+ }
128
+ });
129
+ });
130
+ }
131
+
132
+ /**
133
+ * Check if binary exists and is executable
134
+ */
135
+ function binaryExists() {
136
+ try {
137
+ fs.accessSync(BINARY_PATH, fs.constants.F_OK | fs.constants.X_OK);
138
+ return true;
139
+ } catch {
140
+ return false;
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Get version of installed binary
146
+ */
147
+ function getInstalledVersion() {
148
+ try {
149
+ const output = execSync(`"${BINARY_PATH}" --version`, { encoding: 'utf8', timeout: 5000 });
150
+ const match = output.match(/v?(\d+\.\d+\.\d+)/);
151
+ return match ? match[1] : null;
152
+ } catch {
153
+ return null;
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Execute the Go binary with provided arguments
159
+ */
160
+ function executeBinary(args) {
161
+ const child = spawn(BINARY_PATH, args, {
162
+ stdio: 'inherit',
163
+ shell: false
164
+ });
165
+
166
+ child.on('error', (err) => {
167
+ console.error(`❌ Failed to execute binary: ${err.message}`);
168
+ process.exit(1);
169
+ });
170
+
171
+ child.on('exit', (code) => {
172
+ process.exit(code || 0);
173
+ });
174
+ }
175
+
176
+ /**
177
+ * Main bootstrap logic
178
+ */
179
+ async function bootstrap() {
180
+ try {
181
+ const platform = detectPlatform();
182
+ const latestVersion = await getLatestVersion();
183
+ const installedVersion = getInstalledVersion();
184
+
185
+ // Check if we need to download the binary
186
+ const needsDownload = !binaryExists() ||
187
+ (installedVersion !== latestVersion && latestVersion !== 'dev');
188
+
189
+ if (needsDownload) {
190
+ await downloadBinary(latestVersion, platform);
191
+ console.log(`✅ Alurkerja CLI ${latestVersion} ready!`);
192
+ }
193
+
194
+ // Execute the binary with all arguments passed to this script
195
+ const args = process.argv.slice(2);
196
+ executeBinary(args);
197
+
198
+ } catch (error) {
199
+ console.error(`❌ Bootstrap failed: ${error.message}`);
200
+ console.log('💡 Try installing directly: curl -fsSL https://alurkerja.com/install.sh | bash');
201
+ process.exit(1);
202
+ }
203
+ }
204
+
205
+ // Handle termination signals
206
+ process.on('SIGINT', () => process.exit(0));
207
+ process.on('SIGTERM', () => process.exit(0));
208
+
209
+ // Start bootstrap
210
+ bootstrap();
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Alurkerja CLI - npx Wrapper
5
+ *
6
+ * This is a bootstrapper that downloads and executes the Go binary.
7
+ * As per PRD: npx wrapper should NOT contain business logic.
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ const https = require('https');
13
+ const { execSync, spawn } = require('child_process');
14
+ const os = require('os');
15
+
16
+ const REPO = 'alurkerja/alurkerja-cli';
17
+ const VERSION = 'v1.0.0.'; // Will be replaced during build
18
+ const INSTALL_DIR = path.join(os.homedir(), '.alurkerja', 'bin');
19
+ const BINARY_PATH = path.join(INSTALL_DIR, 'alurkerja');
20
+
21
+ /**
22
+ * Detect current platform
23
+ */
24
+ function detectPlatform() {
25
+ const platform = os.platform();
26
+ const arch = os.arch();
27
+
28
+ let osName;
29
+ switch (platform) {
30
+ case 'linux': osName = 'linux'; break;
31
+ case 'darwin': osName = 'darwin'; break;
32
+ case 'win32': osName = 'windows'; break;
33
+ default: throw new Error(`Unsupported platform: ${platform}`);
34
+ }
35
+
36
+ let archName;
37
+ switch (arch) {
38
+ case 'x64': archName = 'amd64'; break;
39
+ case 'arm64': archName = 'arm64'; break;
40
+ default: throw new Error(`Unsupported architecture: ${arch}`);
41
+ }
42
+
43
+ return { os: osName, arch: archName };
44
+ }
45
+
46
+ /**
47
+ * Get the latest version from GitHub if VERSION is 'latest'
48
+ */
49
+ async function getLatestVersion() {
50
+ if (VERSION !== 'latest' && VERSION !== 'v1.0.0.') {
51
+ return VERSION;
52
+ }
53
+
54
+ return new Promise((resolve, reject) => {
55
+ const options = {
56
+ hostname: 'api.github.com',
57
+ path: `/repos/${REPO}/releases/latest`,
58
+ headers: { 'User-Agent': 'alurkerja-cli-wrapper' }
59
+ };
60
+
61
+ const req = https.get(options, (res) => {
62
+ let data = '';
63
+ res.on('data', chunk => data += chunk);
64
+ res.on('end', () => {
65
+ try {
66
+ const release = JSON.parse(data);
67
+ resolve(release.tag_name);
68
+ } catch (err) {
69
+ reject(new Error('Failed to parse GitHub API response'));
70
+ }
71
+ });
72
+ });
73
+
74
+ req.on('error', reject);
75
+ req.setTimeout(10000, () => {
76
+ req.abort();
77
+ reject(new Error('GitHub API request timeout'));
78
+ });
79
+ });
80
+ }
81
+
82
+ /**
83
+ * Download binary from GitHub releases
84
+ */
85
+ async function downloadBinary(version, platform) {
86
+ const binaryName = `alurkerja-${platform.os}-${platform.arch}${platform.os === 'windows' ? '.exe' : ''}`;
87
+ const downloadUrl = `https://github.com/${REPO}/releases/download/${version}/${binaryName}`;
88
+
89
+ console.log(`📥 Downloading Alurkerja CLI ${version}...`);
90
+
91
+ // Ensure install directory exists
92
+ fs.mkdirSync(INSTALL_DIR, { recursive: true });
93
+
94
+ return new Promise((resolve, reject) => {
95
+ const file = fs.createWriteStream(BINARY_PATH);
96
+
97
+ const req = https.get(downloadUrl, (res) => {
98
+ if (res.statusCode === 302 || res.statusCode === 301) {
99
+ // Follow redirect
100
+ return https.get(res.headers.location, (redirectRes) => {
101
+ redirectRes.pipe(file);
102
+ redirectRes.on('end', resolve);
103
+ });
104
+ }
105
+
106
+ if (res.statusCode !== 200) {
107
+ reject(new Error(`Download failed with status ${res.statusCode}`));
108
+ return;
109
+ }
110
+
111
+ res.pipe(file);
112
+ res.on('end', resolve);
113
+ });
114
+
115
+ req.on('error', reject);
116
+ req.setTimeout(30000, () => {
117
+ req.abort();
118
+ reject(new Error('Download timeout'));
119
+ });
120
+
121
+ file.on('error', reject);
122
+ file.on('finish', () => {
123
+ file.close();
124
+ // Make executable on Unix systems
125
+ if (platform.os !== 'windows') {
126
+ fs.chmodSync(BINARY_PATH, '755');
127
+ }
128
+ });
129
+ });
130
+ }
131
+
132
+ /**
133
+ * Check if binary exists and is executable
134
+ */
135
+ function binaryExists() {
136
+ try {
137
+ fs.accessSync(BINARY_PATH, fs.constants.F_OK | fs.constants.X_OK);
138
+ return true;
139
+ } catch {
140
+ return false;
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Get version of installed binary
146
+ */
147
+ function getInstalledVersion() {
148
+ try {
149
+ const output = execSync(`"${BINARY_PATH}" --version`, { encoding: 'utf8', timeout: 5000 });
150
+ const match = output.match(/v?(\d+\.\d+\.\d+)/);
151
+ return match ? match[1] : null;
152
+ } catch {
153
+ return null;
154
+ }
155
+ }
156
+
157
+ /**
158
+ * Execute the Go binary with provided arguments
159
+ */
160
+ function executeBinary(args) {
161
+ const child = spawn(BINARY_PATH, args, {
162
+ stdio: 'inherit',
163
+ shell: false
164
+ });
165
+
166
+ child.on('error', (err) => {
167
+ console.error(`❌ Failed to execute binary: ${err.message}`);
168
+ process.exit(1);
169
+ });
170
+
171
+ child.on('exit', (code) => {
172
+ process.exit(code || 0);
173
+ });
174
+ }
175
+
176
+ /**
177
+ * Main bootstrap logic
178
+ */
179
+ async function bootstrap() {
180
+ try {
181
+ const platform = detectPlatform();
182
+ const latestVersion = await getLatestVersion();
183
+ const installedVersion = getInstalledVersion();
184
+
185
+ // Check if we need to download the binary
186
+ const needsDownload = !binaryExists() ||
187
+ (installedVersion !== latestVersion && latestVersion !== 'dev');
188
+
189
+ if (needsDownload) {
190
+ await downloadBinary(latestVersion, platform);
191
+ console.log(`✅ Alurkerja CLI ${latestVersion} ready!`);
192
+ }
193
+
194
+ // Execute the binary with all arguments passed to this script
195
+ const args = process.argv.slice(2);
196
+ executeBinary(args);
197
+
198
+ } catch (error) {
199
+ console.error(`❌ Bootstrap failed: ${error.message}`);
200
+ console.log('💡 Try installing directly: curl -fsSL https://alurkerja.com/install.sh | bash');
201
+ process.exit(1);
202
+ }
203
+ }
204
+
205
+ // Handle termination signals
206
+ process.on('SIGINT', () => process.exit(0));
207
+ process.on('SIGTERM', () => process.exit(0));
208
+
209
+ // Start bootstrap
210
+ bootstrap();
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "alurkerja-cli",
3
+ "version": "0.0.1",
4
+ "description": "Alurkerja CLI - npx wrapper for Go binary",
5
+ "main": "index.js",
6
+ "private": false,
7
+ "bin": {
8
+ "alurkerja": "./index.js"
9
+ },
10
+ "keywords": [
11
+ "alurkerja",
12
+ "cli",
13
+ "addon",
14
+ "ci",
15
+ "cd"
16
+ ],
17
+ "author": "Alurkerja Team",
18
+ "license": "MIT",
19
+ "engines": {
20
+ "node": ">=14.0.0"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/alurkerja/alurkerja-cli"
25
+ },
26
+ "homepage": "https://alurkerja.com",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "dependencies": {}
31
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "alurkerja-cli",
3
+ "version": "1.0.0",
4
+ "description": "Alurkerja CLI - npx wrapper for Go binary",
5
+ "main": "index.js",
6
+ "private": false,
7
+ "bin": {
8
+ "alurkerja": "./index.js"
9
+ },
10
+ "keywords": [
11
+ "alurkerja",
12
+ "cli",
13
+ "addon",
14
+ "ci",
15
+ "cd"
16
+ ],
17
+ "author": "Alurkerja Team",
18
+ "license": "MIT",
19
+ "engines": {
20
+ "node": ">=14.0.0"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/alurkerja/alurkerja-cli"
25
+ },
26
+ "homepage": "https://alurkerja.com",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "dependencies": {}
31
+ }