@ghini/xstart 25.8.6124323

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 ADDED
@@ -0,0 +1,16 @@
1
+ # 一个Ghini简单标准(不使用ts)的npm库开始结构
2
+
3
+ ## dev纯js开发环境
4
+ ## dist(转化为支持ts的环境(简单标准没有ts))起个备份作用
5
+ ## private私有测试
6
+ ## test公开测试
7
+
8
+ ## build.js用来修改version和打包
9
+
10
+ ## 全屏替换xstart为新库名
11
+ ```
12
+ git init
13
+ git branch -M new_branch
14
+ git remote add origin https://github.com/xghini/mynpm.git
15
+ git push -u origin new_branch
16
+ ```
package/build.js ADDED
@@ -0,0 +1,88 @@
1
+ // build.js
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ const devDir = './dev';
5
+ const distDir = './dist';
6
+ const packageJsonPath = './package.json';
7
+ /**
8
+ * 递归地复制一个目录及其所有内容。
9
+ * @param {string} src 源目录路径。
10
+ * @param {string} dest 目标目录路径。
11
+ */
12
+ function copyDirRecursive(src, dest) {
13
+ const exists = fs.existsSync(src);
14
+ if (!exists) {
15
+ console.error(`错误:源目录 "${src}" 不存在。`);
16
+ throw new Error(`源目录 ${src} 未找到。`);
17
+ }
18
+ const stats = fs.statSync(src);
19
+ const isDirectory = stats.isDirectory();
20
+ if (isDirectory) {
21
+ // 如果是目录,创建目标目录
22
+ fs.mkdirSync(dest, { recursive: true });
23
+ // 读取源目录中的所有项,并对每一项进行递归调用
24
+ fs.readdirSync(src).forEach(childItemName => {
25
+ copyDirRecursive(
26
+ path.join(src, childItemName),
27
+ path.join(dest, childItemName)
28
+ );
29
+ });
30
+ } else {
31
+ // 如果是文件,直接复制
32
+ fs.copyFileSync(src, dest);
33
+ }
34
+ }
35
+
36
+ /**
37
+ * 根据当前日期生成版本号。
38
+ * 格式:年.月.日时分秒 (例如: 25.7.3111405)
39
+ * @returns {string} 新的版本号。
40
+ */
41
+ function generateVersionFromDate() {
42
+ const now = new Date();
43
+ const year = now.getFullYear().toString().slice(-2); // 获取年份后两位
44
+ const month = (now.getMonth() + 1).toString(); // 月份(1-12)
45
+ const day = now.getDate().toString(); // 日(1-31)
46
+ const hours = now.getHours().toString().padStart(2, '0'); // 小时(00-23)
47
+ const minutes = now.getMinutes().toString().padStart(2, '0'); // 分钟(00-59)
48
+ const seconds = now.getSeconds().toString().padStart(2, '0'); // 秒(00-59)
49
+ return `${year}.${month}.${day}${hours}${minutes}${seconds}`;
50
+ }
51
+
52
+
53
+ // --- 主要构建流程 ---
54
+ try {
55
+ console.log('🚀 开始执行构建流程...');
56
+
57
+ // 步骤 1: 清理旧的 'dist' 目录
58
+ if (fs.existsSync(distDir)) {
59
+ console.log(`[1/3] 正在删除旧目录: ${distDir}`);
60
+ // fs.rmSync 是一个现代且高效的递归删除目录的方法
61
+ fs.rmSync(distDir, { recursive: true, force: true });
62
+ }
63
+
64
+ // 步骤 2: 将 'dev' 目录复制为 'dist'
65
+ console.log(`[2/3] 正在复制 "${devDir}" 到 "${distDir}"...`);
66
+ copyDirRecursive(devDir, distDir);
67
+ console.log('...目录复制完成。');
68
+
69
+ // 步骤 3: 更新 package.json 中的版本号
70
+ console.log(`[3/3] 正在更新 ${packageJsonPath} 中的版本号...`);
71
+ const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
72
+ const packageJson = JSON.parse(packageJsonContent);
73
+
74
+ const oldVersion = packageJson.version;
75
+ const newVersion = generateVersionFromDate();
76
+ packageJson.version = newVersion;
77
+
78
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
79
+ console.log(`...版本号已从 ${oldVersion} 更新为 ${newVersion}。`);
80
+
81
+ console.log('\n✅ 构建流程成功完成!');
82
+
83
+ } catch (error) {
84
+ console.error('\n❌ 构建流程失败:');
85
+ console.error(error.message);
86
+ // 以错误码退出,表示构建失败
87
+ process.exit(1);
88
+ }
@@ -0,0 +1,3 @@
1
+ export function start(){
2
+ console.log('Hello Ghini')
3
+ }
package/dev/main.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ // dist/main.d.ts
2
+ declare const main: any;
3
+ export default main;
package/dev/main.js ADDED
@@ -0,0 +1,6 @@
1
+ import * as index from "./lib/index.js";
2
+ const xstart = {
3
+ ...index,
4
+ };
5
+ export default xstart;
6
+ export * from "./lib/index.js";
@@ -0,0 +1,3 @@
1
+ export function start(){
2
+ console.log('Hello Ghini')
3
+ }
package/dist/main.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ // dist/main.d.ts
2
+ declare const main: any;
3
+ export default main;
package/dist/main.js ADDED
@@ -0,0 +1,6 @@
1
+ import * as index from "./lib/index.js";
2
+ const xstart = {
3
+ ...index,
4
+ };
5
+ export default xstart;
6
+ export * from "./lib/index.js";
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@ghini/xstart",
3
+ "version": "25.8.6124323",
4
+ "scripts": {
5
+ "build": "node ./build.js",
6
+ "pub": "npm run build && npm publish && git add . && git commit -m 'update' && git push"
7
+ },
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/main.js",
11
+ "types": "./dist/main.d.ts"
12
+ },
13
+ "./dev": {
14
+ "import": "./dev/main.js",
15
+ "types": "./dev/main.d.ts"
16
+ }
17
+ },
18
+ "type": "module",
19
+ "author": "Ghini",
20
+ "license": "MIT",
21
+ "publishConfig": {
22
+ "access": "public"
23
+ }
24
+ }
package/test/0.js ADDED
@@ -0,0 +1,3 @@
1
+ import { start } from "@ghini/start/dev";
2
+
3
+ start();