create-unibest 3.0.11 → 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.
- package/README.md +6 -6
- package/dist/index.js +51 -10
- 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
|
|
22
|
-
npm update -g 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
|
|
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
|
@@ -611,7 +611,7 @@ async function generateProject(options) {
|
|
|
611
611
|
}
|
|
612
612
|
|
|
613
613
|
// package.json
|
|
614
|
-
var version = "3.0
|
|
614
|
+
var version = "3.1.0";
|
|
615
615
|
var package_default = {
|
|
616
616
|
name: "create-unibest",
|
|
617
617
|
type: "module",
|
|
@@ -662,7 +662,42 @@ import { bold as bold3, yellow as yellow3, green as green3 } from "kolorist";
|
|
|
662
662
|
|
|
663
663
|
// src/utils/unibestVersion.ts
|
|
664
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
|
+
}
|
|
665
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
|
+
}
|
|
666
701
|
try {
|
|
667
702
|
const apiUrl = `https://gitee.com/api/v5/repos/feige996/unibest/contents/package.json?ref=main`;
|
|
668
703
|
const response = await fetch(apiUrl, {
|
|
@@ -677,15 +712,21 @@ async function getUnibestVersion() {
|
|
|
677
712
|
if (encoding === "base64") {
|
|
678
713
|
const decodedContent = Buffer.from(content, "base64").toString("utf8");
|
|
679
714
|
const packageJson = JSON.parse(decodedContent);
|
|
680
|
-
|
|
715
|
+
const version2 = packageJson.version || null;
|
|
716
|
+
const newCache = {
|
|
717
|
+
version: version2,
|
|
718
|
+
timestamp: now
|
|
719
|
+
};
|
|
720
|
+
void writeCacheToFile(newCache);
|
|
721
|
+
return version2;
|
|
681
722
|
} else {
|
|
682
723
|
return null;
|
|
683
724
|
}
|
|
684
725
|
} else {
|
|
685
|
-
return null;
|
|
726
|
+
return cachedData?.version || null;
|
|
686
727
|
}
|
|
687
728
|
} catch (error) {
|
|
688
|
-
return null;
|
|
729
|
+
return cachedData?.version || null;
|
|
689
730
|
}
|
|
690
731
|
}
|
|
691
732
|
var unibestVersion_default = getUnibestVersion;
|
|
@@ -693,7 +734,7 @@ var unibestVersion_default = getUnibestVersion;
|
|
|
693
734
|
// src/utils/beacon.ts
|
|
694
735
|
import fetch2 from "node-fetch";
|
|
695
736
|
import dayjs from "dayjs";
|
|
696
|
-
import
|
|
737
|
+
import os2 from "os";
|
|
697
738
|
import crypto from "crypto";
|
|
698
739
|
async function beacon(options) {
|
|
699
740
|
try {
|
|
@@ -711,9 +752,9 @@ async function beacon(options) {
|
|
|
711
752
|
createAt: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
|
712
753
|
nodeVersion: process.version,
|
|
713
754
|
osPlatform: process.platform,
|
|
714
|
-
cpuModel:
|
|
715
|
-
osRelease:
|
|
716
|
-
totalMem: Math.round(
|
|
755
|
+
cpuModel: os2.cpus()[0]?.model || "unknown",
|
|
756
|
+
osRelease: os2.release(),
|
|
757
|
+
totalMem: Math.round(os2.totalmem() / (1024 * 1024 * 1024)),
|
|
717
758
|
// 四舍五入为整数 GB
|
|
718
759
|
cpuArch: process.arch,
|
|
719
760
|
uuid: deviceIdentifier
|
|
@@ -725,7 +766,7 @@ async function beacon(options) {
|
|
|
725
766
|
}
|
|
726
767
|
}
|
|
727
768
|
function generateDeviceIdentifier() {
|
|
728
|
-
const deviceInfo = [
|
|
769
|
+
const deviceInfo = [os2.cpus()[0]?.model || "", os2.totalmem().toString(), os2.platform(), os2.userInfo().username].join(
|
|
729
770
|
"|"
|
|
730
771
|
);
|
|
731
772
|
const hash = crypto.createHash("sha256").update(deviceInfo).digest("hex");
|
|
@@ -735,7 +776,7 @@ function generateDeviceIdentifier() {
|
|
|
735
776
|
// src/commands/create.ts
|
|
736
777
|
async function createCommand(args) {
|
|
737
778
|
const projectName = args._[1];
|
|
738
|
-
const versionUnibest = await unibestVersion_default() || "
|
|
779
|
+
const versionUnibest = await unibestVersion_default() || "4.0.0";
|
|
739
780
|
intro(bold3(green3(`create-unibest@v${version} \u5FEB\u901F\u521B\u5EFA ${yellow3(`unibest@v${versionUnibest}`)} \u9879\u76EE`)));
|
|
740
781
|
if (projectName) {
|
|
741
782
|
const errorMessage = checkProjectNameExistAndValidate(projectName);
|