@scriptdb/cli 1.0.1 → 1.0.3

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 +133 -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,116 @@ 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-workspace",
768
+ version: "1.0.3",
769
+ description: "ScriptDB workspace for custom scripts, services, and databases",
770
+ private: true,
771
+ devDependencies: {
772
+ "@types/bun": "^1.3.2",
773
+ "@types/node": "^20.0.0",
774
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
775
+ "@typescript-eslint/parser": "^6.0.0",
776
+ "bun-types": "latest",
777
+ eslint: "^8.0.0",
778
+ typescript: "^5.0.0"
779
+ },
780
+ dependencies: {
781
+ lodash: "^4.17.21"
782
+ }
783
+ };
784
+ writeFileSync(PACKAGE_JSON, JSON.stringify(packageJsonContent, null, 2));
785
+ console.log("Created ~/.scriptdb/package.json");
786
+ }
787
+ }
672
788
  async function isServerRunning() {
673
789
  const pid = getPid();
674
790
  if (!pid)
@@ -717,16 +833,22 @@ Commands:
717
833
  status Check server status
718
834
  logs Show server logs
719
835
  shell Start interactive shell (requires server running)
836
+ add Install packages to ~/.scriptdb/packages
837
+ remove, rm Remove packages from ~/.scriptdb/packages
720
838
  help Show this help message
721
839
  version Show version information
722
840
 
723
841
  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
842
+ scriptdb start -d Start server in background
843
+ scriptdb status Check if server is running
844
+ scriptdb shell Start interactive shell
845
+ scriptdb stop Stop the server
846
+ scriptdb restart -d Restart in background
847
+ scriptdb logs View server logs
848
+ scriptdb add lodash Install package to ScriptDB
849
+ scriptdb add axios express Install multiple packages
850
+ scriptdb add --local lodash Install to current directory
851
+ scriptdb remove lodash Remove package from ScriptDB
730
852
 
731
853
  Configuration:
732
854
  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.3",
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.3",
42
+ "@scriptdb/client": "^1.0.3",
43
43
  "ps-list": "^9.0.0"
44
44
  }
45
45
  }