@vino.tian/myte 0.1.12 → 0.1.20

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/bin/myte.js CHANGED
@@ -6,16 +6,16 @@ const { join } = require("node:path");
6
6
 
7
7
  function detectTarget() {
8
8
  if (process.platform === "linux" && process.arch === "x64") {
9
- return { key: "linux-x64", binary: "myte" };
9
+ return { dir: "linux-x64", binary: "myte" };
10
10
  }
11
11
  if (process.platform === "linux" && process.arch === "arm64") {
12
- return { key: "linux-arm64", binary: "myte" };
12
+ return { dir: "linux-arm64", binary: "myte" };
13
13
  }
14
14
  if (process.platform === "win32" && process.arch === "x64") {
15
- return { key: "win32-x64", binary: "myte.exe" };
15
+ return { dir: "windows-x64", binary: "myte.exe" };
16
16
  }
17
17
  if (process.platform === "darwin" && process.arch === "arm64") {
18
- return { key: "darwin-arm64", binary: "myte" };
18
+ return { dir: "macos-arm64", binary: "myte" };
19
19
  }
20
20
 
21
21
  console.error(`暂不支持的平台:${process.platform}-${process.arch}`);
@@ -23,7 +23,7 @@ function detectTarget() {
23
23
  }
24
24
 
25
25
  const target = detectTarget();
26
- const binaryPath = join(__dirname, "..", "vendor", target.key, target.binary);
26
+ const binaryPath = join(__dirname, "..", "dist", target.dir, target.binary);
27
27
 
28
28
  if (!existsSync(binaryPath)) {
29
29
  console.error(`缺少当前平台的 myte 二进制:${binaryPath}`);
package/dist/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vino.tian/myte",
3
- "version": "0.1.12",
3
+ "version": "0.1.20",
4
4
  "description": "myte CLI",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -13,14 +13,11 @@
13
13
  "files": [
14
14
  "bin",
15
15
  "scripts",
16
- "vendor",
17
- "README.md"
16
+ "dist",
17
+ "README.md",
18
+ "release-meta.json"
18
19
  ],
19
20
  "scripts": {
20
21
  "postinstall": "node ./scripts/install.js"
21
- },
22
- "myte": {
23
- "packageKey": "myte",
24
- "releaseRepository": "tianweilong/deploy-center"
25
22
  }
26
23
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "packageName": "@vino.tian/myte",
4
+ "packageVersion": "0.1.20",
5
+ "releaseRepository": "tianweilong/deploy-center",
6
+ "releaseTag": "myte-v0.1.20",
7
+ "releasePackageKey": "myte",
8
+ "distributionMode": "github_release"
9
+ }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { createHash } = require("node:crypto");
4
- const { createWriteStream, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } = require("node:fs");
4
+ const { chmodSync, copyFileSync, createWriteStream, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } = require("node:fs");
5
5
  const { tmpdir } = require("node:os");
6
6
  const { dirname, join } = require("node:path");
7
7
  const { pipeline } = require("node:stream/promises");
@@ -11,16 +11,16 @@ const SEMVER_VERSION = /^\d+\.\d+\.\d+$/;
11
11
 
12
12
  function detectTarget() {
13
13
  if (process.platform === "linux" && process.arch === "x64") {
14
- return { key: "linux-x64", assetExt: "tar.gz", binary: "myte" };
14
+ return { dir: "linux-x64", release: "linux-x64", assetExt: "tar.gz", binary: "myte" };
15
15
  }
16
16
  if (process.platform === "linux" && process.arch === "arm64") {
17
- return { key: "linux-arm64", assetExt: "tar.gz", binary: "myte" };
17
+ return { dir: "linux-arm64", release: "linux-arm64", assetExt: "tar.gz", binary: "myte" };
18
18
  }
19
19
  if (process.platform === "win32" && process.arch === "x64") {
20
- return { key: "win32-x64", assetExt: "zip", binary: "myte.exe" };
20
+ return { dir: "windows-x64", release: "win32-x64", assetExt: "zip", binary: "myte.exe" };
21
21
  }
22
22
  if (process.platform === "darwin" && process.arch === "arm64") {
23
- return { key: "darwin-arm64", assetExt: "tar.gz", binary: "myte" };
23
+ return { dir: "macos-arm64", release: "darwin-arm64", assetExt: "tar.gz", binary: "myte" };
24
24
  }
25
25
 
26
26
  throw new Error(`暂不支持的平台:${process.platform}-${process.arch}`);
@@ -30,6 +30,10 @@ function packageMetadata() {
30
30
  return require(join(__dirname, "..", "package.json"));
31
31
  }
32
32
 
33
+ function releaseMetadata() {
34
+ return require(join(__dirname, "..", "release-meta.json"));
35
+ }
36
+
33
37
  function validatePackageVersion(version) {
34
38
  if (version === "0.0.0") {
35
39
  throw new Error("检测到占位版本 0.0.0,说明发布流程未注入 npm 实际版本。");
@@ -39,8 +43,42 @@ function validatePackageVersion(version) {
39
43
  }
40
44
  }
41
45
 
46
+ function validateReleaseMetadata(meta, pkg) {
47
+ if (!meta || typeof meta !== "object") {
48
+ throw new Error("release-meta.json 内容非法。");
49
+ }
50
+ if (meta.schemaVersion !== 1) {
51
+ throw new Error(`release-meta.json schemaVersion 非法:${meta.schemaVersion}`);
52
+ }
53
+ if (meta.packageName !== pkg.name) {
54
+ throw new Error(`release-meta.json packageName 与 package.json 不一致:${meta.packageName}`);
55
+ }
56
+ if (meta.packageVersion !== pkg.version) {
57
+ throw new Error(`release-meta.json packageVersion 与 package.json 不一致:${meta.packageVersion}`);
58
+ }
59
+ if (meta.distributionMode !== "github_release") {
60
+ throw new Error(`myte 安装脚本当前仅支持 github_release,收到:${meta.distributionMode}`);
61
+ }
62
+ if (typeof meta.releaseRepository !== "string" || !meta.releaseRepository) {
63
+ throw new Error("release-meta.json 缺少 releaseRepository。");
64
+ }
65
+ if (typeof meta.releaseTag !== "string" || !meta.releaseTag) {
66
+ throw new Error("release-meta.json 缺少 releaseTag。");
67
+ }
68
+ if (typeof meta.releasePackageKey !== "string" || !meta.releasePackageKey) {
69
+ throw new Error("release-meta.json 缺少 releasePackageKey。");
70
+ }
71
+ }
72
+
42
73
  function vendorBinaryPath(target) {
43
- return join(__dirname, "..", "vendor", target.key, target.binary);
74
+ return join(__dirname, "..", "dist", target.dir, target.binary);
75
+ }
76
+
77
+ function ensureExecutable(filePath) {
78
+ if (process.platform === "win32") {
79
+ return;
80
+ }
81
+ chmodSync(filePath, 0o755);
44
82
  }
45
83
 
46
84
  function fetchBuffer(url) {
@@ -155,11 +193,13 @@ async function install() {
155
193
  }
156
194
 
157
195
  const pkg = packageMetadata();
196
+ const meta = releaseMetadata();
158
197
  validatePackageVersion(pkg.version);
159
- const packageKey = pkg.myte.packageKey;
160
- const releaseRepository = pkg.myte.releaseRepository;
161
- const releaseTag = `${packageKey}-v${pkg.version}`;
162
- const assetName = `${releaseTag}-${target.key}.${target.assetExt}`;
198
+ validateReleaseMetadata(meta, pkg);
199
+ const packageKey = meta.releasePackageKey;
200
+ const releaseRepository = meta.releaseRepository;
201
+ const releaseTag = meta.releaseTag;
202
+ const assetName = `${releaseTag}-${target.release}.${target.assetExt}`;
163
203
  const checksumName = `${releaseTag}-checksums.txt`;
164
204
  const baseUrl = `https://github.com/${releaseRepository}/releases/download/${releaseTag}`;
165
205
  const tempDir = mkdtempSync(join(tmpdir(), "myte-install-"));
@@ -173,13 +213,14 @@ async function install() {
173
213
  const extractDir = join(tempDir, "extract");
174
214
  extractArchive(assetPath, extractDir);
175
215
 
176
- const extractedBinary = join(extractDir, "package", "vendor", target.key, target.binary);
216
+ const extractedBinary = join(extractDir, target.binary);
177
217
  if (!existsSync(extractedBinary)) {
178
218
  throw new Error(`资产中缺少平台二进制:${assetName}`);
179
219
  }
180
220
 
181
221
  mkdirSync(dirname(binaryPath), { recursive: true });
182
- require("node:fs").copyFileSync(extractedBinary, binaryPath);
222
+ copyFileSync(extractedBinary, binaryPath);
223
+ ensureExecutable(binaryPath);
183
224
  } finally {
184
225
  rmSync(tempDir, { recursive: true, force: true });
185
226
  }
package/vendor/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.12
@@ -1,4 +0,0 @@
1
- {
2
- "generatedAt": "2026-03-16T10:31:02.336Z",
3
- "targets": []
4
- }