-
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.
* add extract command * small rfks, finish cmd * bump ver
- Loading branch information
Showing
10 changed files
with
158 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "dria-cli", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "A command-line tool for Dria", | ||
"author": "FirstBatch Team <[email protected]>", | ||
"contributors": [ | ||
|
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { logger } from "../common"; | ||
import { getConfig } from "../configurations"; | ||
|
||
const config = getConfig(); | ||
|
||
/** ContractID parameter, as seen on every Dria knowledge. */ | ||
const contractId = { | ||
id: "contract" as const, | ||
opts: { | ||
alias: "c", | ||
describe: "Contract ID", | ||
type: "string", | ||
default: config.contract, | ||
} as const, | ||
} as const; | ||
|
||
/** Verbosity, will show extra information when enabled. */ | ||
const verbose = { | ||
id: "verbose" as const, | ||
opts: { | ||
alias: "v", | ||
describe: "Show extra information", | ||
boolean: true, | ||
default: false, | ||
coerce: (verbose: boolean) => { | ||
logger.setLevel(verbose ? "DEBUG" : "INFO"); | ||
return verbose; | ||
}, | ||
} as const, | ||
} as const; | ||
|
||
/** An Arweave txID, required for the `fetch` command. */ | ||
const txId = { | ||
id: "txid" as const, | ||
opts: { | ||
describe: "Transaction ID", | ||
type: "string", | ||
demandOption: true, | ||
} as const, | ||
} as const; | ||
|
||
/** A zip path, required for the `extract` command. */ | ||
const zipPath = { | ||
id: "zipPath" as const, | ||
opts: { | ||
describe: "Path to zip", | ||
type: "string", | ||
demandOption: true, | ||
} as const, | ||
} as const; | ||
|
||
export default { | ||
txId, | ||
zipPath, | ||
contractId, | ||
verbose, | ||
} as const; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { extractZip } from "../common"; | ||
import constants from "../constants"; | ||
|
||
/** | ||
* Extracts a zipped knowledge. | ||
* | ||
* This command is used in particular when you have a large knowledge and you would like to | ||
* move it around locally, without downloading the entire thing again. | ||
* | ||
* @param path Arweave txID to download | ||
*/ | ||
export default async function cmdExtract(path: string) { | ||
const outDir = constants.DRIA.DATA; | ||
await extractZip(path, outDir); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unzipper from "unzipper"; | ||
import { createReadStream, rmSync } from "fs"; | ||
import { logger } from "."; | ||
|
||
/** | ||
* Unzips a zip file. | ||
* | ||
* @param zipPath path to zip file | ||
* @param outDir path to extraction | ||
*/ | ||
export async function extractZip(zipPath: string, outDir: string) { | ||
try { | ||
await new Promise<void>((resolve, reject) => { | ||
createReadStream(zipPath) | ||
// unzips to out directory | ||
.pipe(unzipper.Extract({ path: outDir, verbose: process.env.NODE_ENV !== "test" })) | ||
.on("error", (err) => { | ||
reject(err); | ||
}) | ||
.on("close", () => { | ||
logger.info("Knowledge extracted at", outDir); | ||
logger.info("Cleaning up zip artifacts."); | ||
rmSync(zipPath); | ||
logger.info("Done."); | ||
resolve(); | ||
}); | ||
}); | ||
} catch (err) { | ||
logger.error((err as Error).toString()); | ||
|
||
logger.info(`Something went wrong while extracting the downloaded zip file. | ||
You can instead try unzipping via: | ||
unzip ${zipPath} -d ~/.dria/data | ||
`); | ||
} | ||
} |
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