create-unibest 3.0.9 → 3.1.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.
Files changed (3) hide show
  1. package/README.md +6 -6
  2. package/dist/index.js +138 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -18,17 +18,17 @@
18
18
  ### 全局安装
19
19
 
20
20
  ```shell
21
- npm i -g create-unibest # 全局安装,得到 best 命令
22
- npm update -g create-unibest # 更新 create-unibest 包
21
+ npm i -g create-unibest # 全局安装,得到 best 命令
22
+ npm update -g create-unibest # 更新 create-unibest 包
23
23
  ```
24
24
 
25
25
  安装后可使用的命令:
26
26
 
27
27
  ```shell
28
- best <command> [options] # 基本命令格式
29
- best new my-project # 创建新的unibest项目
30
- best -v # 查看版本信息
31
- best -h # 查看帮助信息
28
+ best <command> [options] # 基本命令格式
29
+ best new my-project # 创建新的unibest项目
30
+ best -v # 查看版本信息
31
+ best -h # 查看帮助信息
32
32
  ```
33
33
 
34
34
  ### 临时使用
package/dist/index.js CHANGED
@@ -145,6 +145,7 @@ async function promptUser(projectName, argv = {}) {
145
145
 
146
146
  // src/commands/create/generate.ts
147
147
  import process3 from "process";
148
+ import { log } from "@clack/prompts";
148
149
 
149
150
  // src/utils/cloneRepo.ts
150
151
  import { exec } from "child_process";
@@ -424,8 +425,7 @@ ${importCode}`);
424
425
  } else {
425
426
  content = `${content}
426
427
  <style lang="scss">
427
- ${importCode}
428
- </style>`;
428
+ ${importCode}</style>`;
429
429
  }
430
430
  writeFileSync2(appVuePath, content);
431
431
  }
@@ -597,7 +597,7 @@ async function generateProject(options) {
597
597
  }
598
598
  }
599
599
  try {
600
- logger.success(`\u9879\u76EE${projectName}\u521B\u5EFA\u6210\u529F\uFF01`);
600
+ log.success(`\u9879\u76EE${projectName}\u521B\u5EFA\u6210\u529F\uFF01`);
601
601
  logger.info("\u4E0B\u4E00\u6B65:");
602
602
  logger.info(` cd ${projectName}`);
603
603
  logger.info(" pnpm install");
@@ -611,15 +611,93 @@ async function generateProject(options) {
611
611
  }
612
612
 
613
613
  // package.json
614
- var version = "3.0.9";
614
+ var version = "3.1.0";
615
+ var package_default = {
616
+ name: "create-unibest",
617
+ type: "module",
618
+ version,
619
+ packageManager: "pnpm@9.0.0",
620
+ description: "\u5FEB\u901F\u521B\u5EFAunibest\u9879\u76EE\u7684\u811A\u624B\u67B6\u5DE5\u5177",
621
+ author: "",
622
+ license: "ISC",
623
+ keywords: [],
624
+ main: "dist/index.js",
625
+ bin: {
626
+ best: "bin/index.js",
627
+ "create-unibest": "bin/index.js"
628
+ },
629
+ files: [
630
+ "bin",
631
+ "dist"
632
+ ],
633
+ scripts: {
634
+ dev: "cross-env NODE_ENV=development tsup --watch",
635
+ build: "cross-env NODE_ENV=production tsup",
636
+ prepare: "cross-env NODE_ENV=production npm run build",
637
+ start: "cross-env NODE_ENV=development node bin/index.js"
638
+ },
639
+ dependencies: {
640
+ "@clack/prompts": "^0.11.0",
641
+ dayjs: "^1.11.18",
642
+ ejs: "^3.1.10",
643
+ "fs-extra": "^11.3.0",
644
+ kolorist: "^1.8.0",
645
+ minimist: "^1.2.8",
646
+ "node-fetch": "^3.3.2"
647
+ },
648
+ devDependencies: {
649
+ "@types/ejs": "^3.1.5",
650
+ "@types/fs-extra": "^11.0.4",
651
+ "@types/minimist": "^1.2.5",
652
+ "@types/node": "^24.5.0",
653
+ "cross-env": "^7.0.3",
654
+ tsup: "^8.5.0",
655
+ typescript: "^5.9.0"
656
+ }
657
+ };
615
658
 
616
659
  // src/commands/create.ts
617
- import { intro, log } from "@clack/prompts";
660
+ import { intro, log as log2 } from "@clack/prompts";
618
661
  import { bold as bold3, yellow as yellow3, green as green3 } from "kolorist";
619
662
 
620
663
  // src/utils/unibestVersion.ts
621
664
  import fetch from "node-fetch";
665
+ import { promises as fs2 } from "fs";
666
+ import { join as join5 } from "path";
667
+ import os from "os";
668
+ var CACHE_EXPIRY_TIME = 4 * 60 * 60 * 1e3;
669
+ var getCacheFilePath = () => {
670
+ const homeDir = os.homedir();
671
+ const cacheDir = join5(homeDir, ".unibest", "cache");
672
+ return join5(cacheDir, "version.json");
673
+ };
674
+ async function readCacheFromFile() {
675
+ try {
676
+ const cachePath = getCacheFilePath();
677
+ const data = await fs2.readFile(cachePath, "utf8");
678
+ return JSON.parse(data);
679
+ } catch (error) {
680
+ return null;
681
+ }
682
+ }
683
+ async function writeCacheToFile(cache) {
684
+ try {
685
+ const cachePath = getCacheFilePath();
686
+ const cacheDir = join5(cachePath, "..");
687
+ try {
688
+ await fs2.mkdir(cacheDir, { recursive: true });
689
+ } catch (mkdirError) {
690
+ }
691
+ await fs2.writeFile(cachePath, JSON.stringify(cache, null, 2));
692
+ } catch (error) {
693
+ }
694
+ }
622
695
  async function getUnibestVersion() {
696
+ const now = Date.now();
697
+ const cachedData = await readCacheFromFile();
698
+ if (cachedData && now - cachedData.timestamp < CACHE_EXPIRY_TIME) {
699
+ return cachedData.version;
700
+ }
623
701
  try {
624
702
  const apiUrl = `https://gitee.com/api/v5/repos/feige996/unibest/contents/package.json?ref=main`;
625
703
  const response = await fetch(apiUrl, {
@@ -634,37 +712,85 @@ async function getUnibestVersion() {
634
712
  if (encoding === "base64") {
635
713
  const decodedContent = Buffer.from(content, "base64").toString("utf8");
636
714
  const packageJson = JSON.parse(decodedContent);
637
- return packageJson.version || null;
715
+ const version2 = packageJson.version || null;
716
+ const newCache = {
717
+ version: version2,
718
+ timestamp: now
719
+ };
720
+ void writeCacheToFile(newCache);
721
+ return version2;
638
722
  } else {
639
723
  return null;
640
724
  }
641
725
  } else {
642
- return null;
726
+ return cachedData?.version || null;
643
727
  }
644
728
  } catch (error) {
645
- return null;
729
+ return cachedData?.version || null;
646
730
  }
647
731
  }
648
732
  var unibestVersion_default = getUnibestVersion;
649
733
 
734
+ // src/utils/beacon.ts
735
+ import fetch2 from "node-fetch";
736
+ import dayjs from "dayjs";
737
+ import os2 from "os";
738
+ import crypto from "crypto";
739
+ async function beacon(options) {
740
+ try {
741
+ const unibestVersion = await unibestVersion_default();
742
+ const deviceIdentifier = generateDeviceIdentifier();
743
+ await fetch2("https://ukw0y1.laf.run/create-unibest-v3/beacon", {
744
+ method: "POST",
745
+ headers: {
746
+ "Content-Type": "application/json"
747
+ },
748
+ body: JSON.stringify({
749
+ ...options,
750
+ version: unibestVersion,
751
+ cbVersion: package_default.version,
752
+ createAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
753
+ nodeVersion: process.version,
754
+ osPlatform: process.platform,
755
+ cpuModel: os2.cpus()[0]?.model || "unknown",
756
+ osRelease: os2.release(),
757
+ totalMem: Math.round(os2.totalmem() / (1024 * 1024 * 1024)),
758
+ // 四舍五入为整数 GB
759
+ cpuArch: process.arch,
760
+ uuid: deviceIdentifier
761
+ // 添加设备唯一标识符
762
+ })
763
+ });
764
+ debug("Beacon sent successfully");
765
+ } catch (error) {
766
+ }
767
+ }
768
+ function generateDeviceIdentifier() {
769
+ const deviceInfo = [os2.cpus()[0]?.model || "", os2.totalmem().toString(), os2.platform(), os2.userInfo().username].join(
770
+ "|"
771
+ );
772
+ const hash = crypto.createHash("sha256").update(deviceInfo).digest("hex");
773
+ return hash;
774
+ }
775
+
650
776
  // src/commands/create.ts
651
777
  async function createCommand(args) {
652
778
  const projectName = args._[1];
653
- const versionUnibest = await unibestVersion_default() || "3.18.3";
779
+ const versionUnibest = await unibestVersion_default() || "4.0.0";
654
780
  intro(bold3(green3(`create-unibest@v${version} \u5FEB\u901F\u521B\u5EFA ${yellow3(`unibest@v${versionUnibest}`)} \u9879\u76EE`)));
655
781
  if (projectName) {
656
782
  const errorMessage = checkProjectNameExistAndValidate(projectName);
657
783
  if (errorMessage) {
658
- log.error(errorMessage);
784
+ log2.error(errorMessage);
659
785
  process.exit(1);
660
786
  }
661
787
  }
662
788
  try {
663
789
  const projectOptions = await promptUser(projectName, args);
664
790
  await generateProject(projectOptions);
665
- log.success("\u9879\u76EE\u521B\u5EFA\u6210\u529F\uFF01");
791
+ beacon(projectOptions);
666
792
  } catch (error) {
667
- log.error(`\u521B\u5EFA\u9879\u76EE\u5931\u8D25: ${error.message}`);
793
+ log2.error(`\u521B\u5EFA\u9879\u76EE\u5931\u8D25: ${error.message}`);
668
794
  process.exit(1);
669
795
  }
670
796
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-unibest",
3
3
  "type": "module",
4
- "version": "3.0.9",
4
+ "version": "3.1.0",
5
5
  "description": "快速创建unibest项目的脚手架工具",
6
6
  "author": "",
7
7
  "license": "ISC",