@antfu/ni
Version:
Use the right package manager
51 lines (43 loc) • 1.42 kB
JavaScript
; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _chunkRSW6MLYIjs = require('./chunk-RSW6MLYI.js');
// src/nr.ts
var import_prompts = _chunkRSW6MLYIjs.__toModule.call(void 0, _chunkRSW6MLYIjs.require_prompts.call(void 0, ));
// src/fs.ts
var _path = require('path');
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
function getPackageJSON() {
const path = _path.resolve.call(void 0, process.cwd(), "package.json");
if (_fs2.default.existsSync(path)) {
try {
const raw = _fs2.default.readFileSync(path, "utf-8");
const data = JSON.parse(raw);
return data;
} catch (e) {
console.warn("Failed to parse package.json");
process.exit(0);
}
}
}
// src/nr.ts
_chunkRSW6MLYIjs.runCli.call(void 0, async (agent, args) => {
if (args.length === 0) {
const scripts = getPackageJSON().scripts || {};
const names = Object.entries(scripts);
if (!names.length)
return;
try {
const {fn} = await (0, import_prompts.default)({
name: "fn",
message: "script to run",
type: "select",
choices: names.map(([value, description]) => ({title: value, value, description}))
});
if (!fn)
return;
args.push(fn);
} catch (e) {
process.exit(0);
}
}
return _chunkRSW6MLYIjs.parseNr.call(void 0, agent, args);
});