Skip to content

Commit

Permalink
Merge pull request #14 from subquery/feedback-fixes
Browse files Browse the repository at this point in the history
Feedback fixes
  • Loading branch information
stwiname authored Oct 23, 2024
2 parents 228fbfa + dd6537b commit 668bccc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 18 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subql/ai-app-framework",
"version": "1.0.0-4",
"version": "1.0.0-11",
"exports": {
"./cli": "./src/index.ts",
".": "./src/mod.ts"
Expand Down
4 changes: 4 additions & 0 deletions deno.lock

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

39 changes: 28 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ const sharedArgs = {
},
} satisfies Record<string, Options>;

const debugArgs = {
debug: {
description: "Enable debug logging",
type: "boolean",
default: false,
},
logFmt: {
description: "Set the logger format",
type: "string",
choices: ["json", "pretty"],
default: "pretty",
},
} satisfies Record<string, Options>;

function ipfsFromArgs(
argv: ArgumentsCamelCase<InferredOptionTypes<typeof sharedArgs>>,
): IPFSClient {
Expand All @@ -60,6 +74,7 @@ yargs(Deno.args)
"Run a SubQuery AI app",
{
...sharedArgs,
...debugArgs,
host: {
alias: "h",
description: "The ollama RPC host",
Expand Down Expand Up @@ -91,17 +106,6 @@ yargs(Deno.args)
type: "number",
default: 10_000, // 10s
},
debug: {
description: "Enable debug logging",
type: "boolean",
default: false,
},
logFmt: {
description: "Set the logger format",
type: "string",
choices: ["json", "pretty"],
default: "pretty",
},
},
async (argv) => {
try {
Expand Down Expand Up @@ -132,6 +136,7 @@ yargs(Deno.args)
"Get information on a project",
{
...sharedArgs,
...debugArgs,
json: {
description: "Log the project in JSON format",
default: false,
Expand All @@ -140,6 +145,10 @@ yargs(Deno.args)
},
async (argv) => {
try {
await initLogger(
argv.logFmt as "json" | "pretty",
argv.debug ? "debug" : undefined,
);
const { projectInfo } = await import("./subcommands/info.ts");
await projectInfo(argv.project, ipfsFromArgs(argv), argv.json);
Deno.exit(0);
Expand Down Expand Up @@ -214,13 +223,21 @@ yargs(Deno.args)
"Publishes a project to IPFS so it can be easily distributed",
{
...sharedArgs,
...debugArgs,
silent: {
description: "Disable all logging except for the output",
type: "boolean",
},
},
async (argv) => {
try {
if (!argv.silent) {
await initLogger(
argv.logFmt as "json" | "pretty",
argv.debug ? "debug" : undefined,
);
}

const { publishProject } = await import("./subcommands/bundle.ts");
if (argv.silent) {
setSpinner(ora({ isSilent: true }));
Expand Down
25 changes: 20 additions & 5 deletions src/loader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { dirname } from "@std/path/dirname";
import { CIDReg, type IPFSClient } from "./ipfs.ts";
import { resolve } from "@std/path/resolve";
import { fromFileUrl } from "@std/path/from-file-url";
import { CIDReg, type IPFSClient } from "./ipfs.ts";

import { UntarStream } from "@std/tar";
import { ensureDir, exists } from "@std/fs";
import type { Source } from "./util.ts";
Expand Down Expand Up @@ -31,7 +33,7 @@ async function loadScript(path: string): Promise<unknown> {
/**
* Loads a local manifest file (either json, ts or js)
*/
export async function loadManfiest(path: string): Promise<ProjectManifest> {
async function loadManfiest(path: string): Promise<ProjectManifest> {
let manifest: unknown;
try {
manifest = await loadJson(path);
Expand Down Expand Up @@ -104,7 +106,11 @@ export async function pullContent(

try {
// This should throw if the project is not a valid URL. This allows loading lancedb from gcs/s3
new URL(path);
const url = new URL(path);

if (url.protocol === "file:") {
return [fromFileUrl(path), "local"];
}

return [path, "remote"];
} catch (_e) {
Expand All @@ -118,12 +124,18 @@ export class Loader {
#ipfs: IPFSClient;
#force: boolean;

readonly projectPath: string;

constructor(
readonly projectPath: string,
projectPath: string,
ipfs: IPFSClient,
readonly tmpDir?: string,
force?: boolean,
) {
this.projectPath = projectPath.startsWith("file://")
? fromFileUrl(projectPath)
: projectPath;

this.#ipfs = ipfs;
this.#force = force ?? false;
}
Expand Down Expand Up @@ -154,10 +166,13 @@ export class Loader {
const [manifestPath, source] = await this.pullContent(
this.projectPath,
"manifest.json",
undefined,
Deno.cwd(),
);

const manifest = await loadManfiest(manifestPath);
logger.debug(`getManifest [${source}] ${manifestPath}`);
const manifest = await loadManfiest(manifestPath);

return [manifestPath, manifest, source];
}

Expand Down
2 changes: 1 addition & 1 deletion subquery-delegator

0 comments on commit 668bccc

Please sign in to comment.