@smbcloud / cli / commits / fbc31df

NPM package is scoped as @smbpndk/cli, but the command is smb. why not

Seto Elkahfi committed Apr 7, 2023 at 12:35 UTC fbc31df420b999e5e71147620f085ffc83bd1ced
3 files changed +24 -16
.github/workflows/release-npm.yml
+12 -6
@@ -77,9 +77,15 @@ jobs:
77 - name: Publish to NPM
78 shell: bash
79 run: |
80 + # We want to name our npm package @smbpndk/cli, but the main command is smb.
81 + # This is the tricky part. All the optional dependencies should follow the naming convention.
82 + # So, we will generate @smbpndk/cli-${matrix.build.TARGET}
83 +
84 + # Move to the npm directory
85 cd npm
81 - # set the binary name
82 - bin="smb"
86 + # set the binary name, this is from the rust Cargo.toml file
87 + cargo_bin="smb"
88 + node_pkg_prefix="cli"
89 # derive the OS and architecture from the build matrix name
90 # note: when split by a hyphen, first part is the OS and the second is the architecture
91 node_os=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f1)
@@ -91,9 +97,9 @@ jobs:
97 # set the package name
98 # note: use 'windows' as OS name instead of 'win32'
99 if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
94 - export node_pkg="${bin}-windows-${node_arch}"
100 + export node_pkg="${node_pkg_prefix}-windows-${node_arch}"
101 else
96 - export node_pkg="${bin}-${node_os}-${node_arch}"
102 + export node_pkg="${node_pkg_prefix}-${node_os}-${node_arch}"
103 fi
104 # create the package directory
105 mkdir -p "${node_pkg}/bin"
@@ -102,9 +108,9 @@ jobs:
108 # copy the binary into the package
109 # note: windows binaries has '.exe' extension
110 if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
105 - bin="${bin}.exe"
111 + cargo_bin="${cargo_bin}.exe"
112 fi
107 - cp "../target/${{ matrix.build.TARGET }}/release/${bin}" "${node_pkg}/bin"
113 + cp "../target/${{ matrix.build.TARGET }}/release/${cargo_bin}" "${node_pkg}/bin"
114 # publish the package
115 cd "${node_pkg}"
116 npm publish --access public
npm/smbpndk-cli/package.json
+9 -7
@@ -1,7 +1,9 @@
1 {
2 "name": "@smbpndk/cli",
3 "version": "0.1.0",
4 - "bin": "lib/index.js",
4 + "bin": {
5 + "smb": "lib/index.js"
6 + },
7 "description": "A CLI for accessing the SmbPndk platform.",
8 "license": "MIT",
9 "scripts": {
@@ -19,11 +21,11 @@
21 "typescript": "^4.9.4"
22 },
23 "optionalDependencies": {
22 - "app-darwin-arm64": "0.1.0",
23 - "app-darwin-x64": "0.1.0",
24 - "app-linux-arm64": "0.1.0",
25 - "app-linux-x64": "0.1.0",
26 - "app-windows-arm64": "0.1.0",
27 - "app-windows-x64": "0.1.0"
24 + "@smbpndk/cli-darwin-arm64": "0.1.0",
25 + "@smbpndk/cli-darwin-x64": "0.1.0",
26 + "@smbpndk/cli-linux-arm64": "0.1.0",
27 + "@smbpndk/cli-linux-x64": "0.1.0",
28 + "@smbpndk/cli-windows-arm64": "0.1.0",
29 + "@smbpndk/cli-windows-x64": "0.1.0"
30 }
31 }
\ No newline at end of file
npm/smbpndk-cli/src/index.ts
+3 -3
@@ -4,11 +4,11 @@ import { spawnSync } from "child_process";
4
5 /**
6 * Returns the executable path which is located inside `node_modules`
7 - * The naming convention is app-${os}-${arch}
7 + * The naming convention is cli-${os}-${arch}
8 * If the platform is `win32` or `cygwin`, executable will include a `.exe` extension.
9 * @see https://nodejs.org/api/os.html#osarch
10 * @see https://nodejs.org/api/os.html#osplatform
11 - * @example "x/xx/node_modules/app-darwin-arm64"
11 + * @example "x/xx/node_modules/cli-darwin-arm64"
12 */
13 function getExePath() {
14 const arch = process.arch;
@@ -21,7 +21,7 @@ function getExePath() {
21
22 try {
23 // Since the binary will be located inside `node_modules`, we can simply call `require.resolve`
24 - return require.resolve(`app-${os}-${arch}/bin/app${extension}`);
24 + return require.resolve(`cli-${os}-${arch}/bin/cli${extension}`);
25 } catch (e) {
26 throw new Error(
27 `Couldn't find application binary inside node_modules for ${os}-${arch}`