Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMcCulloh committed Jun 26, 2023
2 parents cfba47d + 6c60b4e commit 66ee18d
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ jobs:
- build
env:
HANGAR_WING_SPEC: "file:${{ github.workspace }}/wing/winglang-${{ needs.build.outputs.version }}.tgz"
HANGAR_WINGCONSOLE_APP_SPEC: "file:${{ github.workspace }}/wingconsoleapp/wingconsole-app-${{ needs.build.outputs.version }}.tgz"
HANGAR_WINGCONSOLE_SERVER_SPEC: "file:${{ github.workspace }}/wingconsoleserver/wingconsole-server-${{ needs.build.outputs.version }}.tgz"
HANGAR_WINGCOMPILER_SPEC: "file:${{ github.workspace }}/wingcompiler/winglang-compiler-${{ needs.build.outputs.version }}.tgz"
HANGAR_WINGSDK_SPEC: "file:${{ github.workspace }}/wingsdk/winglang-sdk-${{ needs.build.outputs.version }}.tgz"
steps:
Expand Down Expand Up @@ -272,6 +274,8 @@ jobs:
runs-on: "${{ matrix.runner }}-latest"
env:
HANGAR_WING_SPEC: "file:${{ github.workspace }}/target/wing/winglang-${{ needs.build.outputs.version }}.tgz"
HANGAR_WINGCONSOLE_APP_SPEC: "file:${{ github.workspace }}/target/wingconsoleapp/wingconsole-app-${{ needs.build.outputs.version }}.tgz"
HANGAR_WINGCONSOLE_SERVER_SPEC: "file:${{ github.workspace }}/target/wingconsoleserver/wingconsole-server-${{ needs.build.outputs.version }}.tgz"
HANGAR_WINGCOMPILER_SPEC: "file:${{ github.workspace }}/target/wingcompiler/winglang-compiler-${{ needs.build.outputs.version }}.tgz"
HANGAR_WINGSDK_SPEC: "file:${{ github.workspace }}/target/wingsdk/winglang-sdk-${{ needs.build.outputs.version }}.tgz"
steps:
Expand Down
2 changes: 2 additions & 0 deletions apps/wing-playground/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions apps/wing/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions apps/wing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"package": "bump-pack -b"
},
"dependencies": {
"@wingconsole/app": "file:../wing-console/console/app",
"@winglang/compiler": "file:../../libs/wingcompiler",
"@winglang/sdk": "file:../../libs/wingsdk",
"chalk": "^4.1.2",
"codespan-wasm": "0.4.0",
"commander": "^10.0.0",
Expand All @@ -35,23 +38,21 @@
"open": "^8.4.0",
"ora": "^5.4.1",
"update-notifier": "^6.0.2",
"vscode-languageserver": "^8.0.2",
"@winglang/sdk": "file:../../libs/wingsdk",
"@winglang/compiler": "file:../../libs/wingcompiler"
"vscode-languageserver": "^8.0.2"
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/node": "^18.11.18",
"@types/node-persist": "^3.1.3",
"@types/semver-utils": "^1.1.1",
"@types/update-notifier": "^6.0.1",
"bump-pack": "file:../../tools/bump-pack",
"esbuild": "^0.17.19",
"typescript": "^4.9.4",
"vitest": "^0.30.1",
"bump-pack": "file:../../tools/bump-pack"
"vitest": "^0.30.1"
},
"volta": {
"node": "18.16.0",
"npm": "8.19.3"
}
}
}
2 changes: 1 addition & 1 deletion apps/wing/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "winglang",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"implicitDependencies": ["wingc", "sdk", "compiler"],
"implicitDependencies": ["wingc", "sdk", "compiler", "console-app"],
"targets": {
"build": {
"dependsOn": ["^build"],
Expand Down
5 changes: 3 additions & 2 deletions apps/wing/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ async function main() {
program
.command("run")
.alias("it")
.description("Runs a Wing simulator file in the Wing Console")
.argument("[simfile]", ".wsim simulator file")
.description("Runs a Wing program in the Wing Console")
.argument("[entrypoint]", "program .w entrypoint")
.option("-p, --port <port>", "specify port")
.action(run);

program.command("lsp").description("Run the Wing language server on stdio").action(run_server);
Expand Down
68 changes: 65 additions & 3 deletions apps/wing/src/commands/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import open from "open";
import { createConsoleApp } from "@wingconsole/app";
import { run } from "./run";
import { mkdtemp } from "fs/promises";
import { join } from "path";
Expand All @@ -9,6 +10,16 @@ import { vi, test, expect } from "vitest";

vi.mock("open");

vi.mock("@wingconsole/app", () => {
return {
createConsoleApp: vi.fn((options?: { requestedPort?: number }) => {
return {
port: options?.requestedPort ?? 3000,
};
}),
};
});

test("wing it runs the only .w file", async () => {
const workdir = await mkdtemp(join(tmpdir(), "-wing-it-test"));
const prevdir = process.cwd();
Expand All @@ -18,7 +29,12 @@ test("wing it runs the only .w file", async () => {
writeFileSync("foo.w", "bring cloud;");

await run();
expect(open).toBeCalledWith("wing-console://" + resolve("foo.w"));
expect(createConsoleApp).toBeCalledWith({
wingfile: resolve("foo.w"),
requestedPort: undefined,
hostUtils: expect.anything(),
});
expect(open).toBeCalledWith("http://localhost:3000/");
} finally {
process.chdir(prevdir);
}
Expand Down Expand Up @@ -48,7 +64,12 @@ test("wing it with a file runs", async () => {
writeFileSync("foo.w", "bring cloud;");

await run("foo.w");
expect(open).toBeCalledWith("wing-console://" + resolve("foo.w"));
expect(createConsoleApp).toBeCalledWith({
wingfile: resolve("foo.w"),
requestedPort: undefined,
hostUtils: expect.anything(),
});
expect(open).toBeCalledWith("http://localhost:3000/");
} finally {
process.chdir(prevdir);
}
Expand All @@ -66,7 +87,12 @@ test("wing it with a nested file runs", async () => {
writeFileSync(filePath, "bring cloud;");

await run(filePath);
expect(open).toBeCalledWith("wing-console://" + resolve(filePath));
expect(createConsoleApp).toBeCalledWith({
wingfile: resolve(filePath),
requestedPort: undefined,
hostUtils: expect.anything(),
});
expect(open).toBeCalledWith("http://localhost:3000/");
} finally {
process.chdir(prevdir);
}
Expand All @@ -85,3 +111,39 @@ test("wing it with an invalid file throws exception", async () => {
process.chdir(prevdir);
}
});

test("wing it with a custom port runs", async () => {
const workdir = await mkdtemp(join(tmpdir(), "-wing-it-test"));
const prevdir = process.cwd();
try {
process.chdir(workdir);

writeFileSync("foo.w", "bring cloud;");

await run("foo.w", { port: "5000" });
expect(createConsoleApp).toBeCalledWith({
wingfile: resolve("foo.w"),
requestedPort: 5000,
hostUtils: expect.anything(),
});
expect(open).toBeCalledWith("http://localhost:5000/");
} finally {
process.chdir(prevdir);
}
});

test("wing it throws when invalid port number is used", async () => {
const workdir = await mkdtemp(join(tmpdir(), "-wing-it-test"));
const prevdir = process.cwd();
try {
process.chdir(workdir);

writeFileSync("foo.w", "bring cloud;");

await expect(async () => {
await run("foo.w", { port: "not a number" });
}).rejects.toThrowError('"not a number" is not a number');
} finally {
process.chdir(prevdir);
}
});
48 changes: 40 additions & 8 deletions apps/wing/src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,53 @@ import { readdirSync, existsSync } from "fs";
import { debug } from "debug";
import { resolve } from "path";
import open from "open";
import { createConsoleApp } from "@wingconsole/app";
import { parseNumericString } from "../util";

export async function run(simfile?: string) {
if (!simfile) {
/**
* Options for the `run` command.
* This is passed from Commander to the `run` function.
*/
export interface RunOptions {
/**
* Preferred port number.
*
* Falls back to a random port number if necessary.
*/
readonly port?: string;
}

/**
* Runs a Wing program in the Console.
* @param entrypoint The program .w entrypoint. Looks for a .w file in the current directory if not specified.
* @param options Run options.
*/
export async function run(entrypoint?: string, options?: RunOptions) {
if (!entrypoint) {
const wingFiles = readdirSync(".").filter((item) => item.endsWith(".w"));
if (wingFiles.length !== 1) {
throw new Error("Please specify which file you want to run");
}
simfile = wingFiles[0];
entrypoint = wingFiles[0];
}

if (!existsSync(simfile)) {
throw new Error(simfile + " doesn't exist");
if (!existsSync(entrypoint)) {
throw new Error(entrypoint + " doesn't exist");
}

simfile = resolve(simfile);
debug("calling wing console protocol with:" + simfile);
await open("wing-console://" + simfile);
entrypoint = resolve(entrypoint);
debug("opening the wing console with:" + entrypoint);

const { port } = await createConsoleApp({
wingfile: entrypoint,
requestedPort: parseNumericString(options?.port),
hostUtils: {
async openExternal(url) {
await open(url);
},
},
});
const url = `http://localhost:${port}/`;
await open(url);
console.log(`The Wing Console is running at ${url}`);
}
20 changes: 20 additions & 0 deletions apps/wing/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,23 @@ export async function generateTmpDir(sourcePath: string, ...additionalFiles: str

return tempWingFile;
}

/**
* Casts a numeric string to a number.
*
* Returns `undefined` if the string is empty.
*
* @throws If the string is not a number.
*/
export function parseNumericString(text?: string) {
if (!text) {
return undefined;
}

const number = Number(text);
if (isNaN(number)) {
throw new Error(`"${text}" is not a number`);
}

return number;
}
4 changes: 4 additions & 0 deletions tools/hangar/src/package.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
targetWingSDKSpec,
targetWingCompilerSpec,
targetWingSpec,
targetWingConsoleAppSpec,
targetWingConsoleServerSpec,
tmpDir,
wingBin,
} from "./paths";
Expand Down Expand Up @@ -44,6 +46,8 @@ export default async function () {
targetWingSDKSpec,
targetWingCompilerSpec,
targetWingSpec,
targetWingConsoleAppSpec,
targetWingConsoleServerSpec,
];
const installResult = await execa(npmBin, installArgs, {
cwd: tmpDir,
Expand Down
Loading

0 comments on commit 66ee18d

Please sign in to comment.