Skip to content

Commit

Permalink
extract and cache files
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2-nomo committed Nov 22, 2023
1 parent 4796073 commit b57a364
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ nomo_cli.config.js
out/nomo_manifest.json

# Webon Files
out/nomo.tar.gz
out/nomo.tar.gz

# Cached WebOn Files
cache/
Empty file added cache/.gitkeep
Empty file.
48 changes: 48 additions & 0 deletions src/util/extract-tar-gz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { logFatal } from "../util/util";
import * as tar from "tar";
import { resolve, join } from "path";
import { existsSync } from "fs";

const requiredFiles = ["index.html", "nomo_icon.svg", "nomo_manifest.json"];
const cacheDirectory = "./cache";

export async function extractAndCache(args: {
tarFilePath: string;
destinationDir?: string;
}) {
const { tarFilePath, destinationDir = cacheDirectory } = args;

try {
await tar.x({
file: tarFilePath,
cwd: resolve(destinationDir),
});

/* Maybe possible to fetch fileNames as stream before extracting:
const getEntryFilenamesSync = (tarFilePath as any) => {
const filenames = requiredFiles;
tar.t({
file: tarFilePath,
onentry: (entry) => filenames.push(entry.path),
sync: true,
});
return filenames
};*/

const missingFiles = requiredFiles.filter((file) => {
const filePath = join(resolve(destinationDir), "/out/", file);
console.log(filePath);
return !existsSync(filePath);
});
if (missingFiles.length > 0) {
logFatal(
`Error: The following required files are missing: ${missingFiles.join(
", "
)}`
);
}
console.log(`Tar.gz file extracted successfully to: ${destinationDir}`);
} catch (error) {
logFatal(`Error extracting tar.gz file: ${error}`);
}
}
4 changes: 4 additions & 0 deletions src/util/ssh-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { logFatal, readCliConfig, runCommandsSequentially } from "../util/util";
import { extractAndCache } from "../util/extract-tar-gz";

let sshConnect = "";

Expand All @@ -21,6 +22,9 @@ export async function connectToSSH(args: {
const portOption = sshPort ? `-p ${sshPort}` : "";
sshConnect = `ssh -t ${sshHost} ${portOption}`;

await extractAndCache({
tarFilePath: archive,
});
const commands = [ls(), checkCreateDir(sshBaseDir)];

await runCommandsSequentially(commands);
Expand Down

0 comments on commit b57a364

Please sign in to comment.