fcuni 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/README.md +1 -0
- package/os.js +113 -0
- package/package.json +21 -0
- package/src/index.ts +3 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
配合fc-uniapp使用
|
package/os.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const indexTsPath = path.join(__dirname, 'src', 'index.ts');
|
|
6
|
+
// 命令行解析
|
|
7
|
+
const [command, target] = process.argv.slice(2);
|
|
8
|
+
const modules = ['request', 'upload', 'download', 'websocket', 'locale', 'authorize', 'updated', 'jgpush', 'utils'];
|
|
9
|
+
|
|
10
|
+
// 命令解析
|
|
11
|
+
if (
|
|
12
|
+
command == "help"
|
|
13
|
+
|| !command
|
|
14
|
+
|| !['c', 'cre', 'create', 'd', 'dle', 'delete', 'help'].includes(command)
|
|
15
|
+
|| !modules.includes(target)
|
|
16
|
+
) {
|
|
17
|
+
console.log('\n-----fcuni命令-----\n');
|
|
18
|
+
console.log('创建模块:');
|
|
19
|
+
console.log(' 网络请求 : fcuni c request');
|
|
20
|
+
console.log(' 网络上传 : fcuni c upload');
|
|
21
|
+
console.log(' 网络下载 : fcuni c download');
|
|
22
|
+
console.log(' WebSocket : fcuni c websocket');
|
|
23
|
+
console.log(' 国际化 : fcuni c locale');
|
|
24
|
+
console.log(' 权限申请 : fcuni c authorize');
|
|
25
|
+
console.log(' 应用更新 : fcuni c updated');
|
|
26
|
+
console.log(' 极光推送 : fcuni c jgPush');
|
|
27
|
+
console.log(' 实用工具 : fcuni c utils\n');
|
|
28
|
+
console.log('删除模块:');
|
|
29
|
+
console.log(' 网络请求 : fcuni d request');
|
|
30
|
+
console.log(' 网络上传 : fcuni d upload');
|
|
31
|
+
console.log(' 网络下载 : fcuni d download');
|
|
32
|
+
console.log(' WebSocket : fcuni d websocket');
|
|
33
|
+
console.log(' 国际化 : fcuni d locale');
|
|
34
|
+
console.log(' 权限申请 : fcuni d authorize');
|
|
35
|
+
console.log(' 应用更新 : fcuni d updated');
|
|
36
|
+
console.log(' 极光推送 : fcuni d jgPush');
|
|
37
|
+
console.log(' 实用工具 : fcuni d utils\n');
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function opModule(index) {
|
|
42
|
+
const line = index - 1;
|
|
43
|
+
if (command === 'c' || command === 'cre' || command === 'create') {
|
|
44
|
+
try {
|
|
45
|
+
const content = fs.readFileSync(indexTsPath, 'utf8');
|
|
46
|
+
const lines = content.split('\n');
|
|
47
|
+
if (lines[line] && lines[line].trim().startsWith('//')) {
|
|
48
|
+
lines[line] = lines[line].replace(/^\/\//, '');
|
|
49
|
+
fs.writeFileSync(indexTsPath, lines.join('\n'));
|
|
50
|
+
console.log(`✅ 已添加 ${target} 模块`);
|
|
51
|
+
} else {
|
|
52
|
+
console.warn(`⚠️ ${target} 模块已经存在`);
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error(`❌ 操作${target} 模块失败: ${err.message}`);
|
|
56
|
+
}
|
|
57
|
+
} else if (command === 'd' || command === 'dle' || command === 'delete') {
|
|
58
|
+
try {
|
|
59
|
+
const content = fs.readFileSync(indexTsPath, 'utf8');
|
|
60
|
+
const lines = content.split('\n');
|
|
61
|
+
if (lines[line] && !lines[line].trim().startsWith('//')) {
|
|
62
|
+
lines[line] = '// ' + lines[line].trim();
|
|
63
|
+
fs.writeFileSync(indexTsPath, lines.join('\n'));
|
|
64
|
+
console.log(`✅ 已移除 ${target} 模块`);
|
|
65
|
+
} else {
|
|
66
|
+
console.warn(`⚠️ ${target} 模块已经移除`);
|
|
67
|
+
}
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error(`❌ 操作${target} 模块失败: ${err.message}`);
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
console.warn(`✗ 错误: 命令行错误,可以输入 fcuni help 查看帮助`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
if (!target) throw new Error('缺少目标路径参数');
|
|
78
|
+
console.log(`✅ 执行 ${target} 模块`);
|
|
79
|
+
switch (target) {
|
|
80
|
+
case 'request':
|
|
81
|
+
opModule(1);
|
|
82
|
+
break;
|
|
83
|
+
case 'upload':
|
|
84
|
+
opModule(2);
|
|
85
|
+
break;
|
|
86
|
+
case 'download':
|
|
87
|
+
opModule(3);
|
|
88
|
+
break;
|
|
89
|
+
case 'websocket':
|
|
90
|
+
opModule(4);
|
|
91
|
+
break;
|
|
92
|
+
case 'locale':
|
|
93
|
+
opModule(5);
|
|
94
|
+
break;
|
|
95
|
+
case 'authorize':
|
|
96
|
+
opModule(6);
|
|
97
|
+
break;
|
|
98
|
+
case 'updated':
|
|
99
|
+
opModule(7);
|
|
100
|
+
break;
|
|
101
|
+
case 'jgpush':
|
|
102
|
+
opModule(8);
|
|
103
|
+
break;
|
|
104
|
+
case 'utils':
|
|
105
|
+
opModule(9);
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.error(`❌ 错误: ${err.message}`);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fcuni",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "配合fc-uniapp项目使用的命令行工具",
|
|
5
|
+
"bin": {
|
|
6
|
+
"fcuni": "./os.js"
|
|
7
|
+
},
|
|
8
|
+
"preferGlobal": true,
|
|
9
|
+
"keywords": [
|
|
10
|
+
"fcuni",
|
|
11
|
+
"fc-uniapp",
|
|
12
|
+
"fcuniapp",
|
|
13
|
+
"uniapp",
|
|
14
|
+
"uni"
|
|
15
|
+
],
|
|
16
|
+
"author": "L",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"main": "./src/index.ts",
|
|
19
|
+
"module": "./src/index.ts",
|
|
20
|
+
"types": "./src/type.d.ts"
|
|
21
|
+
}
|
package/src/index.ts
ADDED