Skip to content

Commit

Permalink
astro lifting
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Sep 5, 2023
1 parent e33dc9d commit 04d7bcb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/wing-console/console/app/demo/index.w
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
bring ex;

new ex.Astro(root: "../../astro");
let astro = new ex.Astro(root: "../../astro");

bring cloud;

new cloud.Website(path: "");

let bucket = new cloud.Bucket();

astro.defineVirtualModule("test", {
"bucket" => bucket,
});

let queue = new cloud.Queue();
let api = new cloud.Api();

Expand Down
7 changes: 7 additions & 0 deletions apps/wing-console/console/astrotest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const bucket = (function(env) {
let handle = process.env[env];
if (!handle) {
throw new Error("Missing environment variable: " + env);
}
return $simulator.findInstance(handle);
})("BUCKET_HANDLE_2cd0933d");
6 changes: 6 additions & 0 deletions libs/wingsdk/src/ex/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export abstract class Astro extends Resource {
this._domain = props.domain;
}

// TODO: how do we annotate that the map is <string, any preflight value>?
public abstract defineVirtualModule(
name: string,
values: Record<string, any>
): void;

/** @internal */
public _getInflightOps(): string[] {
return [];
Expand Down
11 changes: 11 additions & 0 deletions libs/wingsdk/src/target-sim/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ import { bindSimulatorResource, makeSimulatorJsClient } from "./util";
import * as ex from "../ex";
import { IInflightHost } from "../std";
import { BaseResourceSchema } from "../testing/simulator";
import { liftObject } from "../core/internal";
import { writeFileSync } from "fs";

export class Astro extends ex.Astro implements ISimulatorResource {
constructor(scope: Construct, id: string, props: ex.AstroProps) {
super(scope, id, props);
}

public defineVirtualModule(name: string, values: Record<string, any>): void {
const lines = [];
for (const value in values) {
lines.push(`export const ${value} = ${liftObject(this, values[value])};`);
}
const outfile = `${this.root}${name}.js`;
writeFileSync(outfile, lines.join("\n"));
}

public get url(): string {
return simulatorAttrToken(this, "url");
}
Expand Down

0 comments on commit 04d7bcb

Please sign in to comment.