create-unibest 3.1.1 → 3.2.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 +2 -0
  2. package/dist/index.js +27 -64
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -26,6 +26,7 @@ npm update -g create-unibest # 更新 create-unibest 包
26
26
 
27
27
  ```shell
28
28
  best <command> [options] # 基本命令格式
29
+ best my-project # 创建新的unibest项目
29
30
  best new my-project # 创建新的unibest项目
30
31
  best -v # 查看版本信息
31
32
  best -h # 查看帮助信息
@@ -35,6 +36,7 @@ best -h # 查看帮助信息
35
36
 
36
37
  ```shell
37
38
  pnpm create unibest <command> [options] # 基本命令格式
39
+ pnpm create unibest my-project # 创建新的unibest项目
38
40
  pnpm create unibest new my-project # 创建新的unibest项目
39
41
  pnpm create unibest -v # 查看版本信息
40
42
  pnpm create unibest -h # 查看帮助信息
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ import { existsSync } from "fs";
37
37
  import { yellow as yellow2 } from "kolorist";
38
38
  import { join } from "path";
39
39
  function validateProjectName(name) {
40
- const reg = /^[a-z0-9_-]+$/;
40
+ const reg = /^[a-zA-Z0-9_-]+$/;
41
41
  if (!reg.test(name)) {
42
42
  return false;
43
43
  }
@@ -174,7 +174,7 @@ async function removeGitFolder(localPath) {
174
174
  const gitFolderPath = join3(localPath, ".git");
175
175
  await fs.rm(gitFolderPath, { recursive: true, force: true });
176
176
  }
177
- var REPO_URL = "https://gitee.com/feige996/unibest.git";
177
+ var REPO_URL = "https://github.com/unibest-tech/unibest.git";
178
178
  async function cloneRepo(projectName, branch) {
179
179
  try {
180
180
  await new Promise((resolve, reject) => {
@@ -612,7 +612,7 @@ async function generateProject(options) {
612
612
  }
613
613
 
614
614
  // package.json
615
- var version = "3.1.1";
615
+ var version = "3.2.0";
616
616
  var package_default = {
617
617
  name: "create-unibest",
618
618
  type: "module",
@@ -663,48 +663,15 @@ import { bold as bold3, yellow as yellow3, green as green3 } from "kolorist";
663
663
 
664
664
  // src/utils/unibestVersion.ts
665
665
  import fetch from "node-fetch";
666
- import { promises as fs2 } from "fs";
667
- import { join as join5 } from "path";
668
- import os from "os";
669
- var CACHE_EXPIRY_TIME = 4 * 60 * 60 * 1e3;
670
- var getCacheFilePath = () => {
671
- const homeDir = os.homedir();
672
- const cacheDir = join5(homeDir, ".unibest", "cache");
673
- return join5(cacheDir, "version.json");
674
- };
675
- async function readCacheFromFile() {
676
- try {
677
- const cachePath = getCacheFilePath();
678
- const data = await fs2.readFile(cachePath, "utf8");
679
- return JSON.parse(data);
680
- } catch (error) {
681
- return null;
682
- }
683
- }
684
- async function writeCacheToFile(cache) {
685
- try {
686
- const cachePath = getCacheFilePath();
687
- const cacheDir = join5(cachePath, "..");
688
- try {
689
- await fs2.mkdir(cacheDir, { recursive: true });
690
- } catch (mkdirError) {
691
- }
692
- await fs2.writeFile(cachePath, JSON.stringify(cache, null, 2));
693
- } catch (error) {
694
- }
695
- }
696
- async function getUnibestVersion() {
697
- const now = Date.now();
698
- const cachedData = await readCacheFromFile();
699
- if (cachedData && now - cachedData.timestamp < CACHE_EXPIRY_TIME) {
700
- return cachedData.version;
701
- }
666
+ async function getUnibestVersionFromGithub() {
702
667
  try {
703
- const apiUrl = `https://gitee.com/api/v5/repos/feige996/unibest/contents/package.json?ref=main`;
668
+ const apiUrl = `https://api.github.com/repos/feige996/unibest/contents/package.json?ref=main`;
704
669
  const response = await fetch(apiUrl, {
705
670
  method: "GET",
706
671
  headers: {
707
- "Content-Type": "application/json"
672
+ "Content-Type": "application/json",
673
+ // GitHub API 要求 User-Agent 头
674
+ "User-Agent": "unibest-cli"
708
675
  }
709
676
  });
710
677
  if (response.ok) {
@@ -713,33 +680,26 @@ async function getUnibestVersion() {
713
680
  if (encoding === "base64") {
714
681
  const decodedContent = Buffer.from(content, "base64").toString("utf8");
715
682
  const packageJson = JSON.parse(decodedContent);
716
- const version2 = packageJson.version || null;
717
- const newCache = {
718
- version: version2,
719
- timestamp: now
720
- };
721
- void writeCacheToFile(newCache);
722
- return version2;
683
+ return packageJson.version || null;
723
684
  } else {
724
685
  return null;
725
686
  }
726
687
  } else {
727
- return cachedData?.version || null;
688
+ return null;
728
689
  }
729
690
  } catch (error) {
730
- return cachedData?.version || null;
691
+ return null;
731
692
  }
732
693
  }
733
- var unibestVersion_default = getUnibestVersion;
734
694
 
735
695
  // src/utils/beacon.ts
736
696
  import fetch2 from "node-fetch";
737
697
  import dayjs from "dayjs";
738
- import os2 from "os";
698
+ import os from "os";
739
699
  import crypto from "crypto";
740
700
  async function beacon(options) {
741
701
  try {
742
- const unibestVersion = await unibestVersion_default();
702
+ const unibestVersion = await getUnibestVersionFromGithub();
743
703
  const deviceIdentifier = generateDeviceIdentifier();
744
704
  await fetch2("https://ukw0y1.laf.run/create-unibest-v3/beacon", {
745
705
  method: "POST",
@@ -753,9 +713,9 @@ async function beacon(options) {
753
713
  createAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
754
714
  nodeVersion: process.version,
755
715
  osPlatform: process.platform,
756
- cpuModel: os2.cpus()[0]?.model || "unknown",
757
- osRelease: os2.release(),
758
- totalMem: Math.round(os2.totalmem() / (1024 * 1024 * 1024)),
716
+ cpuModel: os.cpus()[0]?.model || "unknown",
717
+ osRelease: os.release(),
718
+ totalMem: Math.round(os.totalmem() / (1024 * 1024 * 1024)),
759
719
  // 四舍五入为整数 GB
760
720
  cpuArch: process.arch,
761
721
  uuid: deviceIdentifier
@@ -767,7 +727,7 @@ async function beacon(options) {
767
727
  }
768
728
  }
769
729
  function generateDeviceIdentifier() {
770
- const deviceInfo = [os2.cpus()[0]?.model || "", os2.totalmem().toString(), os2.platform(), os2.userInfo().username].join(
730
+ const deviceInfo = [os.cpus()[0]?.model || "", os.totalmem().toString(), os.platform(), os.userInfo().username].join(
771
731
  "|"
772
732
  );
773
733
  const hash = crypto.createHash("sha256").update(deviceInfo).digest("hex");
@@ -777,7 +737,7 @@ function generateDeviceIdentifier() {
777
737
  // src/commands/create.ts
778
738
  async function createCommand(args) {
779
739
  const projectName = args._[1] || args._[0];
780
- const versionUnibest = await unibestVersion_default() || "4.0.0";
740
+ const versionUnibest = await getUnibestVersionFromGithub() || "4.0.0";
781
741
  intro(bold3(green3(`create-unibest@v${version} \u5FEB\u901F\u521B\u5EFA ${yellow3(`unibest@v${versionUnibest}`)} \u9879\u76EE`)));
782
742
  if (projectName) {
783
743
  const errorMessage = checkProjectNameExistAndValidate(projectName);
@@ -859,12 +819,15 @@ function main() {
859
819
  }
860
820
  }
861
821
  async function printVersion() {
862
- console.log(green5(`create-unibest: `) + yellow5(version));
863
- try {
864
- const unibestVersion = await unibestVersion_default();
865
- console.log(green5(`unibest: `) + yellow5(unibestVersion || "1.0.0"));
866
- } catch (error) {
867
- console.log(green5(`unibest: \u672A\u80FD\u83B7\u53D6\u5230\u7248\u672C\u53F7`));
822
+ const cliVersion = version;
823
+ const latestVersion = await getUnibestVersionFromGithub();
824
+ if (latestVersion && latestVersion !== cliVersion) {
825
+ console.log(`unibest-cli ${cliVersion} ${yellow5(`->`)} ${green5(`\u6700\u65B0\u7248\u672C: ${latestVersion}`)}`);
826
+ console.log(`\u4F7F\u7528 ${green5(`npm update -g create-unibest`)} \u6216 ${green5(`pnpm add -g create-unibest`)} \u66F4\u65B0`);
827
+ console.log();
828
+ } else {
829
+ console.log(`unibest-cli ${cliVersion}`);
830
+ console.log();
868
831
  }
869
832
  }
870
833
  main();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-unibest",
3
3
  "type": "module",
4
- "version": "3.1.1",
4
+ "version": "3.2.0",
5
5
  "packageManager": "pnpm@9.0.0",
6
6
  "description": "快速创建unibest项目的脚手架工具",
7
7
  "author": "",