continue-custom/scripts/util/index.js
maxxrdrgz 5edc0cba7e
Multi-Build/Package VS Code extensions on single computer. (#1473)
* added try catch on newly added code to buildjs that copies node_sqlite3 to a build directory that may not exist

* fix typo extensioins -> extensions

* added new npm command to build for all platforms

* started adding code to download the ripgrep binaries, will have to finish at a later date

* - added platforms global variable
- added check for --all parameter
- moved alpine check to utils
- moved all packaging code to package()
- added links to esbuild binaries
- chaged code in IIFE to either package for all or package for target

* moved alpine config to utils

* added the code that will download the ripgrep binaries

* added npm run script package-all which will run the package-all.js script

* added package-all script which will package all major builds

* - commented out old downloadEsbuildBinary and rewrote it
- finished the downloadRipgrepBinary() and exported it

* - added back some of the old code to make this script reusable
- commented out the esbuild download and install in favor of downloading the prebuilt binary
- download the ripgrep binary
- containerized the all of the package code into package() and call it in the IIFE

* added a check for the --target flag and append it to the vsce command

* removed unused variable
2024-06-14 10:43:31 -07:00

105 lines
2.8 KiB
JavaScript

const fs = require("fs");
const os = require("os");
const { execSync } = require("child_process");
function execCmdSync(cmd) {
try {
execSync(cmd);
} catch (err) {
console.error(`Error executing command '${cmd}': `, err.output.toString());
process.exit(1);
}
}
function autodetectPlatformAndArch() {
platform = {
aix: "linux",
alpine: "linux",
darwin: "darwin",
freebsd: "linux",
linux: "linux",
openbsd: "linux",
sunos: "linux",
win32: "win32",
}[process.platform];
arch = {
arm: "arm64",
armhf: "arm64",
arm64: "arm64",
ia32: "x64",
loong64: "arm64",
mips: "arm64",
mipsel: "arm64",
ppc: "x64",
ppc64: "x64",
riscv64: "arm64",
s390: "x64",
s390x: "x64",
x64: "x64",
}[process.arch];
return [platform, arch];
}
function validateFilesPresent(pathsToVerify) {
// This script verifies after pacakging that necessary files are in the correct locations
// In many cases just taking a sample file from the folder when they are all roughly the same thing
let missingFiles = [];
let emptyFiles = [];
for (const path of pathsToVerify) {
if (!fs.existsSync(path)) {
const parentFolder = path.split("/").slice(0, -1).join("/");
const grandparentFolder = path.split("/").slice(0, -2).join("/");
const grandGrandparentFolder = path.split("/").slice(0, -3).join("/");
console.error(`File ${path} does not exist`);
if (!fs.existsSync(parentFolder)) {
console.error(`Parent folder ${parentFolder} does not exist`);
} else {
console.error(
"Contents of parent folder:",
fs.readdirSync(parentFolder),
);
}
if (!fs.existsSync(grandparentFolder)) {
console.error(`Grandparent folder ${grandparentFolder} does not exist`);
if (!fs.existsSync(grandGrandparentFolder)) {
console.error(
`Grandgrandparent folder ${grandGrandparentFolder} does not exist`,
);
} else {
console.error(
"Contents of grandgrandparent folder:",
fs.readdirSync(grandGrandparentFolder),
);
}
} else {
console.error(
"Contents of grandparent folder:",
fs.readdirSync(grandparentFolder),
);
}
missingFiles.push(path);
}
if (fs.existsSync(path) && fs.statSync(path).size === 0) {
console.error(`File ${path} is empty`);
emptyFiles.push(path);
}
}
if (missingFiles.length > 0 || emptyFiles.length > 0) {
throw new Error(
`The following files were missing:\n- ${missingFiles.join("\n- ")}\n\nThe following files were empty:\n- ${emptyFiles.join("\n- ")}`,
);
} else {
console.log("All paths exist");
}
}
module.exports = {
execCmdSync,
validateFilesPresent,
autodetectPlatformAndArch,
};