Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions packages/cli/src/deploy.ts
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
import { deployApp } from "@notation/core";
import { createNdjsonEventEmitter, deployApp } from "@notation/core";
import { compile } from "./compile";
import { redirectStdoutToStderr } from "./stdio";

export type DeployCommandOptions = {
json?: boolean;
};

export async function deploy(
entryPoint: string,
opts: DeployCommandOptions = {},
) {
// In --json mode console output moves to stderr so stdout carries only the
// NDJSON event stream; capture the real stdout for the emitter first.
const emit = opts.json
? createNdjsonEventEmitter(redirectStdoutToStderr().write)
: undefined;

export async function deploy(entryPoint: string) {
await compile(entryPoint);
console.log(`Deploying ${entryPoint}`);

try {
await deployApp(entryPoint);
await deployApp(
entryPoint,
undefined,
undefined,
undefined,
undefined,
emit,
);
} catch (err: any) {
if (err.name === "CredentialsProviderError") {
console.log(
Expand Down
18 changes: 15 additions & 3 deletions packages/cli/src/destroy.ts
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
import { destroyApp } from "@notation/core";
import { createNdjsonEventEmitter, destroyApp } from "@notation/core";
import { compile } from "./compile";
import { redirectStdoutToStderr } from "./stdio";

export type DestroyCommandOptions = {
json?: boolean;
};

export async function destroy(
entryPoint: string,
opts: DestroyCommandOptions = {},
) {
const emit = opts.json
? createNdjsonEventEmitter(redirectStdoutToStderr().write)
: undefined;

export async function destroy(entryPoint: string) {
await compile(entryPoint);
await destroyApp(entryPoint);
await destroyApp(entryPoint, undefined, undefined, emit);
}
13 changes: 8 additions & 5 deletions packages/cli/src/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,7 @@ import { plan } from "./plan";
import { visualise } from "./visualise";
import { watch } from "./watch";
import { startDashboardServer } from "@notation/dashboard";
import { createDefaultStateBackend } from "@notation/core";

program
.command("compile")
Expand All@@ -20,23 +21,25 @@ program
.command("dashboard")
.description("Start Notation Dashboard")
.action(async () => {
await startDashboardServer();
await startDashboardServer({ state: createDefaultStateBackend() });
});

program
.command("deploy")
.argument("<entryPoint>", "entryPoint")
.description("Deploy Notation App")
.action(async (entryPoint) => {
await deploy(entryPoint);
.option("--json", "stream reconciler events as NDJSON")
.action(async (entryPoint, options) => {
await deploy(entryPoint, { json: options.json });
});

program
.command("destroy")
.argument("<entryPoint>", "entryPoint")
.description("Destroy Notation App")
.action(async (entryPoint) => {
await destroy(entryPoint);
.option("--json", "stream reconciler events as NDJSON")
.action(async (entryPoint, options) => {
await destroy(entryPoint, { json: options.json });
});

program
Expand Down
14 changes: 3 additions & 11 deletions packages/cli/src/plan.ts
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
import { planApp, type Plan, type PlanNode } from "@notation/core";
import { compile } from "./compile";
import { redirectStdoutToStderr } from "./stdio";

export type PlanCommandOptions = {
json?: boolean;
Expand All@@ -18,12 +19,12 @@ export async function plan(entryPoint: string, opts: PlanCommandOptions = {}) {
try {
if (opts.json) {
let result: Plan;
const restoreStdout = redirectStdoutToStderr();
const { restore } = redirectStdoutToStderr();
try {
await compile(entryPoint);
result = await planApp(entryPoint);
} finally {
restoreStdout();
restore();
}
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
return;
Expand DownExpand Up@@ -68,12 +69,3 @@ function printPlanSummary(result: Plan) {

console.log(`${changedNodes.length > 0 ? "\n" : ""}Plan: ${summary}.`);
}

function redirectStdoutToStderr() {
const originalWrite = process.stdout.write.bind(process.stdout);
process.stdout.write = ((chunk: any, ...args: any[]) =>
(process.stderr.write as any)(chunk, ...args)) as typeof process.stdout.write;
return () => {
process.stdout.write = originalWrite;
};
}
17 changes: 17 additions & 0 deletions packages/cli/src/stdio.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
export function redirectStdoutToStderr() {
const originalWrite = process.stdout.write.bind(process.stdout);
const write = (line: string): void => {
originalWrite(line);
};
process.stdout.write = ((chunk: any, ...args: any[]) =>
(process.stderr.write as any)(
chunk,
...args,
)) as typeof process.stdout.write;
return {
write,
restore: () => {
process.stdout.write = originalWrite;
},
};
}
1 change: 1 addition & 0 deletions packages/core/src/provisioner/index.ts
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
export * from "./workflows";
export * from "./resource-registry";
export * from "./state-backend";
4 changes: 0 additions & 4 deletions packages/core/src/provisioner/operations/index.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/core/src/provisioner/operations/operation.base.ts

This file was deleted.

65 changes: 0 additions & 65 deletions packages/core/src/provisioner/operations/operation.create.ts

This file was deleted.

35 changes: 0 additions & 35 deletions packages/core/src/provisioner/operations/operation.delete.ts

This file was deleted.

66 changes: 0 additions & 66 deletions packages/core/src/provisioner/operations/operation.read.ts

This file was deleted.

Loading
Loading