Skip to content

Commit

Permalink
Support fetching of files from gypsum in CLI scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Feb 20, 2024
1 parent 35a5dd8 commit ec2b31a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion scripts/fresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const args = parseArgs({
registry: {
type: "string",
},
gypsum: {
type: "string",
},
dir: {
type: "string",
}
Expand All @@ -21,7 +24,7 @@ const args = parseArgs({

const dir = utils.required(args, "dir");
const { db_paths, db_tokenizable } = utils.parseConfigurations(utils.required(args, "config"), dir);
const { list_projects, list_assets, list_versions, find_latest, read_summary, read_metadata } = utils.chooseSourceFunctions(utils.optional(args, "registry"));
const { list_projects, list_assets, list_versions, find_latest, read_summary, read_metadata } = utils.chooseSourceFunctions(utils.optional(args, "registry"), utils.optional(args, "gypsum"));

// Creating the timestamp here, just so that if there are any operations
// between now and completion of the index, we catch them in the updates. This
Expand Down
5 changes: 4 additions & 1 deletion scripts/manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const args = parseArgs({
registry: {
type: "string",
},
gypsum: {
type: "string",
},
dir: {
type: "string",
},
Expand All @@ -29,7 +32,7 @@ const args = parseArgs({
});

const { db_paths, db_tokenizable } = utils.parseConfigurations(utils.required(args, "config"), utils.required(args, "dir"));
const { list_projects, list_assets, list_versions, find_latest, read_summary, read_metadata } = utils.chooseSourceFunctions(utils.required(args, "registry"));
const { list_projects, list_assets, list_versions, find_latest, read_summary, read_metadata } = utils.chooseSourceFunctions(utils.optional(args, "registry"), utils.optional(args, "gypsum"));

await manualHandler(
db_paths,
Expand Down
2 changes: 1 addition & 1 deletion scripts/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const args = parseArgs({

const dir = utils.required(args, "dir");
const { db_paths, db_tokenizable } = utils.parseConfigurations(utils.required(args, "config"), dir);
const { list_logs, read_log, read_metadata, find_latest } = utils.chooseSourceFunctions(utils.optional(args, "registry"));
const { list_logs, read_log, read_metadata, find_latest } = utils.chooseSourceFunctions(utils.optional(args, "registry"), utils.optional(args, "gypsum"));

let lastmod_path = path.join(dir, "modified");
let lastmod = new Date(Number(fs.readFileSync(lastmod_path)));
Expand Down
18 changes: 15 additions & 3 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as local from "../src/local/index.js";
import * as gypsum from "../src/gypsum/index.js";
import * as fs from "fs";
import * as path from "path";

Expand All @@ -13,8 +14,8 @@ export function parseConfigurations(configs, dir) {
return { db_paths, db_tokenizable };
}

export function chooseSourceFunctions(registry) {
if (registry) {
export function chooseSourceFunctions(registry, gypsum_url) {
if (registry !== null) {
return {
list_projects: () => local.listProjects(registry),
list_assets: (project) => local.listAssets(registry, project),
Expand All @@ -25,8 +26,19 @@ export function chooseSourceFunctions(registry) {
read_metadata: (project, asset, version, to_extract) => local.readMetadata(registry, project, asset, version, to_extract),
find_latest: (project, asset) => local.fetchLatest(registry, project, asset),
};
} else if (gypsum_url !== null) {
return {
list_projects: () => gypsum.listProjects(gypsum_url),
list_assets: (project) => gypsum.listAssets(gypsum_url, project),
list_versions: (project, asset) => gypsum.listVersions(gypsum_url, project, asset),
list_logs: since => gypsum.listLogs(gypsum_url, since),
read_log: name => gypsum.readLog(gypsum_url, name),
read_summary: (project, asset, version) => gypsum.readSummary(gypsum_url, project, asset, version),
read_metadata: (project, asset, version, to_extract) => gypsum.readMetadata(gypsum_url, project, asset, version, to_extract),
find_latest: (project, asset) => gypsum.fetchLatest(gypsum_url, project, asset),
};
} else {
throw new Error("non-registry arguments are not yet supported");
throw new Error("one of 'registry' or 'gypsum' must be provided");
}
}

Expand Down

0 comments on commit ec2b31a

Please sign in to comment.