@icp-sdk/icp-cli 0.1.0-beta.4

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/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # @icp-sdk/icp-cli
2
+
3
+ npm package for [icp-cli](https://github.com/dfinity/icp-cli) with pre-compiled binaries.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @icp-sdk/icp-cli
9
+ ```
10
+
11
+ ### Linux Users
12
+
13
+ On Linux, you may need to install system dependencies first:
14
+
15
+ ```bash
16
+ # Ubuntu/Debian
17
+ sudo apt-get update
18
+ sudo apt-get install -y libdbus-1-3 libssl3 ca-certificates
19
+
20
+ # Fedora/RHEL
21
+ sudo dnf install -y dbus-libs openssl ca-certificates
22
+ ```
23
+
24
+ Then install icp-cli:
25
+
26
+ ```bash
27
+ npm install -g @icp-sdk/icp-cli
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```bash
33
+ icp --help
34
+ icp --version
35
+ ```
36
+
37
+ ## How it Works
38
+
39
+ This package uses platform-specific optional dependencies to install the correct pre-compiled binary for your system. The binary is ready to use immediately after installation - no additional downloads required.
40
+
41
+ ### Supported Platforms
42
+
43
+ - macOS ARM64 (Apple Silicon)
44
+ - macOS x64 (Intel)
45
+ - Linux ARM64
46
+ - Linux x64
47
+ - Windows x64
48
+
49
+ ### Programmatic Usage
50
+
51
+ ```javascript
52
+ const icp = require('@icp-sdk/icp-cli');
53
+
54
+ console.log('icp binary location:', icp.binaryPath);
55
+ console.log('icp version:', icp.version);
56
+ ```
package/bin/icp.js ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ /**
8
+ * Find the platform-specific binary
9
+ */
10
+ function findBinary() {
11
+ const platform = process.platform;
12
+ const arch = process.arch;
13
+
14
+ // Map Node.js platform/arch to package names
15
+ const platformMap = {
16
+ 'darwin-arm64': '@icp-sdk/icp-cli-darwin-arm64',
17
+ 'darwin-x64': '@icp-sdk/icp-cli-darwin-x64',
18
+ 'linux-arm64': '@icp-sdk/icp-cli-linux-arm64',
19
+ 'linux-x64': '@icp-sdk/icp-cli-linux-x64',
20
+ 'win32-x64': '@icp-sdk/icp-cli-win32-x64'
21
+ };
22
+
23
+ const key = `${platform}-${arch}`;
24
+ const packageName = platformMap[key];
25
+
26
+ if (!packageName) {
27
+ console.error(`Unsupported platform: ${platform}-${arch}`);
28
+ console.error(`Supported platforms: ${Object.keys(platformMap).join(', ')}`);
29
+ process.exit(1);
30
+ }
31
+
32
+ // Try to find the binary in node_modules
33
+ const binaryName = platform === 'win32' ? 'icp.exe' : 'icp';
34
+ const possiblePaths = [
35
+ // When installed globally (scoped packages are siblings)
36
+ path.join(__dirname, '..', '..', '..', packageName, 'bin', binaryName),
37
+ // When installed locally
38
+ path.join(__dirname, '..', 'node_modules', packageName, 'bin', binaryName),
39
+ // Alternative local path
40
+ path.join(process.cwd(), 'node_modules', packageName, 'bin', binaryName)
41
+ ];
42
+
43
+ for (const binaryPath of possiblePaths) {
44
+ if (fs.existsSync(binaryPath)) {
45
+ return binaryPath;
46
+ }
47
+ }
48
+
49
+ console.error(`Could not find icp binary for ${platform}-${arch}`);
50
+ console.error(`Package ${packageName} may not have installed correctly.`);
51
+ console.error(`Searched paths: ${possiblePaths.join(', ')}`);
52
+ process.exit(1);
53
+ }
54
+
55
+ /**
56
+ * Execute the binary with all arguments
57
+ */
58
+ function run() {
59
+ const binaryPath = findBinary();
60
+ const args = process.argv.slice(2);
61
+
62
+ const child = spawn(binaryPath, args, {
63
+ stdio: 'inherit'
64
+ });
65
+
66
+ child.on('exit', (code) => {
67
+ process.exit(code);
68
+ });
69
+
70
+ child.on('error', (err) => {
71
+ console.error('Error executing icp:', err.message);
72
+ process.exit(1);
73
+ });
74
+ }
75
+
76
+ run();
package/index.js ADDED
@@ -0,0 +1,52 @@
1
+ // Main entry point for programmatic usage
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+ const platform = process.platform;
6
+ const arch = process.arch;
7
+
8
+ const platformMap = {
9
+ 'darwin-arm64': '@icp-sdk/icp-cli-darwin-arm64',
10
+ 'darwin-x64': '@icp-sdk/icp-cli-darwin-x64',
11
+ 'linux-arm64': '@icp-sdk/icp-cli-linux-arm64',
12
+ 'linux-x64': '@icp-sdk/icp-cli-linux-x64',
13
+ 'win32-x64': '@icp-sdk/icp-cli-win32-x64'
14
+ };
15
+
16
+ const key = `${platform}-${arch}`;
17
+ const packageName = platformMap[key];
18
+
19
+ function getBinaryPath() {
20
+ if (!packageName) {
21
+ throw new Error(`Unsupported platform: ${platform}-${arch}`);
22
+ }
23
+
24
+ try {
25
+ const platformPackage = require(packageName);
26
+ if (platformPackage.binaryPath && fs.existsSync(platformPackage.binaryPath)) {
27
+ return platformPackage.binaryPath;
28
+ }
29
+ } catch (err) {
30
+ // Package not installed or not found
31
+ }
32
+
33
+ throw new Error(`Could not find icp binary for ${platform}-${arch}. Make sure the platform-specific package ${packageName} is installed.`);
34
+ }
35
+
36
+ // Cache the binary path once found
37
+ let cachedBinaryPath = null;
38
+
39
+ module.exports = {
40
+ version: require('./package.json').version,
41
+
42
+ // Lazy-load binary path using a getter
43
+ get binaryPath() {
44
+ if (cachedBinaryPath === null) {
45
+ cachedBinaryPath = getBinaryPath();
46
+ }
47
+ return cachedBinaryPath;
48
+ },
49
+
50
+ // Also export the function for manual control
51
+ getBinaryPath: getBinaryPath
52
+ };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@icp-sdk/icp-cli",
3
+ "version": "0.1.0-beta.4",
4
+ "description": "npm wrapper for icp-cli - Internet Computer Protocol command-line interface",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "icp": "./bin/icp.js"
8
+ },
9
+ "scripts": {
10
+ "test": "node test.js",
11
+ "postinstall": "node postinstall.js"
12
+ },
13
+ "keywords": [
14
+ "icp",
15
+ "internet-computer",
16
+ "blockchain"
17
+ ],
18
+ "author": "",
19
+ "license": "Apache-2.0",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/dfinity/icp-cli.git",
23
+ "directory": "npm/icp-cli"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/dfinity/icp-cli/issues"
27
+ },
28
+ "homepage": "https://github.com/dfinity/icp-cli#readme",
29
+ "engines": {
30
+ "node": ">=18.0.0"
31
+ },
32
+ "optionalDependencies": {
33
+ "@icp-sdk/icp-cli-darwin-arm64": "0.1.0-beta.4",
34
+ "@icp-sdk/icp-cli-darwin-x64": "0.1.0-beta.4",
35
+ "@icp-sdk/icp-cli-linux-arm64": "0.1.0-beta.4",
36
+ "@icp-sdk/icp-cli-linux-x64": "0.1.0-beta.4",
37
+ "@icp-sdk/icp-cli-win32-x64": "0.1.0-beta.4"
38
+ }
39
+ }
package/postinstall.js ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Post-install script to verify binary installation
5
+ */
6
+
7
+ const fs = require('fs');
8
+ const path = require('path');
9
+
10
+ const platform = process.platform;
11
+ const arch = process.arch;
12
+
13
+ const platformMap = {
14
+ 'darwin-arm64': '@icp-sdk/icp-cli-darwin-arm64',
15
+ 'darwin-x64': '@icp-sdk/icp-cli-darwin-x64',
16
+ 'linux-arm64': '@icp-sdk/icp-cli-linux-arm64',
17
+ 'linux-x64': '@icp-sdk/icp-cli-linux-x64',
18
+ 'win32-x64': '@icp-sdk/icp-cli-win32-x64'
19
+ };
20
+
21
+ const key = `${platform}-${arch}`;
22
+ const packageName = platformMap[key];
23
+
24
+ if (!packageName) {
25
+ console.log(`
26
+ ╔═══════════════════════════════════════════════════════════╗
27
+ ║ ║
28
+ ║ WARNING: Unsupported platform: ${platform}-${arch.padEnd(17)}║
29
+ ║ ║
30
+ ║ Supported platforms: ║
31
+ ║ - macOS ARM64 (Apple Silicon) ║
32
+ ║ - macOS x64 (Intel) ║
33
+ ║ - Linux ARM64 ║
34
+ ║ - Linux x64 ║
35
+ ║ - Windows x64 ║
36
+ ║ ║
37
+ ╚═══════════════════════════════════════════════════════════╝
38
+ `);
39
+ process.exit(0); // Don't fail the install
40
+ }
41
+
42
+ // Try to find and verify the binary
43
+ try {
44
+ const platformPackage = require(packageName);
45
+ const binaryPath = platformPackage.binaryPath;
46
+
47
+ if (binaryPath && fs.existsSync(binaryPath)) {
48
+ // Ensure binary has execute permissions (important for Docker/CI)
49
+ try {
50
+ fs.chmodSync(binaryPath, 0o755);
51
+ } catch (err) {
52
+ // Ignore permission errors - might not have rights to chmod
53
+ }
54
+
55
+ console.log(`
56
+ ╔═══════════════════════════════════════════════════════════╗
57
+ ║ ║
58
+ ║ icp-cli installed successfully! ║
59
+ ║ ║
60
+ ║ Platform: ${key.padEnd(44)}║
61
+ ║ ║
62
+ ║ Usage: ║
63
+ ║ $ icp --help ║
64
+ ║ ║
65
+ ╚═══════════════════════════════════════════════════════════╝
66
+ `);
67
+ } else {
68
+ console.log(`
69
+ ╔═══════════════════════════════════════════════════════════╗
70
+ ║ ║
71
+ ║ WARNING: Binary not found ║
72
+ ║ ║
73
+ ║ Platform: ${key.padEnd(44)}║
74
+ ║ Package: ${packageName.padEnd(45)}║
75
+ ║ ║
76
+ ║ The platform-specific package may not have installed ║
77
+ ║ correctly. Try reinstalling: ║
78
+ ║ $ npm install --force ║
79
+ ║ ║
80
+ ╚═══════════════════════════════════════════════════════════╝
81
+ `);
82
+ }
83
+ } catch (err) {
84
+ console.log(`
85
+ ╔═══════════════════════════════════════════════════════════╗
86
+ ║ ║
87
+ ║ WARNING: Platform package not found ║
88
+ ║ ║
89
+ ║ Platform: ${key.padEnd(44)}║
90
+ ║ Package: ${packageName.padEnd(45)}║
91
+ ║ ║
92
+ ║ The platform-specific package may not have installed ║
93
+ ║ correctly. Try reinstalling: ║
94
+ ║ $ npm install --force ║
95
+ ║ ║
96
+ ╚═══════════════════════════════════════════════════════════╝
97
+ `);
98
+ }