@saws/cli 1.0.2 → 1.0.4

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/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@saws/cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "saws": "./dist/bin/saws.js"
7
7
  },
8
+ "files": [
9
+ "./dist"
10
+ ],
8
11
  "keywords": [],
9
12
  "author": "",
10
13
  "license": "MIT",
@@ -12,12 +15,12 @@
12
15
  "commander": "^12.0.0",
13
16
  "esbuild": "^0.20.1",
14
17
  "find-package-json": "^1.2.0",
15
- "@saws/utils": "^1.0.2",
16
- "@saws/secrets": "^1.0.2"
18
+ "@saws/secrets": "^1.0.4",
19
+ "@saws/utils": "^1.0.4"
17
20
  },
18
21
  "devDependencies": {
19
22
  "@types/find-package-json": "^1.2.6",
20
- "@saws/core": "^1.0.2"
23
+ "@saws/core": "^1.0.4"
21
24
  },
22
25
  "peerDependencies": {
23
26
  "@saws/core": ">=1.0.0"
package/bin/saws.ts DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- process.on("uncaughtException", (e) => {
4
- console.log(e);
5
- });
6
-
7
- import { default as finder } from "find-package-json";
8
- import { program } from "commander";
9
- import { getSawsConfig } from "@saws/core";
10
-
11
- import { createCommand as createDevCommand } from "../src/commands/dev";
12
- import { createCommand as createDeployCommand } from "../src/commands/deploy";
13
- import { createCommand as createExecuteCommand } from "../src/commands/execute";
14
- import { createCommand as createInitCommand } from '../src/commands/init';
15
-
16
- const pkg = finder(__dirname).next().value;
17
-
18
- program
19
- .name("saws")
20
- .description("A tool for building apps quickly")
21
- .version(pkg?.version!);
22
-
23
- program.addCommand(createDevCommand());
24
- program.addCommand(createDeployCommand());
25
- program.addCommand(createExecuteCommand());
26
- program.addCommand(createInitCommand());
27
-
28
- (async () => {
29
- try {
30
- const service = await getSawsConfig()
31
-
32
- const allServices = [...new Set(service.getAllDependencies().map(service => service.constructor))]
33
-
34
- for (const serviceClass of allServices) {
35
- // @ts-expect-error Not all classes will define a getCommands static method
36
- serviceClass.getCommands?.()?.forEach(command => program.addCommand(command))
37
- }
38
- } catch (_err) {
39
- // It's possible for there not to be a saws.js file yet and thus this will fail
40
- } finally {
41
- program.parse(process.argv);
42
- }
43
- })()
@@ -1,15 +0,0 @@
1
- import { createCacheDir } from "@saws/utils/create-directories";
2
- import { getSawsConfig } from "@saws/core";
3
-
4
- export const deployCommand = async (path: string, { stage }: { stage: string }) => {
5
- if (stage === "local") {
6
- console.warn("Can not deploy to local stage");
7
- process.exit();
8
- }
9
-
10
- await createCacheDir();
11
-
12
- const serviceDefinition = await getSawsConfig(path);
13
-
14
- await serviceDefinition.deploy(stage);
15
- };
@@ -1,8 +0,0 @@
1
- import { Command } from "commander";
2
- import { deployCommand } from "./command";
3
-
4
- export const createCommand = () =>
5
- new Command("deploy")
6
- .option("--stage <string>", "stage to deploy")
7
- .argument("[string]", "path to service definition")
8
- .action(deployCommand);
@@ -1,23 +0,0 @@
1
- import { createCacheDir } from "@saws/utils/create-directories";
2
- import { onProcessExit } from "@saws/utils/on-exit";
3
- import { getSawsConfig } from "@saws/core";
4
-
5
- export const devCommand = async (path: string) => {
6
- process.env.NODE_ENV = "development";
7
- process.env.STAGE = "local";
8
- process.env.AWS_REGION = 'us-west-2';
9
-
10
- await createCacheDir();
11
-
12
- const serviceDefinition = await getSawsConfig(path);
13
-
14
- onProcessExit(() => {
15
- serviceDefinition.exit();
16
- });
17
-
18
- await serviceDefinition.dev();
19
-
20
- serviceDefinition.forEachDependency(async (dependency) => {
21
- dependency.getStdOut()?.pipe(process.stdout)
22
- })
23
- };
@@ -1,7 +0,0 @@
1
- import { Command } from "commander";
2
- import { devCommand } from "./command";
3
-
4
- export const createCommand = () =>
5
- new Command("dev")
6
- .argument("[string]", "path to service definition")
7
- .action(devCommand);
@@ -1,43 +0,0 @@
1
- import { getSawsConfig } from "@saws/core";
2
- import { BUILD_DIR } from "@saws/utils/constants";
3
- import { getStageOutputs } from "@saws/utils/stage-outputs";
4
- import { fork } from "child_process";
5
- import esbuild from "esbuild";
6
- import path from "path";
7
-
8
- export const executeCommand = async (
9
- scriptPath: string,
10
- sawsPath: string,
11
- { stage = "local" }: { stage: string }
12
- ) => {
13
- process.env.STAGE = stage;
14
-
15
- const serviceDefinition = await getSawsConfig(sawsPath);
16
-
17
- const stageOutputs = await getStageOutputs(stage);
18
- const services = serviceDefinition.getAllDependencies()
19
- let environment: Record<string, string> = {
20
- NODE_ENV: stage === "local" ? "development" : "production",
21
- STAGE: stage,
22
- }
23
- for (const service of services) {
24
- await service.setOutputs(stageOutputs[service.name], stage)
25
- environment = {
26
- ...environment,
27
- ...await(service.getEnvironmentVariables(stage))
28
- }
29
- }
30
-
31
- const outFile = path.join(BUILD_DIR, "script.js");
32
-
33
- await esbuild.build({
34
- entryPoints: [scriptPath],
35
- bundle: true,
36
- outfile: outFile,
37
- platform: "node",
38
- });
39
-
40
- fork(outFile, {
41
- env: environment,
42
- })
43
- };
@@ -1,9 +0,0 @@
1
- import { Command } from "commander";
2
- import { executeCommand } from "./command";
3
-
4
- export const createCommand = () =>
5
- new Command("execute")
6
- .option("--stage <string>", "Stage")
7
- .argument("<string>", "The path to the script to execute")
8
- .argument("[string]", "The path to the saws file")
9
- .action(executeCommand);
@@ -1,18 +0,0 @@
1
- import path from 'node:path'
2
- import { installMissingDependencies } from '@saws/utils/dependency-management'
3
- import { tsconfigJsonTemplate } from './templates/tsconfig-json.template'
4
- import { sawsJsTemplate } from './templates/saws-js.template'
5
- import { createFileIfNotExists } from '@saws/utils/create-file-if-not-exists'
6
- import { gitignoreTemplate } from './templates/gitignore.template'
7
-
8
- export const initCommand = async () => {
9
- const name = path.parse(path.resolve('.')).name
10
-
11
- // not used for now
12
- await installMissingDependencies([])
13
- await installMissingDependencies(['@saws/core', 'typescript'], { development: true })
14
-
15
- createFileIfNotExists('./tsconfig.json', tsconfigJsonTemplate())
16
- createFileIfNotExists('./saws.js', sawsJsTemplate({ name }))
17
- createFileIfNotExists('./.gitignore', gitignoreTemplate())
18
- }
@@ -1,6 +0,0 @@
1
- import { Command } from "commander";
2
- import { initCommand } from "./command";
3
-
4
- export const createCommand = () =>
5
- new Command("init")
6
- .action(initCommand);
@@ -1,8 +0,0 @@
1
- export const gitignoreTemplate = () => `node_modules
2
- .saws/postgres
3
- .saws/cognito
4
- .saws/saws-*-local-output.json
5
- .saws/cache
6
- .saws/build
7
- .saws/.secrets
8
- .DS_Store`
@@ -1,7 +0,0 @@
1
- export const sawsJsTemplate = ({ name }: { name: string}) => `const { ServiceDefinition } = require('@saws/core')
2
-
3
- module.exports = new ServiceDefinition({
4
- name: '${name}',
5
- dependencies: []
6
- })
7
- `
@@ -1,20 +0,0 @@
1
- export const tsconfigJsonTemplate = () => `{
2
- "include": ["**/*.ts", "*.ts", "**/*.tsx", "global.d.ts"],
3
- "exclude": [".saws", "node_modules"],
4
- "compilerOptions": {
5
- "lib": ["DOM", "DOM.Iterable", "ES2022"],
6
- "isolatedModules": true,
7
- "esModuleInterop": true,
8
- "jsx": "react-jsx",
9
- "target": "ES2022",
10
- "module": "Node16",
11
- "resolveJsonModule": true,
12
- "strict": true,
13
- "allowJs": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "noEmit": true,
16
- "skipLibCheck": true
17
- }
18
- }
19
-
20
- `
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "include": ["bin/**/*", "src/**/*"],
4
- "exclude": ["dist", "node_modules"],
5
- "compilerOptions": {
6
- "rootDir": ".",
7
- "outDir": "./dist"
8
- },
9
- "references": [
10
- { "path": "../secrets" },
11
- { "path": "../utils" },
12
- { "path": "../core" }
13
- ]
14
- }