Skip to content

Commit

Permalink
Fixes command option naming (#115)
Browse files Browse the repository at this point in the history
* fixes command option naming

* increment version
  • Loading branch information
elliotBraem authored Jun 23, 2024
1 parent 12c5c59 commit 04c3792
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 46 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gateway/dist/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script id="env-config" type="application/json">
%ENV_CONFIG%
</script>
<script defer src="/runtime.7e5cf8eba6572b74d8b4.bundle.js"></script><script defer src="/main.fc0e4d548357304447f5.bundle.js"></script></head>
<script defer src="/runtime.8441d271053c46f9400c.bundle.js"></script><script defer src="/main.9f929cc4df2c98a03137.bundle.js"></script></head>

<body>
<noscript style="white-space: pre; font-family: monospace">
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gateway/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script id="env-config" type="application/json">
%ENV_CONFIG%
</script>
<script defer src="/runtime.7e5cf8eba6572b74d8b4.bundle.js"></script><script defer src="/main.fc0e4d548357304447f5.bundle.js"></script></head>
<script defer src="/runtime.8441d271053c46f9400c.bundle.js"></script><script defer src="/main.9f929cc4df2c98a03137.bundle.js"></script></head>

<body>
<noscript style="white-space: pre; font-family: monospace">
Expand Down
8 changes: 8 additions & 0 deletions gateway/dist/main.9f929cc4df2c98a03137.bundle.js

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions gateway/dist/main.fc0e4d548357304447f5.bundle.js

This file was deleted.

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

16 changes: 8 additions & 8 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ async function run() {
.option("-n, --network <network>", "network to build for", "mainnet")
.option("-l, --loglevel <loglevel>", "log level (ERROR, WARN, INFO, DEV, BUILD, DEBUG)", "DEV")
.option("-p, --port <port>", "Port to run the server on", "8080")
.option("-g, --gateway <gateway>", "Path to custom gateway dist", undefined)
.option("--no-gateway", "Disable the gateway", false)
.option("--no-hot", "Disable hot reloading", false)
.option("--no-open", "Disable opening the browser", false)
.option("-g, --gateway <gateway>", "Path to custom gateway dist", true)
.option("--no-gateway", "Disable the gateway")
.option("--no-hot", "Disable hot reloading")
.option("--no-open", "Disable opening the browser")
.action((src, opts) => {
global.log = new Logger(LogLevel[opts.loglevel.toUpperCase() as keyof typeof LogLevel]);
dev(src, opts).catch((e: Error) => {
Expand Down Expand Up @@ -63,10 +63,10 @@ async function run() {
.option("-n, --network <network>", "network to build for", "mainnet")
.option("-l, --loglevel <loglevel>", "log level (ERROR, WARN, INFO, DEV, BUILD, DEBUG)")
.option("-p, --port <port>", "Port to run the server on", "8080")
.option("-g, --gateway <gateway>", "Path to custom gateway dist", undefined)
.option("--no-gateway", "Disable the gateway", false)
.option("--no-hot", "Disable hot reloading", false)
.option("--no-open", "Disable opening the browser", false)
.option("-g, --gateway <gateway>", "Path to custom gateway dist", true)
.option("--no-gateway", "Disable the gateway")
.option("--no-hot", "Disable hot reloading")
.option("--no-open", "Disable opening the browser")
.action(async (command, src, dest, opts) => {
dest = dest || path.join(src, "dist")
if (command === "build") {
Expand Down
11 changes: 5 additions & 6 deletions lib/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ let fileWatcher: null | Gaze = null;

export type DevOptions = {
port?: number; // port to run dev server
NoGateway?: boolean; // disable local gateway
NoHot?: boolean; // disable hot reloading
NoOpen?: boolean; // do not open browser
hot?: boolean; // enable hot reloading
open?: boolean; // open browser
network?: Network; // network to use
gateway?: string; // path to custom gateway dist
gateway?: string | boolean; // path to custom gateway dist, or false to disable
index?: string; // widget to use as index
};

Expand Down Expand Up @@ -60,7 +59,7 @@ export async function dev(src: string, opts: DevOptions) {
const server = startDevServer(appSrcs, appDists, appDevJsonPath, appDevOptions);

// Start the socket server if hot reload is enabled
if (!opts.NoHot) {
if (opts.hot) {
io = startSocket(server, (io: IoServer) => {
readJson(devJsonPath).then((devJson: DevJson) => {
io?.emit("fileChange", devJson);
Expand Down Expand Up @@ -113,7 +112,7 @@ export async function devMulti(root: string, srcs: string[], opts: DevOptions) {
const server = startDevServer(appSrcs, appDists, appDevJsonPath, appDevOptions);

// Start the socket server if hot reload is enabled
if (!opts.NoHot) {
if (opts.hot) {
io = startSocket(server, (io: IoServer) => {
readJson(devJsonPath).then((devJson: DevJson) => {
io?.emit("fileChange", devJson);
Expand Down
2 changes: 1 addition & 1 deletion lib/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const handleReplacements = (html: string, opts: DevOptions): string => {
const envConfig = JSON.stringify({
bosLoaderWs: `ws://127.0.0.1:${opts.port}`,
bosLoaderUrl: `http://127.0.0.1:${opts.port}/api/loader`,
enableHotReload: opts.NoHot ? false : true,
enableHotReload: opts.hot,
network: opts.network,
});

Expand Down
12 changes: 6 additions & 6 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ export function createApp(devJsonPath: string, opts: DevOptions): Express.Applic
*/
app.all('/api/proxy-rpc', proxyMiddleware(RPC_URL[opts.network]));

if (!opts.NoGateway) {
if (opts.gateway) {
// do things with gateway
const gatewayPath = (opts.gateway && path.resolve(opts.gateway)) ?? GATEWAY_PATH;
const gatewayPath = typeof opts.gateway === "string" ? path.resolve(opts.gateway) : GATEWAY_PATH;

// let's check if gateway/dist/index.html exists
if (!(existsSync(path.join(gatewayPath, "index.html")))) {
log.error("Gateway not found. Skipping...");
opts.NoGateway = true;
opts.gateway = false;
} else {
// everything else is redirected to the gateway/dist
app.use((req, res, next) => {
Expand Down Expand Up @@ -241,7 +241,7 @@ export function createApp(devJsonPath: string, opts: DevOptions): Express.Applic
*/
export function startServer(server, opts, sendAddApps) {
server.listen(opts.port, "127.0.0.1", () => {
if (!opts.NoGateway && !opts.NoOpen) {
if (opts.gateway && opts.open) {
// open gateway in browser
let start =
process.platform == "darwin"
Expand All @@ -255,13 +255,13 @@ export function startServer(server, opts, sendAddApps) {
log.log(`
┌─────────────────────────────────────────────────────────────┐
│ BosLoader Server is Up and Running │
│ │${!opts.NoGateway
│ │${opts.gateway
? `
│ ➜ Local Gateway: \u001b[32mhttp://127.0.0.1:${opts.port}\u001b[0m │`
: ""
}
│ │
│ ➜ Bos Loader Http: \u001b[32mhttp://127.0.0.1:${opts.port}/api/loader\u001b[0m │${!opts.NoHot
│ ➜ Bos Loader Http: \u001b[32mhttp://127.0.0.1:${opts.port}/api/loader\u001b[0m │${opts.hot
? `
│ ➜ Bos Loader WebSocket: \u001b[32mws://127.0.0.1:${opts.port}\u001b[0m │`
: ""
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bos-workspace",
"version": "1.0.0-alpha.27",
"version": "1.0.0-alpha.28",
"description": "",
"bin": {
"bos-workspace": "./bin/bw.js",
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ describe("dev", () => {
});

it("should start the socket server if hot reload is enabled", async () => {
const mockHotOpts: DevOptions = { NoHot: false };
await dev(mockSrc, mockHotOpts);
const mockOpts: DevOptions = { hot: true };
await dev(mockSrc, mockOpts);
expect(startSocket).toHaveBeenCalled();
});

it("should not start the socket server if hot reload is disabled", async () => {
const mockNoHotOpts: DevOptions = { NoHot: true };
await dev(mockSrc, mockNoHotOpts);
const mockOpts: DevOptions = { hot: false };
await dev(mockSrc, mockOpts);
expect(startSocket).not.toHaveBeenCalled();
});

Expand All @@ -91,8 +91,8 @@ describe("dev", () => {
it("should add correct watch paths after adding apps", async () => {
const mockedGazeAdd = jest.spyOn(Gaze.prototype, 'add');

const mockHotOpts: DevOptions = { NoHot: true };
await dev(mockSrc, mockHotOpts);
const mockOpts: DevOptions = { hot: false };
await dev(mockSrc, mockOpts);

const mockSrc2 = "/app_example_2";
vol.fromJSON(app_example_2, mockSrc2);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("gateway", () => {
// Mocked input options
const mockOpts: DevOptions = {
port: 8080,
NoHot: false,
hot: true,
network: 'testnet' as Network,
index: "test/widget/index"
};
Expand All @@ -29,7 +29,7 @@ describe("gateway", () => {
const expectedConfig = JSON.stringify({
bosLoaderWs: `ws://127.0.0.1:8080`,
bosLoaderUrl: `http://127.0.0.1:8080/api/loader`,
enableHotReload: !mockOpts.NoHot,
enableHotReload: mockOpts.hot,
network: mockOpts.network,
});
const expectedHtmlOutput = `<html><head>${expectedConfig}</head><body></body></html>`;
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const app_example_1 = {
describe('createApp', () => {
let app;
const mockSrc = "/app_example_1";
const devJsonPath = `${mockSrc}/build/bos-loader.json`; // Replace with your path
const devJsonPath = `${mockSrc}/build/bos-loader.json`;
const opts = {
NoGateway: false,
gateway: true,
port: 3000,
NoHot: false,
hot: true,
network: 'testnet' as Network,
};

Expand Down

0 comments on commit 04c3792

Please sign in to comment.