tmui-cli 1.1.5 → 1.1.7

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.
@@ -1,219 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { spawn, exec } = require('child_process');
4
- const process = require('process');
5
- var codecs = require('codecs')
6
- const psTree = require('ps-tree');
7
- var iconv = require('iconv-lite');
8
-
9
- function detectEncoding(str) {
10
- const buffer = Buffer.from(str);
11
- if (buffer[0] < 128) {
12
- return 'ascii';
13
- } else if (buffer[0] < 224) {
14
- return 'utf8';
15
- } else if (buffer[0] < 240) {
16
- return 'utf16le';
17
- } else {
18
- return 'utf32le';
19
- }
20
- }
21
-
22
-
23
- function send(ws,arg){
24
- ws.forEach(el=>{
25
- el.send(arg)
26
- })
27
- }
28
-
29
- function execCmd(cb, end, command) {
30
- try {
31
- // const npmPath = path.join(process.env.APPDATA, 'npm', 'npm.cmd');
32
- const spawnObj = exec(command, { encoding: 'binary' })
33
- // const spawnObj = spawn("npm.cmd",["run","dev:h5"],{detached:true})
34
-
35
- spawnObj.stdout?.on('data', function (chunk) {
36
- // Buffer.from(chunk,'binary').toString('utf-8')
37
- // var str = iconv.decode(, 'cp936');
38
- if (cb) {
39
- let str = Buffer.from(chunk, 'binary').toString("utf8")
40
-
41
- var codecsDecode = codecs(detectEncoding(chunk))
42
- let strii = codecsDecode.decode(Buffer.from(chunk,'binary')).toString('utf-8');
43
- // 去除控制符
44
- const cleanStr = strii.replace(/[\u001B\u009B][[\]()#;?]*(?:(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[A-PR-Za-z~])/g, '');
45
- cb(cleanStr,spawnObj.pid||0)
46
- }
47
- });
48
- spawnObj.addListener('error', (err) => {
49
- if (end) {
50
- cb(err)
51
- end('error')
52
- }
53
- })
54
- spawnObj.on('close', function (code) {
55
- // console.log('close code : ' + code);
56
- if (end) {
57
- end('end')
58
- }
59
- })
60
- spawnObj.on('exit', (code) => {
61
- // console.log('exit code : ' + code);
62
- if (end) {
63
- end('end')
64
- }
65
- });
66
-
67
- return spawnObj;
68
- } catch (error) {
69
- if (end) {
70
- cb(error)
71
- end('end')
72
- }
73
- return null;
74
- }
75
- }
76
- // 杀死子进程及其所有子孙进程
77
- function killChildAndGrandChildren(pid) {
78
-
79
- if (process.platform === 'win32') {
80
- // 在 Windows 系统上执行的代码
81
- const command = `taskkill /T /F /PID ${pid}`;
82
- exec(command, (err, stdout, stderr) => {
83
- if (err) {
84
- console.error(`服务进程退出失败!不要担心,当你关闭主进程时,未退出的子进程会一并关闭哦`);
85
- }
86
- // console.log(`stdout: ${stdout}`);
87
- // console.error(`stderr: ${stderr}`);
88
- });
89
- } else {
90
- // 在 Linux/Unix/Mac 系统上执行的代码
91
- psTree(pid, (err, children) => {
92
- // 使用 kill 命令杀死所有子孙进程
93
- console.log(5555)
94
- exec(`kill -TERM ${pid} ${children.map(c => c.PID).join(' ')}`);
95
- });
96
- }
97
-
98
- }
99
- function devRunApp(ws, obj) {
100
-
101
- const nowcd = process.cwd();
102
- process.chdir(path.normalize(obj.data.path));
103
-
104
- const childreProcess = execCmd(function (msg,pid) {
105
- send(ws,JSON.stringify({
106
- event: 'info',
107
- data: msg
108
- }))
109
- const reg_1 = /http:\/\/localhost(:\d+)?(\/[^\s]*)?/g;
110
- const reg_2 = /http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?(\/[^\s]*)?/g;
111
-
112
-
113
- if(reg_1.test(msg)){
114
- send(ws,JSON.stringify({
115
- event: '1',
116
- data: {
117
- id:obj.data.id,
118
- msg:msg.match(reg_1)[0],
119
- pid:pid
120
- }
121
- }))
122
- }
123
- if(reg_2.test(msg)){
124
- send(ws,JSON.stringify({
125
- event: '1',
126
- data: {
127
- id:obj.data.id,
128
- msg:msg.match(reg_2)[0],
129
- pid:pid
130
- }
131
- }))
132
- }
133
- if(msg.indexOf('ready')>-1){
134
- send(ws,JSON.stringify({
135
- event: 'ready',
136
- data: {
137
- id:obj.data.id,
138
- pid:pid
139
- },
140
- }))
141
- }
142
- }, function (type) {
143
-
144
-
145
- if(type=='end'){
146
- send(ws,JSON.stringify({
147
- event: 'end',
148
- data: {
149
- id:obj.data.id
150
- },
151
- }))
152
- }else{
153
- send(ws,JSON.stringify({
154
- event: 'error',
155
- data: {
156
- id:obj.data.id
157
- },
158
- }))
159
-
160
- }
161
-
162
- }, obj.command)
163
-
164
- return childreProcess;
165
- }
166
-
167
- function buildApp(ws, obj,end) {
168
-
169
- const nowcd = process.cwd();
170
- process.chdir(path.normalize(obj.data.path));
171
-
172
- const childreProcess = execCmd(function (msg,pid) {
173
- send(ws,JSON.stringify({
174
- event: 'info',
175
- data: msg
176
- }))
177
- if(msg.indexOf('DONE')>-1){
178
- send(ws,JSON.stringify({
179
- event: 'buildSucess',
180
- data: {
181
- id:obj.data.id,
182
- pid:pid
183
- },
184
- }))
185
- }
186
- }, function (type) {
187
-
188
-
189
- if(type=='end'){
190
- send(ws,JSON.stringify({
191
- event: 'end',
192
- data: {
193
- id:obj.data.id
194
- },
195
- }))
196
-
197
- console.log('编译完成')
198
- }else{
199
- send(ws,JSON.stringify({
200
- event: 'error',
201
- data: {
202
- id:obj.data.id
203
- },
204
- }))
205
- }
206
- if(end){
207
- end()
208
- }
209
-
210
- }, obj.command)
211
-
212
- return childreProcess;
213
- }
214
-
215
-
216
- exports.execCmd = execCmd;
217
- exports.devRunApp = devRunApp;
218
- exports.killChildAndGrandChildren = killChildAndGrandChildren;
219
- exports.buildApp = buildApp;
@@ -1,174 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const os = require('os');
4
- const process = require('process');
5
- const { spawn, exec } = require('child_process');
6
-
7
- function getJsonFiles(jsonPath) {
8
- let jsonFiles = [];
9
- function findJsonFile(www) {
10
- let files = fs.readdirSync(www);
11
- files.forEach(function (item, index) {
12
- let fPath = path.join(www, item);
13
- let stat = fs.statSync(fPath);
14
- if (stat.isDirectory() === true) {
15
- findJsonFile(fPath);
16
- }
17
- if (stat.isFile() === true) {
18
- jsonFiles.push(fPath);
19
- }
20
- });
21
- }
22
- findJsonFile(jsonPath);
23
- return jsonFiles;
24
- }
25
-
26
- function getJsonDir(basePath = './') {
27
- const dirPath = basePath;
28
- const root = { name: '', type: 'dir', parent: dirPath, children: [] };
29
- const files = fs.readdirSync(dirPath);
30
-
31
- const tree = [];
32
- for (let i = 0; i < files.length; i++) {
33
- const filename = files[i];
34
- const filePath = path.join(dirPath, filename);
35
- try {
36
- if (filename.lastIndexOf('.tmp') == -1 && filename.lastIndexOf('.sys') == -1) {
37
- const stats = fs.statSync(filePath);
38
- if (stats.isFile()) {
39
- const fileNode = { name: filename, type: 'file', parent: dirPath };
40
- tree.push(fileNode);
41
- } else if (stats.isDirectory()) {
42
- const dirNode = { name: filename, type: 'dir', parent: dirPath, children: [] };
43
- tree.push(dirNode);
44
- }
45
- }
46
- } catch (error) {
47
-
48
- }
49
-
50
- }
51
- root.children = tree;
52
-
53
- return root;
54
- }
55
-
56
- /**读取项目信息根据提供的路径。 */
57
- function checkProject(obj) {
58
- // const {id,path,type} = obj;
59
- let mainsetStrPath = "";
60
- // 检查是否有tmui文件。和目录。
61
- let tmuiDir = ""
62
- //可运行的命令行。
63
- let scriptsPackagePath = ""
64
- if (obj.type == 'cli') {
65
- mainsetStrPath = path.join(obj.path, 'src', 'manifest.json')
66
- tmuiDir = path.join(obj.path, 'src', 'tmui', 'package.json')
67
- scriptsPackagePath = path.join(obj.path, 'package.json')
68
- } else {
69
- mainsetStrPath = path.join(obj.path, 'manifest.json')
70
- tmuiDir = path.join(obj.path, 'tmui', 'package.json')
71
- }
72
-
73
- let str = fs.readFileSync(mainsetStrPath).toString('utf-8');
74
-
75
- reg = /("([^\\\"]*(\\.)?)*")|('([^\\\']*(\\.)?)*')|(\/{2,}.*?(\r|\n|$))|(\/\*(\n|.)*?\*\/)/g;
76
-
77
- str = str.replace(reg, function (word) {
78
- // 去除注释后的文本
79
- return /^\/{2,}/.test(word) || /^\/\*/.test(word) ? "" : word;
80
- });
81
-
82
- const d = JSON.parse(str);
83
- let tmui = "";
84
- if (fs.existsSync(tmuiDir)) {
85
- let str2 = fs.readFileSync(tmuiDir).toString('utf-8');
86
- const p = JSON.parse(str2);
87
- tmui = p.version
88
- }
89
-
90
- // 读取运行的命令行。
91
- let scripts = ""
92
- if (fs.existsSync(scriptsPackagePath)) {
93
- let str2 = fs.readFileSync(scriptsPackagePath).toString('utf-8');
94
- const p = JSON.parse(str2);
95
- scripts = p.scripts
96
- }
97
-
98
- return {
99
- name: d.name,
100
- appid: d.appid,
101
- versionName: d.versionName,
102
- tmui: tmui,
103
- id: obj.id,
104
- scripts: scripts
105
- }
106
- }
107
- /**获取系统磁盘。 */
108
- function getDirver(callbck) {
109
- if (process.platform === 'win32') {
110
- // 执行 wmic 命令
111
- const cmd = spawn('wmic', ['logicaldisk', 'get', 'name']);
112
- // 监听命令输出流
113
- cmd.stdout.on('data', data => {
114
- // 解析命令输出结果
115
- const disks = data.toString()
116
- .split('\r\r\n') // 分割为行
117
- .slice(1) // 跳过标题行
118
- .map(line => line.trim()) // 去除行首尾空格
119
- .filter(name => /^[A-Za-z]:$/.test(name)); // 过滤掉非磁盘名称
120
- const pdist = disks.map(el=>el+"\\")
121
-
122
- if(callbck){
123
- callbck(pdist)
124
- }
125
- });
126
-
127
- // 监听命令错误流
128
- cmd.stderr.on('data', data => {
129
- // console.error(`执行 wmic 命令出错:${data}`);
130
- });
131
-
132
- // 监听命令退出事件
133
- cmd.on('exit', code => {
134
- // console.log(`wmic 命令退出,返回码:${code}`);
135
- });
136
-
137
-
138
- } else {
139
- // 在 Linux/Unix/Mac 系统上执行的代码
140
- // 获取系统中的所有磁盘名称
141
- fs.readFile('/proc/mounts', 'utf8', (err, data) => {
142
- if (err) {
143
- console.error(`获取磁盘信息失败:${err}`);
144
- return;
145
- }
146
- const lines = data.split('\n');
147
- const disks = [];
148
- for (const line of lines) {
149
- const parts = line.split(' ');
150
- const mountpoint = parts[1];
151
-
152
- if (mountpoint.startsWith('/dev/')) {
153
- const disk = parts[0];
154
- disks.push(disk);
155
- }
156
- }
157
-
158
- console.log(`系统中的所有磁盘:${disks}`);
159
- if (callbck) {
160
- callbck(disks)
161
- }
162
-
163
- });
164
-
165
- }
166
-
167
- }
168
-
169
-
170
- exports.getJsonFiles = getJsonFiles;
171
- exports.getJsonDir = getJsonDir;
172
- exports.checkProject = checkProject;
173
- exports.getDirver = getDirver;
174
-
@@ -1,27 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const globalDirectories = require('global-dirs');
4
- const { getJsonDir } = require("./dirTool");
5
-
6
-
7
-
8
- async function selectedDir(cb, end, pathStr) {
9
- try {
10
- let dirpath = globalDirectories.npm.prefix
11
- if(pathStr){
12
- dirpath = path.normalize(pathStr);
13
- }
14
- let str = getJsonDir(dirpath);
15
- cb(str)
16
- end('end')
17
- } catch (error) {
18
- console.log(error,'---')
19
- if (end) {
20
- cb(error)
21
- end('end')
22
- }
23
- }
24
- }
25
-
26
-
27
- exports.selectedDir = selectedDir;
package/bin/donet.js DELETED
@@ -1,50 +0,0 @@
1
- const express = require('express');
2
- const fs = require('fs');
3
- const {spawn} = require('child_process');
4
- var iconv = require('iconv-lite');
5
- var BufferHelper = require('bufferhelper');
6
- const app = express();
7
- const {getJsonFiles} = require("./cmd/dirTool")
8
- const open = require('open');
9
-
10
- app.post("/api/dirlist",(req,res)=>{
11
- res.setHeader("Access-Control-Allow-Headers","*")
12
- res.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS")
13
- res.setHeader("Access-Control-Allow-Headers","DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization")
14
-
15
- const ls = getJsonFiles( __dirname )
16
- res.json(ls)
17
-
18
- })
19
-
20
- app.post("/api/cmd",(req,res)=>{
21
- res.setHeader("Access-Control-Allow-Headers","*")
22
- res.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS")
23
- res.setHeader("Access-Control-Allow-Headers","DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization")
24
-
25
-
26
- res.json(["响应中..."])
27
-
28
- })
29
-
30
-
31
-
32
- app.listen(6170)
33
- // open('http://localhost:6170')
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
package/src/create.js DELETED
@@ -1,176 +0,0 @@
1
- const chalk = import("chalk")
2
- const path = require("path")
3
- const fs = require("fs")
4
- const ft = import("node-fetch")
5
- const compressing = require("compressing")
6
- const chilPro = require("child_process")
7
- var clear = require('clear');
8
- var figlet = require('figlet');
9
- var CLI = require('clui'),
10
- Spinner = CLI.Spinner;
11
- var countdown = new Spinner('请等待... ', ['/','\\','/','\\']);
12
- const delFile = require("./util").default.delFile
13
- exports.run = function(type, name,vr,packname="npm",filename="") {
14
- chalk.then(v=>{
15
- const ck = new v.Chalk();
16
- const nowPath = path.join(path.resolve('./'),filename);
17
- var vrNumber = 0
18
- countdown.message(ck.bgBlue('不 要 关闭窗体,正在创建中....'))
19
- let userInputVer = "";
20
- if(vr!=null){
21
- userInputVer = vr;
22
- }else{
23
- let args = name.parent.rawArgs.filter(el=>{
24
- return el
25
- })
26
- if(args.includes('-c')){
27
- if(args.length==5){
28
- userInputVer = args.pop()||""
29
- userInputVer = typeof userInputVer=='undefined'?"":userInputVer
30
- }
31
- }else if(args.length==4){
32
- userInputVer = args.pop()||""
33
- userInputVer = typeof userInputVer=='undefined'?"":userInputVer
34
- }
35
- }
36
- vrNumber = parseInt(userInputVer.replace(/\./g,''))
37
- if(isNaN(vrNumber)){
38
- console.log(ck.red("没有输入版本号"))
39
- }
40
-
41
- countdown.start()
42
- // 检查是否有router目录?
43
- // fs.existsSync(path.join(nowPath,'router','index.ts'))
44
- if(!fs.existsSync(nowPath)){
45
- fs.mkdirSync(nowPath);
46
- }
47
- ft.then((fah)=>{
48
- const fetch = fah.default
49
- fetch('https://cdn.tmui.design/tmuiVer.txt').then(async (res)=>{
50
- let verText = await res.text();
51
- let ver = verText.split('\n')[0]
52
- if(userInputVer){
53
- ver = userInputVer;
54
- }
55
- let isVer = verText.includes(ver)
56
- if(!isVer){
57
- countdown.stop();
58
- console.log(ck.red('不存在版本号:'+ver))
59
- return;
60
- }
61
-
62
-
63
- countdown.message(ck.green('正在使用版本号:'+ver))
64
- fetch(`https://cdn.tmui.design/public/static/${vrNumber>=320?'cli32':'cli'}.zip`).then(async (rf)=>{
65
- let d = await rf.buffer()
66
- fs.writeFile(path.join(nowPath,'cli.zip'),d,(err)=>{
67
- if(err){
68
- countdown.stop();
69
- console.log(ck.bgRed(err))
70
- return;
71
- }
72
- compressing.zip.uncompress(path.join(nowPath,'cli.zip'),path.join(nowPath))
73
- .then(revalue=>{
74
- //创建tmui目录
75
- let tmuipath = path.join(nowPath,'src','tmui');
76
- if(vrNumber>=320){
77
- tmuipath = path.join(nowPath,'src','uni_modules');
78
- if(!fs.existsSync(tmuipath)){
79
- fs.mkdirSync(tmuipath);
80
- }
81
- tmuipath = path.join(nowPath,'src','uni_modules','tm-ui');
82
- }
83
- if(!fs.existsSync(tmuipath)){
84
- fs.mkdirSync(tmuipath);
85
- }else{
86
- delFile(tmuipath)
87
- }
88
- //下载tmui
89
- let donloadTmui = `https://cdn.tmui.design/public/static/tmui${ver}.zip`
90
- fetch(donloadTmui).then(async (tmuires)=>{
91
- fs.writeFileSync(path.join(nowPath,'tmui.zip'),await tmuires.buffer())
92
-
93
- compressing.zip.uncompress(path.join(nowPath,'tmui.zip'),tmuipath)
94
- .then(comtmui=>{
95
- countdown.message(ck.green('非常nice,安装成功,正在清理'))
96
- if(fs.existsSync(path.join(nowPath,'tmui.zip'))){
97
- fs.unlinkSync(path.join(nowPath,'tmui.zip'))
98
- }
99
- if(fs.existsSync(path.join(nowPath,'cli.zip'))){
100
- fs.unlinkSync(path.join(nowPath,'cli.zip'))
101
- }
102
- countdown.message(ck.green('正在安装依赖'))
103
-
104
- if(filename){
105
- chilPro.exec(`cd ${filename}`,(error1, stdout1, stderr1)=>{
106
- process.chdir(nowPath)
107
- installdir()
108
- })
109
- }else{
110
- installdir()
111
- }
112
-
113
- function installdir(){
114
- const installNpm = chilPro.exec(packname+' install',(error, stdout, stderr)=>{
115
- if(error){
116
- countdown.stop()
117
- console.log('安装失败,请在当前目录手动安装依赖文件执行:',ck.bgRed(error))
118
- console.log(ck.green(packname+' install'))
119
- return
120
- }
121
- countdown.stop()
122
- clear()
123
- figlet('TMUI OK!!', function(err, data) {
124
- if (err) {
125
- console.log('Something went wrong...');
126
- console.dir(err);
127
- return;
128
- }
129
- console.log(ck.bgGreen(data))
130
- console.log(ck.green(`---------------------------------------------------`))
131
- console.log(ck.green(`---------------------------------------------------`))
132
- console.log(ck.green('安装成功请执行uni cli命令,编译一个H5项目试:'))
133
- console.log(ck.green(`请切换到你的项目目录: cd ${filename}`))
134
- console.log(ck.green('再执行: '+packname+' run dev:h5'))
135
-
136
- })
137
- })
138
- installNpm.stdout?.on("data",(msg)=>{
139
- console.log(msg.toString('utf8'))
140
- })
141
-
142
- }
143
-
144
-
145
-
146
-
147
- }).catch(err=>{
148
- countdown.stop()
149
- console.log(ck.bgRed(err))
150
- })
151
- })
152
- .catch(e=>{
153
- countdown.stop()
154
- console.log(ck.bgRed(e))
155
- })
156
-
157
- }).catch(errs=>{
158
- countdown.stop()
159
- console.log(ck.bgRed(errs))
160
- })
161
- })
162
- }).catch(e=>{
163
- countdown.stop();
164
- console.log(ck.red(e))
165
- })
166
- }).catch(e=>{
167
- countdown.stop();
168
- console.log(ck.red(e))
169
- })
170
- }).catch(e=>{
171
- countdown.stop();
172
- console.log(ck.red(e))
173
- })
174
- // fetch()tmuiVer.txt
175
- })
176
- }