From 9466b3be81b58696be91b30827a2c11cd025a992 Mon Sep 17 00:00:00 2001 From: Derek Anderson Date: Thu, 8 Sep 2022 12:57:32 -0500 Subject: [PATCH] cleanup (#40) --- src/commands/function/build.ts | 16 ++++++++++++++-- src/commands/function/deploy.ts | 13 ++++++++++--- src/commands/function/interfaces.ts | 2 ++ src/commands/function/publish.ts | 9 +++++---- src/lib/utils.ts | 17 +++++++++++++---- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/commands/function/build.ts b/src/commands/function/build.ts index 40f1309..5ff3ce4 100644 --- a/src/commands/function/build.ts +++ b/src/commands/function/build.ts @@ -10,12 +10,14 @@ 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, @@ -23,7 +25,9 @@ const createManifest = ( checksum: "", url, }, + contentType: "json", methods: [], + ...manifestOverride, }; return manifest; }; @@ -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" }); diff --git a/src/commands/function/deploy.ts b/src/commands/function/deploy.ts index 1dd65d7..b5f2bf4 100644 --- a/src/commands/function/deploy.ts +++ b/src/commands/function/deploy.ts @@ -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. @@ -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, + }); }; diff --git a/src/commands/function/interfaces.ts b/src/commands/function/interfaces.ts index e82eeca..d8f1fd9 100644 --- a/src/commands/function/interfaces.ts +++ b/src/commands/function/interfaces.ts @@ -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[]; } diff --git a/src/commands/function/publish.ts b/src/commands/function/publish.ts index 5bb7c3e..aa89e35 100644 --- a/src/commands/function/publish.ts +++ b/src/commands/function/publish.ts @@ -7,6 +7,7 @@ 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: "", @@ -14,8 +15,7 @@ const deploymentOptions: IDeploymentOptions = { 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 ( @@ -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( diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 2a213c4..0dd6750 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -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