Skip to content

Commit

Permalink
cleanup (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikey authored Sep 8, 2022
1 parent 7e19588 commit 9466b3b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/commands/function/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ import crypto from "crypto";
const createManifest = (
buildDir: string,
entry: string,
url: string
url: string,
manifestOverride: any
): IManifest => {
const name = entry.split(".")[0];
const manifest: IManifest = {
id: "",
name,
hooks: [],
description: "",
fs_root_path: "./",
entry,
runtime: {
checksum: "",
url,
},
contentType: "json",
methods: [],
...manifestOverride,
};
return manifest;
};
Expand All @@ -33,19 +37,27 @@ export const run = (options: {
name: string;
path: string;
rebuild: boolean;
manifest?: any;
}) => {
const {
debug = false,
name = basename(process.cwd()),
path = process.cwd(),
rebuild = false,
manifest = {},
} = options;
// check for and store unmodified wasm file name to change later
const defaultWasm = debug ? "debug.wasm" : "release.wasm";
const buildDir = `${path}/build`;
const wasmName = `${name}${debug ? "-debug" : ""}.wasm`;
const wasmArchive = `${name}.tar.gz`;
const wasmManifest = createManifest(buildDir, wasmName, wasmArchive);

const wasmManifest = createManifest(
buildDir,
wasmName,
wasmArchive,
manifest
);

const renameWasm = (path: string, oldName: string, newName: string) => {
execSync(`mv ${oldName} ${newName}`, { cwd: path, stdio: "inherit" });
Expand Down
13 changes: 10 additions & 3 deletions src/commands/function/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const deploymentOptions: IDeploymentOptions = {
userFunctionId: "",
};
const consoleServer = getConsoleServer();
const server = "https://console.bls.dev";
const server = consoleServer;
const token = getToken();

//TODO: make this a lot better.
Expand Down Expand Up @@ -76,11 +76,18 @@ export const run = (options: any) => {
} = options;

const {
bls: { functionId: userFunctionId },
bls: { functionId: userFunctionId, manifest },
} = require(`${path}/package`);

//TODO: this is absolutely monstrous and needs sanity applied
deploymentOptions.userFunctionId = userFunctionId;

runPublish({ debug, name, path, publishCallback: deployFunction, rebuild });
runPublish({
debug,
name,
path,
publishCallback: deployFunction,
rebuild,
manifest,
});
};
2 changes: 2 additions & 0 deletions src/commands/function/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ export interface IManifest {
limited_memory?: number;
entry: string;
resouces?: [];
hooks?: [];
runtime: {
checksum: string;
url: string;
};
contentType?: "json" | "html" | "text";
resources?: string[];
methods?: IWasmMethod[];
}
Expand Down
9 changes: 5 additions & 4 deletions src/commands/function/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { IDeploymentOptions } from "./interfaces";
import { run as runBuild } from "./build";
import { createWasmArchive, getBuildDir } from "./shared";
import { basename, resolve } from "path";
import { getWASMRepoServer } from "../../lib/utils";

const deploymentOptions: IDeploymentOptions = {
functionId: "",
functionName: "",
userFunctionId: "",
};

const server = "https://wasi.bls.dev";
// const server = "http://127.0.0.1:3000";
const server = getWASMRepoServer();
const token = getToken();

export const publishFunction = async (
Expand Down Expand Up @@ -61,13 +61,14 @@ export const run = (options: any) => {
const buildDir = getBuildDir(path);
const wasmName = `${name}${debug ? "-debug" : ""}.wasm`;
const wasmArchive = `${name}.tar.gz`;
const pkg = require(`${path}/package`);
const {
bls: { functionId: userFunctionId },
} = require(`${path}/package`);
} = pkg;

//TODO: this is absolutely monstrous and needssanity appplied
deploymentOptions.userFunctionId = userFunctionId;
runBuild({ debug, name, path, rebuild });
runBuild({ debug, name, path, rebuild, manifest: pkg?.bls?.manifest });

console.log(Chalk.yellow(`Publishing function located in ${buildDir}`));
publishFunction(
Expand Down
17 changes: 13 additions & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { execSync } from "child_process";

// API Server
// Console API Server
export const getConsoleServer = (
location: "local" | "remote" = "remote",
port?: number
) => {
const devMode = process.env.NODE_ENV === "development";
const local = location === "local";
const host = local ? "http://localhost" : "https://console.bls.dev";
return `${host}:${port ? port : devMode && local ? 3000 : 443}`;
const host = devMode ? "http://0.0.0.0" : "https://console.bls.dev";
return `${host}:${port ? port : devMode ? 3005 : 443}`;
};

// WASI Repo Server
export const getWASMRepoServer = (
location: "local" | "remote" = "remote",
port?: number
) => {
const devMode = process.env.NODE_ENV === "development";
const host = devMode ? "http://0.0.0.0" : "https://wasi.bls.dev";
return `${host}:${port ? port : devMode ? 3006 : 443}`;
};

// Node/npm config
Expand Down

0 comments on commit 9466b3b

Please sign in to comment.