@buildepicshit/cli 0.0.6 → 0.0.8

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/bes.js CHANGED
@@ -3325,6 +3325,348 @@ var require_commander = __commonJS({
3325
3325
  }
3326
3326
  });
3327
3327
 
3328
+ // ../../node_modules/.pnpm/omelette@0.4.17/node_modules/omelette/src/omelette.js
3329
+ var require_omelette = __commonJS({
3330
+ "../../node_modules/.pnpm/omelette@0.4.17/node_modules/omelette/src/omelette.js"(exports, module) {
3331
+ (function() {
3332
+ var EventEmitter, Omelette, depthOf, fs, os2, path, removeSubstring, hasProp = {}.hasOwnProperty;
3333
+ ({ EventEmitter } = __require("events"));
3334
+ path = __require("path");
3335
+ fs = __require("fs");
3336
+ os2 = __require("os");
3337
+ depthOf = function(object) {
3338
+ var depth, key, level;
3339
+ level = 1;
3340
+ for (key in object) {
3341
+ if (!hasProp.call(object, key)) continue;
3342
+ if (typeof object[key] === "object") {
3343
+ depth = depthOf(object[key]) + 1;
3344
+ level = Math.max(depth, level);
3345
+ }
3346
+ }
3347
+ return level;
3348
+ };
3349
+ removeSubstring = function(haystack, needle) {
3350
+ return haystack.replace(new RegExp(needle.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), "g"), "");
3351
+ };
3352
+ Omelette = (function() {
3353
+ var log;
3354
+ class Omelette2 extends EventEmitter {
3355
+ constructor() {
3356
+ var isFish, isZsh, ref;
3357
+ super();
3358
+ this.asyncs = 0;
3359
+ this.compgen = process.argv.indexOf("--compgen");
3360
+ this.install = process.argv.indexOf("--completion") > -1;
3361
+ this.installFish = process.argv.indexOf("--completion-fish") > -1;
3362
+ isZsh = process.argv.indexOf("--compzsh") > -1;
3363
+ isFish = process.argv.indexOf("--compfish") > -1;
3364
+ this.isDebug = process.argv.indexOf("--debug") > -1;
3365
+ this.fragment = parseInt(process.argv[this.compgen + 1]) - (isZsh ? 1 : 0);
3366
+ this.line = process.argv.slice(this.compgen + 3).join(" ");
3367
+ this.word = (ref = this.line) != null ? ref.trim().split(/\s+/).pop() : void 0;
3368
+ ({ HOME: this.HOME, SHELL: this.SHELL } = process.env);
3369
+ ({ platform: this.platform } = process);
3370
+ this.mainProgram = function() {
3371
+ };
3372
+ }
3373
+ setProgram(programs) {
3374
+ programs = programs.split("|");
3375
+ [this.program] = programs;
3376
+ return this.programs = programs.map(function(program3) {
3377
+ return program3.replace(/[^A-Za-z0-9\.\_\-]/g, "");
3378
+ });
3379
+ }
3380
+ setFragments(...fragments1) {
3381
+ this.fragments = fragments1;
3382
+ }
3383
+ generate() {
3384
+ var data;
3385
+ data = {
3386
+ before: this.word,
3387
+ fragment: this.fragment,
3388
+ line: this.line,
3389
+ reply: this.reply
3390
+ };
3391
+ this.emit("complete", this.fragments[this.fragment - 1], data);
3392
+ this.emit(this.fragments[this.fragment - 1], data);
3393
+ this.emit(`$${this.fragment}`, data);
3394
+ if (this.asyncs === 0) {
3395
+ return process.exit();
3396
+ }
3397
+ }
3398
+ reply(words = []) {
3399
+ var writer;
3400
+ writer = function(options) {
3401
+ console.log(typeof options.join === "function" ? options.join(os2.EOL) : void 0);
3402
+ return process.exit();
3403
+ };
3404
+ if (words instanceof Promise) {
3405
+ return words.then(writer);
3406
+ } else {
3407
+ return writer(words);
3408
+ }
3409
+ }
3410
+ next(handler) {
3411
+ if (typeof handler === "function") {
3412
+ return this.mainProgram = handler;
3413
+ }
3414
+ }
3415
+ tree(objectTree = {}) {
3416
+ var depth, i, level, ref;
3417
+ depth = depthOf(objectTree);
3418
+ for (level = i = 1, ref = depth; 1 <= ref ? i <= ref : i >= ref; level = 1 <= ref ? ++i : --i) {
3419
+ this.on(`$${level}`, function({ fragment, reply, line }) {
3420
+ var accessor, lastIndex, replies;
3421
+ if (!/\s+/.test(line.slice(-1))) {
3422
+ lastIndex = -1;
3423
+ }
3424
+ accessor = (t) => line.split(/\s+/).slice(1, lastIndex).filter(Boolean).reduce((a, v) => a[v], t);
3425
+ replies = fragment === 1 ? Object.keys(objectTree) : accessor(objectTree);
3426
+ return reply((function(replies2) {
3427
+ if (replies2 instanceof Function) {
3428
+ return replies2();
3429
+ }
3430
+ if (replies2 instanceof Array) {
3431
+ return replies2;
3432
+ }
3433
+ if (replies2 instanceof Object) {
3434
+ return Object.keys(replies2);
3435
+ }
3436
+ })(replies));
3437
+ });
3438
+ }
3439
+ return this;
3440
+ }
3441
+ generateCompletionCode() {
3442
+ var completions;
3443
+ completions = this.programs.map((program3) => {
3444
+ var completion;
3445
+ completion = `_${program3}_completion`;
3446
+ return `### ${program3} completion - begin. generated by omelette.js ###
3447
+ if type compdef &>/dev/null; then
3448
+ ${completion}() {
3449
+ compadd -- \`${this.program} --compzsh --compgen "\${CURRENT}" "\${words[CURRENT-1]}" "\${BUFFER}"\`
3450
+ }
3451
+ compdef ${completion} ${program3}
3452
+ elif type complete &>/dev/null; then
3453
+ ${completion}() {
3454
+ local cur prev nb_colon
3455
+ _get_comp_words_by_ref -n : cur prev
3456
+ nb_colon=$(grep -o ":" <<< "$COMP_LINE" | wc -l)
3457
+
3458
+ COMPREPLY=( $(compgen -W '$(${this.program} --compbash --compgen "$((COMP_CWORD - (nb_colon * 2)))" "$prev" "\${COMP_LINE}")' -- "$cur") )
3459
+
3460
+ __ltrim_colon_completions "$cur"
3461
+ }
3462
+ complete -F ${completion} ${program3}
3463
+ elif type compctl &>/dev/null; then
3464
+ ${completion} () {
3465
+ local cword line point si
3466
+ read -Ac words
3467
+ read -cn cword
3468
+ read -l line
3469
+ si="$IFS"
3470
+ if ! IFS=$'
3471
+ ' reply=($(${program3} --compzsh --compgen "\${cword}" "\${words[cword-1]}" "\${line}")); then
3472
+ local ret=$?
3473
+ IFS="$si"
3474
+ return $ret
3475
+ fi
3476
+ IFS="$si"
3477
+ }
3478
+ compctl -K ${completion} ${program3}
3479
+ fi
3480
+ ### ${program3} completion - end ###`;
3481
+ });
3482
+ if (this.isDebug) {
3483
+ completions.push(this.generateTestAliases());
3484
+ }
3485
+ return completions.join(os2.EOL);
3486
+ }
3487
+ generateCompletionCodeFish() {
3488
+ var completions;
3489
+ completions = this.programs.map((program3) => {
3490
+ var completion;
3491
+ completion = `_${program3}_completion`;
3492
+ return `### ${program3} completion - begin. generated by omelette.js ###
3493
+ function ${completion}
3494
+ ${this.program} --compfish --compgen (count (commandline -poc)) (commandline -pt) (commandline -pb)
3495
+ end
3496
+ complete -f -c ${program3} -a '(${completion})'
3497
+ ### ${program3} completion - end ###`;
3498
+ });
3499
+ if (this.isDebug) {
3500
+ completions.push(this.generateTestAliases());
3501
+ }
3502
+ return completions.join(os2.EOL);
3503
+ }
3504
+ generateTestAliases() {
3505
+ var debugAliases, debugUnaliases, fullPath;
3506
+ fullPath = path.join(process.cwd(), this.program);
3507
+ debugAliases = this.programs.map(function(program3) {
3508
+ return ` alias ${program3}=${fullPath}`;
3509
+ }).join(os2.EOL);
3510
+ debugUnaliases = this.programs.map(function(program3) {
3511
+ return ` unalias ${program3}`;
3512
+ }).join(os2.EOL);
3513
+ return `### test method ###
3514
+ omelette-debug-${this.program}() {
3515
+ ${debugAliases}
3516
+ }
3517
+ omelette-nodebug-${this.program}() {
3518
+ ${debugUnaliases}
3519
+ }
3520
+ ### tests ###`;
3521
+ }
3522
+ checkInstall() {
3523
+ if (this.install) {
3524
+ log(this.generateCompletionCode());
3525
+ process.exit();
3526
+ }
3527
+ if (this.installFish) {
3528
+ log(this.generateCompletionCodeFish());
3529
+ return process.exit();
3530
+ }
3531
+ }
3532
+ getActiveShell() {
3533
+ if (!this.SHELL) {
3534
+ throw new Error("Shell could not be detected");
3535
+ }
3536
+ if (this.SHELL.match(/bash/)) {
3537
+ return "bash";
3538
+ } else if (this.SHELL.match(/zsh/)) {
3539
+ return "zsh";
3540
+ } else if (this.SHELL.match(/fish/)) {
3541
+ return "fish";
3542
+ } else {
3543
+ throw new Error(`Unsupported shell: ${this.SHELL}`);
3544
+ }
3545
+ }
3546
+ getDefaultShellInitFile() {
3547
+ var fileAt, fileAtHome;
3548
+ fileAt = function(root) {
3549
+ return function(file) {
3550
+ return path.join(root, file);
3551
+ };
3552
+ };
3553
+ fileAtHome = fileAt(this.HOME);
3554
+ switch (this.shell = this.getActiveShell()) {
3555
+ case "bash":
3556
+ return fileAtHome(this.platform === "darwin" ? ".bash_profile" : ".bashrc");
3557
+ case "zsh":
3558
+ return fileAtHome(".zshrc");
3559
+ case "fish":
3560
+ return fileAtHome(".config/fish/config.fish");
3561
+ }
3562
+ }
3563
+ getCompletionBlock() {
3564
+ var command, completionPath;
3565
+ command = (function() {
3566
+ switch (this.shell) {
3567
+ case "bash":
3568
+ completionPath = path.join(this.HOME, `.${this.program}`, "completion.sh");
3569
+ return `source ${completionPath}`;
3570
+ case "zsh":
3571
+ return `. <(${this.program} --completion)`;
3572
+ case "fish":
3573
+ return `${this.program} --completion-fish | source`;
3574
+ }
3575
+ }).call(this);
3576
+ if (command) {
3577
+ return `
3578
+ # begin ${this.program} completion
3579
+ ${command}
3580
+ # end ${this.program} completion
3581
+ `;
3582
+ }
3583
+ }
3584
+ setupShellInitFile(initFile = this.getDefaultShellInitFile()) {
3585
+ var completionPath, programFolder;
3586
+ if (this.shell == null) {
3587
+ this.shell = this.getActiveShell();
3588
+ }
3589
+ if (this.shell === "bash") {
3590
+ programFolder = path.join(this.HOME, `.${this.program}`);
3591
+ completionPath = path.join(programFolder, "completion.sh");
3592
+ if (!fs.existsSync(programFolder)) {
3593
+ fs.mkdirSync(programFolder);
3594
+ }
3595
+ fs.writeFileSync(completionPath, this.generateCompletionCode());
3596
+ }
3597
+ fs.appendFileSync(initFile, this.getCompletionBlock());
3598
+ return process.exit();
3599
+ }
3600
+ cleanupShellInitFile(initFile = this.getDefaultShellInitFile()) {
3601
+ var cleanedInitFile, completionPath, programFolder;
3602
+ if (this.shell == null) {
3603
+ this.shell = this.getActiveShell();
3604
+ }
3605
+ if (fs.existsSync(initFile)) {
3606
+ cleanedInitFile = removeSubstring(fs.readFileSync(initFile, "utf8"), this.getCompletionBlock());
3607
+ fs.writeFileSync(initFile, cleanedInitFile);
3608
+ }
3609
+ if (this.shell === "bash") {
3610
+ programFolder = path.join(this.HOME, `.${this.program}`);
3611
+ completionPath = path.join(programFolder, "completion.sh");
3612
+ if (fs.existsSync(completionPath)) {
3613
+ fs.unlinkSync(completionPath);
3614
+ }
3615
+ if (fs.existsSync(programFolder) && fs.readdirSync(programFolder).length === 0) {
3616
+ fs.rmdirSync(programFolder);
3617
+ }
3618
+ }
3619
+ return process.exit();
3620
+ }
3621
+ init() {
3622
+ if (this.compgen > -1) {
3623
+ return this.generate();
3624
+ } else {
3625
+ return this.mainProgram();
3626
+ }
3627
+ }
3628
+ onAsync(event, handler) {
3629
+ super.on(event, handler);
3630
+ return this.asyncs += 1;
3631
+ }
3632
+ }
3633
+ ;
3634
+ ({ log } = console);
3635
+ return Omelette2;
3636
+ }).call(this);
3637
+ module.exports = function(template, ...args) {
3638
+ var _omelette, callback, callbacks, fragment, fragments, i, index, len, program3;
3639
+ if (template instanceof Array && args.length > 0) {
3640
+ [program3, callbacks] = [template[0].trim(), args];
3641
+ fragments = callbacks.map(function(callback2, index2) {
3642
+ return `arg${index2}`;
3643
+ });
3644
+ } else {
3645
+ [program3, ...fragments] = template.split(/\s+/);
3646
+ callbacks = [];
3647
+ }
3648
+ fragments = fragments.map(function(fragment2) {
3649
+ return fragment2.replace(/^\<+|\>+$/g, "");
3650
+ });
3651
+ _omelette = new Omelette();
3652
+ _omelette.setProgram(program3);
3653
+ _omelette.setFragments(...fragments);
3654
+ _omelette.checkInstall();
3655
+ for (index = i = 0, len = callbacks.length; i < len; index = ++i) {
3656
+ callback = callbacks[index];
3657
+ fragment = `arg${index}`;
3658
+ (function(callback2) {
3659
+ return _omelette.on(fragment, function(...args2) {
3660
+ return this.reply(callback2 instanceof Array ? callback2 : callback2(...args2));
3661
+ });
3662
+ })(callback);
3663
+ }
3664
+ return _omelette;
3665
+ };
3666
+ }).call(exports);
3667
+ }
3668
+ });
3669
+
3328
3670
  // ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/esm.mjs
3329
3671
  var import_index = __toESM(require_commander(), 1);
3330
3672
  var {
@@ -3342,6 +3684,17 @@ var {
3342
3684
  Help
3343
3685
  } = import_index.default;
3344
3686
 
3687
+ // src/completion.ts
3688
+ var import_omelette = __toESM(require_omelette(), 1);
3689
+ function setupCompletion(commandNames) {
3690
+ const completion = (0, import_omelette.default)("bes <command>");
3691
+ completion.on("command", ({ reply }) => {
3692
+ reply([...commandNames, "--dry"]);
3693
+ });
3694
+ completion.init();
3695
+ return completion;
3696
+ }
3697
+
3345
3698
  // src/config-loader.ts
3346
3699
  import { existsSync } from "node:fs";
3347
3700
  import { dirname, join, resolve } from "node:path";
@@ -3975,6 +4328,12 @@ var program2 = new Command();
3975
4328
  program2.name("bes").description("Build Epic Shit \u2014 dev process manager CLI").version("0.1.0").option("--dry", "Resolve all tokens and print commands without executing");
3976
4329
  async function main() {
3977
4330
  const { root, commands } = await loadConfig();
4331
+ const commandNames = Object.keys(commands);
4332
+ const completion = setupCompletion(commandNames);
4333
+ if (process.argv.includes("--setup-completion")) {
4334
+ completion.setupShellInitFile();
4335
+ return;
4336
+ }
3978
4337
  for (const [name, fn] of Object.entries(commands)) {
3979
4338
  program2.command(name).description(`Run ${name}() from bes.config.ts`).action(async () => {
3980
4339
  const isDry = program2.opts().dry ?? false;