@scriptdb/cli 1.0.1 → 1.0.2

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 (2) hide show
  1. package/dist/index.js +122 -11
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
4
4
 
5
5
  // src/index.ts
6
6
  import { server } from "@scriptdb/server";
7
- import { spawn } from "child_process";
8
- import { existsSync, readFileSync, writeFileSync, unlinkSync } from "fs";
7
+ import { spawn, execSync } from "child_process";
8
+ import { existsSync, readFileSync, writeFileSync, unlinkSync, mkdirSync } from "fs";
9
9
  import { join } from "path";
10
10
  import { homedir } from "os";
11
11
 
@@ -504,9 +504,11 @@ Examples:
504
504
  }
505
505
 
506
506
  // src/index.ts
507
- var PID_FILE = join(homedir(), ".scriptdb", "scriptdb.pid");
508
- var LOG_FILE = join(homedir(), ".scriptdb", "scriptdb.log");
509
- var CONFIG_FILE = join(homedir(), ".scriptdb", "config.json");
507
+ var SCRIPTDB_DIR = join(homedir(), ".scriptdb");
508
+ var PID_FILE = join(SCRIPTDB_DIR, "scriptdb.pid");
509
+ var LOG_FILE = join(SCRIPTDB_DIR, "scriptdb.log");
510
+ var CONFIG_FILE = join(SCRIPTDB_DIR, "config.json");
511
+ var PACKAGE_JSON = join(SCRIPTDB_DIR, "package.json");
510
512
  async function main() {
511
513
  const args = process.argv.slice(2);
512
514
  const command = args[0];
@@ -523,6 +525,10 @@ async function main() {
523
525
  showLogs();
524
526
  } else if (command === "shell") {
525
527
  await shellCommand();
528
+ } else if (command === "add") {
529
+ await addCommand(args.slice(1));
530
+ } else if (command === "remove" || command === "rm") {
531
+ await removeCommand(args.slice(1));
526
532
  } else if (command === "help" || command === "--help" || command === "-h") {
527
533
  printHelp();
528
534
  } else if (command === "version" || command === "--version" || command === "-v") {
@@ -669,6 +675,105 @@ async function shellCommand() {
669
675
  }
670
676
  await startShell({ host, port, secure });
671
677
  }
678
+ async function addCommand(packages) {
679
+ if (packages.length === 0) {
680
+ console.error("Error: No package specified");
681
+ console.log("Usage: scriptdb add <package> [package2] [package3] ...");
682
+ console.log("");
683
+ console.log("Examples:");
684
+ console.log(" scriptdb add lodash # Install to ~/.scriptdb/packages");
685
+ console.log(" scriptdb add axios express # Install multiple packages");
686
+ console.log(" scriptdb add --local lodash # Install to current directory");
687
+ process.exit(1);
688
+ }
689
+ const isLocal = packages.includes("--local") || packages.includes("-l");
690
+ const pkgs = packages.filter((p) => !p.startsWith("-"));
691
+ if (pkgs.length === 0) {
692
+ console.error("Error: No package specified");
693
+ process.exit(1);
694
+ }
695
+ try {
696
+ let cwd;
697
+ if (isLocal) {
698
+ cwd = process.cwd();
699
+ console.log(`Installing ${pkgs.join(", ")} to current directory...`);
700
+ } else {
701
+ ensureScriptDBDir();
702
+ cwd = SCRIPTDB_DIR;
703
+ console.log(`Installing ${pkgs.join(", ")} to ScriptDB packages...`);
704
+ }
705
+ const cmd = "bun add " + pkgs.join(" ");
706
+ execSync(cmd, { stdio: "inherit", cwd });
707
+ if (isLocal) {
708
+ console.log(`✓ Successfully installed ${pkgs.join(", ")} locally`);
709
+ } else {
710
+ console.log(`✓ Successfully installed ${pkgs.join(", ")} to ~/.scriptdb/packages`);
711
+ }
712
+ } catch (error) {
713
+ console.error("Failed to install packages");
714
+ process.exit(1);
715
+ }
716
+ }
717
+ async function removeCommand(packages) {
718
+ if (packages.length === 0) {
719
+ console.error("Error: No package specified");
720
+ console.log("Usage: scriptdb remove <package> [package2] [package3] ...");
721
+ console.log(" scriptdb rm <package> [package2] [package3] ...");
722
+ console.log("");
723
+ console.log("Examples:");
724
+ console.log(" scriptdb remove lodash # Remove from ~/.scriptdb/packages");
725
+ console.log(" scriptdb rm axios express # Remove multiple packages");
726
+ console.log(" scriptdb remove --local lodash # Remove from current directory");
727
+ process.exit(1);
728
+ }
729
+ const isLocal = packages.includes("--local") || packages.includes("-l");
730
+ const pkgs = packages.filter((p) => !p.startsWith("-"));
731
+ if (pkgs.length === 0) {
732
+ console.error("Error: No package specified");
733
+ process.exit(1);
734
+ }
735
+ try {
736
+ let cwd;
737
+ if (isLocal) {
738
+ cwd = process.cwd();
739
+ console.log(`Removing ${pkgs.join(", ")} from current directory...`);
740
+ } else {
741
+ if (!existsSync(PACKAGE_JSON)) {
742
+ console.error("No ScriptDB packages found");
743
+ console.log('Run "scriptdb add <package>" first to install packages');
744
+ process.exit(1);
745
+ }
746
+ cwd = SCRIPTDB_DIR;
747
+ console.log(`Removing ${pkgs.join(", ")} from ScriptDB packages...`);
748
+ }
749
+ const cmd = "bun remove " + pkgs.join(" ");
750
+ execSync(cmd, { stdio: "inherit", cwd });
751
+ if (isLocal) {
752
+ console.log(`✓ Successfully removed ${pkgs.join(", ")} locally`);
753
+ } else {
754
+ console.log(`✓ Successfully removed ${pkgs.join(", ")} from ~/.scriptdb/packages`);
755
+ }
756
+ } catch (error) {
757
+ console.error("Failed to remove packages");
758
+ process.exit(1);
759
+ }
760
+ }
761
+ function ensureScriptDBDir() {
762
+ if (!existsSync(SCRIPTDB_DIR)) {
763
+ mkdirSync(SCRIPTDB_DIR, { recursive: true });
764
+ }
765
+ if (!existsSync(PACKAGE_JSON)) {
766
+ const packageJsonContent = {
767
+ name: "scriptdb-packages",
768
+ version: "1.0.0",
769
+ description: "ScriptDB user packages",
770
+ private: true,
771
+ dependencies: {}
772
+ };
773
+ writeFileSync(PACKAGE_JSON, JSON.stringify(packageJsonContent, null, 2));
774
+ console.log("Created ~/.scriptdb/package.json");
775
+ }
776
+ }
672
777
  async function isServerRunning() {
673
778
  const pid = getPid();
674
779
  if (!pid)
@@ -717,16 +822,22 @@ Commands:
717
822
  status Check server status
718
823
  logs Show server logs
719
824
  shell Start interactive shell (requires server running)
825
+ add Install packages to ~/.scriptdb/packages
826
+ remove, rm Remove packages from ~/.scriptdb/packages
720
827
  help Show this help message
721
828
  version Show version information
722
829
 
723
830
  Examples:
724
- scriptdb start -d Start server in background
725
- scriptdb status Check if server is running
726
- scriptdb shell Start interactive shell
727
- scriptdb stop Stop the server
728
- scriptdb restart -d Restart in background
729
- scriptdb logs View server logs
831
+ scriptdb start -d Start server in background
832
+ scriptdb status Check if server is running
833
+ scriptdb shell Start interactive shell
834
+ scriptdb stop Stop the server
835
+ scriptdb restart -d Restart in background
836
+ scriptdb logs View server logs
837
+ scriptdb add lodash Install package to ScriptDB
838
+ scriptdb add axios express Install multiple packages
839
+ scriptdb add --local lodash Install to current directory
840
+ scriptdb remove lodash Remove package from ScriptDB
730
841
 
731
842
  Configuration:
732
843
  Configuration file: ~/.scriptdb/config.json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scriptdb/cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "CLI tool to start and manage ScriptDB server",
5
5
  "type": "module",
6
6
  "bin": {
@@ -38,8 +38,8 @@
38
38
  "typescript": "^5.0.0"
39
39
  },
40
40
  "dependencies": {
41
- "@scriptdb/server": "^1.0.1",
42
- "@scriptdb/client": "^1.0.1",
41
+ "@scriptdb/server": "^1.0.2",
42
+ "@scriptdb/client": "^1.0.2",
43
43
  "ps-list": "^9.0.0"
44
44
  }
45
45
  }