create-unibest 3.1.2 → 3.2.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.
- package/dist/index.js +30 -63
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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://
|
|
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
|
|
615
|
+
var version = "3.2.1";
|
|
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
|
-
|
|
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://
|
|
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
|
-
|
|
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
|
|
688
|
+
return null;
|
|
728
689
|
}
|
|
729
690
|
} catch (error) {
|
|
730
|
-
return
|
|
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
|
|
698
|
+
import os from "os";
|
|
739
699
|
import crypto from "crypto";
|
|
740
700
|
async function beacon(options) {
|
|
741
701
|
try {
|
|
742
|
-
const unibestVersion = await
|
|
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:
|
|
757
|
-
osRelease:
|
|
758
|
-
totalMem: Math.round(
|
|
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 = [
|
|
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
|
|
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);
|
|
@@ -840,6 +800,10 @@ function main() {
|
|
|
840
800
|
printVersion();
|
|
841
801
|
return;
|
|
842
802
|
}
|
|
803
|
+
if (args.h || args.help) {
|
|
804
|
+
printHelp();
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
843
807
|
switch (command) {
|
|
844
808
|
case "create":
|
|
845
809
|
case "new":
|
|
@@ -859,12 +823,15 @@ function main() {
|
|
|
859
823
|
}
|
|
860
824
|
}
|
|
861
825
|
async function printVersion() {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
console.log(
|
|
866
|
-
|
|
867
|
-
console.log(
|
|
826
|
+
const cliVersion = version;
|
|
827
|
+
const latestVersion = await getUnibestVersionFromGithub();
|
|
828
|
+
if (latestVersion && latestVersion !== cliVersion) {
|
|
829
|
+
console.log(`unibest-cli ${cliVersion} ${yellow5(`->`)} ${green5(`\u6700\u65B0\u7248\u672C: ${latestVersion}`)}`);
|
|
830
|
+
console.log(`\u4F7F\u7528 ${green5(`npm update -g create-unibest`)} \u6216 ${green5(`pnpm add -g create-unibest`)} \u66F4\u65B0`);
|
|
831
|
+
console.log();
|
|
832
|
+
} else {
|
|
833
|
+
console.log(`unibest-cli ${cliVersion}`);
|
|
834
|
+
console.log();
|
|
868
835
|
}
|
|
869
836
|
}
|
|
870
837
|
main();
|