@saws/cli 2.0.0-beta.3 → 2.0.0-beta.6

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.
@@ -1,18 +0,0 @@
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
- );
@@ -1,28 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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);
@@ -1,4 +0,0 @@
1
- export const gitignoreTemplate = () => `node_modules
2
- .saws/saws-*-local-output.json
3
- .saws/.secrets
4
- .DS_Store`;
@@ -1,8 +0,0 @@
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
- `;
@@ -1,4 +0,0 @@
1
- export const tsconfigJsonTemplate = () => /* json */ `{
2
- "extends": "@tsconfig/node26/tsconfig.json",
3
- "files": []
4
- }`;
@@ -1,42 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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 DELETED
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,9 +0,0 @@
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
- }