mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
Initial open-source release
This commit is contained in:
commit
1a42152e6f
1199 changed files with 257054 additions and 0 deletions
44
scripts/prepare-cli-bin.mjs
Normal file
44
scripts/prepare-cli-bin.mjs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import { constants } from 'node:fs';
|
||||
import { access, chmod } from 'node:fs/promises';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
|
||||
export function kloRootDir() {
|
||||
return resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
}
|
||||
|
||||
export function cliBinPath(rootDir = kloRootDir()) {
|
||||
return resolve(rootDir, 'packages', 'cli', 'dist', 'bin.js');
|
||||
}
|
||||
|
||||
async function canExecute(path) {
|
||||
try {
|
||||
await access(path, constants.X_OK);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function ensureCliBinExecutable(rootDir = kloRootDir()) {
|
||||
const binPath = cliBinPath(rootDir);
|
||||
await access(binPath, constants.R_OK);
|
||||
|
||||
if (process.platform !== 'win32' && !(await canExecute(binPath))) {
|
||||
await chmod(binPath, 0o755);
|
||||
}
|
||||
|
||||
return binPath;
|
||||
}
|
||||
|
||||
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||
try {
|
||||
const binPath = await ensureCliBinExecutable();
|
||||
process.stdout.write(`Prepared KLO CLI bin: ${binPath}\n`);
|
||||
} catch (error) {
|
||||
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue