dataset-cli 1.0.0 → 1.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/bin/launcher.js +21 -14
- package/package.json +8 -4
- package/scripts/install.js +44 -33
package/bin/launcher.js
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
const { spawn } = require('child_process');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const os = require('os');
|
|
5
|
+
const fs = require('fs');
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
'linux-arm64': 'linux-arm64',
|
|
10
|
-
'win32-x64': 'windows-amd64.exe'
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const platform = `${os.platform()}-${os.arch()}`;
|
|
14
|
-
const binaryName = platformMap[platform] || platform;
|
|
7
|
+
// 1. Determine the extension based on the OS
|
|
8
|
+
const ext = os.platform() === 'win32' ? '.exe' : '';
|
|
9
|
+
// 2. Look for the binary in the same 'bin' folder where launcher.js lives
|
|
10
|
+
const binaryPath = path.join(__dirname, 'dataset-cli' + ext);
|
|
15
11
|
|
|
16
|
-
|
|
12
|
+
// 3. Safety check: Does the binary actually exist?
|
|
13
|
+
if (!fs.existsSync(binaryPath)) {
|
|
14
|
+
console.error(`❌ Error: dataset-cli binary not found at ${binaryPath}`);
|
|
15
|
+
console.error(`Please try reinstalling: npm install -g dataset-cli@latest`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
// 4. Run the Go binary and pass through all arguments
|
|
19
20
|
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
20
21
|
stdio: 'inherit',
|
|
21
|
-
cwd: process.cwd()
|
|
22
|
+
cwd: process.cwd(),
|
|
23
|
+
shell: true // Added for better compatibility with Windows shells
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
child.on('exit', (code) => {
|
|
25
|
-
process.exit(code);
|
|
27
|
+
process.exit(code || 0);
|
|
26
28
|
});
|
|
29
|
+
|
|
30
|
+
child.on('error', (err) => {
|
|
31
|
+
console.error(`❌ Failed to start dataset-cli: ${err.message}`);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataset-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Dataset processing CLI tool",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/darshan192004/cli-project.git"
|
|
8
8
|
},
|
|
9
9
|
"bin": {
|
|
10
|
-
"dataset-cli": "bin/launcher.js"
|
|
10
|
+
"dataset-cli": "./bin/launcher.js"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"postinstall": "node scripts/install.js"
|
|
14
|
-
}
|
|
13
|
+
"postinstall": "node ./scripts/install.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin/",
|
|
17
|
+
"scripts/"
|
|
18
|
+
]
|
|
15
19
|
}
|
package/scripts/install.js
CHANGED
|
@@ -3,59 +3,70 @@ const fs = require('fs');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const os = require('os');
|
|
5
5
|
const https = require('https');
|
|
6
|
-
const { execSync } = require('child_process');
|
|
7
6
|
|
|
7
|
+
// 1. Fixed Map to match your release.yml naming exactly
|
|
8
8
|
const platformMap = {
|
|
9
9
|
'darwin-x64': 'darwin-amd64',
|
|
10
10
|
'darwin-arm64': 'darwin-arm64',
|
|
11
11
|
'linux-x64': 'linux-amd64',
|
|
12
12
|
'linux-arm64': 'linux-arm64',
|
|
13
|
-
'win32-x64': 'windows-amd64.exe'
|
|
13
|
+
'win32-x64': 'windows-amd64.exe',
|
|
14
|
+
'win32-arm64': 'windows-arm64.exe' // Added for safety
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
const platform = `${os.platform()}-${os.arch()}`;
|
|
17
|
-
const
|
|
18
|
+
const suffix = platformMap[platform];
|
|
18
19
|
|
|
19
|
-
if (!
|
|
20
|
-
console.error(
|
|
20
|
+
if (!suffix) {
|
|
21
|
+
console.error(`❌ Unsupported platform: ${platform}`);
|
|
21
22
|
process.exit(1);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const installDir = path.join(__dirname, 'bin');
|
|
25
|
-
const
|
|
25
|
+
const installDir = path.join(__dirname, '..', 'bin');
|
|
26
|
+
const fullBinaryName = `dataset-cli-${suffix}`;
|
|
27
|
+
const destPath = path.join(installDir, os.platform() === 'win32' ? 'dataset-cli.exe' : 'dataset-cli');
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
// 2. Clear previous failed attempts
|
|
30
|
+
if (!fs.existsSync(installDir)) {
|
|
31
|
+
fs.mkdirSync(installDir, { recursive: true });
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
// 3. Get version from package.json
|
|
35
|
+
const packageJson = require(path.join(__dirname, '..', 'package.json'));
|
|
36
|
+
const version = packageJson.version;
|
|
32
37
|
const repo = 'darshan192004/cli-project';
|
|
33
|
-
const downloadUrl = `https://github.com/${repo}/releases/download/v${version}
|
|
38
|
+
const downloadUrl = `https://github.com/${repo}/releases/download/v${version}/${fullBinaryName}`;
|
|
34
39
|
|
|
35
|
-
console.log(
|
|
40
|
+
console.log(`☁️ Downloading dataset-cli v${version} for ${platform}...`);
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
function download(url) {
|
|
43
|
+
https.get(url, (res) => {
|
|
44
|
+
// Handle Redirects (Important for GitHub)
|
|
45
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
46
|
+
return download(res.headers.location);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (res.statusCode !== 200) {
|
|
50
|
+
console.error(`❌ Download failed! HTTP Status: ${res.statusCode}`);
|
|
51
|
+
console.error(`URL attempted: ${url}`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const file = fs.createWriteStream(destPath);
|
|
56
|
+
res.pipe(file);
|
|
38
57
|
|
|
39
|
-
https.get(downloadUrl, (response) => {
|
|
40
|
-
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
41
|
-
https.get(response.headers.location, (redirectResponse) => {
|
|
42
|
-
redirectResponse.pipe(file);
|
|
43
|
-
file.on('finish', () => {
|
|
44
|
-
file.close();
|
|
45
|
-
fs.chmodSync(binaryPath, 0o755);
|
|
46
|
-
console.log(`Installed dataset-cli v${version}`);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
response.pipe(file);
|
|
51
58
|
file.on('finish', () => {
|
|
52
59
|
file.close();
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
// 4. Only chmod on Non-Windows systems
|
|
61
|
+
if (os.platform() !== 'win32') {
|
|
62
|
+
fs.chmodSync(destPath, 0o755);
|
|
63
|
+
}
|
|
64
|
+
console.log(`✅ Success! Installed to ${destPath}`);
|
|
55
65
|
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
}).on('error', (err) => {
|
|
67
|
+
console.error(`❌ Request Error: ${err.message}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
download(downloadUrl);
|