- Bump Node.js to version 18. This change is necessary as Node.js v16 will reach end-of-life on 2023-09-11. It also ensure compatibility with dependencies requiring minimum of Node.js v18, such as `vite`, `@vitejs`plugin-legacy` and `icon-gen`. - Bump `setup-node` action to v4. - Recommend using the `nvm` tool for managing Node.js versions in the documentation. - Update documentation to point to code reference for required Node.js version. This removes duplication of information, and keeps the code as single source of truth for required Node.js version. - Refactor code to adopt the `node:` protocol for Node API imports as per Node.js 18 standards. This change addresses ambiguities and aligns with Node.js best practices (nodejs/node#38343). Currently, there is no ESLint rule to enforce this protocol, as noted in import-js/eslint-plugin-import#2717. - Replace `cross-fetch` dependency with the native Node.js fetch API introduced in Node.js 18. Adjust type casting for async iterable read streams to align with the latest Node.js APIs, based on discussions in DefinitelyTyped/DefinitelyTyped#65542.
59 lines
2.2 KiB
JavaScript
59 lines
2.2 KiB
JavaScript
/**
|
|
* Description:
|
|
* This script determines the absolute path of a distribution directory based on CLI arguments
|
|
* and outputs its absolute path. It is designed to be run programmatically by other scripts.
|
|
*
|
|
* Usage:
|
|
* node scripts/print-dist-dir.js [options]
|
|
*
|
|
* Options:
|
|
* --electron-unbundled Path for the unbundled Electron application
|
|
* --electron-bundled Path for the bundled Electron application
|
|
* --web Path for the web application
|
|
*/
|
|
|
|
import { resolve } from 'node:path';
|
|
import { readFile } from 'node:fs/promises';
|
|
|
|
const DIST_DIRS_JSON_FILE_PATH = resolve(process.cwd(), 'dist-dirs.json'); // cannot statically import because ESLint does not support it https://github.com/eslint/eslint/discussions/15305
|
|
const CLI_ARGUMENTS = process.argv.slice(2);
|
|
|
|
async function main() {
|
|
const distDirs = await readDistDirsJsonFile(DIST_DIRS_JSON_FILE_PATH);
|
|
const relativeDistDir = determineRelativeDistDir(distDirs, CLI_ARGUMENTS);
|
|
const absoluteDistDir = resolve(process.cwd(), relativeDistDir);
|
|
console.log(absoluteDistDir);
|
|
}
|
|
|
|
function mapCliFlagsToDistDirs(distDirs) {
|
|
return {
|
|
'--electron-unbundled': distDirs.electronUnbundled,
|
|
'--electron-bundled': distDirs.electronBundled,
|
|
'--web': distDirs.web,
|
|
};
|
|
}
|
|
|
|
function determineRelativeDistDir(distDirsJsonObject, cliArguments) {
|
|
const cliFlagDistDirMap = mapCliFlagsToDistDirs(distDirsJsonObject);
|
|
const availableCliFlags = Object.keys(cliFlagDistDirMap);
|
|
const requestedCliFlags = cliArguments.filter((arg) => {
|
|
return availableCliFlags.includes(arg);
|
|
});
|
|
if (!requestedCliFlags.length) {
|
|
throw new Error(`No distribution directory was requested. Please use one of these flags: ${availableCliFlags.join(', ')}`);
|
|
}
|
|
if (requestedCliFlags.length > 1) {
|
|
throw new Error(`Multiple distribution directories were requested, but this script only supports one: ${requestedCliFlags.join(', ')}`);
|
|
}
|
|
const selectedCliFlag = requestedCliFlags[0];
|
|
return cliFlagDistDirMap[selectedCliFlag];
|
|
}
|
|
|
|
async function readDistDirsJsonFile(absoluteConfigJsonFilePath) {
|
|
const fileContentAsText = await readFile(absoluteConfigJsonFilePath, 'utf8');
|
|
const parsedJsonData = JSON.parse(fileContentAsText);
|
|
return parsedJsonData;
|
|
}
|
|
|
|
await main();
|