-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Hiroshiba <[email protected]>
- Loading branch information
1 parent
64e0447
commit 9557b1e
Showing
12 changed files
with
603 additions
and
312 deletions.
There are no files selected for viewing
Binary file not shown.
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,91 @@ | ||
// @ts-check | ||
/** | ||
* OSに合った7-Zipのバイナリとライセンスをダウンロードするスクリプト。 | ||
*/ | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const { spawnSync } = require("child_process"); | ||
|
||
(async () => { | ||
// node-fetchはESModuleなので、import()で読み込む | ||
const { default: fetch } = await import("node-fetch"); | ||
const distPath = path.resolve(__dirname, "vendored", "7z"); | ||
let url; | ||
let filesToExtract; | ||
switch (process.platform) { | ||
case "win32": { | ||
// 7za.exeは7z形式で圧縮されているので、7zr.exeが必要になる。 | ||
// Mac/Linuxと違い、インストーラー以外には7z形式でしか配布されていない。 | ||
// Actionsでインストーラーを動かすことはできないので、単独で配布されている7zr.exeを使い、 | ||
// 7z形式で圧縮されている7za.exeを展開する。 | ||
const sevenzrUrl = "https://www.7-zip.org/a/7zr.exe"; | ||
const sevenzrPath = path.resolve(distPath, "7zr.exe"); | ||
if (!fs.existsSync(sevenzrPath)) { | ||
console.log("Downloading 7zr from " + sevenzrUrl); | ||
const res = await fetch(sevenzrUrl); | ||
const buffer = await res.arrayBuffer(); | ||
|
||
await fs.promises.writeFile(sevenzrPath, Buffer.from(buffer)); | ||
} | ||
|
||
url = "https://www.7-zip.org/a/7z2201-extra.7z"; | ||
// 7za.dll、7zxa.dllはなくても動くので、除外する | ||
// filesToExtract = ["7za.exe", "7za.dll", "7zxa.dll", "License.txt"]; | ||
filesToExtract = ["7za.exe", "License.txt"]; | ||
|
||
break; | ||
} | ||
case "linux": { | ||
url = "https://www.7-zip.org/a/7z2201-linux-x64.tar.xz"; | ||
filesToExtract = ["7zzs", "License.txt"]; | ||
break; | ||
} | ||
case "darwin": { | ||
url = "https://www.7-zip.org/a/7z2107-mac.tar.xz"; | ||
filesToExtract = ["7zz", "License.txt"]; | ||
break; | ||
} | ||
default: { | ||
throw new Error("Unsupported platform"); | ||
} | ||
} | ||
|
||
const existingFiles = await fs.promises.readdir(distPath); | ||
|
||
const notDownloaded = filesToExtract.filter( | ||
(file) => !existingFiles.includes(file) | ||
); | ||
|
||
if (notDownloaded.length === 0) { | ||
console.log("7z already downloaded"); | ||
return; | ||
} | ||
|
||
console.log("Downloading 7z from " + url); | ||
const res = await fetch(url); | ||
const buffer = await res.arrayBuffer(); | ||
const sevenZipPath = path.resolve(distPath, path.basename(url)); | ||
await fs.promises.writeFile(sevenZipPath, Buffer.from(buffer)); | ||
|
||
console.log("Extracting 7z"); | ||
const extractor = url.endsWith(".7z") | ||
? spawnSync( | ||
path.resolve(distPath, "7zr.exe"), | ||
["x", "-y", "-o" + distPath, sevenZipPath, ...filesToExtract], | ||
{ | ||
stdio: ["ignore", "inherit", "inherit"], | ||
} | ||
) | ||
: spawnSync( | ||
"tar", | ||
["xvf", sevenZipPath, "-v", "-C", distPath, ...filesToExtract], | ||
{ | ||
stdio: ["ignore", "inherit", "inherit"], | ||
} | ||
); | ||
|
||
if (extractor.status !== 0) { | ||
console.error("Failed to extract 7z"); | ||
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
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,4 @@ | ||
* | ||
!README.md | ||
!.gitignore | ||
!*/.gitkeep |
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,7 @@ | ||
# build/vendored | ||
|
||
このディレクトリはダウンロードしたファイルを格納するためのものです。 | ||
|
||
| ディレクトリ名 | 内容 | ダウンローダー | | ||
| -------------- | ------------------------------ | --------------------- | | ||
| `7z` | [7-Zip](http://www.7-zip.org/) | `build/download7z.js` | |
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
Oops, something went wrong.