-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds two NPM scripts to handle compressing and decompressing the locations data in a reproducible way. Needs to be tested on Windows.
- Loading branch information
Showing
5 changed files
with
118 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,9 @@ yarn.lock | |
## windows | ||
desktop.ini | ||
|
||
## OSX | ||
.DS_Store | ||
|
||
## parcel | ||
.parcel-cache/ | ||
|
||
|
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,31 @@ | ||
// This script compresses the locations database into a 7z archive. | ||
|
||
const Seven = require("node-7z"); | ||
const path = require("node:path"); | ||
const { path7za } = require("7zip-bin"); | ||
|
||
const archivePath = path.resolve(__dirname, "../assets/compressed/locations.7z"); | ||
const locationsDir = path.resolve(__dirname, "../assets/database/locations/*"); | ||
|
||
let hadError = false; | ||
|
||
console.log(archivePath); | ||
console.log(locationsDir); | ||
|
||
const myStream = Seven.add(archivePath, locationsDir, { | ||
recursive: true, | ||
$bin: path7za, | ||
method: ["0=LZMA2"], | ||
compressionLevel: 9, | ||
}); | ||
|
||
myStream.on("end", () => { | ||
if (!hadError) { | ||
console.log("Compression completed successfully."); | ||
} | ||
}); | ||
|
||
myStream.on("error", (err) => { | ||
hadError = true; | ||
console.error(`Error compressing locations: ${err}`); | ||
}); |
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,47 @@ | ||
// This script removes the contents of the locations directory and then decompresses | ||
// the locations database from a 7z archive. | ||
|
||
const Seven = require("node-7z"); | ||
const path = require("node:path"); | ||
const fs = require("fs-extra"); | ||
const { path7za } = require("7zip-bin"); | ||
|
||
const archivePath = path.resolve(__dirname, "../assets/compressed/locations.7z"); | ||
const databaseDir = path.resolve(__dirname, "../assets/database/locations"); | ||
|
||
(async () => { | ||
try { | ||
const archiveExists = await fs.pathExists(archivePath); | ||
if (!archiveExists) { | ||
console.error("Error: Archive file does not exist:", archivePath); | ||
process.exit(1); | ||
} | ||
|
||
const locationsDir = path.join(databaseDir, "locations"); | ||
if (await fs.pathExists(locationsDir)) { | ||
await fs.remove(locationsDir); | ||
console.log("Existing locations directory removed."); | ||
} | ||
|
||
let hadError = false; | ||
|
||
const myStream = Seven.extractFull(archivePath, databaseDir, { | ||
$bin: path7za, | ||
overwrite: "a", | ||
}); | ||
|
||
myStream.on("end", () => { | ||
if (!hadError) { | ||
console.log("Decompression completed successfully."); | ||
} | ||
}); | ||
|
||
myStream.on("error", (err) => { | ||
hadError = true; | ||
console.error(`Error decompressing locations: ${err}`); | ||
}); | ||
} catch (err) { | ||
console.error(`Error during decompression: ${err}`); | ||
process.exit(1); | ||
} | ||
})(); |
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,30 @@ | ||
// This script sets the execute permission on the 7za binary if you're on macOS or Linux. | ||
|
||
const fs = require("node:fs"); | ||
const path = require("node:path"); | ||
const os = require("node:os"); | ||
|
||
const platform = os.platform(); | ||
const arch = os.arch(); | ||
|
||
let sevenZipPath; | ||
|
||
if (platform === "darwin") { | ||
// macOS | ||
sevenZipPath = path.join(__dirname, "..", "node_modules", "7zip-bin", "mac", arch, "7za"); | ||
} else if (platform === "linux") { | ||
// Linux | ||
sevenZipPath = path.join(__dirname, "..", "node_modules", "7zip-bin", "linux", arch, "7za"); | ||
} else { | ||
// Windows (or other) | ||
process.exit(0); | ||
} | ||
|
||
fs.chmod(sevenZipPath, 0o755, (err) => { | ||
if (err) { | ||
console.error("Failed to set execute permission on 7za:", err); | ||
process.exit(1); | ||
} else { | ||
console.log("Execute permission set on 7za."); | ||
} | ||
}); |