-
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.
- Loading branch information
Showing
4 changed files
with
56 additions
and
1 deletion.
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
Empty file.
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,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}`); | ||
} | ||
} |
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