-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from subquery/new-project
New project structure + various changes
- Loading branch information
Showing
23 changed files
with
633 additions
and
443 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,4 +1,3 @@ | ||
import { getProjectJson } from "./info.ts"; | ||
import { resolve } from "@std/path/resolve"; | ||
import { Tar } from "@std/archive/tar"; | ||
import { walk } from "@std/fs/walk"; | ||
|
@@ -9,20 +8,39 @@ import type { IPFSClient } from "./ipfs.ts"; | |
// import * as esbuild from "https://deno.land/x/[email protected]/wasm.js"; | ||
// import * as esbuild from "esbuild"; | ||
import { denoPlugins } from "@luca/esbuild-deno-loader"; | ||
import { getDefaultSandbox } from "./sandbox/index.ts"; | ||
import { toReadableStream } from "@std/io/to-readable-stream"; | ||
import { readerFromStreamReader } from "@std/io/reader-from-stream-reader"; | ||
import { getSpinner } from "./util.ts"; | ||
import { Loader } from "./loader.ts"; | ||
|
||
export async function publishProject( | ||
projectPath: string, | ||
ipfs: IPFSClient, | ||
sandboxFactory = getDefaultSandbox, | ||
): Promise<string> { | ||
projectPath = await Deno.realPath(projectPath); | ||
const projectJson = await getProjectJson(projectPath, sandboxFactory); | ||
let code = await generateBundle(projectPath); | ||
const vectorDbPath = projectJson.vectorStorage?.path; | ||
const loader = new Loader(projectPath, ipfs); | ||
|
||
const [_, manifest, source] = await loader.getManifest(); | ||
if (source !== "local") { | ||
throw new Error("Cannot bundle a project that isn't local"); | ||
} | ||
|
||
// Upload project | ||
const [project, projectSource] = await loader.getProject(); | ||
if (projectSource === "local") { | ||
const spinner = getSpinner().start("Publishing project code"); | ||
try { | ||
const code = await generateBundle(project); | ||
const [{ cid: codeCid }] = await ipfs.addFile([code]); | ||
manifest.entry = `ipfs://${codeCid}`; | ||
spinner.succeed("Published project code"); | ||
} catch (e) { | ||
spinner.fail("Failed to publish project code"); | ||
throw e; | ||
} | ||
} | ||
|
||
// Upload vector db | ||
const vectorDbPath = manifest.vectorStorage?.path; | ||
if (vectorDbPath) { | ||
// Resolve the db path relative to the project | ||
const dbPath = resolve(dirname(projectPath), vectorDbPath); | ||
|
@@ -39,11 +57,9 @@ export async function publishProject( | |
|
||
const [{ cid }] = await ipfs.addFile([dbBuf]); | ||
|
||
code = updateProjectVectorDbPath( | ||
code, | ||
vectorDbPath, | ||
`ipfs://${cid}`, | ||
); | ||
// Update manifest | ||
manifest.vectorStorage!.path = `ipfs://${cid}`; | ||
|
||
spinner.succeed("Published vector db"); | ||
} catch (e) { | ||
spinner.fail("Failed to publish project vectordb"); | ||
|
@@ -52,8 +68,9 @@ export async function publishProject( | |
} | ||
} | ||
|
||
// Upload manifest | ||
const spinner = getSpinner().start("Publishing project to IPFS"); | ||
const [{ cid }] = await ipfs.addFile([code]); | ||
const [{ cid }] = await ipfs.addFile([JSON.stringify(manifest, null, 2)]); | ||
spinner.succeed("Published project to IPFS"); | ||
return `ipfs://${cid}`; | ||
} | ||
|
@@ -86,20 +103,6 @@ export async function generateBundle(projectPath: string): Promise<string> { | |
} | ||
} | ||
|
||
/** | ||
* @param code The raw bundled code | ||
* @param currentPath The current db path that will get replaced | ||
* @param newPath The new db path to replace | ||
* @returns Updated raw bundled code | ||
*/ | ||
function updateProjectVectorDbPath( | ||
code: string, | ||
currentPath: string, | ||
newPath: string, | ||
): string { | ||
return code.replaceAll(currentPath, newPath); | ||
} | ||
|
||
/** | ||
* Archives the lancedb directory into a file for uploading | ||
* @param dbPath The path to the lancedb directory | ||
|
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
Oops, something went wrong.