@nmakarov/cli-toolkit 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +310 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +298 -1
- package/dist/index.js.map +1 -1
- package/dist/init.cjs +1110 -0
- package/dist/init.cjs.map +1 -0
- package/dist/init.js +1079 -0
- package/dist/init.js.map +1 -0
- package/dist/logger.cjs +13 -2
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.js +13 -2
- package/dist/logger.js.map +1 -1
- package/dist/screen.cjs +24 -2
- package/dist/screen.cjs.map +1 -1
- package/dist/screen.js +15 -1
- package/dist/screen.js.map +1 -1
- package/package.json +4 -2
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
Args: () => Args,
|
|
34
|
+
Box: () => import_ink5.Box,
|
|
34
35
|
Db: () => Db,
|
|
35
36
|
Divider: () => Divider,
|
|
36
37
|
FileDatabase: () => FileDatabase,
|
|
@@ -43,12 +44,14 @@ __export(src_exports, {
|
|
|
43
44
|
MultiColumnListComponent: () => MultiColumnListComponent,
|
|
44
45
|
MultiColumnListWithPreviewComponent: () => MultiColumnListWithPreviewComponent,
|
|
45
46
|
Params: () => Params,
|
|
47
|
+
React: () => import_react5.default,
|
|
46
48
|
ScreenBody: () => ScreenBody,
|
|
47
49
|
ScreenContainer: () => ScreenContainer,
|
|
48
50
|
ScreenDivider: () => ScreenDivider,
|
|
49
51
|
ScreenFooter: () => ScreenFooter,
|
|
50
52
|
ScreenRow: () => ScreenRow,
|
|
51
53
|
ScreenTitle: () => ScreenTitle,
|
|
54
|
+
Text: () => import_ink5.Text,
|
|
52
55
|
TextBlock: () => TextBlock,
|
|
53
56
|
buildBreadcrumb: () => buildBreadcrumb,
|
|
54
57
|
buildDetailBreadcrumb: () => buildDetailBreadcrumb,
|
|
@@ -57,15 +60,23 @@ __export(src_exports, {
|
|
|
57
60
|
defaultVersionSynopsisFunction: () => defaultVersionSynopsisFunction,
|
|
58
61
|
getArgsInstance: () => getArgsInstance,
|
|
59
62
|
getParamsInstance: () => getParamsInstance,
|
|
63
|
+
h: () => import_react5.createElement,
|
|
60
64
|
joiEdateType: () => joiEdateType,
|
|
61
65
|
joiStringArrayType: () => joiStringArrayType,
|
|
62
66
|
organizeFooterMessages: () => organizeFooterMessages,
|
|
67
|
+
setupContext: () => setupContext,
|
|
63
68
|
showListScreen: () => showListScreen,
|
|
64
69
|
showMenuScreen: () => showMenuScreen,
|
|
65
70
|
showMultiColumnListScreen: () => showMultiColumnListScreen,
|
|
66
71
|
showMultiColumnListWithPreviewScreen: () => showMultiColumnListWithPreviewScreen,
|
|
67
72
|
showScreen: () => showScreen,
|
|
68
|
-
showWordGridScreen: () => showWordGridScreen
|
|
73
|
+
showWordGridScreen: () => showWordGridScreen,
|
|
74
|
+
useCallback: () => import_react5.useCallback,
|
|
75
|
+
useEffect: () => import_react5.useEffect,
|
|
76
|
+
useInput: () => import_ink5.useInput,
|
|
77
|
+
useMemo: () => import_react5.useMemo,
|
|
78
|
+
useRef: () => import_react5.useRef,
|
|
79
|
+
useState: () => import_react5.useState
|
|
69
80
|
});
|
|
70
81
|
module.exports = __toCommonJS(src_exports);
|
|
71
82
|
|
|
@@ -798,6 +809,10 @@ var Params = class {
|
|
|
798
809
|
var paramsInstance = null;
|
|
799
810
|
var getParamsInstance = () => paramsInstance;
|
|
800
811
|
|
|
812
|
+
// src/screen/index.ts
|
|
813
|
+
var import_react5 = __toESM(require("react"), 1);
|
|
814
|
+
var import_ink5 = require("ink");
|
|
815
|
+
|
|
801
816
|
// src/screen/screens.ts
|
|
802
817
|
var import_react3 = require("react");
|
|
803
818
|
var import_ink3 = require("ink");
|
|
@@ -2960,9 +2975,292 @@ var Db = class {
|
|
|
2960
2975
|
return this.isConnected && this.knexInstance !== null;
|
|
2961
2976
|
}
|
|
2962
2977
|
};
|
|
2978
|
+
|
|
2979
|
+
// src/logger/index.ts
|
|
2980
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
2981
|
+
var import_util = __toESM(require("util"), 1);
|
|
2982
|
+
|
|
2983
|
+
// src/logger/transports.ts
|
|
2984
|
+
var ConsoleTransport = class {
|
|
2985
|
+
write(payload) {
|
|
2986
|
+
console.info(payload);
|
|
2987
|
+
}
|
|
2988
|
+
};
|
|
2989
|
+
var ParentProcessTransport = class {
|
|
2990
|
+
write(payload) {
|
|
2991
|
+
if (process.env.VITEST || process.env.NODE_ENV === "test") {
|
|
2992
|
+
console.info(payload);
|
|
2993
|
+
return;
|
|
2994
|
+
}
|
|
2995
|
+
if (typeof process.send === "function" && process.connected === true) {
|
|
2996
|
+
process.send(payload);
|
|
2997
|
+
} else {
|
|
2998
|
+
console.info(payload);
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
};
|
|
3002
|
+
|
|
3003
|
+
// src/logger/index.ts
|
|
3004
|
+
var ALL_LEVELS = [
|
|
3005
|
+
"silly",
|
|
3006
|
+
"debug",
|
|
3007
|
+
"logic",
|
|
3008
|
+
"info",
|
|
3009
|
+
"notice",
|
|
3010
|
+
"warn",
|
|
3011
|
+
"error",
|
|
3012
|
+
"results",
|
|
3013
|
+
"request",
|
|
3014
|
+
"response",
|
|
3015
|
+
"progress"
|
|
3016
|
+
];
|
|
3017
|
+
var LEVEL_COLORS = {
|
|
3018
|
+
error: import_chalk.default.red.bold,
|
|
3019
|
+
warn: import_chalk.default.rgb(255, 165, 0),
|
|
3020
|
+
notice: import_chalk.default.cyan,
|
|
3021
|
+
info: import_chalk.default.white.bold,
|
|
3022
|
+
logic: import_chalk.default.gray,
|
|
3023
|
+
debug: import_chalk.default.gray,
|
|
3024
|
+
silly: import_chalk.default.gray,
|
|
3025
|
+
request: import_chalk.default.green,
|
|
3026
|
+
response: import_chalk.default.yellow,
|
|
3027
|
+
progress: import_chalk.default.green,
|
|
3028
|
+
results: import_chalk.default.magenta
|
|
3029
|
+
};
|
|
3030
|
+
var CliToolkitLogger = class {
|
|
3031
|
+
options;
|
|
3032
|
+
transport;
|
|
3033
|
+
startTimes = {};
|
|
3034
|
+
lastProgressTimes = {};
|
|
3035
|
+
constructor(options = {}) {
|
|
3036
|
+
this.options = this.normalizeOptions(options);
|
|
3037
|
+
this.transport = this.options.route === "ipc" ? new ParentProcessTransport() : new ConsoleTransport();
|
|
3038
|
+
}
|
|
3039
|
+
setMode(mode) {
|
|
3040
|
+
if (!this.isValidMode(mode)) {
|
|
3041
|
+
throw new Error(`Unsupported logger mode: ${mode}`);
|
|
3042
|
+
}
|
|
3043
|
+
this.options.mode = mode;
|
|
3044
|
+
}
|
|
3045
|
+
debug(message, ...chunks) {
|
|
3046
|
+
this.out({ level: "debug", message, chunks });
|
|
3047
|
+
}
|
|
3048
|
+
info(message, ...chunks) {
|
|
3049
|
+
this.out({ level: "info", message, chunks });
|
|
3050
|
+
}
|
|
3051
|
+
notice(message, ...chunks) {
|
|
3052
|
+
this.out({ level: "notice", message, chunks });
|
|
3053
|
+
}
|
|
3054
|
+
warn(message, ...chunks) {
|
|
3055
|
+
this.out({ level: "warn", message, chunks });
|
|
3056
|
+
}
|
|
3057
|
+
error(message, ...chunks) {
|
|
3058
|
+
this.out({ level: "error", message, chunks });
|
|
3059
|
+
}
|
|
3060
|
+
logic(message, ...chunks) {
|
|
3061
|
+
this.out({ level: "logic", message, chunks });
|
|
3062
|
+
}
|
|
3063
|
+
silly(message, ...chunks) {
|
|
3064
|
+
this.out({ level: "silly", message, chunks });
|
|
3065
|
+
}
|
|
3066
|
+
results(results) {
|
|
3067
|
+
this.out({ level: "results", message: "results", results });
|
|
3068
|
+
}
|
|
3069
|
+
request(operation, ...chunks) {
|
|
3070
|
+
const message = this.inspectChunks([operation, ...chunks]);
|
|
3071
|
+
this.out({ level: "request", message });
|
|
3072
|
+
}
|
|
3073
|
+
response(operation, ...chunks) {
|
|
3074
|
+
const message = this.inspectChunks([operation, ...chunks]);
|
|
3075
|
+
this.out({ level: "response", message });
|
|
3076
|
+
}
|
|
3077
|
+
progress(message, opts) {
|
|
3078
|
+
const { prefix, count, total } = opts;
|
|
3079
|
+
const paddedTotal = String(total).length;
|
|
3080
|
+
const paddedCount = String(count).padStart(paddedTotal, " ");
|
|
3081
|
+
const payload = {
|
|
3082
|
+
level: "progress",
|
|
3083
|
+
message,
|
|
3084
|
+
count: paddedCount,
|
|
3085
|
+
total,
|
|
3086
|
+
prefix
|
|
3087
|
+
};
|
|
3088
|
+
if (!this.startTimes[prefix ?? ""]) {
|
|
3089
|
+
this.startTimes[prefix ?? ""] = Date.now();
|
|
3090
|
+
}
|
|
3091
|
+
if (this.options.progressTimes) {
|
|
3092
|
+
const elapsedSeconds = (Date.now() - this.startTimes[prefix ?? ""]) / 1e3;
|
|
3093
|
+
let remaining = -1;
|
|
3094
|
+
if (count > 1) {
|
|
3095
|
+
const rate = elapsedSeconds / (count - 1);
|
|
3096
|
+
remaining = (total - count) * rate;
|
|
3097
|
+
}
|
|
3098
|
+
payload.elapsed = this.round(elapsedSeconds, 2);
|
|
3099
|
+
payload.remaining = remaining >= 0 ? this.round(remaining, 2) : remaining;
|
|
3100
|
+
}
|
|
3101
|
+
if (count >= total) {
|
|
3102
|
+
delete this.startTimes[prefix ?? ""];
|
|
3103
|
+
delete this.lastProgressTimes[prefix ?? ""];
|
|
3104
|
+
}
|
|
3105
|
+
if (this.shouldOutputProgress(prefix ?? "", count, total)) {
|
|
3106
|
+
this.out(payload);
|
|
3107
|
+
if (this.options.progressThrottle && prefix) {
|
|
3108
|
+
this.lastProgressTimes[prefix] = Date.now();
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
shouldOutputProgress(prefix, count, total) {
|
|
3113
|
+
if (!this.options.progressThrottle) {
|
|
3114
|
+
return true;
|
|
3115
|
+
}
|
|
3116
|
+
if (count === 1 || count === total || !prefix) {
|
|
3117
|
+
return true;
|
|
3118
|
+
}
|
|
3119
|
+
const lastTime = this.lastProgressTimes[prefix];
|
|
3120
|
+
if (!lastTime) {
|
|
3121
|
+
return true;
|
|
3122
|
+
}
|
|
3123
|
+
return Date.now() - lastTime >= this.options.progressThrottle;
|
|
3124
|
+
}
|
|
3125
|
+
out(struct) {
|
|
3126
|
+
if (this.options.silent) {
|
|
3127
|
+
return;
|
|
3128
|
+
}
|
|
3129
|
+
if (!this.options.levels.includes(struct.level)) {
|
|
3130
|
+
return;
|
|
3131
|
+
}
|
|
3132
|
+
if (this.options.prefix && !struct.prefix) {
|
|
3133
|
+
struct.prefix = this.options.prefix;
|
|
3134
|
+
}
|
|
3135
|
+
const output = this.options.mode === "json" ? struct : this.formatLog(struct);
|
|
3136
|
+
this.transport.write(output);
|
|
3137
|
+
}
|
|
3138
|
+
formatLog(struct) {
|
|
3139
|
+
const parts = [];
|
|
3140
|
+
const now = /* @__PURE__ */ new Date();
|
|
3141
|
+
if (this.options.timestamp) {
|
|
3142
|
+
parts.push(now.toISOString());
|
|
3143
|
+
}
|
|
3144
|
+
if (this.options.showLevel) {
|
|
3145
|
+
parts.push(struct.level.toUpperCase());
|
|
3146
|
+
}
|
|
3147
|
+
if (struct.level === "progress") {
|
|
3148
|
+
if (struct.prefix) {
|
|
3149
|
+
parts.push(LEVEL_COLORS[struct.level].bold(struct.prefix));
|
|
3150
|
+
}
|
|
3151
|
+
if (struct.count !== void 0 && struct.total !== void 0) {
|
|
3152
|
+
parts.push(LEVEL_COLORS[struct.level](`${struct.count}/${struct.total}`));
|
|
3153
|
+
}
|
|
3154
|
+
} else if (struct.prefix) {
|
|
3155
|
+
parts.push(import_chalk.default.cyan(`[${struct.prefix}]`));
|
|
3156
|
+
}
|
|
3157
|
+
if (struct.message) {
|
|
3158
|
+
const formatter = LEVEL_COLORS[struct.level] ?? import_chalk.default.white;
|
|
3159
|
+
parts.push(formatter.bold(struct.message));
|
|
3160
|
+
}
|
|
3161
|
+
if (struct.level === "progress") {
|
|
3162
|
+
if (struct.elapsed !== void 0 && struct.remaining !== void 0) {
|
|
3163
|
+
const formatter = LEVEL_COLORS[struct.level];
|
|
3164
|
+
parts.push(formatter(`${struct.elapsed}/${struct.remaining}`));
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
if (struct.chunks && struct.chunks.length) {
|
|
3168
|
+
parts.push(this.inspectChunks(struct.chunks));
|
|
3169
|
+
}
|
|
3170
|
+
if (struct.results) {
|
|
3171
|
+
const formatter = LEVEL_COLORS[struct.level] ?? import_chalk.default.white;
|
|
3172
|
+
parts.push(formatter(JSON.stringify(struct.results, null, 4)));
|
|
3173
|
+
}
|
|
3174
|
+
return parts.join(" ");
|
|
3175
|
+
}
|
|
3176
|
+
inspectChunks(chunks) {
|
|
3177
|
+
return chunks.map((chunk) => import_util.default.inspect(chunk, { colors: true, depth: null })).join(" ");
|
|
3178
|
+
}
|
|
3179
|
+
normalizeOptions(options) {
|
|
3180
|
+
const { route, mode, prefix, silent, showLevel, timestamp, levels, progress } = options;
|
|
3181
|
+
const shouldUseIpc = this.shouldUseIpcRoute();
|
|
3182
|
+
const normalized = {
|
|
3183
|
+
mode: this.isValidMode(mode) ? mode : "text",
|
|
3184
|
+
route: route ?? (shouldUseIpc ? "ipc" : "console"),
|
|
3185
|
+
prefix,
|
|
3186
|
+
silent: silent ?? false,
|
|
3187
|
+
showLevel: showLevel ?? true,
|
|
3188
|
+
timestamp: timestamp ?? false,
|
|
3189
|
+
levels: this.normalizeLevels(levels),
|
|
3190
|
+
progressTimes: progress?.withTimes ?? false,
|
|
3191
|
+
progressThrottle: progress?.throttleMs
|
|
3192
|
+
};
|
|
3193
|
+
return normalized;
|
|
3194
|
+
}
|
|
3195
|
+
shouldUseIpcRoute() {
|
|
3196
|
+
if (process.env.VITEST || process.env.NODE_ENV === "test") {
|
|
3197
|
+
return false;
|
|
3198
|
+
}
|
|
3199
|
+
return typeof process.send === "function" && process.connected === true;
|
|
3200
|
+
}
|
|
3201
|
+
normalizeLevels(levels) {
|
|
3202
|
+
if (!levels || !levels.length) {
|
|
3203
|
+
return ALL_LEVELS;
|
|
3204
|
+
}
|
|
3205
|
+
const includes = levels.filter((level) => !level.startsWith("-"));
|
|
3206
|
+
const excludes = levels.filter((level) => level.startsWith("-")).map((level) => level.slice(1));
|
|
3207
|
+
const unknown = [...includes, ...excludes].filter((level) => !ALL_LEVELS.includes(level));
|
|
3208
|
+
if (unknown.length) {
|
|
3209
|
+
console.warn(`[Logger] Unknown level(s): ${unknown.join(", ")}`);
|
|
3210
|
+
}
|
|
3211
|
+
const base = includes.length ? includes : ALL_LEVELS;
|
|
3212
|
+
return base.filter((level) => !excludes.includes(level));
|
|
3213
|
+
}
|
|
3214
|
+
isValidMode(mode) {
|
|
3215
|
+
return mode === void 0 || mode === null || mode === "text" || mode === "json";
|
|
3216
|
+
}
|
|
3217
|
+
round(value, places) {
|
|
3218
|
+
const factor = Math.pow(10, places);
|
|
3219
|
+
return Math.round(value * factor) / factor;
|
|
3220
|
+
}
|
|
3221
|
+
};
|
|
3222
|
+
|
|
3223
|
+
// src/init/index.ts
|
|
3224
|
+
var import_events = require("events");
|
|
3225
|
+
function setup(opts = {}) {
|
|
3226
|
+
const args = new Args({
|
|
3227
|
+
overrides: opts.overrides || {},
|
|
3228
|
+
defaults: opts.defaults || {}
|
|
3229
|
+
});
|
|
3230
|
+
const params = new Params({ args }, opts.overrides || {});
|
|
3231
|
+
const loggerOptions = opts.logger || {};
|
|
3232
|
+
const logger = new CliToolkitLogger({
|
|
3233
|
+
mode: loggerOptions.mode || "text",
|
|
3234
|
+
route: loggerOptions.route || "console",
|
|
3235
|
+
prefix: loggerOptions.prefix,
|
|
3236
|
+
silent: loggerOptions.silent,
|
|
3237
|
+
showLevel: loggerOptions.showLevel,
|
|
3238
|
+
timestamp: loggerOptions.timestamp,
|
|
3239
|
+
levels: loggerOptions.levels
|
|
3240
|
+
});
|
|
3241
|
+
const cleanupFunctions = [];
|
|
3242
|
+
const context = {
|
|
3243
|
+
args,
|
|
3244
|
+
params,
|
|
3245
|
+
logger,
|
|
3246
|
+
emitter: new import_events.EventEmitter(),
|
|
3247
|
+
isStop: () => false,
|
|
3248
|
+
// Will be set in init function
|
|
3249
|
+
cleanupFunctions,
|
|
3250
|
+
registerCleanup: (fn) => {
|
|
3251
|
+
cleanupFunctions.push(fn);
|
|
3252
|
+
}
|
|
3253
|
+
};
|
|
3254
|
+
logger.debug("[setup] completed successfully");
|
|
3255
|
+
return context;
|
|
3256
|
+
}
|
|
3257
|
+
function setupContext(opts = {}) {
|
|
3258
|
+
return setup(opts);
|
|
3259
|
+
}
|
|
2963
3260
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2964
3261
|
0 && (module.exports = {
|
|
2965
3262
|
Args,
|
|
3263
|
+
Box,
|
|
2966
3264
|
Db,
|
|
2967
3265
|
Divider,
|
|
2968
3266
|
FileDatabase,
|
|
@@ -2975,12 +3273,14 @@ var Db = class {
|
|
|
2975
3273
|
MultiColumnListComponent,
|
|
2976
3274
|
MultiColumnListWithPreviewComponent,
|
|
2977
3275
|
Params,
|
|
3276
|
+
React,
|
|
2978
3277
|
ScreenBody,
|
|
2979
3278
|
ScreenContainer,
|
|
2980
3279
|
ScreenDivider,
|
|
2981
3280
|
ScreenFooter,
|
|
2982
3281
|
ScreenRow,
|
|
2983
3282
|
ScreenTitle,
|
|
3283
|
+
Text,
|
|
2984
3284
|
TextBlock,
|
|
2985
3285
|
buildBreadcrumb,
|
|
2986
3286
|
buildDetailBreadcrumb,
|
|
@@ -2989,14 +3289,22 @@ var Db = class {
|
|
|
2989
3289
|
defaultVersionSynopsisFunction,
|
|
2990
3290
|
getArgsInstance,
|
|
2991
3291
|
getParamsInstance,
|
|
3292
|
+
h,
|
|
2992
3293
|
joiEdateType,
|
|
2993
3294
|
joiStringArrayType,
|
|
2994
3295
|
organizeFooterMessages,
|
|
3296
|
+
setupContext,
|
|
2995
3297
|
showListScreen,
|
|
2996
3298
|
showMenuScreen,
|
|
2997
3299
|
showMultiColumnListScreen,
|
|
2998
3300
|
showMultiColumnListWithPreviewScreen,
|
|
2999
3301
|
showScreen,
|
|
3000
|
-
showWordGridScreen
|
|
3302
|
+
showWordGridScreen,
|
|
3303
|
+
useCallback,
|
|
3304
|
+
useEffect,
|
|
3305
|
+
useInput,
|
|
3306
|
+
useMemo,
|
|
3307
|
+
useRef,
|
|
3308
|
+
useState
|
|
3001
3309
|
});
|
|
3002
3310
|
//# sourceMappingURL=index.cjs.map
|