UNPKG

typle

Version:

📦 Scan and install missing Typescript type definitions for your dependencies.

42 lines (40 loc) • 2.38 kB
import { __async, __spreadValues, getVersion, install, joincwd, logger_default, run } from "./chunk-EKF7COO5.mjs"; // src/cli.ts import { cli } from "clittle"; import { lilconfigSync } from "lilconfig"; import { existsSync } from "fs"; function runCLI() { return __async(this, null, function* () { let version = yield getVersion(), prog = cli("typle [patterns...]").version(version), configExplorer = lilconfigSync("typle", { stopDir: process.cwd(), packageProp: "typleConfig", cache: !0 }); function loadConfig(configPath) { var _a; try { return configPath && !existsSync(joincwd(configPath)) ? (logger_default.warn(configPath, "doesn't exist"), {}) : (_a = configPath ? configExplorer.load(configPath) : configExplorer.search()) == null ? void 0 : _a.config; } catch (e) { return logger_default.error("couldn't load the config file"), {}; } } prog.describe("Scan and install missing Typescript type definitions for dependencies in 'package.json'.").option("--no-silent, Run install silently.").option("--no-install, Whether to install packages automatically or just update package.json.").option("--pkg-manager [manager], Which package manager to use.", { type: "string" }).option("--ignore-packages [packages...], List of packages to ignore.").option("--ignore-deps [deps...], List of certain dependency fields to ignore e.g. 'dev'.").option("--config [path], Path to the config file.").option("--cwd [path], The current working directory.").option("--dry-run, It won't cause any changes to package.json.").example("$ typle --ignore-packages nodemon eslint").example("$ typle packages/*").action((args) => __async(this, null, function* () { let config = loadConfig(args.options.config), options = __spreadValues(__spreadValues({ patterns: args.patterns }, config), args.options); yield run(options); })), prog.command("install [...libraries]", "Install packages with their corresponding type declarations.", { alias: "i" }).example("$ typle i semver (will install both semver and @types/semver)").action((args) => __async(this, null, function* () { let options = __spreadValues(__spreadValues({}, loadConfig()), args.options); yield install(args.libraries, options); })), prog.parse(), logger_default.info("v" + version); }); } export { runCLI };