@dockflow-tools/cli 2.0.20

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/install.js +121 -0
  2. package/package.json +39 -0
  3. package/run.js +45 -0
package/install.js ADDED
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Dockflow CLI - Binary installer (postinstall)
5
+ *
6
+ * Downloads the correct pre-compiled binary from GitHub Releases
7
+ * based on the current platform and architecture.
8
+ *
9
+ * Zero dependencies - uses only Node.js built-ins.
10
+ */
11
+
12
+ const { createWriteStream, mkdirSync, chmodSync, existsSync, readFileSync } = require('fs');
13
+ const { join, dirname } = require('path');
14
+ const https = require('https');
15
+ const http = require('http');
16
+
17
+ const REPO = 'Shawiizz/dockflow';
18
+
19
+ const PLATFORM_MAP = {
20
+ linux: 'linux',
21
+ darwin: 'macos',
22
+ win32: 'windows',
23
+ };
24
+
25
+ const ARCH_MAP = {
26
+ x64: 'x64',
27
+ arm64: 'arm64',
28
+ };
29
+
30
+ function getVersion() {
31
+ const pkg = JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf8'));
32
+ return pkg.version;
33
+ }
34
+
35
+ function getBinaryName() {
36
+ const platform = PLATFORM_MAP[process.platform];
37
+ const arch = ARCH_MAP[process.arch];
38
+
39
+ if (!platform) {
40
+ throw new Error(`Unsupported platform: ${process.platform}. Supported: linux, darwin, win32`);
41
+ }
42
+ if (!arch) {
43
+ throw new Error(`Unsupported architecture: ${process.arch}. Supported: x64, arm64`);
44
+ }
45
+
46
+ const name = `dockflow-${platform}-${arch}`;
47
+ return process.platform === 'win32' ? `${name}.exe` : name;
48
+ }
49
+
50
+ function getBinaryPath() {
51
+ const binDir = join(__dirname, 'bin');
52
+ const ext = process.platform === 'win32' ? '.exe' : '';
53
+ return join(binDir, `dockflow${ext}`);
54
+ }
55
+
56
+ function download(url) {
57
+ return new Promise((resolve, reject) => {
58
+ const client = url.startsWith('https') ? https : http;
59
+
60
+ client.get(url, { headers: { 'User-Agent': 'dockflow-npm-installer' } }, (res) => {
61
+ // Follow redirects (GitHub releases redirect to S3)
62
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
63
+ return download(res.headers.location).then(resolve, reject);
64
+ }
65
+
66
+ if (res.statusCode !== 200) {
67
+ reject(new Error(`Download failed: HTTP ${res.statusCode} from ${url}`));
68
+ return;
69
+ }
70
+
71
+ const binaryPath = getBinaryPath();
72
+ mkdirSync(dirname(binaryPath), { recursive: true });
73
+
74
+ const file = createWriteStream(binaryPath);
75
+ res.pipe(file);
76
+
77
+ file.on('finish', () => {
78
+ file.close(() => {
79
+ // Make executable on Unix
80
+ if (process.platform !== 'win32') {
81
+ chmodSync(binaryPath, 0o755);
82
+ }
83
+ resolve(binaryPath);
84
+ });
85
+ });
86
+
87
+ file.on('error', (err) => {
88
+ reject(err);
89
+ });
90
+ }).on('error', reject);
91
+ });
92
+ }
93
+
94
+ async function main() {
95
+ const binaryPath = getBinaryPath();
96
+
97
+ // Skip if binary already exists (e.g. re-running postinstall)
98
+ if (existsSync(binaryPath)) {
99
+ return;
100
+ }
101
+
102
+ const version = getVersion();
103
+ const binaryName = getBinaryName();
104
+ const url = `https://github.com/${REPO}/releases/download/${version}/${binaryName}`;
105
+
106
+ console.log(`Downloading Dockflow CLI v${version} (${binaryName})...`);
107
+
108
+ try {
109
+ const path = await download(url);
110
+ console.log(`Dockflow CLI installed to ${path}`);
111
+ } catch (err) {
112
+ console.error(`\nFailed to download Dockflow CLI binary.`);
113
+ console.error(`URL: ${url}`);
114
+ console.error(`Error: ${err.message}`);
115
+ console.error(`\nYou can install manually:`);
116
+ console.error(` curl -fsSL https://raw.githubusercontent.com/${REPO}/main/install.sh | bash`);
117
+ process.exit(1);
118
+ }
119
+ }
120
+
121
+ main();
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@dockflow-tools/cli",
3
+ "version": "2.0.20",
4
+ "description": "Dockflow CLI - Deploy Docker applications with confidence using Docker Swarm",
5
+ "bin": {
6
+ "dockflow": "run.js"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js"
10
+ },
11
+ "files": [
12
+ "install.js",
13
+ "run.js",
14
+ "bin/"
15
+ ],
16
+ "keywords": [
17
+ "dockflow",
18
+ "docker",
19
+ "swarm",
20
+ "deployment",
21
+ "cli",
22
+ "devops"
23
+ ],
24
+ "os": [
25
+ "linux",
26
+ "darwin",
27
+ "win32"
28
+ ],
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "license": "MIT",
33
+ "author": "Shawiizz",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/Shawiizz/dockflow"
37
+ },
38
+ "homepage": "https://dockflow.shawiizz.dev"
39
+ }
package/run.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Dockflow CLI - Binary runner (bin entry)
5
+ *
6
+ * Locates the downloaded binary and executes it,
7
+ * forwarding all arguments and exit code.
8
+ */
9
+
10
+ const { execFileSync } = require('child_process');
11
+ const { existsSync } = require('fs');
12
+ const { join } = require('path');
13
+
14
+ function getBinaryPath() {
15
+ const ext = process.platform === 'win32' ? '.exe' : '';
16
+ return join(__dirname, 'bin', `dockflow${ext}`);
17
+ }
18
+
19
+ function main() {
20
+ const binaryPath = getBinaryPath();
21
+
22
+ if (!existsSync(binaryPath)) {
23
+ // Binary not found — run installer (handles npx or skipped postinstall)
24
+ console.log('Dockflow binary not found, downloading...');
25
+ try {
26
+ execFileSync(process.execPath, [join(__dirname, 'install.js')], { stdio: 'inherit' });
27
+ } catch {
28
+ process.exit(1);
29
+ }
30
+
31
+ if (!existsSync(binaryPath)) {
32
+ console.error('Failed to install Dockflow binary. Run "node install.js" manually.');
33
+ process.exit(1);
34
+ }
35
+ }
36
+
37
+ try {
38
+ execFileSync(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
39
+ } catch (err) {
40
+ // Forward the exit code from the binary
41
+ process.exit(err.status ?? 1);
42
+ }
43
+ }
44
+
45
+ main();