system-user-identifier-cli 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.
Files changed (2) hide show
  1. package/index.js +17 -0
  2. package/package.json +19 -0
package/index.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+
3
+ const os = require('os');
4
+ const { execSync } = require('child_process');
5
+
6
+ // 方法 1:使用 Node.js 内置模块(推荐,跨平台支持更好)
7
+ const user = os.userInfo().username;
8
+ const platform = os.platform();
9
+ console.log(`👋 Hello! (Node内置方法) 当前用户是: ${user} (${platform})`);
10
+
11
+ // 方法 2:直接执行系统的 id 命令(原生 Shell)
12
+ try {
13
+ const idOutput = execSync('id', { encoding: 'utf-8' }).trim();
14
+ console.log(`💻 原生命令输出: ${idOutput}`);
15
+ } catch (error) {
16
+ console.error('执行 id 命令失败:', error.message);
17
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "system-user-identifier-cli",
3
+ "version": "1.0.0",
4
+ "description": "A simple npx tool to check system user identifier",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "system-user-identifier-cli": "index.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [
13
+ "cli",
14
+ "id",
15
+ "npx"
16
+ ],
17
+ "author": "Your Name",
18
+ "license": "ISC"
19
+ }