yuangs 1.0.0 → 1.0.2

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.
Files changed (4) hide show
  1. package/README.md +11 -18
  2. package/cli.js +26 -0
  3. package/index.js +24 -20
  4. package/package.json +8 -5
package/README.md CHANGED
@@ -1,27 +1,20 @@
1
- # yuangs
1
+ # yuangs CLI
2
2
 
3
- 这是我的第一个 npm 包,用于演示标准的发布流程。
3
+ 苑广山的个人命令行工具。
4
4
 
5
5
  ## 安装
6
6
 
7
+ 全局安装以在终端任何位置使用:
8
+
7
9
  ```bash
8
- npm install yuangs
10
+ npm install -g yuangs
9
11
  ```
10
12
 
11
- ## 使用
12
-
13
- ```javascript
14
- const myPkg = require("yuangs");
15
-
16
- // 1. 打印欢迎语
17
- myPkg.sayHello("YGS");
18
- // 输出: Hello, YGS! 恭喜你成功使用了 yuangs
13
+ ## 使用命令
19
14
 
20
- // 2. 做加法
21
- const result = myPkg.add(1, 2);
22
- console.log(result); // 3
15
+ ```bash
16
+ yuangs shici # 打开古诗词
17
+ yuangs dict # 打开词典
18
+ yuangs pong # 打开游戏
19
+ yuangs list # 列出所有链接
23
20
  ```
24
-
25
- ## 维护者
26
-
27
- - yuanguangshan
package/cli.js ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+
3
+ const yuangs = require('./index.js');
4
+ const args = process.argv.slice(2);
5
+ const command = args[0];
6
+
7
+ function printHelp() {
8
+ console.log(`
9
+ Usage: yuangs <command>
10
+
11
+ Commands:
12
+ shici 打开古诗词 PWA
13
+ dict 打开英语词典
14
+ pong 打开 Pong 游戏
15
+ list 列出所有应用链接
16
+ help 显示帮助信息
17
+ `);
18
+ }
19
+
20
+ switch (command) {
21
+ case 'shici': yuangs.openShici(); break;
22
+ case 'dict': yuangs.openDict(); break;
23
+ case 'pong': yuangs.openPong(); break;
24
+ case 'list': yuangs.listApps(); break;
25
+ default: printHelp(); break;
26
+ }
package/index.js CHANGED
@@ -1,25 +1,29 @@
1
- /**
2
- * 打印一条欢迎信息
3
- * @param {string} name - 用户名
4
- * @returns {string} 欢迎语
5
- */
6
- function sayHello(name = "World") {
7
- const message = `Hello, ${name}! 恭喜你成功使用了 yuangs`;
8
- console.log(message);
9
- return message;
10
- }
1
+ const { exec } = require('child_process');
2
+
3
+ const APPS = {
4
+ shici: 'https://wealth.want.biz/shici/index.html',
5
+ dict: 'https://wealth.want.biz/pages/dict.html',
6
+ pong: 'https://wealth.want.biz/pages/pong.html'
7
+ };
11
8
 
12
- /**
13
- * 一个简单的加法函数
14
- * @param {number} a
15
- * @param {number} b
16
- * @returns {number}
17
- */
18
- function add(a, b) {
19
- return a + b;
9
+ function openUrl(url) {
10
+ let command;
11
+ switch (process.platform) {
12
+ case 'darwin': command = `open "${url}"`; break;
13
+ case 'win32': command = `start "${url}"`; break;
14
+ default: command = `xdg-open "${url}"`; break;
15
+ }
16
+ console.log(`正在打开: ${url} ...`);
17
+ exec(command);
20
18
  }
21
19
 
22
20
  module.exports = {
23
- sayHello,
24
- add,
21
+ urls: APPS,
22
+ openShici: () => openUrl(APPS.shici),
23
+ openDict: () => openUrl(APPS.dict),
24
+ openPong: () => openUrl(APPS.pong),
25
+ listApps: () => {
26
+ console.log('--- YGS Apps ---');
27
+ Object.entries(APPS).forEach(([key, url]) => console.log(`${key}: ${url}`));
28
+ }
25
29
  };
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "yuangs",
3
- "version": "1.0.0",
4
- "description": "我的第一个标准 npm 包,用于演示发布流程",
3
+ "version": "1.0.2",
4
+ "description": "苑广山的个人应用集合 CLI",
5
5
  "main": "index.js",
6
+ "bin": {
7
+ "yuangs": "./cli.js"
8
+ },
6
9
  "scripts": {
7
10
  "test": "echo \"Error: no test specified\" && exit 1"
8
11
  },
9
12
  "keywords": [
10
- "demo",
11
- "first-package",
12
- "learning"
13
+ "yuangs",
14
+ "cli",
15
+ "tools"
13
16
  ],
14
17
  "author": "yuanguangshan",
15
18
  "license": "ISC",