@goboost/cli 1.1.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.
package/bin/.gitkeep ADDED
File without changes
package/bin/cli.js ADDED
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * goBoost CLI JavaScript shim
5
+ *
6
+ * This script resolves the appropriate platform-specific binary
7
+ * and executes it with forwarded arguments.
8
+ */
9
+
10
+ const { execFileSync } = require('child_process');
11
+ const path = require('path');
12
+ const fs = require('fs');
13
+
14
+ // Supported platforms
15
+ const SUPPORTED_PLATFORMS = [
16
+ 'linux-x64',
17
+ 'linux-arm64',
18
+ 'darwin-x64',
19
+ 'darwin-arm64',
20
+ 'win32-x64'
21
+ ];
22
+
23
+ // Map platform-arch to package name
24
+ const PLATFORM_PACKAGES = {
25
+ 'linux-x64': '@goboost/cli-linux-x64',
26
+ 'linux-arm64': '@goboost/cli-linux-arm64',
27
+ 'darwin-x64': '@goboost/cli-darwin-x64',
28
+ 'darwin-arm64': '@goboost/cli-darwin-arm64',
29
+ 'win32-x64': '@goboost/cli-win32-x64'
30
+ };
31
+
32
+ // Binary name per platform
33
+ const BINARY_NAME = process.platform === 'win32' ? 'goboost.exe' : 'goboost';
34
+
35
+ /**
36
+ * Get the platform key for the current system
37
+ */
38
+ function getPlatformKey() {
39
+ return `${process.platform}-${process.arch}`;
40
+ }
41
+
42
+ /**
43
+ * Check if the current platform is supported
44
+ */
45
+ function isSupportedPlatform() {
46
+ return SUPPORTED_PLATFORMS.includes(getPlatformKey());
47
+ }
48
+
49
+ /**
50
+ * Try to resolve binary from optionalDependency
51
+ */
52
+ function resolveFromOptionalDependency() {
53
+ const platformKey = getPlatformKey();
54
+ const packageName = PLATFORM_PACKAGES[platformKey];
55
+
56
+ if (!packageName) {
57
+ return null;
58
+ }
59
+
60
+ try {
61
+ // Try to resolve the package
62
+ const packagePath = require.resolve(path.join(packageName, 'package.json'));
63
+ const packageDir = path.dirname(packagePath);
64
+ const binaryPath = path.join(packageDir, 'bin', BINARY_NAME);
65
+
66
+ if (fs.existsSync(binaryPath)) {
67
+ return binaryPath;
68
+ }
69
+ } catch (e) {
70
+ // Package not found
71
+ }
72
+
73
+ return null;
74
+ }
75
+
76
+ /**
77
+ * Try to resolve binary from local fallback (downloaded by postinstall)
78
+ */
79
+ function resolveFromLocalFallback() {
80
+ const fallbackDir = path.join(__dirname, '..');
81
+ const binaryPath = path.join(fallbackDir, BINARY_NAME);
82
+
83
+ if (fs.existsSync(binaryPath)) {
84
+ return binaryPath;
85
+ }
86
+
87
+ return null;
88
+ }
89
+
90
+ /**
91
+ * Main execution
92
+ */
93
+ function main() {
94
+ // Check platform support
95
+ if (!isSupportedPlatform()) {
96
+ const platformKey = getPlatformKey();
97
+ console.error(`Error: goboost does not support ${platformKey}.`);
98
+ console.error(`Supported platforms: ${SUPPORTED_PLATFORMS.join(', ')}`);
99
+ process.exit(1);
100
+ }
101
+
102
+ // Try to find the binary
103
+ let binaryPath = resolveFromOptionalDependency();
104
+
105
+ if (!binaryPath) {
106
+ binaryPath = resolveFromLocalFallback();
107
+ }
108
+
109
+ if (!binaryPath) {
110
+ console.error('Error: Could not find the goboost binary. Please reinstall @goboost/cli.');
111
+ process.exit(1);
112
+ }
113
+
114
+ // Execute the binary with forwarded arguments
115
+ try {
116
+ execFileSync(binaryPath, process.argv.slice(2), {
117
+ stdio: 'inherit',
118
+ windowsHide: true
119
+ });
120
+ } catch (error) {
121
+ // Propagate exit code from the Go binary
122
+ if (error.status !== undefined) {
123
+ process.exit(error.status);
124
+ } else {
125
+ console.error(`Error executing goboost: ${error.message}`);
126
+ process.exit(1);
127
+ }
128
+ }
129
+ }
130
+
131
+ main();
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@goboost/cli",
3
+ "version": "1.1.0",
4
+ "description": "Progressive NestJS-to-Go migration CLI",
5
+ "bin": {
6
+ "goboost": "bin/cli.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node scripts/install.js"
10
+ },
11
+ "optionalDependencies": {
12
+ "@goboost/cli-linux-x64": "1.1.0",
13
+ "@goboost/cli-linux-arm64": "1.1.0",
14
+ "@goboost/cli-darwin-x64": "1.1.0",
15
+ "@goboost/cli-darwin-arm64": "1.1.0",
16
+ "@goboost/cli-win32-x64": "1.1.0"
17
+ },
18
+ "keywords": [
19
+ "nestjs",
20
+ "go",
21
+ "golang",
22
+ "migration",
23
+ "cli",
24
+ "goboost"
25
+ ],
26
+ "author": "goBoost Contributors",
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/abdullahal39/GoBoost.git"
31
+ },
32
+ "homepage": "https://github.com/abdullahal39/GoBoost",
33
+ "engines": {
34
+ "node": ">=16"
35
+ }
36
+ }
@@ -0,0 +1,186 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * goBoost postinstall fallback script.
5
+ *
6
+ * If the platform-specific optionalDependency failed to install
7
+ * (e.g., unsupported platform, registry issues), this script
8
+ * downloads the correct binary from GitHub Releases as a fallback.
9
+ */
10
+
11
+ const https = require('https');
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const { execSync } = require('child_process');
15
+ const os = require('os');
16
+
17
+ const BINARY_NAME = process.platform === 'win32' ? 'goboost.exe' : 'goboost';
18
+ const PACKAGE_DIR = path.resolve(__dirname, '..');
19
+ const BINARY_PATH = path.join(PACKAGE_DIR, BINARY_NAME);
20
+
21
+ // Platform mapping for GitHub release asset names
22
+ const PLATFORM_MAP = {
23
+ 'linux-x64': 'linux_amd64',
24
+ 'linux-arm64': 'linux_arm64',
25
+ 'darwin-x64': 'darwin_amd64',
26
+ 'darwin-arm64': 'darwin_arm64',
27
+ 'win32-x64': 'windows_amd64'
28
+ };
29
+
30
+ // Archive extension per platform
31
+ const ARCHIVE_EXT = {
32
+ 'linux-x64': '.tar.gz',
33
+ 'linux-arm64': '.tar.gz',
34
+ 'darwin-x64': '.tar.gz',
35
+ 'darwin-arm64': '.tar.gz',
36
+ 'win32-x64': '.zip'
37
+ };
38
+
39
+ function getPlatformKey() {
40
+ return `${process.platform}-${process.arch}`;
41
+ }
42
+
43
+ function binaryExists() {
44
+ // Check if optional dependency already provided the binary
45
+ const platformKey = getPlatformKey();
46
+ const packageName = `@goboost/cli-${platformKey}`;
47
+
48
+ try {
49
+ const packagePath = require.resolve(path.join(packageName, 'package.json'));
50
+ const packageDir = path.dirname(packagePath);
51
+ const binaryPath = path.join(packageDir, 'bin', BINARY_NAME);
52
+ if (fs.existsSync(binaryPath)) {
53
+ return true;
54
+ }
55
+ } catch (e) {
56
+ // Package not installed
57
+ }
58
+
59
+ // Check local fallback
60
+ return fs.existsSync(BINARY_PATH);
61
+ }
62
+
63
+ function getVersion() {
64
+ const pkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_DIR, 'package.json'), 'utf8'));
65
+ return pkg.version;
66
+ }
67
+
68
+ function downloadRelease(version) {
69
+ const platformKey = getPlatformKey();
70
+ const releasePlatform = PLATFORM_MAP[platformKey];
71
+
72
+ if (!releasePlatform) {
73
+ console.error(`Unsupported platform: ${platformKey}`);
74
+ console.error('Please download the binary manually from https://github.com/goboost/goboost/releases');
75
+ process.exit(0); // Don't fail install
76
+ }
77
+
78
+ const ext = ARCHIVE_EXT[platformKey];
79
+ const assetName = `goboost_${version}_${releasePlatform}${ext}`;
80
+ const url = `https://github.com/goboost/goboost/releases/download/v${version}/${assetName}`;
81
+
82
+ console.log(`Downloading goboost v${version} for ${platformKey}...`);
83
+ console.log(`URL: ${url}`);
84
+
85
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'goboost-'));
86
+ const tmpFile = path.join(tmpDir, assetName);
87
+
88
+ return new Promise((resolve, reject) => {
89
+ downloadFile(url, tmpFile, (err) => {
90
+ if (err) {
91
+ reject(err);
92
+ return;
93
+ }
94
+
95
+ try {
96
+ // Extract binary
97
+ if (ext === '.tar.gz') {
98
+ execSync(`tar xzf "${tmpFile}" -C "${tmpDir}"`, { stdio: 'pipe' });
99
+ } else if (ext === '.zip') {
100
+ // Use PowerShell on Windows
101
+ execSync(
102
+ `powershell -Command "Expand-Archive -Path '${tmpFile}' -DestinationPath '${tmpDir}' -Force"`,
103
+ { stdio: 'pipe' }
104
+ );
105
+ }
106
+
107
+ // Move binary to package directory
108
+ const extractedBinary = path.join(tmpDir, BINARY_NAME);
109
+ if (!fs.existsSync(extractedBinary)) {
110
+ reject(new Error(`Binary not found in archive: ${extractedBinary}`));
111
+ return;
112
+ }
113
+
114
+ fs.copyFileSync(extractedBinary, BINARY_PATH);
115
+ fs.chmodSync(BINARY_PATH, 0o755);
116
+
117
+ // Cleanup
118
+ fs.rmSync(tmpDir, { recursive: true, force: true });
119
+
120
+ console.log(`Successfully installed goboost v${version}`);
121
+ resolve();
122
+ } catch (extractErr) {
123
+ // Cleanup on error
124
+ try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch (e) { /* ignore */ }
125
+ reject(extractErr);
126
+ }
127
+ });
128
+ });
129
+ }
130
+
131
+ function downloadFile(url, dest, callback, redirectCount) {
132
+ redirectCount = redirectCount || 0;
133
+ if (redirectCount > 5) {
134
+ callback(new Error('Too many redirects'));
135
+ return;
136
+ }
137
+
138
+ const protocol = url.startsWith('https') ? https : require('http');
139
+ protocol.get(url, { headers: { 'User-Agent': 'goboost-installer' } }, (response) => {
140
+ // Handle redirects (GitHub releases redirect to S3)
141
+ if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
142
+ downloadFile(response.headers.location, dest, callback, redirectCount + 1);
143
+ return;
144
+ }
145
+
146
+ if (response.statusCode !== 200) {
147
+ callback(new Error(`Download failed with status ${response.statusCode}`));
148
+ return;
149
+ }
150
+
151
+ const file = fs.createWriteStream(dest);
152
+ response.pipe(file);
153
+ file.on('finish', () => {
154
+ file.close(callback);
155
+ });
156
+ file.on('error', (err) => {
157
+ fs.unlink(dest, () => {}); // Cleanup partial file
158
+ callback(err);
159
+ });
160
+ }).on('error', callback);
161
+ }
162
+
163
+ // Main
164
+ async function main() {
165
+ // Skip if binary already available via optionalDependency
166
+ if (binaryExists()) {
167
+ return;
168
+ }
169
+
170
+ const version = getVersion();
171
+ if (version === '0.0.0') {
172
+ // Development mode, skip download
173
+ console.log('goboost: development version, skipping binary download');
174
+ return;
175
+ }
176
+
177
+ try {
178
+ await downloadRelease(version);
179
+ } catch (err) {
180
+ console.error(`Warning: Failed to download goboost binary: ${err.message}`);
181
+ console.error('You can download it manually from https://github.com/goboost/goboost/releases');
182
+ // Don't fail the install
183
+ }
184
+ }
185
+
186
+ main();