alurkerja-cli 1.0.3 → 1.0.5
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 +61 -57
- package/index.js.backup +61 -57
- package/package.json +1 -1
- package/package.json.backup +1 -1
package/index.js
CHANGED
|
@@ -56,8 +56,10 @@ function getVersion() {
|
|
|
56
56
|
*/
|
|
57
57
|
async function downloadBinary(version, platform) {
|
|
58
58
|
const binaryName = `alurkerja-${platform.os}-${platform.arch}${platform.os === 'windows' ? '.exe' : ''}`;
|
|
59
|
-
// Use GitLab raw file download
|
|
60
|
-
const
|
|
59
|
+
// Use GitLab API v4 for raw file download to get actual binary
|
|
60
|
+
const encodedPath = encodeURIComponent(`dist/${binaryName}`);
|
|
61
|
+
const encodedProject = encodeURIComponent('alurkerja/on-premises/toolkits/alurkerja-cli');
|
|
62
|
+
const downloadUrl = `https://gitlab.javan.co.id/api/v4/projects/${encodedProject}/repository/files/${encodedPath}/raw?ref=master`;
|
|
61
63
|
|
|
62
64
|
console.log(`📥 Downloading Alurkerja CLI ${version}...`);
|
|
63
65
|
|
|
@@ -69,54 +71,59 @@ async function downloadBinary(version, platform) {
|
|
|
69
71
|
|
|
70
72
|
return new Promise((resolve, reject) => {
|
|
71
73
|
const file = fs.createWriteStream(tempPath);
|
|
74
|
+
let downloadComplete = false;
|
|
72
75
|
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
const downloadFile = (targetUrl) => {
|
|
77
|
+
const url = new URL(targetUrl);
|
|
78
|
+
const options = {
|
|
79
|
+
hostname: url.hostname,
|
|
80
|
+
path: url.pathname + url.search,
|
|
81
|
+
headers: {
|
|
82
|
+
'PRIVATE-TOKEN': GITLAB_TOKEN
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const req = https.get(options, (res) => {
|
|
87
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
88
|
+
// Follow redirect
|
|
89
|
+
const redirectUrl = res.headers.location.startsWith('http')
|
|
90
|
+
? res.headers.location
|
|
91
|
+
: `https://${url.hostname}${res.headers.location}`;
|
|
92
|
+
return downloadFile(redirectUrl);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (res.statusCode !== 200) {
|
|
96
|
+
file.close();
|
|
97
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
98
|
+
reject(new Error(`Download failed with status ${res.statusCode}`));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
res.pipe(file);
|
|
103
|
+
res.on('end', () => {
|
|
104
|
+
downloadComplete = true;
|
|
95
105
|
});
|
|
96
|
-
}
|
|
106
|
+
});
|
|
97
107
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
req.on('error', (err) => {
|
|
109
|
+
if (!downloadComplete) {
|
|
110
|
+
file.close();
|
|
111
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
112
|
+
reject(err);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
104
115
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
req.setTimeout(30000, () => {
|
|
117
|
+
if (!downloadComplete) {
|
|
118
|
+
req.abort();
|
|
119
|
+
file.close();
|
|
120
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
121
|
+
reject(new Error('Download timeout'));
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
};
|
|
113
125
|
|
|
114
|
-
|
|
115
|
-
req.abort();
|
|
116
|
-
file.close();
|
|
117
|
-
try { fs.unlinkSync(tempPath); } catch {}
|
|
118
|
-
reject(new Error('Download timeout'));
|
|
119
|
-
});
|
|
126
|
+
downloadFile(downloadUrl);
|
|
120
127
|
|
|
121
128
|
file.on('error', (err) => {
|
|
122
129
|
try { fs.unlinkSync(tempPath); } catch {}
|
|
@@ -131,7 +138,15 @@ async function downloadBinary(version, platform) {
|
|
|
131
138
|
return;
|
|
132
139
|
}
|
|
133
140
|
|
|
134
|
-
//
|
|
141
|
+
// Validate the downloaded file
|
|
142
|
+
const stats = fs.statSync(tempPath);
|
|
143
|
+
if (stats.size < 1000) {
|
|
144
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
145
|
+
reject(new Error(`Download failed: received invalid file (${stats.size} bytes)`));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Make executable on Unix systems
|
|
135
150
|
if (platform.os !== 'windows') {
|
|
136
151
|
try {
|
|
137
152
|
fs.chmodSync(tempPath, '755');
|
|
@@ -142,19 +157,8 @@ async function downloadBinary(version, platform) {
|
|
|
142
157
|
}
|
|
143
158
|
}
|
|
144
159
|
|
|
145
|
-
// Validate the downloaded file
|
|
146
|
-
const stats = fs.statSync(tempPath);
|
|
147
|
-
if (stats.size < 1000) {
|
|
148
|
-
// File too small, likely an error page
|
|
149
|
-
const content = fs.readFileSync(tempPath, 'utf8');
|
|
150
|
-
try { fs.unlinkSync(tempPath); } catch {}
|
|
151
|
-
reject(new Error(`Download failed: received invalid file (${stats.size} bytes)`));
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
160
|
// Rename temp file to final path
|
|
156
161
|
try {
|
|
157
|
-
// Remove old binary if exists
|
|
158
162
|
if (fs.existsSync(BINARY_PATH)) {
|
|
159
163
|
fs.unlinkSync(BINARY_PATH);
|
|
160
164
|
}
|
package/index.js.backup
CHANGED
|
@@ -56,8 +56,10 @@ function getVersion() {
|
|
|
56
56
|
*/
|
|
57
57
|
async function downloadBinary(version, platform) {
|
|
58
58
|
const binaryName = `alurkerja-${platform.os}-${platform.arch}${platform.os === 'windows' ? '.exe' : ''}`;
|
|
59
|
-
// Use GitLab raw file download
|
|
60
|
-
const
|
|
59
|
+
// Use GitLab API v4 for raw file download to get actual binary
|
|
60
|
+
const encodedPath = encodeURIComponent(`dist/${binaryName}`);
|
|
61
|
+
const encodedProject = encodeURIComponent('alurkerja/on-premises/toolkits/alurkerja-cli');
|
|
62
|
+
const downloadUrl = `https://gitlab.javan.co.id/api/v4/projects/${encodedProject}/repository/files/${encodedPath}/raw?ref=master`;
|
|
61
63
|
|
|
62
64
|
console.log(`📥 Downloading Alurkerja CLI ${version}...`);
|
|
63
65
|
|
|
@@ -69,54 +71,59 @@ async function downloadBinary(version, platform) {
|
|
|
69
71
|
|
|
70
72
|
return new Promise((resolve, reject) => {
|
|
71
73
|
const file = fs.createWriteStream(tempPath);
|
|
74
|
+
let downloadComplete = false;
|
|
72
75
|
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
const downloadFile = (targetUrl) => {
|
|
77
|
+
const url = new URL(targetUrl);
|
|
78
|
+
const options = {
|
|
79
|
+
hostname: url.hostname,
|
|
80
|
+
path: url.pathname + url.search,
|
|
81
|
+
headers: {
|
|
82
|
+
'PRIVATE-TOKEN': GITLAB_TOKEN
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const req = https.get(options, (res) => {
|
|
87
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
88
|
+
// Follow redirect
|
|
89
|
+
const redirectUrl = res.headers.location.startsWith('http')
|
|
90
|
+
? res.headers.location
|
|
91
|
+
: `https://${url.hostname}${res.headers.location}`;
|
|
92
|
+
return downloadFile(redirectUrl);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (res.statusCode !== 200) {
|
|
96
|
+
file.close();
|
|
97
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
98
|
+
reject(new Error(`Download failed with status ${res.statusCode}`));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
res.pipe(file);
|
|
103
|
+
res.on('end', () => {
|
|
104
|
+
downloadComplete = true;
|
|
95
105
|
});
|
|
96
|
-
}
|
|
106
|
+
});
|
|
97
107
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
req.on('error', (err) => {
|
|
109
|
+
if (!downloadComplete) {
|
|
110
|
+
file.close();
|
|
111
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
112
|
+
reject(err);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
104
115
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
req.setTimeout(30000, () => {
|
|
117
|
+
if (!downloadComplete) {
|
|
118
|
+
req.abort();
|
|
119
|
+
file.close();
|
|
120
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
121
|
+
reject(new Error('Download timeout'));
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
};
|
|
113
125
|
|
|
114
|
-
|
|
115
|
-
req.abort();
|
|
116
|
-
file.close();
|
|
117
|
-
try { fs.unlinkSync(tempPath); } catch {}
|
|
118
|
-
reject(new Error('Download timeout'));
|
|
119
|
-
});
|
|
126
|
+
downloadFile(downloadUrl);
|
|
120
127
|
|
|
121
128
|
file.on('error', (err) => {
|
|
122
129
|
try { fs.unlinkSync(tempPath); } catch {}
|
|
@@ -131,7 +138,15 @@ async function downloadBinary(version, platform) {
|
|
|
131
138
|
return;
|
|
132
139
|
}
|
|
133
140
|
|
|
134
|
-
//
|
|
141
|
+
// Validate the downloaded file
|
|
142
|
+
const stats = fs.statSync(tempPath);
|
|
143
|
+
if (stats.size < 1000) {
|
|
144
|
+
try { fs.unlinkSync(tempPath); } catch {}
|
|
145
|
+
reject(new Error(`Download failed: received invalid file (${stats.size} bytes)`));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Make executable on Unix systems
|
|
135
150
|
if (platform.os !== 'windows') {
|
|
136
151
|
try {
|
|
137
152
|
fs.chmodSync(tempPath, '755');
|
|
@@ -142,19 +157,8 @@ async function downloadBinary(version, platform) {
|
|
|
142
157
|
}
|
|
143
158
|
}
|
|
144
159
|
|
|
145
|
-
// Validate the downloaded file
|
|
146
|
-
const stats = fs.statSync(tempPath);
|
|
147
|
-
if (stats.size < 1000) {
|
|
148
|
-
// File too small, likely an error page
|
|
149
|
-
const content = fs.readFileSync(tempPath, 'utf8');
|
|
150
|
-
try { fs.unlinkSync(tempPath); } catch {}
|
|
151
|
-
reject(new Error(`Download failed: received invalid file (${stats.size} bytes)`));
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
160
|
// Rename temp file to final path
|
|
156
161
|
try {
|
|
157
|
-
// Remove old binary if exists
|
|
158
162
|
if (fs.existsSync(BINARY_PATH)) {
|
|
159
163
|
fs.unlinkSync(BINARY_PATH);
|
|
160
164
|
}
|
package/package.json
CHANGED