mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 08:11:24 +02:00
Only download protoc if necessary
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"app-build": "tauri build",
|
"app-build": "tauri build",
|
||||||
"app-dev": "tauri dev --no-watch --config ./src-tauri/tauri-dev.conf.json",
|
"app-dev": "tauri dev --no-watch --config ./src-tauri/tauri-dev.conf.json",
|
||||||
"bootstrap": "run-p bootstrap:* && npm run --workspaces --if-present build",
|
"bootstrap": "run-p bootstrap:* && npm run -w plugin-runtime build",
|
||||||
"bootstrap:vendor-node": "node scripts/vendor-node.cjs",
|
"bootstrap:vendor-node": "node scripts/vendor-node.cjs",
|
||||||
"bootstrap:vendor-plugins": "node scripts/vendor-plugins.cjs",
|
"bootstrap:vendor-plugins": "node scripts/vendor-plugins.cjs",
|
||||||
"bootstrap:vendor-protoc": "node scripts/vendor-protoc.cjs",
|
"bootstrap:vendor-protoc": "node scripts/vendor-protoc.cjs",
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const decompress = require('decompress');
|
const decompress = require('decompress');
|
||||||
const Downloader = require("nodejs-file-downloader");
|
const Downloader = require('nodejs-file-downloader');
|
||||||
const {rmSync, cpSync, mkdirSync, existsSync} = require("node:fs");
|
const { rmSync, cpSync, mkdirSync, existsSync } = require('node:fs');
|
||||||
const {execSync} = require("node:child_process");
|
const { execSync } = require('node:child_process');
|
||||||
|
|
||||||
const NODE_VERSION = 'v22.5.1';
|
const NODE_VERSION = 'v22.5.1';
|
||||||
|
|
||||||
@@ -39,20 +39,20 @@ const destDir = path.join(__dirname, `..`, 'src-tauri', 'vendored', 'node');
|
|||||||
const binDest = path.join(destDir, DST_BIN_MAP[key]);
|
const binDest = path.join(destDir, DST_BIN_MAP[key]);
|
||||||
console.log(`Vendoring NodeJS ${NODE_VERSION} for ${key}`);
|
console.log(`Vendoring NodeJS ${NODE_VERSION} for ${key}`);
|
||||||
|
|
||||||
if (existsSync(binDest) && execSync(`${binDest} --version`).toString('utf-8').trim() === NODE_VERSION) {
|
if (existsSync(binDest) && tryExecSync(`${binDest} --version`).trim() === NODE_VERSION) {
|
||||||
console.log("NodeJS already vendored");
|
console.log('NodeJS already vendored');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rmSync(destDir, {recursive: true, force: true});
|
rmSync(destDir, { recursive: true, force: true });
|
||||||
mkdirSync(destDir, {recursive: true});
|
mkdirSync(destDir, { recursive: true });
|
||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
const url = URL_MAP[key];
|
const url = URL_MAP[key];
|
||||||
const tmpDir = path.join(__dirname, 'tmp', Date.now().toString());
|
const tmpDir = path.join(__dirname, 'tmp', Date.now().toString());
|
||||||
|
|
||||||
// Download GitHub release artifact
|
// Download GitHub release artifact
|
||||||
const {filePath} = await new Downloader({url, directory: tmpDir}).download();
|
const { filePath } = await new Downloader({ url, directory: tmpDir }).download();
|
||||||
|
|
||||||
// Decompress to the same directory
|
// Decompress to the same directory
|
||||||
await decompress(filePath, tmpDir, {});
|
await decompress(filePath, tmpDir, {});
|
||||||
@@ -60,10 +60,18 @@ mkdirSync(destDir, {recursive: true});
|
|||||||
// Copy binary
|
// Copy binary
|
||||||
const binSrc = path.join(tmpDir, SRC_BIN_MAP[key]);
|
const binSrc = path.join(tmpDir, SRC_BIN_MAP[key]);
|
||||||
cpSync(binSrc, binDest);
|
cpSync(binSrc, binDest);
|
||||||
rmSync(tmpDir, {recursive: true, force: true});
|
rmSync(tmpDir, { recursive: true, force: true });
|
||||||
|
|
||||||
console.log("Downloaded NodeJS to", binDest);
|
console.log('Downloaded NodeJS to', binDest);
|
||||||
})().catch(err => {
|
})().catch((err) => {
|
||||||
console.log('Script failed:', err);
|
console.log('Script failed:', err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function tryExecSync(cmd) {
|
||||||
|
try {
|
||||||
|
return execSync(cmd).toString('utf-8');
|
||||||
|
} catch (_) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
const decompress = require('decompress');
|
const decompress = require('decompress');
|
||||||
const Downloader = require("nodejs-file-downloader");
|
const Downloader = require('nodejs-file-downloader');
|
||||||
const path = require("node:path");
|
const path = require('node:path');
|
||||||
const {rmSync, mkdirSync, cpSync} = require("node:fs");
|
const { rmSync, mkdirSync, cpSync, existsSync } = require('node:fs');
|
||||||
|
const { execSync } = require('node:child_process');
|
||||||
|
|
||||||
const VERSION = '27.2';
|
const VERSION = '27.2';
|
||||||
|
|
||||||
@@ -33,32 +34,46 @@ const DST_BIN_MAP = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const dstDir = path.join(__dirname, `..`, 'src-tauri', 'vendored', 'protoc');
|
const dstDir = path.join(__dirname, `..`, 'src-tauri', 'vendored', 'protoc');
|
||||||
rmSync(dstDir, {recursive: true, force: true});
|
const key = `${process.platform}_${process.env.YAAK_TARGET_ARCH ?? process.arch}`;
|
||||||
mkdirSync(dstDir, {recursive: true});
|
console.log(`Vendoring protoc ${VERSION} for ${key}`);
|
||||||
|
|
||||||
|
const url = URL_MAP[key];
|
||||||
|
const tmpDir = path.join(__dirname, 'tmp', Date.now().toString());
|
||||||
|
const binSrc = path.join(tmpDir, SRC_BIN_MAP[key]);
|
||||||
|
const binDst = path.join(dstDir, DST_BIN_MAP[key]);
|
||||||
|
|
||||||
|
if (existsSync(binDst) && tryExecSync(`${binDst} --version`).trim().includes(VERSION)) {
|
||||||
|
console.log('Protoc already vendored');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rmSync(dstDir, { recursive: true, force: true });
|
||||||
|
mkdirSync(dstDir, { recursive: true });
|
||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
const key = `${process.platform}_${process.env.YAAK_TARGET_ARCH ?? process.arch}`;
|
|
||||||
console.log(`Vendoring protoc ${VERSION} for ${key}`);
|
|
||||||
const url = URL_MAP[key];
|
|
||||||
const tmpDir = path.join(__dirname, 'tmp', Date.now().toString());
|
|
||||||
|
|
||||||
// Download GitHub release artifact
|
// Download GitHub release artifact
|
||||||
const {filePath} = await new Downloader({url, directory: tmpDir,}).download();
|
const { filePath } = await new Downloader({ url, directory: tmpDir }).download();
|
||||||
|
|
||||||
// Decompress to the same directory
|
// Decompress to the same directory
|
||||||
await decompress(filePath, tmpDir, {});
|
await decompress(filePath, tmpDir, {});
|
||||||
|
|
||||||
// Copy binary
|
// Copy binary
|
||||||
const binSrc = path.join(tmpDir, SRC_BIN_MAP[key]);
|
|
||||||
const binDst = path.join(dstDir, DST_BIN_MAP[key]);
|
|
||||||
cpSync(binSrc, binDst);
|
cpSync(binSrc, binDst);
|
||||||
|
|
||||||
// Copy other files
|
// Copy other files
|
||||||
const includeSrc = path.join(tmpDir, 'include');
|
const includeSrc = path.join(tmpDir, 'include');
|
||||||
const includeDst = path.join(dstDir, 'include');
|
const includeDst = path.join(dstDir, 'include');
|
||||||
cpSync(includeSrc, includeDst, {recursive: true});
|
cpSync(includeSrc, includeDst, { recursive: true });
|
||||||
|
|
||||||
rmSync(tmpDir, {recursive: true, force: true});
|
rmSync(tmpDir, { recursive: true, force: true });
|
||||||
|
|
||||||
console.log("Downloaded protoc to", binDst);
|
console.log('Downloaded protoc to', binDst);
|
||||||
})().catch(err => console.log('Script failed:', err));
|
})().catch((err) => console.log('Script failed:', err));
|
||||||
|
|
||||||
|
function tryExecSync(cmd) {
|
||||||
|
try {
|
||||||
|
return execSync(cmd).toString('utf-8');
|
||||||
|
} catch (_) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user