mirror of https://github.com/nodejs/corepack.git
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import cmdShim from '@zkochan/cmd-shim';
|
|
import fs from 'fs';
|
|
|
|
import config from './config.json';
|
|
import {SupportedPackageManagers} from 'sources/types';
|
|
|
|
async function main() {
|
|
for (const packageManager of Object.keys(config.definitions) as SupportedPackageManagers[]) {
|
|
const binSet = new Set<string>();
|
|
|
|
for (const spec of Object.values(config.definitions[packageManager].ranges)) {
|
|
if (Array.isArray(spec.bin)) {
|
|
for (const entry of spec.bin) {
|
|
binSet.add(entry);
|
|
}
|
|
} else {
|
|
for (const entry of Object.keys(spec.bin)) {
|
|
binSet.add(entry);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (const binaryName of binSet) {
|
|
const entryPath = `${__dirname}/dist/${binaryName}.js`;
|
|
const entryScript = [
|
|
`#!/usr/bin/env node\n`,
|
|
`require('./pmm').runMain(['${packageManager}', '${binaryName}', ...process.argv.slice(2)]);\n`,
|
|
].join(``);
|
|
|
|
fs.writeFileSync(entryPath, entryScript);
|
|
fs.chmodSync(entryPath, 0o755);
|
|
|
|
await cmdShim(entryPath, `${__dirname}/shims/${binaryName}`, {});
|
|
}
|
|
}
|
|
|
|
console.log(`All shims have been generated.`);
|
|
}
|
|
|
|
main().catch(err => {
|
|
console.log(err.stack);
|
|
process.exitCode = 1;
|
|
});
|