@jixo/cli 0.23.6 → 0.23.7

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/bundle/index.js CHANGED
@@ -13,7 +13,7 @@ import url2, { URL as URL$2, fileURLToPath as fileURLToPath$1, pathToFileURL as
13
13
  import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
14
14
  import process$1 from "node:process";
15
15
  import { execFile, spawn } from "node:child_process";
16
- import * as fs$1 from "fs/promises";
16
+ import * as fs$2 from "fs/promises";
17
17
  import fs2 from "fs/promises";
18
18
  import process2 from "process";
19
19
  import { spawn as spawn$1 } from "child_process";
@@ -23,7 +23,7 @@ import * as readline from "node:readline";
23
23
  import { promisify, stripVTControlCharacters } from "node:util";
24
24
  import { EventEmitter, on, once } from "node:events";
25
25
  import { finished } from "node:stream/promises";
26
- import fsPromises, { copyFile, mkdir, rm, writeFile as writeFile$1 } from "node:fs/promises";
26
+ import fs$1, { copyFile, mkdir, rm, writeFile as writeFile$1 } from "node:fs/promises";
27
27
  import { Buffer as Buffer$1 } from "node:buffer";
28
28
  import { builtinModules, createRequire as createRequire$1 } from "module";
29
29
  import v8 from "v8";
@@ -4688,7 +4688,7 @@ var yargs_default = Yargs;
4688
4688
  //#endregion
4689
4689
  //#region package.json
4690
4690
  var name = "@jixo/cli";
4691
- var version$1 = "0.23.6";
4691
+ var version$1 = "0.23.7";
4692
4692
  var type = "module";
4693
4693
  var bin = { "jixo": "./bundle/index.js" };
4694
4694
  var files = [
@@ -5281,19 +5281,6 @@ const iter_map_not_null = (values, callbackfn) => {
5281
5281
  else for (const value of values) if (value != null) result.push(value);
5282
5282
  return result;
5283
5283
  };
5284
- /**
5285
- * 类似与 map not null,但只取第一个
5286
- *
5287
- * 支持任何可迭代的对象
5288
- */
5289
- const iter_first_not_null = (values, callbackfn) => {
5290
- let index$1 = 0;
5291
- if (callbackfn) for (const value of values) {
5292
- const r$1 = callbackfn(value, index$1++, values);
5293
- if (r$1 != null) return r$1;
5294
- }
5295
- else for (const value of values) if (value != null) return value;
5296
- };
5297
5284
 
5298
5285
  //#endregion
5299
5286
  //#region ../../node_modules/.pnpm/@gaubee+util@0.34.2/node_modules/@gaubee/util/esm/pure_event.js
@@ -5929,31 +5916,33 @@ const abort_signal_race = (signal, fn_or_promise) => {
5929
5916
  };
5930
5917
 
5931
5918
  //#endregion
5932
- //#region ../../node_modules/.pnpm/@gaubee+util@0.34.2/node_modules/@gaubee/util/esm/debounce.js
5933
- const func_debounce = (fn, wait = 0, options$1 = {}) => {
5934
- if (!Number.isFinite(wait)) throw new TypeError("Expected `wait` to be a finite number");
5919
+ //#region ../../node_modules/.pnpm/@gaubee+util@0.34.2/node_modules/@gaubee/util/esm/throttle.js
5920
+ const func_throttle = (fn, wait = 0, options$1 = {}) => {
5935
5921
  const timmer = timmers.from(wait);
5936
- let leadingValue;
5937
5922
  let clear;
5938
- let jobList = [];
5939
- let trigger;
5940
- return obj_assign_props(function(...args) {
5923
+ let jobs = [];
5924
+ let target;
5925
+ return obj_assign_props(function throttled(...args) {
5941
5926
  const job = Promise.withResolvers();
5942
- const shouldCallNow = options$1.before && null == clear;
5943
- if (shouldCallNow) {
5944
- leadingValue = fn.apply(this, args);
5945
- job.resolve(leadingValue);
5946
- } else jobList.push(job);
5947
- clear?.();
5948
- clear = timmer(trigger = () => {
5949
- clear = void 0;
5950
- trigger = void 0;
5951
- const result = options$1.before ? leadingValue : fn.apply(this, args);
5952
- for (const job$1 of jobList) job$1.resolve(result);
5953
- jobList = [];
5954
- }, (reason) => {
5955
- for (const job$1 of jobList) job$1.reject(reason);
5956
- });
5927
+ if (clear == null) {
5928
+ clear = timmer(target = async () => {
5929
+ target = void 0;
5930
+ if (!options$1.waitPromise) clear = void 0;
5931
+ const res = await func_catch(() => fn.apply(this, args))();
5932
+ if (options$1.waitPromise) clear = void 0;
5933
+ if (res.success) for (const job$1 of jobs) job$1.resolve(res.result);
5934
+ else for (const job$1 of jobs) job$1.reject(res.error);
5935
+ jobs = [];
5936
+ }, (reason) => {
5937
+ for (const job$1 of jobs) job$1.reject(reason);
5938
+ });
5939
+ if (options$1.before) (async () => {
5940
+ const res = await func_catch(() => fn.apply(this, args))();
5941
+ if (res.success) job.resolve(res.result);
5942
+ else job.reject(res.error);
5943
+ })();
5944
+ else jobs.push(job);
5945
+ } else jobs.push(job);
5957
5946
  return job.promise;
5958
5947
  }, {
5959
5948
  get isPending() {
@@ -5961,13 +5950,13 @@ const func_debounce = (fn, wait = 0, options$1 = {}) => {
5961
5950
  },
5962
5951
  cancel() {
5963
5952
  clear?.();
5953
+ clear = void 0;
5964
5954
  },
5965
5955
  source: fn,
5966
5956
  flush() {
5967
- if (clear != null) {
5968
- clear();
5969
- trigger?.();
5970
- }
5957
+ clear?.();
5958
+ clear = void 0;
5959
+ target?.();
5971
5960
  }
5972
5961
  });
5973
5962
  };
@@ -6354,7 +6343,7 @@ var require_is_extendable = __commonJS$2({ "../../node_modules/.pnpm/is-extendab
6354
6343
  //#region ../../node_modules/.pnpm/extend-shallow@2.0.1/node_modules/extend-shallow/index.js
6355
6344
  var require_extend_shallow = __commonJS$2({ "../../node_modules/.pnpm/extend-shallow@2.0.1/node_modules/extend-shallow/index.js"(exports, module) {
6356
6345
  var isObject$5 = require_is_extendable();
6357
- module.exports = function extend$3(o$1) {
6346
+ module.exports = function extend$4(o$1) {
6358
6347
  if (!isObject$5(o$1)) o$1 = {};
6359
6348
  var len = arguments.length;
6360
6349
  for (var i$2 = 1; i$2 < len; i$2++) {
@@ -6378,7 +6367,7 @@ var require_extend_shallow = __commonJS$2({ "../../node_modules/.pnpm/extend-sha
6378
6367
  //#region ../../node_modules/.pnpm/section-matter@1.0.0/node_modules/section-matter/index.js
6379
6368
  var require_section_matter = __commonJS$2({ "../../node_modules/.pnpm/section-matter@1.0.0/node_modules/section-matter/index.js"(exports, module) {
6380
6369
  var typeOf$3 = require_kind_of();
6381
- var extend$2 = require_extend_shallow();
6370
+ var extend$3 = require_extend_shallow();
6382
6371
  /**
6383
6372
  * Parse sections in `input` with the given `options`.
6384
6373
  *
@@ -6399,7 +6388,7 @@ var require_section_matter = __commonJS$2({ "../../node_modules/.pnpm/section-ma
6399
6388
  section_delimiter: "---",
6400
6389
  parse: identity
6401
6390
  };
6402
- var opts = extend$2({}, defaults$4, options$1);
6391
+ var opts = extend$3({}, defaults$4, options$1);
6403
6392
  var delim = opts.section_delimiter;
6404
6393
  var lines = file$1.content.split(/\r?\n/);
6405
6394
  var sections$1 = null;
@@ -6494,7 +6483,7 @@ var require_common$4 = __commonJS$2({ "../../node_modules/.pnpm/js-yaml@3.14.1/n
6494
6483
  else if (isNothing(sequence)) return [];
6495
6484
  return [sequence];
6496
6485
  }
6497
- function extend$1(target, source$1) {
6486
+ function extend$2(target, source$1) {
6498
6487
  var index$1, length, key$1, sourceKeys;
6499
6488
  if (source$1) {
6500
6489
  sourceKeys = Object.keys(source$1);
@@ -6518,7 +6507,7 @@ var require_common$4 = __commonJS$2({ "../../node_modules/.pnpm/js-yaml@3.14.1/n
6518
6507
  module.exports.toArray = toArray;
6519
6508
  module.exports.repeat = repeat;
6520
6509
  module.exports.isNegativeZero = isNegativeZero;
6521
- module.exports.extend = extend$1;
6510
+ module.exports.extend = extend$2;
6522
6511
  } });
6523
6512
 
6524
6513
  //#endregion
@@ -8976,7 +8965,7 @@ var require_parse$3 = __commonJS$2({ "../../node_modules/.pnpm/gray-matter@4.0.3
8976
8965
  //#endregion
8977
8966
  //#region ../../node_modules/.pnpm/gray-matter@4.0.3/node_modules/gray-matter/index.js
8978
8967
  var require_gray_matter = __commonJS$2({ "../../node_modules/.pnpm/gray-matter@4.0.3/node_modules/gray-matter/index.js"(exports, module) {
8979
- const fs$9 = __require$1("fs");
8968
+ const fs$10 = __require$1("fs");
8980
8969
  const sections = require_section_matter();
8981
8970
  const defaults = require_defaults();
8982
8971
  const stringify$4 = require_stringify$2();
@@ -9101,7 +9090,7 @@ var require_gray_matter = __commonJS$2({ "../../node_modules/.pnpm/gray-matter@4
9101
9090
  * @api public
9102
9091
  */
9103
9092
  matter$2.read = function(filepath, options$1) {
9104
- const str = fs$9.readFileSync(filepath, "utf8");
9093
+ const str = fs$10.readFileSync(filepath, "utf8");
9105
9094
  const file$1 = matter$2(str, options$1);
9106
9095
  file$1.path = filepath;
9107
9096
  return file$1;
@@ -16897,8 +16886,8 @@ var require_utils$2 = __commonJS$2({ "../../node_modules/.pnpm/fast-glob@3.3.3/n
16897
16886
  exports.array = array$3;
16898
16887
  const errno = require_errno$1();
16899
16888
  exports.errno = errno;
16900
- const fs$8 = require_fs$4();
16901
- exports.fs = fs$8;
16889
+ const fs$9 = require_fs$4();
16890
+ exports.fs = fs$9;
16902
16891
  const path$6 = require_path$1();
16903
16892
  exports.path = path$6;
16904
16893
  const pattern = require_pattern$1();
@@ -17070,12 +17059,12 @@ var require_sync$6 = __commonJS$2({ "../../node_modules/.pnpm/@nodelib+fs.stat@2
17070
17059
  var require_fs$3 = __commonJS$2({ "../../node_modules/.pnpm/@nodelib+fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/adapters/fs.js"(exports) {
17071
17060
  Object.defineProperty(exports, "__esModule", { value: true });
17072
17061
  exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
17073
- const fs$7 = __require$1("fs");
17062
+ const fs$8 = __require$1("fs");
17074
17063
  exports.FILE_SYSTEM_ADAPTER = {
17075
- lstat: fs$7.lstat,
17076
- stat: fs$7.stat,
17077
- lstatSync: fs$7.lstatSync,
17078
- statSync: fs$7.statSync
17064
+ lstat: fs$8.lstat,
17065
+ stat: fs$8.stat,
17066
+ lstatSync: fs$8.lstatSync,
17067
+ statSync: fs$8.statSync
17079
17068
  };
17080
17069
  function createFileSystemAdapter$1(fsMethods) {
17081
17070
  if (fsMethods === void 0) return exports.FILE_SYSTEM_ADAPTER;
@@ -17088,12 +17077,12 @@ var require_fs$3 = __commonJS$2({ "../../node_modules/.pnpm/@nodelib+fs.stat@2.0
17088
17077
  //#region ../../node_modules/.pnpm/@nodelib+fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/settings.js
17089
17078
  var require_settings$4 = __commonJS$2({ "../../node_modules/.pnpm/@nodelib+fs.stat@2.0.5/node_modules/@nodelib/fs.stat/out/settings.js"(exports) {
17090
17079
  Object.defineProperty(exports, "__esModule", { value: true });
17091
- const fs$6 = require_fs$3();
17080
+ const fs$7 = require_fs$3();
17092
17081
  var Settings$3 = class {
17093
17082
  constructor(_options = {}) {
17094
17083
  this._options = _options;
17095
17084
  this.followSymbolicLink = this._getValue(this._options.followSymbolicLink, true);
17096
- this.fs = fs$6.createFileSystemAdapter(this._options.fs);
17085
+ this.fs = fs$7.createFileSystemAdapter(this._options.fs);
17097
17086
  this.markSymbolicLink = this._getValue(this._options.markSymbolicLink, false);
17098
17087
  this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
17099
17088
  }
@@ -17233,8 +17222,8 @@ var require_fs$2 = __commonJS$2({ "../../node_modules/.pnpm/@nodelib+fs.scandir@
17233
17222
  var require_utils$1 = __commonJS$2({ "../../node_modules/.pnpm/@nodelib+fs.scandir@2.1.5/node_modules/@nodelib/fs.scandir/out/utils/index.js"(exports) {
17234
17223
  Object.defineProperty(exports, "__esModule", { value: true });
17235
17224
  exports.fs = void 0;
17236
- const fs$5 = require_fs$2();
17237
- exports.fs = fs$5;
17225
+ const fs$6 = require_fs$2();
17226
+ exports.fs = fs$6;
17238
17227
  } });
17239
17228
 
17240
17229
  //#endregion
@@ -17412,14 +17401,14 @@ var require_sync$5 = __commonJS$2({ "../../node_modules/.pnpm/@nodelib+fs.scandi
17412
17401
  var require_fs$1 = __commonJS$2({ "../../node_modules/.pnpm/@nodelib+fs.scandir@2.1.5/node_modules/@nodelib/fs.scandir/out/adapters/fs.js"(exports) {
17413
17402
  Object.defineProperty(exports, "__esModule", { value: true });
17414
17403
  exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
17415
- const fs$4 = __require$1("fs");
17404
+ const fs$5 = __require$1("fs");
17416
17405
  exports.FILE_SYSTEM_ADAPTER = {
17417
- lstat: fs$4.lstat,
17418
- stat: fs$4.stat,
17419
- lstatSync: fs$4.lstatSync,
17420
- statSync: fs$4.statSync,
17421
- readdir: fs$4.readdir,
17422
- readdirSync: fs$4.readdirSync
17406
+ lstat: fs$5.lstat,
17407
+ stat: fs$5.stat,
17408
+ lstatSync: fs$5.lstatSync,
17409
+ statSync: fs$5.statSync,
17410
+ readdir: fs$5.readdir,
17411
+ readdirSync: fs$5.readdirSync
17423
17412
  };
17424
17413
  function createFileSystemAdapter(fsMethods) {
17425
17414
  if (fsMethods === void 0) return exports.FILE_SYSTEM_ADAPTER;
@@ -17434,12 +17423,12 @@ var require_settings$3 = __commonJS$2({ "../../node_modules/.pnpm/@nodelib+fs.sc
17434
17423
  Object.defineProperty(exports, "__esModule", { value: true });
17435
17424
  const path$5 = __require$1("path");
17436
17425
  const fsStat$3 = require_out$4();
17437
- const fs$3 = require_fs$1();
17426
+ const fs$4 = require_fs$1();
17438
17427
  var Settings$2 = class {
17439
17428
  constructor(_options = {}) {
17440
17429
  this._options = _options;
17441
17430
  this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
17442
- this.fs = fs$3.createFileSystemAdapter(this._options.fs);
17431
+ this.fs = fs$4.createFileSystemAdapter(this._options.fs);
17443
17432
  this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path$5.sep);
17444
17433
  this.stats = this._getValue(this._options.stats, false);
17445
17434
  this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
@@ -18632,7 +18621,7 @@ var require_sync$1 = __commonJS$2({ "../../node_modules/.pnpm/fast-glob@3.3.3/no
18632
18621
  var require_settings$1 = __commonJS$2({ "../../node_modules/.pnpm/fast-glob@3.3.3/node_modules/fast-glob/out/settings.js"(exports) {
18633
18622
  Object.defineProperty(exports, "__esModule", { value: true });
18634
18623
  exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
18635
- const fs$2 = __require$1("fs");
18624
+ const fs$3 = __require$1("fs");
18636
18625
  const os = __require$1("os");
18637
18626
  /**
18638
18627
  * The `os.cpus` method can return zero. We expect the number of cores to be greater than zero.
@@ -18640,12 +18629,12 @@ var require_settings$1 = __commonJS$2({ "../../node_modules/.pnpm/fast-glob@3.3.
18640
18629
  */
18641
18630
  const CPU_COUNT = Math.max(os.cpus().length, 1);
18642
18631
  exports.DEFAULT_FILE_SYSTEM_ADAPTER = {
18643
- lstat: fs$2.lstat,
18644
- lstatSync: fs$2.lstatSync,
18645
- stat: fs$2.stat,
18646
- statSync: fs$2.statSync,
18647
- readdir: fs$2.readdir,
18648
- readdirSync: fs$2.readdirSync
18632
+ lstat: fs$3.lstat,
18633
+ lstatSync: fs$3.lstatSync,
18634
+ stat: fs$3.stat,
18635
+ statSync: fs$3.statSync,
18636
+ readdir: fs$3.readdir,
18637
+ readdirSync: fs$3.readdirSync
18649
18638
  };
18650
18639
  var Settings = class {
18651
18640
  constructor(_options = {}) {
@@ -18792,7 +18781,7 @@ var require_out$1 = __commonJS$2({ "../../node_modules/.pnpm/fast-glob@3.3.3/nod
18792
18781
  async function isType(fsStatType, statsMethodName, filePath) {
18793
18782
  if (typeof filePath !== "string") throw new TypeError(`Expected a string, got ${typeof filePath}`);
18794
18783
  try {
18795
- const stats = await fsPromises[fsStatType](filePath);
18784
+ const stats = await fs$1[fsStatType](filePath);
18796
18785
  return stats[statsMethodName]();
18797
18786
  } catch (error$41) {
18798
18787
  if (error$41.code === "ENOENT") return false;
@@ -18889,7 +18878,7 @@ const isIgnoredByIgnoreFiles = async (patterns, options$1) => {
18889
18878
  });
18890
18879
  const files$1 = await Promise.all(paths.map(async (filePath) => ({
18891
18880
  filePath,
18892
- content: await fsPromises.readFile(filePath, "utf8")
18881
+ content: await fs$1.readFile(filePath, "utf8")
18893
18882
  })));
18894
18883
  return getIsIgnoredPredicate(files$1, cwd);
18895
18884
  };
@@ -19275,7 +19264,7 @@ var require_common$1 = __commonJS$2({ "../../node_modules/.pnpm/debug@4.4.1/node
19275
19264
  debug$5.namespace = namespace;
19276
19265
  debug$5.useColors = createDebug.useColors();
19277
19266
  debug$5.color = createDebug.selectColor(namespace);
19278
- debug$5.extend = extend$3;
19267
+ debug$5.extend = extend$4;
19279
19268
  debug$5.destroy = createDebug.destroy;
19280
19269
  Object.defineProperty(debug$5, "enabled", {
19281
19270
  enumerable: true,
@@ -19295,7 +19284,7 @@ var require_common$1 = __commonJS$2({ "../../node_modules/.pnpm/debug@4.4.1/node
19295
19284
  if (typeof createDebug.init === "function") createDebug.init(debug$5);
19296
19285
  return debug$5;
19297
19286
  }
19298
- function extend$3(namespace, delimiter) {
19287
+ function extend$4(namespace, delimiter) {
19299
19288
  const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
19300
19289
  newDebug.log = this.log;
19301
19290
  return newDebug;
@@ -30680,10 +30669,10 @@ var require_fnmatch = __commonJS({ "node_modules/editorconfig/src/lib/fnmatch.js
30680
30669
  return list$1;
30681
30670
  };
30682
30671
  Minimatch.prototype.match = match;
30683
- function match(f$1, partial$1) {
30672
+ function match(f$1, partial$2) {
30684
30673
  if (this.comment) return false;
30685
30674
  if (this.empty) return f$1 === "";
30686
- if (f$1 === "/" && partial$1) return true;
30675
+ if (f$1 === "/" && partial$2) return true;
30687
30676
  var options8 = this.options;
30688
30677
  if (platform === "win32") f$1 = f$1.split("\\").join("/");
30689
30678
  f$1 = f$1.split(slashSplit);
@@ -30691,7 +30680,7 @@ var require_fnmatch = __commonJS({ "node_modules/editorconfig/src/lib/fnmatch.js
30691
30680
  var set$1 = this.set;
30692
30681
  for (var i$2 = 0, l$1 = set$1.length; i$2 < l$1; i$2++) {
30693
30682
  var pattern$1 = set$1[i$2];
30694
- var hit = this.matchOne(f$1, pattern$1, partial$1);
30683
+ var hit = this.matchOne(f$1, pattern$1, partial$2);
30695
30684
  if (hit) {
30696
30685
  if (options8.flipNegate) return true;
30697
30686
  return !this.negate;
@@ -30700,7 +30689,7 @@ var require_fnmatch = __commonJS({ "node_modules/editorconfig/src/lib/fnmatch.js
30700
30689
  if (options8.flipNegate) return false;
30701
30690
  return this.negate;
30702
30691
  }
30703
- Minimatch.prototype.matchOne = function(file$1, pattern$1, partial$1) {
30692
+ Minimatch.prototype.matchOne = function(file$1, pattern$1, partial$2) {
30704
30693
  var options8 = this.options;
30705
30694
  if (options8.debug) console.error("matchOne", {
30706
30695
  "this": this,
@@ -30729,7 +30718,7 @@ var require_fnmatch = __commonJS({ "node_modules/editorconfig/src/lib/fnmatch.js
30729
30718
  WHILE: while (fr < fl) {
30730
30719
  var swallowee = file$1[fr];
30731
30720
  if (options8.debug) console.error("\nglobstar while", file$1, fr, pattern$1, pr, swallowee);
30732
- if (this.matchOne(file$1.slice(fr), pattern$1.slice(pr), partial$1)) {
30721
+ if (this.matchOne(file$1.slice(fr), pattern$1.slice(pr), partial$2)) {
30733
30722
  if (options8.debug) console.error("globstar found match!", fr, fl, swallowee);
30734
30723
  return true;
30735
30724
  } else {
@@ -30741,7 +30730,7 @@ var require_fnmatch = __commonJS({ "node_modules/editorconfig/src/lib/fnmatch.js
30741
30730
  fr++;
30742
30731
  }
30743
30732
  }
30744
- if (partial$1) {
30733
+ if (partial$2) {
30745
30734
  if (fr === fl) return true;
30746
30735
  }
30747
30736
  return false;
@@ -30758,7 +30747,7 @@ var require_fnmatch = __commonJS({ "node_modules/editorconfig/src/lib/fnmatch.js
30758
30747
  if (!hit) return false;
30759
30748
  }
30760
30749
  if (fi === fl && pi === pl) return true;
30761
- else if (fi === fl) return partial$1;
30750
+ else if (fi === fl) return partial$2;
30762
30751
  else if (pi === pl) {
30763
30752
  var emptyFileEnd = fi === fl - 1 && file$1[fi] === "";
30764
30753
  return emptyFileEnd;
@@ -33946,7 +33935,7 @@ async function findInDirectory(nameOrNames, { typeCheck, cwd, allowSymlinks = tr
33946
33935
  }
33947
33936
  async function safeStat(path14, allowSymlinks = true) {
33948
33937
  try {
33949
- return await (allowSymlinks ? fs$1.stat : fs$1.lstat)(path14);
33938
+ return await (allowSymlinks ? fs$2.stat : fs$2.lstat)(path14);
33950
33939
  } catch {}
33951
33940
  }
33952
33941
  function findFile(nameOrNames, options8) {
@@ -41873,7 +41862,7 @@ async function gitWorkingContents(repoPath, options$1) {
41873
41862
  return async () => {
41874
41863
  results.set(filepath, {
41875
41864
  path: filepath,
41876
- content: status === "D" ? void 0 : await fsPromises.readFile(path.join(repoPath, filepath), "utf-8"),
41865
+ content: status === "D" ? void 0 : await fs$1.readFile(path.join(repoPath, filepath), "utf-8"),
41877
41866
  status
41878
41867
  });
41879
41868
  };
@@ -52946,7 +52935,7 @@ __export$4(util_exports, {
52946
52935
  defineLazy: () => defineLazy,
52947
52936
  esc: () => esc,
52948
52937
  escapeRegex: () => escapeRegex,
52949
- extend: () => extend,
52938
+ extend: () => extend$1,
52950
52939
  finalizeIssue: () => finalizeIssue,
52951
52940
  floatSafeRemainder: () => floatSafeRemainder,
52952
52941
  getElementAtPath: () => getElementAtPath,
@@ -52966,7 +52955,7 @@ __export$4(util_exports, {
52966
52955
  numKeys: () => numKeys,
52967
52956
  omit: () => omit,
52968
52957
  optionalKeys: () => optionalKeys,
52969
- partial: () => partial,
52958
+ partial: () => partial$1,
52970
52959
  pick: () => pick,
52971
52960
  prefixIssues: () => prefixIssues,
52972
52961
  primitiveTypes: () => primitiveTypes,
@@ -53257,7 +53246,7 @@ function omit(schema, mask) {
53257
53246
  });
53258
53247
  return clone(schema, def);
53259
53248
  }
53260
- function extend(schema, shape) {
53249
+ function extend$1(schema, shape) {
53261
53250
  if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
53262
53251
  const def = mergeDefs(schema._zod.def, {
53263
53252
  get shape() {
@@ -53289,7 +53278,7 @@ function merge(a$1, b$1) {
53289
53278
  });
53290
53279
  return clone(a$1, def);
53291
53280
  }
53292
- function partial(Class$1, schema, mask) {
53281
+ function partial$1(Class$1, schema, mask) {
53293
53282
  const def = mergeDefs(schema._zod.def, {
53294
53283
  get shape() {
53295
53284
  const oldShape = schema._zod.def.shape;
@@ -62123,6 +62112,12 @@ function looseObject$1(shape, params) {
62123
62112
  ...normalizeParams(params)
62124
62113
  });
62125
62114
  }
62115
+ function extend(schema, shape) {
62116
+ return extend$1(schema, shape);
62117
+ }
62118
+ function partial(schema, mask) {
62119
+ return partial$1(ZodMiniOptional, schema, mask);
62120
+ }
62126
62121
  const ZodMiniUnion = /* @__PURE__ */ $constructor("ZodMiniUnion", (inst, def) => {
62127
62122
  $ZodUnion.init(inst, def);
62128
62123
  ZodMiniType.init(inst, def);
@@ -62144,6 +62139,108 @@ function optional$1(innerType) {
62144
62139
  innerType
62145
62140
  });
62146
62141
  }
62142
+ const ZodMiniCustom = /* @__PURE__ */ $constructor("ZodMiniCustom", (inst, def) => {
62143
+ $ZodCustom.init(inst, def);
62144
+ ZodMiniType.init(inst, def);
62145
+ });
62146
+ function custom$1(fn, _params) {
62147
+ return _custom(ZodMiniCustom, fn ?? (() => true), _params);
62148
+ }
62149
+ function _instanceof$1(cls, params = { error: `Input not instance of ${cls.name}` }) {
62150
+ const inst = custom$1((data) => data instanceof cls, params);
62151
+ inst._zod.bag.Class = cls;
62152
+ return inst;
62153
+ }
62154
+
62155
+ //#endregion
62156
+ //#region ../dev/dist/google-aistudio/node/function_call.js
62157
+ const zFunctionCallConfig = object$1({
62158
+ name: string$2(),
62159
+ description: optional$1(string$2()),
62160
+ safeDescription: string$2(),
62161
+ paramsSchema: optional$1(unknown$1())
62162
+ });
62163
+ const zFunctionCallFn = _instanceof$1(Function);
62164
+ /**
62165
+ * 标准版本
62166
+ */
62167
+ const zFunctionCallStandardModule = looseObject$1({
62168
+ ...zFunctionCallConfig.shape,
62169
+ name: optional$1(string$2()),
62170
+ functionCall: zFunctionCallFn
62171
+ });
62172
+ /**
62173
+ * 极简版本,只导出一个 functionCall 函数即可
62174
+ * name 默认使用 `${infer name}.function.ts`
62175
+ * description 默认使用 functionCall.toString() 可以由AI猜测生成对应的params
62176
+ */
62177
+ const zFunctionCallMiniModule = extend(partial(zFunctionCallConfig), { functionCall: zFunctionCallFn });
62178
+ const safeParseModule = (unsafeModule) => {
62179
+ if (unsafeModule.default) {
62180
+ const safeModule = zFunctionCallStandardModule.safeParse(unsafeModule.default);
62181
+ if (safeModule.success) return safeModule.data;
62182
+ }
62183
+ if (unsafeModule.functionCall) {
62184
+ const safeModule = zFunctionCallMiniModule.safeParse(unsafeModule);
62185
+ if (safeModule.success) return safeModule.data;
62186
+ }
62187
+ };
62188
+ const esmImporter = async (codeEntry) => {
62189
+ const unsafeModule = await import(`${pathToFileURL(codeEntry.fullpath).href}?_=${codeEntry.stat.mtime}`);
62190
+ const safeModule = safeParseModule(unsafeModule);
62191
+ if (!safeModule) {
62192
+ console.warn(`无法解析 ${codeEntry.filename} 做为 functionCall 模块。`);
62193
+ return;
62194
+ }
62195
+ return {
62196
+ name: safeModule.name ?? codeEntry.filename,
62197
+ description: safeModule.description,
62198
+ safeDescription: safeModule.description ?? String(safeModule.functionCall),
62199
+ paramsSchema: safeModule.paramsSchema,
62200
+ functionCall: safeModule.functionCall
62201
+ };
62202
+ };
62203
+ const supportImports = new Map([[/\.function_call\.js$/, {
62204
+ getKey: (filename) => {
62205
+ return filename.replace(/\.function_call\.js$/, "");
62206
+ },
62207
+ importer: esmImporter
62208
+ }], [/\.function_call\.ts$/, {
62209
+ getKey: (filename) => {
62210
+ return filename.replace(/\.function_call\.ts$/, "");
62211
+ },
62212
+ importer: esmImporter
62213
+ }]]);
62214
+ const defineFunctionCalls = async (dir) => {
62215
+ const codeEntries = /* @__PURE__ */ new Map();
62216
+ for (const filename of readdirSync(dir)) {
62217
+ const fullpath = path.join(dir, filename);
62218
+ const stat$1 = statSync(fullpath);
62219
+ if (!stat$1.isFile()) continue;
62220
+ let key$1;
62221
+ for (const [suffix, config$1] of supportImports) if (suffix.test(filename)) {
62222
+ key$1 = config$1.getKey(filename).trim();
62223
+ if (key$1 != "") {
62224
+ const codeEntry = {
62225
+ key: key$1,
62226
+ filename,
62227
+ dirname: dir,
62228
+ fullpath,
62229
+ stat: stat$1
62230
+ };
62231
+ const module$1 = await config$1.importer(codeEntry);
62232
+ if (module$1) {
62233
+ codeEntries.set(codeEntry.key, {
62234
+ codeEntry,
62235
+ module: module$1
62236
+ });
62237
+ break;
62238
+ }
62239
+ }
62240
+ }
62241
+ }
62242
+ return codeEntries;
62243
+ };
62147
62244
 
62148
62245
  //#endregion
62149
62246
  //#region ../dev/dist/google-aistudio/node/types.js
@@ -62220,67 +62317,95 @@ const zContentSchema = looseObject$1({
62220
62317
  });
62221
62318
 
62222
62319
  //#endregion
62223
- //#region ../dev/dist/google-aistudio/node/index.js
62224
- const doGoogleAiStudioAutomation = (dir = process.cwd()) => {
62225
- const watcher = fs.watch(dir);
62226
- const handle = func_debounce(async () => {
62227
- const names = fs.readdirSync(dir);
62228
- const contentNames = names.filter((name$1) => name$1.endsWith(".contents.json"));
62229
- for (const contentFilename of contentNames) {
62230
- const contentFilepath = path.join(dir, contentFilename);
62231
- const basename$1 = contentFilename.replace(".contents.json", "");
62232
- await parseContent(basename$1, contentFilepath, names).catch(console.error);
62320
+ //#region ../dev/dist/google-aistudio/node/tasks.js
62321
+ const parseContent = async (fcs, dir, basename$1, contentFilepath, filenames) => {
62322
+ console.log(magenta("开始处理文件"), path.relative(process.cwd(), contentFilepath));
62323
+ const fileData = await zContentSchema.parse(JSON.parse(reactiveFs.readFile(contentFilepath)));
62324
+ const { contents } = fileData.generateContentParameters;
62325
+ const latestContent = contents.at(-1);
62326
+ if (!latestContent) return;
62327
+ if (latestContent.role !== "user") return;
62328
+ const functionResponsePart = latestContent.parts.find((p$1) => "functionResponse" in p$1);
62329
+ if (!functionResponsePart) return;
62330
+ if (functionResponsePart.functionResponse.response !== "") return;
62331
+ const modelContent = contents.findLast((content$2) => {
62332
+ return content$2.role === "model" && content$2.parts.find((p$1) => "functionCall" in p$1);
62333
+ });
62334
+ if (!modelContent) return;
62335
+ const functionCallPart = modelContent.parts.find((p$1) => "functionCall" in p$1)?.functionCall;
62336
+ if (!functionCallPart) {
62337
+ console.log(gray("发现任务已经有输入的内容,跳过任务"));
62338
+ return;
62339
+ }
62340
+ const modelIndex = contents.indexOf(modelContent);
62341
+ const hash = createHash("sha256").update(`INDEX:${modelIndex}`).update(JSON.stringify(modelContent)).digest("hex").slice(0, 8);
62342
+ const taskFilename = `${basename$1}.${functionCallPart.name}.${modelIndex}-${hash}.function_call.json`;
62343
+ if (filenames.includes(taskFilename)) return;
62344
+ console.log(blue("收到 functionCallPart 任务请求"), functionCallPart);
62345
+ const fc = fcs.get(functionCallPart.name);
62346
+ if (!fc) {
62347
+ console.warn("找不到任务处理工具");
62348
+ return false;
62349
+ } else {
62350
+ const { functionCall } = await fc.module;
62351
+ const input = JSON.parse(functionCallPart.parameters);
62352
+ try {
62353
+ console.log(cyan("开始执行任务"));
62354
+ const output = await functionCall(input);
62355
+ console.log(green("生成任务结果:"), taskFilename);
62356
+ fs.writeFileSync(path.join(dir, taskFilename), JSON.stringify({
62357
+ input,
62358
+ output
62359
+ }, null, 2));
62360
+ return true;
62361
+ } catch (e$1) {
62362
+ console.log(red("任务执行失败:"), e$1);
62363
+ return false;
62233
62364
  }
62234
- }, 200);
62235
- const parseContent = async (basename$1, contentFilepath, filenames) => {
62236
- console.log(magenta("开始处理文件"), path.relative(process.cwd(), contentFilepath));
62237
- const fileData = await zContentSchema.parse(JSON.parse(fs.readFileSync(contentFilepath, "utf-8")));
62238
- const { contents } = fileData.generateContentParameters;
62239
- const latestContent = contents.at(-1);
62240
- if (!latestContent) return;
62241
- if (latestContent.role !== "user") return;
62242
- const functionResponsePart = latestContent.parts.find((p$1) => "functionResponse" in p$1);
62243
- if (!functionResponsePart) return;
62244
- if (functionResponsePart.functionResponse.response !== "") return;
62245
- const modelContent = contents.findLast((content$2) => {
62246
- return content$2.role === "model" && content$2.parts.find((p$1) => "functionCall" in p$1);
62247
- });
62248
- if (!modelContent) return;
62249
- const functionCallPart = modelContent.parts.find((p$1) => "functionCall" in p$1)?.functionCall;
62250
- if (!functionCallPart) return;
62251
- const modelIndex = contents.indexOf(modelContent);
62252
- const hash = createHash("sha256").update(`INDEX:${modelIndex}`).update(JSON.stringify(modelContent)).digest("hex").slice(0, 8);
62253
- const taskFilename = `${basename$1}.${functionCallPart.name}.${modelIndex}-${hash}.function_call.json`;
62254
- if (filenames.includes(taskFilename)) return;
62255
- console.log(blue("收到 functionCallPart 任务请求"), functionCallPart);
62256
- const scriptFilepath = iter_first_not_null(function* () {
62257
- for (const scriptFilename of [`${functionCallPart.name}.function_call.js`, `${functionCallPart.name}.function_call.ts`]) yield path.join(dir, scriptFilename);
62258
- }(), (scriptFilepath$1) => {
62259
- if (fs.existsSync(scriptFilepath$1)) return scriptFilepath$1;
62260
- });
62261
- if (!scriptFilepath) console.warn("找不到任务处理工具");
62262
- else {
62263
- const { functionCall } = await import(pathToFileURL(scriptFilepath).href);
62264
- const input = JSON.parse(functionCallPart.parameters);
62265
- try {
62266
- console.log(cyan("开始执行任务"));
62267
- const output = await functionCall(input);
62268
- console.log(green("生成任务结果:"), taskFilename);
62269
- fs.writeFileSync(path.join(dir, taskFilename), JSON.stringify({
62270
- input,
62271
- output
62272
- }, null, 2));
62273
- } catch (e$1) {
62274
- console.log(red("任务执行失败:"), e$1);
62275
- }
62365
+ }
62366
+ };
62367
+ const getFunctionCalls = func_remember(async (dir) => {
62368
+ const fcs = await defineFunctionCalls(dir);
62369
+ if (fcs.size === 0) {
62370
+ console.log(red("No Found functionCalls"));
62371
+ return;
62372
+ }
62373
+ console.log(green(`Found functionCalls (${fcs.size}):`));
62374
+ for (const [index$1, [name$1, fc]] of Array.from(fcs).entries()) console.log(gray(`${index$1 + 1}.`), blue(name$1), fc.module.description ?? "");
62375
+ return fcs;
62376
+ });
62377
+ const googleAiStudioAutomation = async ({ dir = process.cwd() }) => {
62378
+ const fcs = await getFunctionCalls(dir);
62379
+ if (!fcs) return;
62380
+ const contentNames = reactiveFs.readDirByGlob(dir, "*.contents.json");
62381
+ if (contentNames.length === 0) {
62382
+ console.log(red("No Found aistudio browser output contents file"));
62383
+ return;
62384
+ }
62385
+ console.log(gray((/* @__PURE__ */ new Date()).toLocaleTimeString()), magenta("处理开始"));
62386
+ for (const contentFilename of contentNames) {
62387
+ const contentFilepath = path.join(dir, contentFilename);
62388
+ const basename$1 = contentFilename.replace(".contents.json", "");
62389
+ try {
62390
+ const result = await parseContent(fcs, dir, basename$1, contentFilepath, contentNames).catch(console.error);
62391
+ } catch (e$1) {
62392
+ console.error(red(e$1 instanceof Error ? e$1.stack ?? e$1.message : String(e$1)));
62276
62393
  }
62277
- };
62278
- watcher.on("change", (eventType) => {
62279
- if (eventType === "delete" || eventType === "unlink") return;
62280
- handle();
62281
- });
62282
- handle();
62283
- console.log(gray("\nWatching for file changes... Press Ctrl+C to exit."));
62394
+ }
62395
+ console.log(gray((/* @__PURE__ */ new Date()).toLocaleTimeString()), magenta("处理结束"));
62396
+ };
62397
+
62398
+ //#endregion
62399
+ //#region ../dev/dist/google-aistudio/node/index.js
62400
+ const doGoogleAiStudioAutomation = async ({ watch,...opts }) => {
62401
+ const handle = func_throttle(() => {
62402
+ return googleAiStudioAutomation(opts);
62403
+ }, 200);
62404
+ const printWatchTip = func_remember(() => console.log(gray("\nWatching for file changes... Press Ctrl+C to exit.")));
62405
+ await reactiveFs.use(async () => {
62406
+ await handle();
62407
+ if (watch) printWatchTip();
62408
+ }, { once: !watch });
62284
62409
  };
62285
62410
 
62286
62411
  //#endregion
@@ -62822,12 +62947,12 @@ const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
62822
62947
  catchall: void 0
62823
62948
  });
62824
62949
  inst.extend = (incoming) => {
62825
- return extend(inst, incoming);
62950
+ return extend$1(inst, incoming);
62826
62951
  };
62827
62952
  inst.merge = (other) => merge(inst, other);
62828
62953
  inst.pick = (mask) => pick(inst, mask);
62829
62954
  inst.omit = (mask) => omit(inst, mask);
62830
- inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
62955
+ inst.partial = (...args) => partial$1(ZodOptional, inst, args[0]);
62831
62956
  inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
62832
62957
  });
62833
62958
  function object(shape, params) {
@@ -63719,9 +63844,14 @@ const browserCommand = {
63719
63844
  describe: "Directory for aistudio output contents",
63720
63845
  type: "string",
63721
63846
  default: process.cwd()
63847
+ }).option("watch", {
63848
+ alias: "W",
63849
+ type: "boolean",
63850
+ describe: "Watch for browser response automatically",
63851
+ default: true
63722
63852
  }),
63723
63853
  handler: async (argv) => {
63724
- doGoogleAiStudioAutomation(argv.dir);
63854
+ doGoogleAiStudioAutomation(argv);
63725
63855
  }
63726
63856
  };
63727
63857
  const initCommand = {