sst 2.0.0-rc.31 → 2.0.0-rc.34

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/bus.js CHANGED
@@ -30,7 +30,7 @@ export const useBus = Context.memo(() => {
30
30
  unsubscribe(sub) {
31
31
  const arr = subscribers(sub.type);
32
32
  const index = arr.indexOf(sub);
33
- if (!index)
33
+ if (index < 0)
34
34
  return;
35
35
  arr.splice(index, 1);
36
36
  },
@@ -0,0 +1,7 @@
1
+ import chalk from "chalk";
2
+ export declare const Colors: {
3
+ primary: chalk.Chalk;
4
+ link: chalk.Chalk;
5
+ success: chalk.Chalk;
6
+ danger: chalk.Chalk;
7
+ };
package/cli/colors.js ADDED
@@ -0,0 +1,7 @@
1
+ import chalk from "chalk";
2
+ export const Colors = {
3
+ primary: chalk.hex("#E27152"),
4
+ link: chalk.cyan,
5
+ success: chalk.green,
6
+ danger: chalk.red,
7
+ };
@@ -6,6 +6,8 @@ export declare const bind: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  command: string;
11
13
  }>;
@@ -6,6 +6,8 @@ export declare const build: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  to: string | undefined;
11
13
  }>;
@@ -6,4 +6,6 @@ export declare const consoleCommand: (program: Program) => Promise<import("yargs
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  }>>;
@@ -7,9 +7,9 @@ export declare const deploy: (program: Program) => import("yargs").Argv<{
7
7
  } & {
8
8
  region: string | undefined;
9
9
  } & {
10
- from: string | undefined;
10
+ verbose: boolean | undefined;
11
11
  } & {
12
- fullscreen: boolean;
12
+ from: string | undefined;
13
13
  } & {
14
14
  filter: string | undefined;
15
15
  }>;
@@ -2,11 +2,6 @@ export const deploy = (program) => program.command("deploy [filter]", "Deploy yo
2
2
  .option("from", {
3
3
  type: "string",
4
4
  describe: "Deploy using previously built output",
5
- })
6
- .option("fullscreen", {
7
- type: "boolean",
8
- describe: "Disable full screen UI",
9
- default: true,
10
5
  })
11
6
  .positional("filter", {
12
7
  type: "string",
@@ -16,23 +11,33 @@ export const deploy = (program) => program.command("deploy [filter]", "Deploy yo
16
11
  const { printDeploymentResults } = await import("../ui/deploy.js");
17
12
  const { createSpinner } = await import("../spinner.js");
18
13
  const { CloudAssembly } = await import("aws-cdk-lib/cx-api");
19
- const { blue, bold } = await import("colorette");
14
+ const { dim, blue, bold } = await import("colorette");
20
15
  const { useProject } = await import("../../project.js");
21
16
  const { Stacks } = await import("../../stacks/index.js");
22
17
  const { render } = await import("ink");
23
18
  const { DeploymentUI } = await import("../ui/deploy.js");
19
+ const { Colors } = await import("../colors.js");
24
20
  const project = useProject();
21
+ console.log();
22
+ console.log(` ${Colors.primary(`${bold(`SST`)} v${project.version}`)}`);
23
+ console.log();
24
+ console.log(` ${Colors.primary(`➜`)} ${bold(`Stage:`)} ${dim(project.config.stage)}`);
25
+ console.log();
25
26
  const assembly = await (async function () {
26
27
  if (args.from) {
27
28
  const result = new CloudAssembly(args.from);
28
29
  return result;
29
30
  }
30
- const spinner = createSpinner("Building stacks");
31
+ const spinner = createSpinner({
32
+ text: " Building stacks",
33
+ indent: 2,
34
+ });
31
35
  const result = await Stacks.synth({
32
36
  fn: project.stacks,
33
37
  mode: "deploy",
34
38
  });
35
39
  spinner.succeed();
40
+ console.log();
36
41
  return result;
37
42
  })();
38
43
  const target = assembly.stacks.filter((s) => !args.filter ||
@@ -41,22 +46,11 @@ export const deploy = (program) => program.command("deploy [filter]", "Deploy yo
41
46
  console.log(`No stacks found matching ${blue(args.filter)}`);
42
47
  process.exit(1);
43
48
  }
44
- console.log(`Deploying ${bold(target.length + " stacks")} for stage ${blue(project.config.stage)}...`);
45
- const cleanup = (() => {
46
- if (args.fullscreen) {
47
- process.stdout.write("\x1b[?1049h");
48
- const component = render(React.createElement(DeploymentUI, { stacks: assembly.stacks.map((s) => s.stackName) }));
49
- return () => {
50
- component.unmount();
51
- process.stdout.write("\x1b[?1049l");
52
- };
53
- }
54
- const spinner = createSpinner("Deploying stacks");
55
- return () => spinner.succeed();
56
- })();
57
- const results = await Stacks.deployMany(target);
58
- cleanup();
59
- printDeploymentResults(results);
49
+ const component = render(React.createElement(DeploymentUI, { stacks: assembly.stacks.map((s) => s.stackName) }));
50
+ const results = await Stacks.deployMany(assembly.stacks);
51
+ component.clear();
52
+ component.unmount();
53
+ printDeploymentResults(assembly, results);
60
54
  if (Object.values(results).some((stack) => Stacks.isFailed(stack.status)))
61
55
  process.exit(1);
62
56
  process.exit(0);
@@ -7,5 +7,5 @@ export declare const dev: (program: Program) => import("yargs").Argv<{
7
7
  } & {
8
8
  region: string | undefined;
9
9
  } & {
10
- fullscreen: boolean;
10
+ verbose: boolean | undefined;
11
11
  }>;
@@ -1,8 +1,7 @@
1
- export const dev = (program) => program.command(["dev", "start"], "Work on your app locally", (yargs) => yargs.option("fullscreen", {
2
- type: "boolean",
3
- describe: "Disable full screen UI",
4
- default: true,
5
- }), async (args) => {
1
+ import chalk from "chalk";
2
+ import { Colors } from "../colors.js";
3
+ import { Functions } from "../ui/functions.js";
4
+ export const dev = (program) => program.command(["dev", "start"], "Work on your app locally", (yargs) => yargs, async (args) => {
6
5
  const { useRuntimeWorkers } = await import("../../runtime/workers.js");
7
6
  const { useIOTBridge } = await import("../../runtime/iot.js");
8
7
  const { useRuntimeServer } = await import("../../runtime/server.js");
@@ -33,36 +32,65 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
33
32
  console.log(yellow(`Warning: ${bold(`sst start`)} has been renamed to ${bold(`sst dev`)}`));
34
33
  }
35
34
  const useFunctionLogger = Context.memo(async () => {
35
+ const component = render(React.createElement(Functions, null));
36
36
  const bus = useBus();
37
+ /*
37
38
  bus.subscribe("function.invoked", async (evt) => {
38
- console.log(bold(magenta(`Invoked `)), useFunctions().fromID(evt.properties.functionID).handler);
39
+ console.log(
40
+ bold(magenta(` ➜ `)),
41
+ useFunctions().fromID(evt.properties.functionID).handler!
42
+ );
39
43
  });
44
+
40
45
  bus.subscribe("function.build.success", async (evt) => {
41
- console.log(bold(gray(`Built `)), useFunctions().fromID(evt.properties.functionID).handler);
46
+ console.log(
47
+ bold(gray(`Built `)),
48
+ useFunctions().fromID(evt.properties.functionID).handler!
49
+ );
42
50
  });
43
51
  bus.subscribe("function.build.failed", async (evt) => {
44
- console.log(bold(red(`Build failed `)), useFunctions().fromID(evt.properties.functionID).handler);
45
- console.log(dim(evt.properties.errors.join("\n")));
52
+ console.log(
53
+ bold(red(`Build failed `)),
54
+ useFunctions().fromID(evt.properties.functionID).handler!
55
+ );
56
+ console.log(dim(evt.properties.errors.join("\n")));
46
57
  });
58
+
47
59
  bus.subscribe("worker.stdout", async (evt) => {
48
- const { message } = evt.properties;
49
- const lines = message.split("\n");
50
- for (let i = 0; i < lines.length; i++) {
51
- const line = lines[i];
52
- lines[i] = " " + line;
53
- }
54
- console.log(bold(blue(`Log `)), useFunctions().fromID(evt.properties.functionID).handler);
55
- console.log(dim(lines.join("\n")));
60
+ const { message } = evt.properties;
61
+ const lines = message.split("\n");
62
+ for (let i = 0; i < lines.length; i++) {
63
+ const line = lines[i];
64
+ lines[i] = " " + line;
65
+ }
66
+ console.log(
67
+ bold(blue(` ➜ `)),
68
+ useFunctions().fromID(evt.properties.functionID).handler!
69
+ );
70
+ console.log(dim(lines.join("\n")));
56
71
  });
72
+ */
73
+ /*
57
74
  bus.subscribe("function.success", async (evt) => {
58
- console.log(bold(green(`Success `)), useFunctions().fromID(evt.properties.functionID).handler);
75
+ console.log(
76
+ bold(green(` ✔ `)),
77
+ useFunctions().fromID(evt.properties.functionID).handler!
78
+ );
79
+ console.log();
59
80
  });
81
+ */
82
+ /*
60
83
  bus.subscribe("function.error", async (evt) => {
61
- console.log(bold(red(`Error `)), useFunctions().fromID(evt.properties.functionID).handler, evt.properties.errorMessage);
62
- for (const line of evt.properties.trace || []) {
63
- console.log(` ${dim(line)}`);
64
- }
84
+ console.log(
85
+ bold(red(` ✖ `)),
86
+ useFunctions().fromID(evt.properties.functionID).handler!
87
+ );
88
+ console.log(` ${Colors.danger(evt.properties.errorMessage)}`);
89
+ for (const line of evt.properties.trace || []) {
90
+ console.log(` ${dim(line)}`);
91
+ }
65
92
  });
93
+ */
66
94
  });
67
95
  const useStackBuilder = Context.memo(async () => {
68
96
  const watcher = useWatcher();
@@ -72,7 +100,13 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
72
100
  let pending;
73
101
  let isDeploying = false;
74
102
  async function build() {
75
- const spinner = createSpinner("Building stacks").start();
103
+ const spinner = createSpinner({
104
+ indent: 2,
105
+ color: "gray",
106
+ text: lastDeployed
107
+ ? ` Building stacks`
108
+ : dim(` Checking for changes`),
109
+ }).start();
76
110
  try {
77
111
  const [metafile, sstConfig] = await Stacks.load(project.paths.config);
78
112
  project.metafile = metafile;
@@ -86,17 +120,27 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
86
120
  const next = await checksum(assembly.directory);
87
121
  Logger.debug("Checksum", "next", next, "old", lastDeployed);
88
122
  if (next === lastDeployed) {
89
- spinner.succeed("Stacks built! No changes");
123
+ spinner.succeed(" No changes");
124
+ console.log();
90
125
  return;
91
126
  }
92
- spinner.succeed(lastDeployed ? `Stacks built!` : `Stacks built!`);
127
+ if (!lastDeployed) {
128
+ spinner.stop();
129
+ spinner.clear();
130
+ }
131
+ else {
132
+ spinner.succeed(` Stacks built!`);
133
+ }
93
134
  pending = assembly;
94
135
  if (lastDeployed)
95
- deploy();
136
+ setTimeout(() => deploy(), 100);
96
137
  }
97
138
  catch (ex) {
98
139
  spinner.fail();
99
- console.error(ex);
140
+ console.log(ex.stack
141
+ .split("\n")
142
+ .map((line) => " " + line)
143
+ .join("\n"));
100
144
  }
101
145
  }
102
146
  async function deploy() {
@@ -108,22 +152,14 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
108
152
  const assembly = pending;
109
153
  const nextChecksum = await checksum(assembly.directory);
110
154
  pending = undefined;
111
- const cleanup = (() => {
112
- if (args.fullscreen) {
113
- process.stdout.write("\x1b[?1049h");
114
- const component = render(React.createElement(DeploymentUI, { stacks: assembly.stacks.map((s) => s.stackName) }));
115
- return () => {
116
- component.unmount();
117
- process.stdout.write("\x1b[?1049l");
118
- };
119
- }
120
- const spinner = createSpinner("Deploying stacks");
121
- return () => spinner.succeed();
122
- })();
155
+ console.log();
156
+ const component = render(React.createElement(DeploymentUI, { stacks: assembly.stacks.map((s) => s.stackName) }));
123
157
  const results = await Stacks.deployMany(assembly.stacks);
124
- cleanup();
158
+ component.clear();
159
+ component.unmount();
160
+ render(React.createElement(Functions, null));
125
161
  lastDeployed = nextChecksum;
126
- printDeploymentResults(results);
162
+ printDeploymentResults(assembly, results);
127
163
  const keys = await SiteEnv.keys();
128
164
  if (keys.length) {
129
165
  const result = {};
@@ -169,10 +205,26 @@ export const dev = (program) => program.command(["dev", "start"], "Work on your
169
205
  await build();
170
206
  await deploy();
171
207
  });
172
- createSpinner("").start().succeed("Ready for function invocations");
173
- createSpinner("")
174
- .start()
175
- .succeed(`Console ready at https://console.sst.dev`);
208
+ const project = useProject();
209
+ const primary = chalk.hex("#E27152");
210
+ const link = chalk.cyan;
211
+ console.clear();
212
+ console.log();
213
+ console.log(` ${Colors.primary(`${bold(`SST`)} v${project.version}`)} ${dim(`ready!`)}`);
214
+ console.log();
215
+ console.log(` ${primary(`➜`)} ${bold(`Stage:`)} ${dim(project.config.stage)}`);
216
+ console.log(` ${primary(`➜`)} ${bold(`Console:`)} ${link(`https://console.sst.dev/${project.config.name}/${project.config.stage}`)}`);
217
+ /*
218
+ console.log(` ${primary(`➜`)} ${bold(dim(`Outputs:`))}`);
219
+ for (let i = 0; i < 3; i++) {
220
+ console.log(` ${dim(`thdxr-scratch-MyStack`)}`);
221
+ console.log(
222
+ ` ${bold(
223
+ dim(`ApiEndpoint`)
224
+ )}: https://hdq3z0es2d.execute-api.us-east-1.amazonaws.com`
225
+ );
226
+ }
227
+ */
176
228
  await Promise.all([
177
229
  useLocalServer({
178
230
  key: "",
@@ -6,6 +6,8 @@ export declare const diff: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  dev: boolean | undefined;
11
13
  }>;
@@ -6,6 +6,8 @@ export declare const env: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  command: string;
11
13
  }>;
@@ -7,9 +7,9 @@ export declare const remove: (program: Program) => import("yargs").Argv<{
7
7
  } & {
8
8
  region: string | undefined;
9
9
  } & {
10
- from: string | undefined;
10
+ verbose: boolean | undefined;
11
11
  } & {
12
- fullscreen: boolean;
12
+ from: string | undefined;
13
13
  } & {
14
14
  filter: string | undefined;
15
15
  }>;
@@ -1,57 +1,43 @@
1
- export const remove = (program) => program.command("remove [filter]", "Remove your app from AWS", (yargs) => yargs
2
- .option("from", { type: "string" })
3
- .option("fullscreen", {
4
- type: "boolean",
5
- describe: "Disable full screen UI",
6
- default: true,
7
- })
8
- .positional("filter", {
1
+ export const remove = (program) => program.command("remove [filter]", "Remove your app from AWS", (yargs) => yargs.option("from", { type: "string" }).positional("filter", {
9
2
  type: "string",
10
3
  describe: "Optionally filter stacks to remove",
11
4
  }), async (args) => {
12
5
  const React = await import("react");
13
6
  const { CloudAssembly } = await import("aws-cdk-lib/cx-api");
14
- const { blue, bold } = await import("colorette");
7
+ const { dim, blue, bold } = await import("colorette");
15
8
  const { useProject } = await import("../../project.js");
16
9
  const { Stacks } = await import("../../stacks/index.js");
17
10
  const { render } = await import("ink");
18
11
  const { DeploymentUI } = await import("../ui/deploy.js");
19
12
  const { printDeploymentResults } = await import("../ui/deploy.js");
20
- const { createSpinner } = await import("../spinner.js");
13
+ const { Colors } = await import("../colors.js");
14
+ const project = useProject();
15
+ console.log();
16
+ console.log(` ${Colors.primary(`${bold(`SST`)} v${project.version}`)}`);
17
+ console.log();
18
+ console.log(` ${Colors.primary(`➜`)} ${bold(`Stage:`)} ${dim(project.config.stage)}`);
19
+ console.log();
21
20
  const assembly = await (async function () {
22
21
  if (args.from) {
23
22
  const result = new CloudAssembly(args.from);
24
23
  return result;
25
24
  }
26
- const project = useProject();
27
25
  return await Stacks.synth({
28
26
  fn: project.stacks,
29
27
  mode: "remove",
30
28
  });
31
29
  })();
32
- const project = useProject();
33
30
  const target = assembly.stacks.filter((s) => !args.filter ||
34
31
  s.stackName.toLowerCase().includes(args.filter.toLowerCase()));
35
32
  if (!target.length) {
36
33
  console.log(`No stacks found matching ${blue(args.filter)}`);
37
34
  process.exit(1);
38
35
  }
39
- console.log(`Removing ${bold(target.length + " stacks")} for stage ${blue(project.config.stage)}...`);
40
- const cleanup = (() => {
41
- if (args.fullscreen) {
42
- process.stdout.write("\x1b[?1049h");
43
- const component = render(React.createElement(DeploymentUI, { stacks: assembly.stacks.map((s) => s.stackName) }));
44
- return () => {
45
- component.unmount();
46
- process.stdout.write("\x1b[?1049l");
47
- };
48
- }
49
- const spinner = createSpinner("Removing stacks");
50
- return () => spinner.succeed();
51
- })();
36
+ const component = render(React.createElement(DeploymentUI, { stacks: assembly.stacks.map((s) => s.stackName) }));
52
37
  const results = await Stacks.removeMany(target);
53
- cleanup();
54
- printDeploymentResults(results);
38
+ component.clear();
39
+ component.unmount();
40
+ printDeploymentResults(assembly, results);
55
41
  if (Object.values(results).some((stack) => Stacks.isFailed(stack.status)))
56
42
  process.exit(1);
57
43
  process.exit(0);
@@ -6,6 +6,8 @@ export declare const get: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  name: string;
11
13
  } & {
@@ -6,6 +6,8 @@ export declare const list: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  format: string | undefined;
11
13
  }>;
@@ -6,6 +6,8 @@ export declare const remove: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  name: string;
11
13
  } & {
@@ -6,6 +6,8 @@ export declare const set: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  name: string;
11
13
  } & {
@@ -6,6 +6,8 @@ export declare const update: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  version: string | undefined;
11
13
  }>;
@@ -6,6 +6,8 @@ export declare const env: (program: Program) => import("yargs").Argv<{
6
6
  profile: string | undefined;
7
7
  } & {
8
8
  region: string | undefined;
9
+ } & {
10
+ verbose: boolean | undefined;
9
11
  } & {
10
12
  command: string;
11
13
  }>;
package/cli/program.d.ts CHANGED
@@ -5,5 +5,7 @@ export declare const program: import("yargs").Argv<{
5
5
  profile: string | undefined;
6
6
  } & {
7
7
  region: string | undefined;
8
+ } & {
9
+ verbose: boolean | undefined;
8
10
  }>;
9
11
  export type Program = typeof program;
package/cli/program.js CHANGED
@@ -13,9 +13,16 @@ export const program = yargs(hideBin(process.argv))
13
13
  .option("region", {
14
14
  type: "string",
15
15
  describe: "The AWS region to use",
16
+ })
17
+ .option("verbose", {
18
+ type: "boolean",
19
+ describe: "Print verbose logs",
16
20
  })
17
21
  .group(["stage", "profile", "region", "help"], "Global:")
18
22
  .middleware(async (argv) => {
23
+ if (argv.verbose) {
24
+ process.env.SST_VERBOSE = "1";
25
+ }
19
26
  if (argv._.length > 0) {
20
27
  const { initProject } = await import("../project.js");
21
28
  await initProject(argv);
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" resolution-mode="require"/>
2
2
  import { Stacks } from "../../stacks/index.js";
3
+ import { CloudAssembly } from "aws-cdk-lib/cx-api";
3
4
  interface Props {
4
5
  stacks: string[];
5
6
  }
6
7
  export declare const DeploymentUI: (props: Props) => JSX.Element;
7
- export declare function printDeploymentResults(results: Awaited<ReturnType<typeof Stacks.deployMany>>): void;
8
+ export declare function printDeploymentResults(assembly: CloudAssembly, results: Awaited<ReturnType<typeof Stacks.deployMany>>): void;
8
9
  export {};