-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
static www in api, remove corporate site (#2122)
* www: kind of working static build! * www: package all folder complexity in an esbuild plugin * www: fix static build, remove front page * www: implement isExport(), don't export Stripe * www: hide usage and billing in export * www: hide bottom navigation in export * www: remove components/site * www: make brand name more consistent * www: don't export ripe * www: don't export segment * www: default API url to document.location * www: don't export mux * www: safer getEndpoint resolution * www: cauterize window.analytics * build: remove pkg, use esbuild instead * api: fix docker build path * api: downgrade mime i guess * api: minify esbuild
- Loading branch information
Showing
128 changed files
with
615 additions
and
13,972 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
data | ||
dist | ||
dist-esbuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,75 @@ | ||
import esbuild from "esbuild"; | ||
// Builds a single-file zero-dependency version of the API server | ||
// with an embedded static version of the frontend. | ||
|
||
import * as esbuild from "esbuild"; | ||
import { readFile, readdir } from "fs/promises"; | ||
import { resolve, relative } from "path"; | ||
|
||
async function getFiles(dir) { | ||
const dirents = await readdir(dir, { withFileTypes: true }); | ||
let files = await Promise.all( | ||
dirents.map((dirent) => { | ||
const res = resolve(dir, dirent.name); | ||
return dirent.isDirectory() ? getFiles(res) : res; | ||
}) | ||
); | ||
return Array.prototype.concat(...files).filter((f) => !f.includes("cache")); | ||
} | ||
|
||
const generateFrontendManifest = async (rootPath) => { | ||
const output = [`module.exports = {`]; | ||
let files = await getFiles(rootPath); | ||
for (const file of files) { | ||
const key = relative(rootPath, file); | ||
output.push(` "${key}": require("${file}"),`); | ||
} | ||
output.push(`};`); | ||
return output.join("\n"); | ||
}; | ||
|
||
let frontendBundlePlugin = { | ||
name: "frontendBundle", | ||
setup(build) { | ||
build.onResolve({ filter: /.*frontend-stub$/ }, async (args) => { | ||
return { | ||
path: resolve(args.resolveDir, "..", "..", "www", "static-build"), | ||
namespace: "frontendBundle", | ||
}; | ||
}); | ||
|
||
// Any files from the static-build directory should be bundled as binary | ||
build.onLoad( | ||
{ namespace: "frontendBundle", filter: /.*static\-build/ }, | ||
async (args) => { | ||
return { | ||
contents: await generateFrontendManifest(args.path), | ||
loader: "js", | ||
resolveDir: resolve(args.resolveDir, args.path), | ||
}; | ||
} | ||
); | ||
|
||
// Any files from the static-build directory should be bundled as binary | ||
build.onLoad({ filter: /.*static\-build.+/ }, async (args) => { | ||
const contents = await readFile(args.path); | ||
return { | ||
contents: contents, | ||
loader: "binary", | ||
}; | ||
}); | ||
}, | ||
}; | ||
|
||
(async () => { | ||
await esbuild.build({ | ||
entryPoints: ["./src/cli.ts"], | ||
bundle: true, | ||
platform: "node", | ||
outfile: "./dist-esbuild/api.js", | ||
outfile: "./dist-esbuild/livepeer-api", | ||
target: "node18", | ||
alias: { | ||
"@livepeer.studio/www": "./src/frontend-stub.ts", | ||
}, | ||
external: ["pg-native"], | ||
sourcemap: "inline", | ||
plugins: [frontendBundlePlugin], | ||
minify: true, | ||
}); | ||
})(); |
Oops, something went wrong.