@maiyunnet/kebab 9.3.5 → 9.3.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/doc/kebab-rag.md CHANGED
@@ -1360,7 +1360,7 @@ index/variables/VER.md
1360
1360
 
1361
1361
  # Variable: VER
1362
1362
 
1363
- > `const` **VER**: `"9.3.5"` = `'9.3.5'`
1363
+ > `const` **VER**: `"9.3.7"` = `'9.3.7'`
1364
1364
 
1365
1365
  Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
1366
1366
 
@@ -3258,7 +3258,7 @@ lib/core/functions/clone.md
3258
3258
 
3259
3259
  > **clone**\<`T`\>(`obj`): `T`
3260
3260
 
3261
- Defined in: [lib/core.ts:1048](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1048)
3261
+ Defined in: [lib/core.ts:1102](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1102)
3262
3262
 
3263
3263
  完整的克隆一份数组/对象
3264
3264
 
@@ -3322,7 +3322,7 @@ lib/core/functions/debug.md
3322
3322
 
3323
3323
  > **debug**(`message?`, ...`optionalParams`): `void`
3324
3324
 
3325
- Defined in: [lib/core.ts:1082](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1082)
3325
+ Defined in: [lib/core.ts:1136](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1136)
3326
3326
 
3327
3327
  打印调试信息,线上环境不会打印
3328
3328
 
@@ -3357,7 +3357,7 @@ lib/core/functions/display.md
3357
3357
 
3358
3358
  > **display**(`message?`, ...`optionalParams`): `void`
3359
3359
 
3360
- Defined in: [lib/core.ts:1095](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1095)
3360
+ Defined in: [lib/core.ts:1149](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1149)
3361
3361
 
3362
3362
  向控制台直接显示内容,一般情况下禁止使用
3363
3363
 
@@ -3462,7 +3462,7 @@ lib/core/functions/getLog.md
3462
3462
 
3463
3463
  > **getLog**(`opt`): `Promise`\<`false` \| `string`[][] \| `null`\>
3464
3464
 
3465
- Defined in: [lib/core.ts:955](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L955)
3465
+ Defined in: [lib/core.ts:1009](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1009)
3466
3466
 
3467
3467
  获取日志内容为一个数组
3468
3468
 
@@ -3568,7 +3568,7 @@ lib/core/functions/loadEnv.md
3568
3568
 
3569
3569
  > **loadEnv**(`dir`): `Promise`\<`void`\>
3570
3570
 
3571
- Defined in: [lib/core.ts:1147](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1147)
3571
+ Defined in: [lib/core.ts:1201](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1201)
3572
3572
 
3573
3573
  加载 .env 文件到 process.env,若文件不存在则跳过
3574
3574
 
@@ -3597,7 +3597,7 @@ lib/core/functions/log.md
3597
3597
 
3598
3598
  > **log**(`opt`, `msg`, `fend?`): `void`
3599
3599
 
3600
- Defined in: [lib/core.ts:849](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L849)
3600
+ Defined in: [lib/core.ts:903](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L903)
3601
3601
 
3602
3602
  写入文件日志
3603
3603
 
@@ -3638,7 +3638,7 @@ lib/core/functions/ls.md
3638
3638
 
3639
3639
  > **ls**(`opt`): `Promise`\<`object`[]\>
3640
3640
 
3641
- Defined in: [lib/core.ts:1009](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1009)
3641
+ Defined in: [lib/core.ts:1063](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1063)
3642
3642
 
3643
3643
  获取目录内文件/文件夹列表
3644
3644
 
@@ -3964,7 +3964,7 @@ lib/core/functions/removeGlobal.md
3964
3964
 
3965
3965
  > **removeGlobal**(`key`, `hosts?`): `Promise`\<`string`[]\>
3966
3966
 
3967
- Defined in: [lib/core.ts:730](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L730)
3967
+ Defined in: [lib/core.ts:736](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L736)
3968
3968
 
3969
3969
  移除某个跨线程/跨内网服务器全局变量
3970
3970
 
@@ -3999,7 +3999,7 @@ lib/core/functions/resolveEnvVars.md
3999
3999
 
4000
4000
  > **resolveEnvVars**(`obj`): `void`
4001
4001
 
4002
- Defined in: [lib/core.ts:1177](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1177)
4002
+ Defined in: [lib/core.ts:1231](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1231)
4003
4003
 
4004
4004
  将配置对象中的 ${ENV_VAR} 占位符替换为 process.env 的值
4005
4005
 
@@ -4028,7 +4028,7 @@ lib/core/functions/sendNpm.md
4028
4028
 
4029
4029
  > **sendNpm**(`path`, `hosts?`): `Promise`\<`string`[]\>
4030
4030
 
4031
- Defined in: [lib/core.ts:646](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L646)
4031
+ Defined in: [lib/core.ts:649](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L649)
4032
4032
 
4033
4033
  向本机或局域网 RPC 发送 npm install 操作
4034
4034
 
@@ -4050,6 +4050,41 @@ Defined in: [lib/core.ts:646](https://github.com/maiyunnet/kebab/blob/master/lib
4050
4050
 
4051
4051
  `Promise`\<`string`[]\>
4052
4052
 
4053
+ lib/core/functions/sendPackage.md
4054
+ ---
4055
+
4056
+ [**Documents for @maiyunnet/kebab**](../../../index.md)
4057
+
4058
+ ***
4059
+
4060
+ [Documents for @maiyunnet/kebab](../../../index.md) / [lib/core](../index.md) / sendPackage
4061
+
4062
+ # Function: sendPackage()
4063
+
4064
+ > **sendPackage**(`content`, `hosts?`): `Promise`\<`string`[]\>
4065
+
4066
+ Defined in: [lib/core.ts:848](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L848)
4067
+
4068
+ 向本机或局域网 RPC 发送 package.json 更新操作
4069
+
4070
+ ## Parameters
4071
+
4072
+ ### content
4073
+
4074
+ `string`
4075
+
4076
+ package.json 文件内容
4077
+
4078
+ ### hosts?
4079
+
4080
+ `string`[] \| `"config"`
4081
+
4082
+ 局域网列表
4083
+
4084
+ ## Returns
4085
+
4086
+ `Promise`\<`string`[]\>
4087
+
4053
4088
  lib/core/functions/sendPm2.md
4054
4089
  ---
4055
4090
 
@@ -4104,7 +4139,7 @@ lib/core/functions/sendProject.md
4104
4139
 
4105
4140
  > **sendProject**(`path`, `key`, `value`, `hosts?`): `Promise`\<`string`[]\>
4106
4141
 
4107
- Defined in: [lib/core.ts:796](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L796)
4142
+ Defined in: [lib/core.ts:805](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L805)
4108
4143
 
4109
4144
  向本机或局域网 RPC 发送项目配置更新操作
4110
4145
 
@@ -4254,7 +4289,7 @@ lib/core/functions/setGlobal.md
4254
4289
 
4255
4290
  > **setGlobal**(`key`, `data`, `hosts?`): `Promise`\<`string`[]\>
4256
4291
 
4257
- Defined in: [lib/core.ts:689](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L689)
4292
+ Defined in: [lib/core.ts:695](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L695)
4258
4293
 
4259
4294
  设置跨线程/指定的局域网主机的全局变量
4260
4295
 
@@ -4353,7 +4388,7 @@ lib/core/functions/updateCode.md
4353
4388
 
4354
4389
  > **updateCode**(`sourcePath`, `path`, `hosts?`, `config?`, `strict?`): `Promise`\<`Record`\<`string`, \{ `result`: `boolean`; `return`: `string`; \}\>\>
4355
4390
 
4356
- Defined in: [lib/core.ts:742](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L742)
4391
+ Defined in: [lib/core.ts:748](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L748)
4357
4392
 
4358
4393
  上传并覆盖代码文件,config.json、kebab.json、.js.map、.ts, .gitignore 不会被覆盖和新创建
4359
4394
 
@@ -4406,7 +4441,7 @@ lib/core/functions/writeEventStreamHead.md
4406
4441
 
4407
4442
  > **writeEventStreamHead**(`res`): `void`
4408
4443
 
4409
- Defined in: [lib/core.ts:1117](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1117)
4444
+ Defined in: [lib/core.ts:1171](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1171)
4410
4445
 
4411
4446
  ## Parameters
4412
4447
 
@@ -4431,7 +4466,7 @@ lib/core/functions/writeHead.md
4431
4466
 
4432
4467
  > **writeHead**(`res`, `statusCode`, `headers?`): `void`
4433
4468
 
4434
- Defined in: [lib/core.ts:1106](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1106)
4469
+ Defined in: [lib/core.ts:1160](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1160)
4435
4470
 
4436
4471
  让 res 发送头部(前提是头部没有被发送才能调用本方法
4437
4472
 
@@ -4472,7 +4507,7 @@ lib/core/functions/write.md
4472
4507
 
4473
4508
  > **write**(`res`, `data`): `void`
4474
4509
 
4475
- Defined in: [lib/core.ts:1129](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1129)
4510
+ Defined in: [lib/core.ts:1183](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L1183)
4476
4511
 
4477
4512
  向 res 发送数据
4478
4513
 
@@ -4555,6 +4590,7 @@ lib/core/index.md
4555
4590
  - [removeGlobal](functions/removeGlobal.md)
4556
4591
  - [resolveEnvVars](functions/resolveEnvVars.md)
4557
4592
  - [sendNpm](functions/sendNpm.md)
4593
+ - [sendPackage](functions/sendPackage.md)
4558
4594
  - [sendPm2](functions/sendPm2.md)
4559
4595
  - [sendProject](functions/sendProject.md)
4560
4596
  - [sendReload](functions/sendReload.md)
@@ -4642,7 +4678,7 @@ lib/core/interfaces/ILogOptions.md
4642
4678
 
4643
4679
  # Interface: ILogOptions
4644
4680
 
4645
- Defined in: [lib/core.ts:832](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L832)
4681
+ Defined in: [lib/core.ts:886](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L886)
4646
4682
 
4647
4683
  log 设置的选项
4648
4684
 
@@ -4652,7 +4688,7 @@ log 设置的选项
4652
4688
 
4653
4689
  > `optional` **cookie?**: `Record`\<`string`, `string`\>
4654
4690
 
4655
- Defined in: [lib/core.ts:838](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L838)
4691
+ Defined in: [lib/core.ts:892](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L892)
4656
4692
 
4657
4693
  ***
4658
4694
 
@@ -4660,7 +4696,7 @@ Defined in: [lib/core.ts:838](https://github.com/maiyunnet/kebab/blob/master/lib
4660
4696
 
4661
4697
  > `optional` **get?**: `Record`\<`string`, `any`\>
4662
4698
 
4663
- Defined in: [lib/core.ts:837](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L837)
4699
+ Defined in: [lib/core.ts:891](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L891)
4664
4700
 
4665
4701
  ***
4666
4702
 
@@ -4668,7 +4704,7 @@ Defined in: [lib/core.ts:837](https://github.com/maiyunnet/kebab/blob/master/lib
4668
4704
 
4669
4705
  > `optional` **headers?**: `IncomingHttpHeaders`
4670
4706
 
4671
- Defined in: [lib/core.ts:840](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L840)
4707
+ Defined in: [lib/core.ts:894](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L894)
4672
4708
 
4673
4709
  ***
4674
4710
 
@@ -4676,7 +4712,7 @@ Defined in: [lib/core.ts:840](https://github.com/maiyunnet/kebab/blob/master/lib
4676
4712
 
4677
4713
  > `optional` **hostname?**: `string`
4678
4714
 
4679
- Defined in: [lib/core.ts:835](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L835)
4715
+ Defined in: [lib/core.ts:889](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L889)
4680
4716
 
4681
4717
  ***
4682
4718
 
@@ -4684,7 +4720,7 @@ Defined in: [lib/core.ts:835](https://github.com/maiyunnet/kebab/blob/master/lib
4684
4720
 
4685
4721
  > `optional` **path?**: `string`
4686
4722
 
4687
- Defined in: [lib/core.ts:833](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L833)
4723
+ Defined in: [lib/core.ts:887](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L887)
4688
4724
 
4689
4725
  ***
4690
4726
 
@@ -4692,7 +4728,7 @@ Defined in: [lib/core.ts:833](https://github.com/maiyunnet/kebab/blob/master/lib
4692
4728
 
4693
4729
  > `optional` **req?**: `IncomingMessage` \| `Http2ServerRequest` \| `null`
4694
4730
 
4695
- Defined in: [lib/core.ts:836](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L836)
4731
+ Defined in: [lib/core.ts:890](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L890)
4696
4732
 
4697
4733
  ***
4698
4734
 
@@ -4700,7 +4736,7 @@ Defined in: [lib/core.ts:836](https://github.com/maiyunnet/kebab/blob/master/lib
4700
4736
 
4701
4737
  > `optional` **session?**: `Record`\<`string`, `any`\>
4702
4738
 
4703
- Defined in: [lib/core.ts:839](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L839)
4739
+ Defined in: [lib/core.ts:893](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L893)
4704
4740
 
4705
4741
  ***
4706
4742
 
@@ -4708,7 +4744,7 @@ Defined in: [lib/core.ts:839](https://github.com/maiyunnet/kebab/blob/master/lib
4708
4744
 
4709
4745
  > `optional` **urlFull?**: `string`
4710
4746
 
4711
- Defined in: [lib/core.ts:834](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L834)
4747
+ Defined in: [lib/core.ts:888](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L888)
4712
4748
 
4713
4749
  lib/core/type-aliases/TPm2Action.md
4714
4750
  ---
@@ -4797,7 +4833,7 @@ lib/core/variables/global.md
4797
4833
 
4798
4834
  > `const` **global**: `Record`\<`string`, `any`\> = `{}`
4799
4835
 
4800
- Defined in: [lib/core.ts:681](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L681)
4836
+ Defined in: [lib/core.ts:687](https://github.com/maiyunnet/kebab/blob/master/lib/core.ts#L687)
4801
4837
 
4802
4838
  跨进程全局变量
4803
4839
 
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "9.3.5";
8
+ export declare const VER = "9.3.7";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  /** --- 框架的 LIB,以 / 结尾 --- */
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '9.3.5';
9
+ export const VER = '9.3.7';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/lib/core.d.ts CHANGED
@@ -218,6 +218,12 @@ export declare function updateCode(sourcePath: string, path: string, hosts?: str
218
218
  * @param hosts 局域网列表
219
219
  */
220
220
  export declare function sendProject(path: string, key: string, value: string, hosts?: string[] | 'config'): Promise<string[]>;
221
+ /**
222
+ * --- 向本机或局域网 RPC 发送 package.json 更新操作 ---
223
+ * @param content package.json 文件内容
224
+ * @param hosts 局域网列表
225
+ */
226
+ export declare function sendPackage(content: string, hosts?: string[] | 'config'): Promise<string[]>;
221
227
  /** --- log 设置的选项 --- */
222
228
  export interface ILogOptions {
223
229
  'path'?: string;
package/lib/core.js CHANGED
@@ -532,7 +532,10 @@ export async function sendPm2(name, action = 'restart', hosts) {
532
532
  if (hosts === 'config') {
533
533
  hosts = globalConfig.hosts;
534
534
  }
535
- hosts ??= ['127.0.0.1'];
535
+ // --- 未传或 config 展开后为空数组,均回退到本机 ---
536
+ if (!hosts?.length) {
537
+ hosts = ['127.0.0.1'];
538
+ }
536
539
  // --- 局域网模式 ---
537
540
  const time = lTime.stamp();
538
541
  /** --- 返回成功的 host --- */
@@ -569,7 +572,10 @@ export async function sendNpm(path, hosts) {
569
572
  if (hosts === 'config') {
570
573
  hosts = globalConfig.hosts;
571
574
  }
572
- hosts ??= ['127.0.0.1'];
575
+ // --- 未传或 config 展开后为空数组,均回退到本机 ---
576
+ if (!hosts?.length) {
577
+ hosts = ['127.0.0.1'];
578
+ }
573
579
  // --- 局域网模式 ---
574
580
  const time = lTime.stamp();
575
581
  /** --- 返回成功的 host --- */
@@ -659,7 +665,10 @@ export async function updateCode(sourcePath, path, hosts, config = true, strict
659
665
  if (hosts === 'config') {
660
666
  hosts = globalConfig.hosts;
661
667
  }
662
- hosts ??= ['127.0.0.1'];
668
+ // --- 未传或 config 展开后为空数组,均回退到本机 ---
669
+ if (!hosts?.length) {
670
+ hosts = ['127.0.0.1'];
671
+ }
663
672
  /** --- 返回成功的 host --- */
664
673
  const rtn = {};
665
674
  for (const host of hosts) {
@@ -703,7 +712,10 @@ export async function sendProject(path, key, value, hosts) {
703
712
  if (hosts === 'config') {
704
713
  hosts = globalConfig.hosts;
705
714
  }
706
- hosts ??= ['127.0.0.1'];
715
+ // --- 未传或 config 展开后为空数组,均回退到本机 ---
716
+ if (!hosts?.length) {
717
+ hosts = ['127.0.0.1'];
718
+ }
707
719
  // --- 局域网模式 ---
708
720
  const time = lTime.stamp();
709
721
  /** --- 返回成功的 host --- */
@@ -731,6 +743,45 @@ export async function sendProject(path, key, value, hosts) {
731
743
  }
732
744
  return rtn;
733
745
  }
746
+ /**
747
+ * --- 向本机或局域网 RPC 发送 package.json 更新操作 ---
748
+ * @param content package.json 文件内容
749
+ * @param hosts 局域网列表
750
+ */
751
+ export async function sendPackage(content, hosts) {
752
+ if (hosts === 'config') {
753
+ hosts = globalConfig.hosts;
754
+ }
755
+ // --- 未传或 config 展开后为空数组,均回退到本机 ---
756
+ if (!hosts?.length) {
757
+ hosts = ['127.0.0.1'];
758
+ }
759
+ // --- 局域网模式 ---
760
+ const time = lTime.stamp();
761
+ /** --- 返回成功的 host --- */
762
+ const rtn = [];
763
+ for (const host of hosts) {
764
+ const res = await lUndici.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
765
+ 'action': 'package',
766
+ 'time': time,
767
+ 'content': content
768
+ }), globalConfig.rpcSecret), {
769
+ 'timeout': 2
770
+ });
771
+ const resContent = await res.getContent();
772
+ if (!resContent) {
773
+ continue;
774
+ }
775
+ const str = resContent.toString();
776
+ if (str === 'Done') {
777
+ rtn.push(host);
778
+ }
779
+ else {
780
+ debug('[CORE][sendPackage] rpc server content error:', str);
781
+ }
782
+ }
783
+ return rtn;
784
+ }
734
785
  /**
735
786
  * --- 写入文件日志 ---
736
787
  * @param opt 选项
@@ -31,7 +31,7 @@ export declare class Response {
31
31
  /**
32
32
  * --- 获取响应读取流对象 ---
33
33
  */
34
- getStream(): zlib.BrotliDecompress | zlib.Gunzip | zlib.Inflate | (import("undici/types/readable").default & undici.Dispatcher.BodyMixin) | null;
34
+ getStream(): (import("undici/types/readable").default & undici.Dispatcher.BodyMixin) | zlib.Gunzip | zlib.Inflate | zlib.BrotliDecompress | null;
35
35
  /**
36
36
  * --- 获取原生响应读取流对象 ---
37
37
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "9.3.5",
3
+ "version": "9.3.7",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
package/sys/master.js CHANGED
@@ -252,6 +252,24 @@ function createRpcListener() {
252
252
  }
253
253
  break;
254
254
  }
255
+ case 'package': {
256
+ // --- 将用户的 package.json 的内容替换掉项目根的 package.json ---
257
+ if (!msg.content || typeof msg.content !== 'string') {
258
+ res.end('Invalid content');
259
+ return;
260
+ }
261
+ const packageFile = kebab.ROOT_CWD + 'package.json';
262
+ if (!await lFs.isFile(packageFile)) {
263
+ res.end('package.json not found');
264
+ return;
265
+ }
266
+ const wrtn = await lFs.putContent(packageFile, msg.content);
267
+ if (!wrtn) {
268
+ res.end('Failed to write package.json');
269
+ return;
270
+ }
271
+ break;
272
+ }
255
273
  case 'code': {
256
274
  // --- 更新 code 代码包 ---
257
275
  const rtn = await sRoute.getFormData(req);
@@ -19,9 +19,9 @@
19
19
  * 如需打包为 .bundle.js,执行:node ./source/main build
20
20
  *
21
21
  * 【Tailwind CSS 构建】
22
- * bundle 模式下不再加载 CDN,需提前构建 CSS 产物。
23
- * 执行 node ./source/main build 时会自动构建同名 .css,无需单独执行。
24
- * 框架通过 _urlStc _staticVer 自动拼接正确的带版本号 URL。
22
+ * 需提前执行 node ./source/main build -d source/www/example/stc 生成 CSS 产物。
23
+ * 框架通过 _staticPath _staticVer 自动拼接带版本号 URL;
24
+ * import map、props JSON、水合脚本均由框架自动注入 HTML,组件无需手动处理。
25
25
  */
26
26
  interface IUser {
27
27
  'id': string;
@@ -42,17 +42,11 @@ interface IProps {
42
42
  '_staticVer': string;
43
43
  /** --- 框架注入:BrowserRouter 的 basename,如 /test/react-router-page --- */
44
44
  '_routerBase'?: string;
45
- /** --- 框架注入:import map JSON 字符串 --- */
46
- '_importMapJson'?: string;
47
- /** --- 框架注入:水合脚本 --- */
48
- '_hydrateScript'?: string;
49
- /** --- 框架注入:fullProps 序列化 JSON --- */
50
- '_propsJson'?: string;
51
45
  }
52
46
  /**
53
47
  * --- Kebab React BrowserRouter 全页面演示 ---
54
48
  * 框架负责用 StaticRouter(服务端)/ BrowserRouter(客户端)包裹本组件,
55
49
  * 组件内部只需使用 Routes/Route/Link 等,无需自行包裹 Router。
56
50
  */
57
- export default function ReactRouterPage({ title, serverTime, node, users, user, _urlBase, _urlStc, _staticVer, _importMapJson, _hydrateScript, _propsJson, }: IProps): import("react/jsx-runtime").JSX.Element;
51
+ export default function ReactRouterPage({ title, serverTime, node, users, user, _urlBase, _urlStc, _staticVer, }: IProps): import("react/jsx-runtime").JSX.Element;
58
52
  export {};
@@ -20,9 +20,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
20
  * 如需打包为 .bundle.js,执行:node ./source/main build
21
21
  *
22
22
  * 【Tailwind CSS 构建】
23
- * bundle 模式下不再加载 CDN,需提前构建 CSS 产物。
24
- * 执行 node ./source/main build 时会自动构建同名 .css,无需单独执行。
25
- * 框架通过 _urlStc _staticVer 自动拼接正确的带版本号 URL。
23
+ * 需提前执行 node ./source/main build -d source/www/example/stc 生成 CSS 产物。
24
+ * 框架通过 _staticPath _staticVer 自动拼接带版本号 URL;
25
+ * import map、props JSON、水合脚本均由框架自动注入 HTML,组件无需手动处理。
26
26
  */
27
27
  import { useState, useEffect } from 'react';
28
28
  import { Routes, Route, Link, NavLink, useParams, useNavigate, useLocation, Outlet } from 'react-router-dom';
@@ -135,8 +135,6 @@ function PageNotFound() {
135
135
  * 框架负责用 StaticRouter(服务端)/ BrowserRouter(客户端)包裹本组件,
136
136
  * 组件内部只需使用 Routes/Route/Link 等,无需自行包裹 Router。
137
137
  */
138
- export default function ReactRouterPage({ title, serverTime, node, users, user, _urlBase, _urlStc, _staticVer, _importMapJson, _hydrateScript, _propsJson, }) {
139
- return (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx("meta", { charSet: "UTF-8" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }), _jsx("title", { suppressHydrationWarning: true, children: title }), _importMapJson
140
- ? _jsx("script", { src: "https://cdn.tailwindcss.com" })
141
- : _jsx("link", { rel: "stylesheet", href: `${_urlStc}view/react-router-page.css?v=${_staticVer}` }), _importMapJson && (_jsx("script", { type: "importmap", dangerouslySetInnerHTML: { '__html': _importMapJson } }))] }), _jsxs("body", { className: "bg-slate-50 min-h-screen", children: [_jsxs("div", { className: "max-w-2xl mx-auto px-4 py-10 space-y-6", children: [_jsxs("div", { className: "flex items-start justify-between", children: [_jsxs("div", { children: [_jsx("h1", { className: "text-2xl font-bold text-slate-900", children: "Kebab React Router" }), _jsxs("p", { className: "text-slate-500 mt-1 text-sm", children: [_jsx("code", { className: "bg-slate-100 px-1.5 py-0.5 rounded font-mono text-xs", children: "router: 'browser'" }), "\u00A0mode \u2014 URL synced with routes"] })] }), _jsx("a", { href: `${_urlBase}`, className: "text-xs text-slate-400 hover:text-slate-600 transition-colors mt-1", children: "Back to Index" })] }), _jsx("div", { className: "bg-white rounded-xl shadow-sm border border-slate-200 px-4 py-3", children: _jsx(NavBar, {}) }), _jsx("div", { className: "bg-white rounded-xl shadow-sm border border-slate-200 p-6", children: _jsxs(Routes, { children: [_jsx(Route, { path: "/", element: _jsx(PageHome, { serverTime: serverTime, node: node }) }), _jsx(Route, { path: "/about", element: _jsx(PageAbout, {}) }), _jsx(Route, { path: "/user", element: _jsx(PageUsers, { users: users, urlBase: _urlBase }) }), _jsx(Route, { path: "/user/:id", element: _jsx(PageUserDetail, { user: user, urlBase: _urlBase }), children: _jsx(Route, { path: "profile", element: _jsx(PageUserProfile, {}) }) }), _jsx(Route, { path: "*", element: _jsx(PageNotFound, {}) })] }) }), _jsxs(Card, { className: "text-xs text-slate-500 space-y-1.5", children: [_jsx("p", { className: "font-semibold text-slate-700 text-sm", children: "How It Works" }), _jsxs("p", { children: ["\u2022 Server: framework wraps with ", _jsx("code", { className: "bg-slate-100 px-1 rounded", children: "StaticRouter" }), " to SSR the matching route"] }), _jsxs("p", { children: ["\u2022 Client: hydration script wraps with ", _jsx("code", { className: "bg-slate-100 px-1 rounded", children: "BrowserRouter" }), " for URL-synced navigation"] }), _jsxs("p", { children: ["\u2022 Data: one backend method (", _jsx("code", { className: "bg-slate-100 px-1 rounded", children: "_getRouteData" }), ") serves both SSR props and SPA API"] }), _jsxs("p", { children: ["\u2022 Deep links like ", _jsx("code", { className: "bg-slate-100 px-1 rounded", children: "/test/react-router-page/user/42" }), " work out of the box"] })] })] }), _propsJson && (_jsx("script", { id: "__kebab_props__", type: "application/json", suppressHydrationWarning: true, dangerouslySetInnerHTML: { '__html': _propsJson } })), _hydrateScript && (_jsx("script", { type: "module", suppressHydrationWarning: true, dangerouslySetInnerHTML: { '__html': _hydrateScript } }))] })] }));
138
+ export default function ReactRouterPage({ title, serverTime, node, users, user, _urlBase, _urlStc, _staticVer, }) {
139
+ return (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx("meta", { charSet: "UTF-8" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" }), _jsx("title", { suppressHydrationWarning: true, children: title }), _jsx("link", { rel: "stylesheet", href: `${_urlStc}view/react-router-page.css?v=${_staticVer}` })] }), _jsx("body", { className: "bg-slate-50 min-h-screen", children: _jsxs("div", { className: "max-w-2xl mx-auto px-4 py-10 space-y-6", children: [_jsxs("div", { className: "flex items-start justify-between", children: [_jsxs("div", { children: [_jsx("h1", { className: "text-2xl font-bold text-slate-900", children: "Kebab React Router" }), _jsxs("p", { className: "text-slate-500 mt-1 text-sm", children: [_jsx("code", { className: "bg-slate-100 px-1.5 py-0.5 rounded font-mono text-xs", children: "router: 'browser'" }), "\u00A0mode \u2014 URL synced with routes"] })] }), _jsx("a", { href: `${_urlBase}`, className: "text-xs text-slate-400 hover:text-slate-600 transition-colors mt-1", children: "Back to Index" })] }), _jsx("div", { className: "bg-white rounded-xl shadow-sm border border-slate-200 px-4 py-3", children: _jsx(NavBar, {}) }), _jsx("div", { className: "bg-white rounded-xl shadow-sm border border-slate-200 p-6", children: _jsxs(Routes, { children: [_jsx(Route, { path: "/", element: _jsx(PageHome, { serverTime: serverTime, node: node }) }), _jsx(Route, { path: "/about", element: _jsx(PageAbout, {}) }), _jsx(Route, { path: "/user", element: _jsx(PageUsers, { users: users, urlBase: _urlBase }) }), _jsx(Route, { path: "/user/:id", element: _jsx(PageUserDetail, { user: user, urlBase: _urlBase }), children: _jsx(Route, { path: "profile", element: _jsx(PageUserProfile, {}) }) }), _jsx(Route, { path: "*", element: _jsx(PageNotFound, {}) })] }) }), _jsxs(Card, { className: "text-xs text-slate-500 space-y-1.5", children: [_jsx("p", { className: "font-semibold text-slate-700 text-sm", children: "How It Works" }), _jsxs("p", { children: ["\u2022 Server: framework wraps with ", _jsx("code", { className: "bg-slate-100 px-1 rounded", children: "StaticRouter" }), " to SSR the matching route"] }), _jsxs("p", { children: ["\u2022 Client: hydration script wraps with ", _jsx("code", { className: "bg-slate-100 px-1 rounded", children: "BrowserRouter" }), " for URL-synced navigation"] }), _jsxs("p", { children: ["\u2022 Data: one backend method (", _jsx("code", { className: "bg-slate-100 px-1 rounded", children: "_getRouteData" }), ") serves both SSR props and SPA API"] }), _jsxs("p", { children: ["\u2022 Deep links like ", _jsx("code", { className: "bg-slate-100 px-1 rounded", children: "/test/react-router-page/user/42" }), " work out of the box"] })] })] }) })] }));
142
140
  }
@@ -19,9 +19,9 @@
19
19
  * 如需打包为 .bundle.js,执行:node ./source/main build
20
20
  *
21
21
  * 【Tailwind CSS 构建】
22
- * bundle 模式下不再加载 CDN,需提前构建 CSS 产物。
23
- * 执行 node ./source/main build 时会自动构建同名 .css,无需单独执行。
24
- * 框架通过 _urlStc _staticVer 自动拼接正确的带版本号 URL。
22
+ * 需提前执行 node ./source/main build -d source/www/example/stc 生成 CSS 产物。
23
+ * 框架通过 _staticPath _staticVer 自动拼接带版本号 URL;
24
+ * import map、props JSON、水合脚本均由框架自动注入 HTML,组件无需手动处理。
25
25
  */
26
26
 
27
27
  import { useState, useEffect } from 'react';
@@ -49,12 +49,6 @@ interface IProps {
49
49
  '_staticVer': string;
50
50
  /** --- 框架注入:BrowserRouter 的 basename,如 /test/react-router-page --- */
51
51
  '_routerBase'?: string;
52
- /** --- 框架注入:import map JSON 字符串 --- */
53
- '_importMapJson'?: string;
54
- /** --- 框架注入:水合脚本 --- */
55
- '_hydrateScript'?: string;
56
- /** --- 框架注入:fullProps 序列化 JSON --- */
57
- '_propsJson'?: string;
58
52
  }
59
53
 
60
54
  // --- 基础控件 ---
@@ -334,7 +328,7 @@ function PageNotFound() {
334
328
  * 组件内部只需使用 Routes/Route/Link 等,无需自行包裹 Router。
335
329
  */
336
330
  export default function ReactRouterPage({
337
- title, serverTime, node, users, user, _urlBase, _urlStc, _staticVer, _importMapJson, _hydrateScript, _propsJson,
331
+ title, serverTime, node, users, user, _urlBase, _urlStc, _staticVer,
338
332
  }: IProps) {
339
333
  return (
340
334
  <html lang="en">
@@ -343,14 +337,9 @@ export default function ReactRouterPage({
343
337
  <meta name="viewport" content="width=device-width, initial-scale=1" />
344
338
  {/* eslint-disable-next-line @typescript-eslint/naming-convention */}
345
339
  <title suppressHydrationWarning>{title}</title>
346
- {/* --- CSS:dev 模式(无 bundle)用 Tailwind CDN;bundle 模式加载本地构建产物 --- */}
347
- {_importMapJson
348
- ? <script src="https://cdn.tailwindcss.com" />
349
- : <link rel="stylesheet" href={`${_urlStc}view/react-router-page.css?v=${_staticVer}`} />}
350
- {/* --- import map:让浏览器识别 bare import,esm.sh 自动解析依赖 --- */}
351
- {_importMapJson && (
352
- <script type="importmap" dangerouslySetInnerHTML={{ '__html': _importMapJson }} />
353
- )}
340
+ {/* --- import map 由框架自动注入在此标签前,无需手动添加 --- */}
341
+ {/* --- dev: 需先执行 node ./source/main build -d source/www/example/stc 生成 CSS --- */}
342
+ <link rel="stylesheet" href={`${_urlStc}view/react-router-page.css?v=${_staticVer}`} />
354
343
  </head>
355
344
  <body className="bg-slate-50 min-h-screen">
356
345
  <div className="max-w-2xl mx-auto px-4 py-10 space-y-6">
@@ -403,23 +392,7 @@ export default function ReactRouterPage({
403
392
  </Card>
404
393
  </div>
405
394
 
406
- {/* --- 框架注入:props JSON,供客户端水合读取 --- */}
407
- {_propsJson && (
408
- <script
409
- id="__kebab_props__"
410
- type="application/json"
411
- suppressHydrationWarning
412
- dangerouslySetInnerHTML={{ '__html': _propsJson }}
413
- />
414
- )}
415
- {/* --- 框架注入:水合脚本 --- */}
416
- {_hydrateScript && (
417
- <script
418
- type="module"
419
- suppressHydrationWarning
420
- dangerouslySetInnerHTML={{ '__html': _hydrateScript }}
421
- />
422
- )}
395
+ {/* --- props JSON + 水合脚本由框架自动注入在此标签前,无需手动添加 --- */}
423
396
  </body>
424
397
  </html>
425
398
  );