create-unibest 3.0.11 → 3.1.1

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 +56 -17
  3. package/package.json +9 -7
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
@@ -229,7 +229,8 @@ var UI_LIBRARY_CONFIGS = {
229
229
  pattern: "^sar-(.*)",
230
230
  path: "sard-uniapp/components/$1/$1.vue"
231
231
  },
232
- types: ["sard-uniapp/global"]
232
+ types: ["sard-uniapp/global"],
233
+ appVueImport: "@import 'sard-uniapp/index.scss';"
233
234
  },
234
235
  "uview-pro": {
235
236
  packageName: "uview-pro",
@@ -600,7 +601,7 @@ async function generateProject(options) {
600
601
  log.success(`\u9879\u76EE${projectName}\u521B\u5EFA\u6210\u529F\uFF01`);
601
602
  logger.info("\u4E0B\u4E00\u6B65:");
602
603
  logger.info(` cd ${projectName}`);
603
- logger.info(" pnpm install");
604
+ logger.info(" pnpm i");
604
605
  logger.info(" pnpm dev");
605
606
  logger.info(" \u8FD0\u884C\u5B8C\u4EE5\u4E0A\u547D\u4EE4\u540E\uFF0C\u518D\u8FD0\u884C\u5176\u4ED6\u5E73\u53F0");
606
607
  logger.info(" \u5982\uFF1Apnpm dev:mp, pnpm dev:app \u7B49");
@@ -611,7 +612,7 @@ async function generateProject(options) {
611
612
  }
612
613
 
613
614
  // package.json
614
- var version = "3.0.11";
615
+ var version = "3.1.1";
615
616
  var package_default = {
616
617
  name: "create-unibest",
617
618
  type: "module",
@@ -662,7 +663,42 @@ import { bold as bold3, yellow as yellow3, green as green3 } from "kolorist";
662
663
 
663
664
  // src/utils/unibestVersion.ts
664
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
+ }
665
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
702
  try {
667
703
  const apiUrl = `https://gitee.com/api/v5/repos/feige996/unibest/contents/package.json?ref=main`;
668
704
  const response = await fetch(apiUrl, {
@@ -677,15 +713,21 @@ async function getUnibestVersion() {
677
713
  if (encoding === "base64") {
678
714
  const decodedContent = Buffer.from(content, "base64").toString("utf8");
679
715
  const packageJson = JSON.parse(decodedContent);
680
- return packageJson.version || null;
716
+ const version2 = packageJson.version || null;
717
+ const newCache = {
718
+ version: version2,
719
+ timestamp: now
720
+ };
721
+ void writeCacheToFile(newCache);
722
+ return version2;
681
723
  } else {
682
724
  return null;
683
725
  }
684
726
  } else {
685
- return null;
727
+ return cachedData?.version || null;
686
728
  }
687
729
  } catch (error) {
688
- return null;
730
+ return cachedData?.version || null;
689
731
  }
690
732
  }
691
733
  var unibestVersion_default = getUnibestVersion;
@@ -693,7 +735,7 @@ var unibestVersion_default = getUnibestVersion;
693
735
  // src/utils/beacon.ts
694
736
  import fetch2 from "node-fetch";
695
737
  import dayjs from "dayjs";
696
- import os from "os";
738
+ import os2 from "os";
697
739
  import crypto from "crypto";
698
740
  async function beacon(options) {
699
741
  try {
@@ -711,9 +753,9 @@ async function beacon(options) {
711
753
  createAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
712
754
  nodeVersion: process.version,
713
755
  osPlatform: process.platform,
714
- cpuModel: os.cpus()[0]?.model || "unknown",
715
- osRelease: os.release(),
716
- totalMem: Math.round(os.totalmem() / (1024 * 1024 * 1024)),
756
+ cpuModel: os2.cpus()[0]?.model || "unknown",
757
+ osRelease: os2.release(),
758
+ totalMem: Math.round(os2.totalmem() / (1024 * 1024 * 1024)),
717
759
  // 四舍五入为整数 GB
718
760
  cpuArch: process.arch,
719
761
  uuid: deviceIdentifier
@@ -725,7 +767,7 @@ async function beacon(options) {
725
767
  }
726
768
  }
727
769
  function generateDeviceIdentifier() {
728
- const deviceInfo = [os.cpus()[0]?.model || "", os.totalmem().toString(), os.platform(), os.userInfo().username].join(
770
+ const deviceInfo = [os2.cpus()[0]?.model || "", os2.totalmem().toString(), os2.platform(), os2.userInfo().username].join(
729
771
  "|"
730
772
  );
731
773
  const hash = crypto.createHash("sha256").update(deviceInfo).digest("hex");
@@ -734,8 +776,8 @@ function generateDeviceIdentifier() {
734
776
 
735
777
  // src/commands/create.ts
736
778
  async function createCommand(args) {
737
- const projectName = args._[1];
738
- const versionUnibest = await unibestVersion_default() || "3.18.3";
779
+ const projectName = args._[1] || args._[0];
780
+ const versionUnibest = await unibestVersion_default() || "4.0.0";
739
781
  intro(bold3(green3(`create-unibest@v${version} \u5FEB\u901F\u521B\u5EFA ${yellow3(`unibest@v${versionUnibest}`)} \u9879\u76EE`)));
740
782
  if (projectName) {
741
783
  const errorMessage = checkProjectNameExistAndValidate(projectName);
@@ -812,10 +854,7 @@ function main() {
812
854
  printVersion();
813
855
  break;
814
856
  default:
815
- if (command) {
816
- console.log(color.red(`\u672A\u77E5\u547D\u4EE4: ${command}`));
817
- }
818
- printHelp();
857
+ createCommand(args);
819
858
  break;
820
859
  }
821
860
  }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "create-unibest",
3
3
  "type": "module",
4
- "version": "3.0.11",
4
+ "version": "3.1.1",
5
+ "packageManager": "pnpm@9.0.0",
5
6
  "description": "快速创建unibest项目的脚手架工具",
6
7
  "author": "",
7
8
  "license": "ISC",
@@ -15,6 +16,12 @@
15
16
  "bin",
16
17
  "dist"
17
18
  ],
19
+ "scripts": {
20
+ "dev": "cross-env NODE_ENV=development tsup --watch",
21
+ "build": "cross-env NODE_ENV=production tsup",
22
+ "prepare": "cross-env NODE_ENV=production npm run build",
23
+ "start": "cross-env NODE_ENV=development node bin/index.js"
24
+ },
18
25
  "dependencies": {
19
26
  "@clack/prompts": "^0.11.0",
20
27
  "dayjs": "^1.11.18",
@@ -32,10 +39,5 @@
32
39
  "cross-env": "^7.0.3",
33
40
  "tsup": "^8.5.0",
34
41
  "typescript": "^5.9.0"
35
- },
36
- "scripts": {
37
- "dev": "cross-env NODE_ENV=development tsup --watch",
38
- "build": "cross-env NODE_ENV=production tsup",
39
- "start": "cross-env NODE_ENV=development node bin/index.js"
40
42
  }
41
- }
43
+ }