@saws/cli 2.0.0-beta.2 → 2.0.0-beta.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 (73) hide show
  1. package/README.md +96 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/bin/saws.d.ts +0 -1
  4. package/dist/bin/saws.js +28 -40
  5. package/dist/commands/deploy/command.d.ts +2 -7
  6. package/dist/commands/deploy/command.js +13 -19
  7. package/dist/commands/deploy/index.d.ts +0 -1
  8. package/dist/commands/deploy/index.js +1 -4
  9. package/dist/commands/dev/command.d.ts +1 -7
  10. package/dist/commands/dev/command.js +46 -48
  11. package/dist/commands/dev/index.d.ts +0 -1
  12. package/dist/commands/dev/index.js +1 -6
  13. package/dist/commands/dev/tui/dev-tui.d.ts +18 -3
  14. package/dist/commands/dev/tui/dev-tui.js +263 -29
  15. package/dist/commands/host/command.d.ts +2 -2
  16. package/dist/commands/host/command.js +130 -7
  17. package/dist/commands/host/index.d.ts +0 -1
  18. package/dist/commands/host/index.js +4 -3
  19. package/dist/commands/init/command.d.ts +1 -7
  20. package/dist/commands/init/command.js +24 -15
  21. package/dist/commands/init/index.d.ts +0 -1
  22. package/dist/commands/init/index.js +1 -5
  23. package/dist/commands/init/templates/gitignore.template.d.ts +1 -0
  24. package/dist/commands/init/templates/gitignore.template.js +4 -0
  25. package/dist/commands/init/templates/saws-ts.template.d.ts +3 -0
  26. package/dist/commands/init/templates/saws-ts.template.js +7 -0
  27. package/dist/commands/init/templates/tsconfig-json.template.d.ts +1 -0
  28. package/dist/commands/init/templates/tsconfig-json.template.js +4 -0
  29. package/dist/commands/secrets/command.d.ts +2 -2
  30. package/dist/commands/secrets/command.js +21 -9
  31. package/dist/commands/secrets/index.d.ts +0 -1
  32. package/dist/commands/secrets/index.js +7 -5
  33. package/dist/hosts.d.ts +1 -3
  34. package/dist/hosts.js +11 -10
  35. package/package.json +8 -25
  36. package/src/bin/saws.ts +59 -0
  37. package/src/commands/deploy/command.ts +20 -0
  38. package/src/commands/deploy/index.ts +8 -0
  39. package/src/commands/dev/command.ts +68 -0
  40. package/src/commands/dev/index.ts +5 -0
  41. package/src/commands/dev/tui/dev-tui.ts +471 -0
  42. package/src/commands/execute/command.ts.tmp +43 -0
  43. package/src/commands/execute/index.ts.tmp +9 -0
  44. package/src/commands/host/command.ts +188 -0
  45. package/src/commands/host/index.ts +18 -0
  46. package/src/commands/init/command.ts +28 -0
  47. package/src/commands/init/index.ts +8 -0
  48. package/src/commands/init/templates/gitignore.template.ts +4 -0
  49. package/src/commands/init/templates/saws-ts.template.ts +8 -0
  50. package/src/commands/init/templates/tsconfig-json.template.ts +4 -0
  51. package/src/commands/secrets/command.ts +42 -0
  52. package/src/commands/secrets/index.ts +13 -0
  53. package/src/hosts.ts +21 -0
  54. package/tsconfig.json +9 -0
  55. package/dist/bin/saws.d.ts.map +0 -1
  56. package/dist/commands/deploy/command.d.ts.map +0 -1
  57. package/dist/commands/deploy/index.d.ts.map +0 -1
  58. package/dist/commands/dev/command.d.ts.map +0 -1
  59. package/dist/commands/dev/index.d.ts.map +0 -1
  60. package/dist/commands/dev/tui/dev-tui.d.ts.map +0 -1
  61. package/dist/commands/host/command.d.ts.map +0 -1
  62. package/dist/commands/host/command.test.d.ts +0 -2
  63. package/dist/commands/host/command.test.d.ts.map +0 -1
  64. package/dist/commands/host/command.test.js +0 -13
  65. package/dist/commands/host/index.d.ts.map +0 -1
  66. package/dist/commands/init/command.d.ts.map +0 -1
  67. package/dist/commands/init/command.test.d.ts +0 -2
  68. package/dist/commands/init/command.test.d.ts.map +0 -1
  69. package/dist/commands/init/command.test.js +0 -40
  70. package/dist/commands/init/index.d.ts.map +0 -1
  71. package/dist/commands/secrets/command.d.ts.map +0 -1
  72. package/dist/commands/secrets/index.d.ts.map +0 -1
  73. package/dist/hosts.d.ts.map +0 -1
@@ -0,0 +1,18 @@
1
+ import { Command } from "commander";
2
+ import { configureHostCommand } from "./command.js";
3
+
4
+ export const createCommand = () =>
5
+ new Command("host")
6
+ .description("configure deployment hosts")
7
+ .addCommand(
8
+ new Command("configure")
9
+ .description("bootstrap a deployment user and apply host security policy")
10
+ .argument("[name]", "host name; optional when exactly one host exists")
11
+ .requiredOption(
12
+ "--user <bootstrap-user>",
13
+ "existing SSH account used for initial configuration",
14
+ )
15
+ .option("--config <path>", "path to saws.ts")
16
+ .option("--dry-run", "describe configuration without making changes")
17
+ .action(configureHostCommand),
18
+ );
@@ -0,0 +1,28 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs/promises";
3
+ import { findServiceDefinition, getSawsConfig } from "@saws/core";
4
+ import { installDependencies } from "@saws/core/utils/dependency-management";
5
+ import { createFileIfNotExists } from "@saws/core/utils/create-file-if-not-exists";
6
+ import { sawsTsTemplate } from "./templates/saws-ts.template.js";
7
+ import { tsconfigJsonTemplate } from "./templates/tsconfig-json.template.js";
8
+ import { gitignoreTemplate } from "./templates/gitignore.template.js";
9
+
10
+ export const initCommand = async (serviceName?: string, configPath?: string) => {
11
+ if (serviceName != null) {
12
+ const serviceDefinition = await getSawsConfig(configPath);
13
+ await findServiceDefinition(serviceDefinition, serviceName).init();
14
+ return;
15
+ }
16
+
17
+ const name = path.parse(path.resolve(".")).name;
18
+
19
+ // not used for now
20
+ await installDependencies([]);
21
+ await installDependencies(["@saws/core", "typescript", "@tsconfig/node26"], {
22
+ development: true,
23
+ });
24
+
25
+ await fs.writeFile("./tsconfig.json", tsconfigJsonTemplate(), {});
26
+ await createFileIfNotExists("./saws.ts", sawsTsTemplate({ name }));
27
+ await createFileIfNotExists("./.gitignore", gitignoreTemplate());
28
+ };
@@ -0,0 +1,8 @@
1
+ import { Command } from "commander";
2
+ import { initCommand } from "./command.js";
3
+
4
+ export const createCommand = () =>
5
+ new Command("init")
6
+ .argument("[service]", "name of the service to initialize")
7
+ .argument("[config]", "path to service definition")
8
+ .action(initCommand);
@@ -0,0 +1,4 @@
1
+ export const gitignoreTemplate = () => `node_modules
2
+ .saws/saws-*-local-output.json
3
+ .saws/.secrets
4
+ .DS_Store`;
@@ -0,0 +1,8 @@
1
+ export const sawsTsTemplate = ({ name }: { name: string }) =>
2
+ `import { ServiceDefinition } from "@saws/core";
3
+
4
+ export default new ServiceDefinition({
5
+ name: "${name}",
6
+ dependencies: [],
7
+ });
8
+ `;
@@ -0,0 +1,4 @@
1
+ export const tsconfigJsonTemplate = () => /* json */ `{
2
+ "extends": "@tsconfig/node26/tsconfig.json",
3
+ "files": []
4
+ }`;
@@ -0,0 +1,42 @@
1
+ import { getSawsConfigModule, SecretsManager, type GlobalSecrets } from "@saws/core";
2
+
3
+ export interface SecretsCommandOptions {
4
+ config?: string;
5
+ stage?: string;
6
+ global?: boolean;
7
+ set?: string;
8
+ get?: boolean;
9
+ }
10
+
11
+ export async function secretsCommand(name: string, options: SecretsCommandOptions) {
12
+ const value = options.set;
13
+ if (options.get && value != null) {
14
+ throw new Error("secrets accepts only one of --get or --set <value>");
15
+ }
16
+ if (!options.get && value == null) {
17
+ throw new Error("secrets requires either --get or --set <value>");
18
+ }
19
+
20
+ if (!options.global) {
21
+ process.env.STAGE = options.stage ?? "local";
22
+ }
23
+
24
+ const config = await getSawsConfigModule(options.config);
25
+ const manager = config.secrets;
26
+ if (!(manager instanceof SecretsManager)) {
27
+ throw new Error('saws.ts must export a SecretsManager instance named "secrets"');
28
+ }
29
+
30
+ const secrets: SecretsManager | GlobalSecrets = options.global ? manager.global : manager;
31
+
32
+ if (options.get) {
33
+ console.log(await secrets.get(name));
34
+ return;
35
+ }
36
+
37
+ if (value == null) {
38
+ throw new Error("secrets requires --set <value>");
39
+ }
40
+ await secrets.set(name, value);
41
+ console.log("Set secret");
42
+ }
@@ -0,0 +1,13 @@
1
+ import { Command } from "commander";
2
+ import { secretsCommand } from "./command.js";
3
+
4
+ export const createCommand = () =>
5
+ new Command("secrets")
6
+ .description("get or set encrypted project secrets")
7
+ .argument("<name>", "secret name")
8
+ .option("--stage <string>", "stage for a stage-scoped secret", "local")
9
+ .option("--global", "use the global secret scope")
10
+ .option("--set <string>", "set the secret value")
11
+ .option("--get", "get the secret value")
12
+ .option("--config <string>", "path to service definition")
13
+ .action(secretsCommand);
package/src/hosts.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Host, type ServiceDefinition } from "@saws/core";
2
+
3
+ export function findConfiguredHosts(root: ServiceDefinition) {
4
+ const hosts = new Set<Host>();
5
+ const visited = new WeakSet<object>();
6
+
7
+ const visit = (value: unknown) => {
8
+ if (value == null || typeof value !== "object" || visited.has(value)) return;
9
+ visited.add(value);
10
+
11
+ if (value instanceof Host) {
12
+ hosts.add(value);
13
+ return;
14
+ }
15
+
16
+ for (const child of Object.values(value)) visit(child);
17
+ };
18
+
19
+ visit(root);
20
+ return [...hosts];
21
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig-node.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "tsBuildInfoFile": "./dist/.tsbuildinfo",
7
+ "types": ["find-package-json"]
8
+ }
9
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"saws.d.ts","sourceRoot":"","sources":["../../src/bin/saws.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy/command.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE,oBAAoB,iBA2B9B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,eAAO,MAAM,aAAa,eAOA,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/dev/command.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE,iBAAiB,iBAoD3B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/dev/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,eAAO,MAAM,aAAa,eAMH,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dev-tui.d.ts","sourceRoot":"","sources":["../../../../src/commands/dev/tui/dev-tui.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,YAAY,CAAC;AAkBlE,qBAAa,MAAM;IACjB,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAiC;IAEjE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiC;IACtD,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;gBAErB,QAAQ,EAAE,MAAM,EAAE;IAQ9B,KAAK;IAkBL,IAAI;IAUJ,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,QAAQ,GAAG,QAAmB;IAStE,OAAO,CAAC,cAAc,CAqBpB;IAEF,OAAO,CAAC,MAAM;IAkBd,OAAO,CAAC,MAAM,CA6BZ;CACH"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/host/command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGvC,MAAM,WAAW,2BAA2B;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE,2BAA2B,iBAOrC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,QAmBtD"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=command.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.test.d.ts","sourceRoot":"","sources":["../../../src/commands/host/command.test.ts"],"names":[],"mappings":""}
@@ -1,13 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import { Host } from "@saws/host";
4
- import { selectHost } from "./command.js";
5
- const first = new Host({ name: "first", address: "first.example.test" });
6
- const second = new Host({ name: "second", address: "second.example.test" });
7
- test("selects the only configured host when its name is omitted", () => {
8
- assert.equal(selectHost([first]), first);
9
- });
10
- test("requires a valid name when several hosts are configured", () => {
11
- assert.throws(() => selectHost([second, first]), /Host name is required\. Available hosts: first, second/);
12
- assert.throws(() => selectHost([first, second], "missing"), /Host "missing" was not found\. Available hosts: first, second/);
13
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/host/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,eAAO,MAAM,aAAa,eAUrB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/init/command.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,WAAW,CAC/B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE,kBAAkB,iBAiB5B"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=command.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.test.d.ts","sourceRoot":"","sources":["../../../src/commands/init/command.test.ts"],"names":[],"mappings":""}
@@ -1,40 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { mkdtemp, readFile, writeFile } from "node:fs/promises";
3
- import os from "node:os";
4
- import path from "node:path";
5
- import test from "node:test";
6
- import { pathToFileURL } from "node:url";
7
- import { initCommand } from "./command.js";
8
- test("initializes only the selected service branch in dependency order", async () => {
9
- const directory = await mkdtemp(path.join(os.tmpdir(), "saws-init-"));
10
- const configPath = path.join(directory, "saws.mjs");
11
- const packageUrl = pathToFileURL(path.resolve("../core/dist/index.js")).href;
12
- await writeFile(configPath, `
13
- import { appendFile } from "node:fs/promises";
14
- import path from "node:path";
15
- import { ServiceDefinition } from ${JSON.stringify(packageUrl)};
16
-
17
- class InitializableService extends ServiceDefinition {
18
- async onInit(context) {
19
- await appendFile(path.join(context.rootDir, "initialized.txt"), this.name + "\\n");
20
- }
21
- }
22
-
23
- const shared = new InitializableService({ name: "shared" });
24
- const api = new InitializableService({
25
- name: "api",
26
- dependencies: [shared],
27
- });
28
- const worker = new InitializableService({ name: "worker" });
29
-
30
- export default new InitializableService({
31
- name: "app",
32
- dependencies: [api, worker],
33
- });
34
- `);
35
- await initCommand("api", undefined, {
36
- config: configPath,
37
- rootDir: directory,
38
- });
39
- assert.equal(await readFile(path.join(directory, "initialized.txt"), "utf8"), "shared\napi\n");
40
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/init/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,eAAO,MAAM,aAAa,eAQF,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../src/commands/secrets/command.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,qBAAqB,iBAkB/B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/secrets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,eAAO,MAAM,aAAa,eAOC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hosts.d.ts","sourceRoot":"","sources":["../src/hosts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,UAkB1D"}