@softpractice/softpractice-cli 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Arthur Sultanbekov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Softpractice CLI npm installer
2
+
3
+ This package is a launcher for the native Softpractice CLI. During installation
4
+ it downloads the GoReleaser archive with the same version from the GitHub
5
+ Release, verifies it against `checksums.txt`, and installs the `softpractice`
6
+ command.
7
+
8
+ ```bash
9
+ npm install -g @softpractice/softpractice-cli
10
+ softpractice --help
11
+ ```
12
+
13
+ The installer supports macOS, Linux, and Windows on `arm64` and `x64`. It
14
+ requires Node.js 18 or newer and access to GitHub Releases. Installation with
15
+ `--ignore-scripts` is unsupported because npm would not download the native
16
+ binary.
17
+
18
+ ## Manual release
19
+
20
+ The npm version must equal the GitHub release version without its `v` prefix.
21
+ For example, npm `0.1.0` installs artifacts from GitHub Release `v0.1.0`.
22
+
23
+ 1. Update the `version` in this directory's `package.json`.
24
+ 2. Commit it and create the matching Git tag, for example `v0.1.0`.
25
+ 3. Run `goreleaser release --clean` from the repository root and confirm that
26
+ the GitHub Release contains all platform archives and `checksums.txt`.
27
+ 4. From this directory, run `npm install`, `npm test`, and `npm pack --dry-run`.
28
+ 5. Authenticate once with `npm login`, then publish with:
29
+
30
+ ```bash
31
+ npm publish --access public
32
+ ```
33
+
34
+ 6. In an empty temporary directory, verify the published package:
35
+
36
+ ```bash
37
+ npm install -g @softpractice/softpractice-cli@0.1.0
38
+ softpractice --help
39
+ ```
40
+
41
+ Do not publish the npm package before its matching GitHub Release exists.
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { existsSync } = require("node:fs");
6
+ const { spawnSync } = require("node:child_process");
7
+ const { binaryPath } = require("../lib/platform");
8
+
9
+ const executable = binaryPath();
10
+
11
+ if (!existsSync(executable)) {
12
+ console.error(
13
+ "softpractice: the native binary is missing. Reinstall @softpractice/softpractice-cli without --ignore-scripts.",
14
+ );
15
+ process.exit(1);
16
+ }
17
+
18
+ const result = spawnSync(executable, process.argv.slice(2), { stdio: "inherit" });
19
+ if (result.error) {
20
+ console.error(`softpractice: could not start native binary: ${result.error.message}`);
21
+ process.exit(1);
22
+ }
23
+ process.exit(result.status === null ? 1 : result.status);
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ const path = require("node:path");
4
+
5
+ const platforms = {
6
+ darwin: "Darwin",
7
+ linux: "Linux",
8
+ win32: "Windows",
9
+ };
10
+
11
+ const architectures = {
12
+ arm64: "arm64",
13
+ x64: "x86_64",
14
+ };
15
+
16
+ function releaseArtifact(platform = process.platform, architecture = process.arch) {
17
+ const os = platforms[platform];
18
+ const arch = architectures[architecture];
19
+ if (!os || !arch) {
20
+ throw new Error(`unsupported platform: ${platform}/${architecture}`);
21
+ }
22
+
23
+ const extension = platform === "win32" ? "zip" : "tar.gz";
24
+ return {
25
+ filename: `softpractice-cli_${os}_${arch}.${extension}`,
26
+ executable: platform === "win32" ? "softpractice.exe" : "softpractice",
27
+ };
28
+ }
29
+
30
+ function binaryPath(packageRoot = path.resolve(__dirname, "..")) {
31
+ return path.join(packageRoot, "dist", releaseArtifact().executable);
32
+ }
33
+
34
+ module.exports = { binaryPath, releaseArtifact };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@softpractice/softpractice-cli",
3
+ "version": "0.1.0",
4
+ "description": "Cross-platform command-line companion for a Softpractice learning workspace",
5
+ "license": "MIT",
6
+ "author": "Arthur Sultanbekov",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/arthur-s/softpractice-cli.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/arthur-s/softpractice-cli/issues"
13
+ },
14
+ "homepage": "https://github.com/arthur-s/softpractice-cli#readme",
15
+ "bin": {
16
+ "softpractice": "bin/softpractice.js"
17
+ },
18
+ "scripts": {
19
+ "postinstall": "node scripts/install.js",
20
+ "test": "node --test test/**/*.test.js",
21
+ "pack:dry-run": "npm pack --dry-run"
22
+ },
23
+ "files": [
24
+ "bin",
25
+ "scripts",
26
+ "lib",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "dependencies": {
34
+ "adm-zip": "^0.6.1",
35
+ "tar": "^7.4.3"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ const crypto = require("node:crypto");
4
+ const fs = require("node:fs/promises");
5
+ const os = require("node:os");
6
+ const path = require("node:path");
7
+ const AdmZip = require("adm-zip");
8
+ const tar = require("tar");
9
+ const { releaseArtifact } = require("../lib/platform");
10
+
11
+ const packageRoot = path.resolve(__dirname, "..");
12
+ const packageInfo = require(path.join(packageRoot, "package.json"));
13
+ const repository = "https://github.com/arthur-s/softpractice-cli";
14
+
15
+ async function download(url) {
16
+ const response = await fetch(url);
17
+ if (!response.ok) {
18
+ throw new Error(`download ${url}: HTTP ${response.status}`);
19
+ }
20
+ return Buffer.from(await response.arrayBuffer());
21
+ }
22
+
23
+ function expectedChecksum(checksums, filename) {
24
+ const escapedFilename = filename.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
25
+ const match = checksums.match(new RegExp(`^([a-fA-F0-9]{64})\\s+\\*?${escapedFilename}$`, "m"));
26
+ if (!match) {
27
+ throw new Error(`checksum for ${filename} is absent from checksums.txt`);
28
+ }
29
+ return match[1].toLowerCase();
30
+ }
31
+
32
+ async function extract(archive, artifact, directory) {
33
+ const archivePath = path.join(directory, artifact.filename);
34
+ await fs.writeFile(archivePath, archive);
35
+ if (artifact.filename.endsWith(".zip")) {
36
+ new AdmZip(archivePath).extractAllTo(directory, true);
37
+ return;
38
+ }
39
+ await tar.x({ file: archivePath, cwd: directory, strict: true });
40
+ }
41
+
42
+ async function install() {
43
+ const artifact = releaseArtifact();
44
+ const tag = `v${packageInfo.version}`;
45
+ const releaseURL = `${repository}/releases/download/${tag}`;
46
+ const [archive, checksums] = await Promise.all([
47
+ download(`${releaseURL}/${artifact.filename}`),
48
+ download(`${releaseURL}/checksums.txt`),
49
+ ]);
50
+ const actualChecksum = crypto.createHash("sha256").update(archive).digest("hex");
51
+ if (actualChecksum !== expectedChecksum(checksums.toString("utf8"), artifact.filename)) {
52
+ throw new Error(`checksum mismatch for ${artifact.filename}`);
53
+ }
54
+
55
+ const temporaryDirectory = await fs.mkdtemp(path.join(os.tmpdir(), "softpractice-npm-"));
56
+ try {
57
+ await extract(archive, artifact, temporaryDirectory);
58
+ const source = path.join(temporaryDirectory, artifact.executable);
59
+ const destinationDirectory = path.join(packageRoot, "dist");
60
+ const destination = path.join(destinationDirectory, artifact.executable);
61
+ await fs.access(source);
62
+ await fs.rm(destinationDirectory, { recursive: true, force: true });
63
+ await fs.mkdir(destinationDirectory, { recursive: true });
64
+ await fs.copyFile(source, destination);
65
+ if (process.platform !== "win32") {
66
+ await fs.chmod(destination, 0o755);
67
+ }
68
+ console.log(`Installed Softpractice CLI ${packageInfo.version} for ${process.platform}/${process.arch}.`);
69
+ } finally {
70
+ await fs.rm(temporaryDirectory, { recursive: true, force: true });
71
+ }
72
+ }
73
+
74
+ install().catch((error) => {
75
+ console.error(`softpractice install: ${error.message}`);
76
+ process.exitCode = 1;
77
+ });