tmui-cli 1.1.4 → 1.1.6

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/bin/dirTool.js ADDED
@@ -0,0 +1,152 @@
1
+ import fs from "fs"
2
+ import path from "path"
3
+ import {
4
+ spawn,
5
+ exec
6
+ } from "child_process"
7
+ import process from "process"
8
+ import os from "os"
9
+
10
+
11
+ export function getJsonFiles(jsonPath) {
12
+ let jsonFiles = [];
13
+
14
+ function findJsonFile(www) {
15
+ let files = fs.readdirSync(www);
16
+ files.forEach(function(item, index) {
17
+ let fPath = path.join(www, item);
18
+ let stat = fs.statSync(fPath);
19
+ if (stat.isDirectory() === true) {
20
+ findJsonFile(fPath);
21
+ }
22
+ if (stat.isFile() === true) {
23
+ jsonFiles.push(fPath);
24
+ }
25
+ });
26
+ }
27
+ findJsonFile(jsonPath);
28
+ return jsonFiles;
29
+ }
30
+
31
+ export function getJsonDir(basePath = './') {
32
+ const dirPath = basePath;
33
+ const root = {
34
+ name: '',
35
+ type: 'dir',
36
+ parent: dirPath,
37
+ children: []
38
+ };
39
+ const files = fs.readdirSync(dirPath);
40
+
41
+ const tree = [];
42
+ for (let i = 0; i < files.length; i++) {
43
+ const filename = files[i];
44
+ const filePath = path.join(dirPath, filename);
45
+ const suffix = path.extname(filename)
46
+
47
+ try {
48
+ if (filename.lastIndexOf('.tmp') == -1 && filename.lastIndexOf('.sys') == -1&&filename[0]!='.') {
49
+ const stats = fs.statSync(filePath);
50
+ if (stats.isFile()) {
51
+ const fileNode = {
52
+ name: filename,
53
+ type: 'file',
54
+ parent: dirPath,
55
+ suffix
56
+ };
57
+ tree.push(fileNode);
58
+ } else if (stats.isDirectory()) {
59
+ const dirNode = {
60
+ name: filename,
61
+ type: 'dir',
62
+ parent: dirPath,
63
+ suffix:'',
64
+ children: []
65
+ };
66
+ tree.push(dirNode);
67
+ }
68
+ }
69
+ } catch (error) {
70
+
71
+ }
72
+
73
+ }
74
+ root.children = tree;
75
+
76
+
77
+ return root;
78
+ }
79
+
80
+ /**读取项目信息根据提供的路径。 */
81
+ export function checkProject(obj) {
82
+
83
+ // const {id,path,type} = obj;
84
+ let mainsetStrPath = "";
85
+ // 检查是否有tmui文件。和目录。
86
+ let tmuiDir = ""
87
+ //可运行的命令行。
88
+ let scriptsPackagePath = ""
89
+ let tmuix4dir = ""
90
+ if (obj.type == 'cli') {
91
+ mainsetStrPath = path.join(obj.path, 'src', 'manifest.json')
92
+ tmuiDir = path.join(obj.path, 'src', 'tmui', 'package.json')
93
+ if(!fs.existsSync(tmuiDir)){
94
+ tmuiDir = path.join(obj.path, 'src', 'uni_modules', 'tm-ui', 'package.json')
95
+ }
96
+ scriptsPackagePath = path.join(obj.path, 'package.json')
97
+ } else {
98
+ mainsetStrPath = path.join(obj.path, 'manifest.json')
99
+ tmuiDir = path.join(obj.path, 'tmui', 'package.json')
100
+ if(!fs.existsSync(tmuiDir)){
101
+ tmuiDir = path.join(obj.path, 'uni_modules', 'tm-ui', 'package.json')
102
+ }
103
+ tmuix4dir = path.join(obj.path, 'uni_modules','tmx-ui', 'package.json')
104
+ }
105
+
106
+ let str = fs.readFileSync(mainsetStrPath).toString('utf-8');
107
+
108
+ let reg = /("([^\\\"]*(\\.)?)*")|('([^\\\']*(\\.)?)*')|(\/{2,}.*?(\r|\n|$))|(\/\*(\n|.)*?\*\/)/g;
109
+
110
+ str = str.replace(reg, function(word) {
111
+ // 去除注释后的文本
112
+ return /^\/{2,}/.test(word) || /^\/\*/.test(word) ? "" : word;
113
+ });
114
+
115
+ const d = JSON.parse(str);
116
+ // 是否是x项目
117
+ const isUniappx = d['uni-app-x']
118
+ let tmui = "";
119
+ if(isUniappx){
120
+ if (fs.existsSync(tmuix4dir)) {
121
+ let str2 = fs.readFileSync(tmuix4dir).toString('utf-8');
122
+ const p = JSON.parse(str2);
123
+ tmui = p.version
124
+ }
125
+ }else{
126
+ if (fs.existsSync(tmuiDir)) {
127
+ let str2 = fs.readFileSync(tmuiDir).toString('utf-8');
128
+ const p = JSON.parse(str2);
129
+ tmui = p.version
130
+ }
131
+ }
132
+
133
+
134
+ // 读取运行的命令行。
135
+ let scripts = ""
136
+ if (fs.existsSync(scriptsPackagePath)) {
137
+ let str2 = fs.readFileSync(scriptsPackagePath).toString('utf-8');
138
+ const p = JSON.parse(str2);
139
+ scripts = p.scripts
140
+ }
141
+
142
+ return {
143
+ name: d.name,
144
+ appid: d.appid,
145
+ versionName: d.versionName,
146
+ tmui: tmui,
147
+ unix:isUniappx,
148
+ id: obj.id,
149
+ scripts: scripts
150
+ }
151
+ }
152
+
package/bin/hooks.js CHANGED
@@ -1,16 +1,22 @@
1
1
 
2
- const ws = require('ws')
3
- const wss = new ws.WebSocketServer({ port: 6169 });
4
- const { execCmd, devRunApp, killChildAndGrandChildren, buildApp } = require("./cmd/cmdTool");
5
- const { selectedDir } = require('./cmd/selectedDir');
6
- const { checkProject, getDirver } = require('./cmd/dirTool');
7
- const osUtils = require('node-os-utils');
2
+ import {WebSocketServer} from 'ws'
3
+ import osUtils from 'node-os-utils'
4
+ import { execCmd, devRunApp, killChildAndGrandChildren, buildApp } from './cmdTool.js'
5
+ import { selectedDir } from './selectedDir.js'
6
+ import { checkProject} from './dirTool.js'
7
+ import { Chalk } from "chalk";
8
+ import { createTmui,UpdateTmui } from './createTmui.js'
8
9
 
10
+ let chalk = new Chalk()
11
+
12
+
13
+
14
+ const wss = new WebSocketServer({ port: 6169 });
9
15
  var client
10
16
  var processList = [];
11
17
  var runAppInfoList = [];
12
18
  var wslist = [];
13
- console.log(getDirver())
19
+
14
20
  function uuid(len = 24, radix) {
15
21
  var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
16
22
  var uuid = [], i;
@@ -55,7 +61,11 @@ wss.on('connection', function connection(ws) {
55
61
  ws.on('error', console.error);
56
62
  ws.on('message', function message(data) {
57
63
  try {
64
+
58
65
  let obj = JSON.parse(data)
66
+ if(obj.event!='getCpu'){
67
+ console.log(chalk.white(data))
68
+ }
59
69
  // 执行命令
60
70
  if (obj.event == 'cmd') {
61
71
  execCmd(function (str) {
@@ -71,14 +81,17 @@ wss.on('connection', function connection(ws) {
71
81
  }, obj.command)
72
82
  // 选择文件目录。
73
83
  } else if (obj.event == '18') {
84
+
74
85
  selectedDir(function (str) {
75
86
  send(JSON.stringify({
76
87
  event: '18',
88
+ flag:'',
77
89
  data: str
78
90
  }))
79
91
  }, function () {
80
92
  send(JSON.stringify({
81
- event: 'end',
93
+ event: '18',
94
+ flag:'end',
82
95
  data: ""
83
96
  }))
84
97
  }, obj.command)
@@ -89,10 +102,12 @@ wss.on('connection', function connection(ws) {
89
102
  send(JSON.stringify({
90
103
  event: '17',
91
104
  data: result,
105
+ flag:'',
92
106
  run: runfl
93
107
  }))
94
108
  send(JSON.stringify({
95
- event: 'end',
109
+ event: '17',
110
+ flag:'end',
96
111
  data: ""
97
112
  }))
98
113
  /**运行项目dev:xxx */
@@ -140,7 +155,7 @@ wss.on('connection', function connection(ws) {
140
155
  }
141
156
  /**获取系统使用率 */
142
157
  } else if (obj.event == 'getCpu') {
143
-
158
+
144
159
  Promise.all([osUtils.mem.info(),osUtils.cpu.usage()])
145
160
  .then(arg=>{
146
161
  send(JSON.stringify({
@@ -151,13 +166,43 @@ wss.on('connection', function connection(ws) {
151
166
  }
152
167
  }))
153
168
  })
154
-
169
+ }else if(obj.event=='21'){
170
+ // npm view @dcloudio/uni-app versions --json
171
+ UpdateTmui(obj.command,(str)=>{
172
+ send(JSON.stringify({
173
+ event: 'info',
174
+ flag:'',
175
+ data: str
176
+ }))
177
+ },()=>{
178
+ send(JSON.stringify({
179
+ event: '21',
180
+ flag:'end',
181
+ data: '完成'
182
+ }))
183
+ })
184
+ // 创建项目.
185
+ }else if(obj.event=='22'){
186
+ // npm view @dcloudio/uni-app versions --json
187
+ createTmui(obj.command,(str)=>{
188
+ send(JSON.stringify({
189
+ event: 'info',
190
+ flag:'',
191
+ data: str
192
+ }))
193
+ },(prejectdir)=>{
194
+ send(JSON.stringify({
195
+ event: '22',
196
+ flag:'end',
197
+ data: prejectdir
198
+ }))
199
+ })
155
200
  }
156
201
 
157
202
 
158
-
159
203
  } catch (error) {
160
-
204
+ console.log(chalk.red(data))
205
+ console.log(chalk.red(error))
161
206
  }
162
207
  });
163
208
  ws.on('close', () => {
@@ -166,5 +211,3 @@ wss.on('connection', function connection(ws) {
166
211
  send('something');
167
212
  });
168
213
 
169
-
170
-
package/bin/net.js ADDED
@@ -0,0 +1,136 @@
1
+ import express from "express"
2
+ import fs from "fs"
3
+ import {spawn} from "child_process"
4
+ import iconv from "iconv-lite"
5
+ import BufferHelper from "bufferhelper"
6
+ import open from "open"
7
+ import bodyParser from "body-parser"
8
+ import fetch from "node-fetch"
9
+ const app = express();
10
+
11
+ var jsonParser = bodyParser.json()
12
+ var urlencodedParser = bodyParser.urlencoded({ extended: false })
13
+ app.use(urlencodedParser)
14
+ app.use(jsonParser)
15
+ function setResHeader(res){
16
+ res.setHeader("Access-Control-Allow-Headers","*")
17
+ res.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS")
18
+ 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")
19
+
20
+ }
21
+
22
+ app.use(express.static('website'))
23
+ app.use('/store', express.static('websitemod'))
24
+
25
+ app.all("/api/dirlist",(req,res)=>{
26
+ setResHeader(res)
27
+ // const ls = getJsonFiles( __dirname )
28
+ // res.json(ls)
29
+
30
+ res.json({'code':0})
31
+ })
32
+ //获取tmui版本
33
+ app.post("/api/cehckTmuiVer",async (req,res)=>{
34
+ setResHeader(res)
35
+ let type = req.body?.type??'uniapp'
36
+
37
+ let resdata = await fetch(`https:cdn.tmui.design/${type=='uniapp'?'tmuiVer':'tmui4x'}.txt`,{method:'GET',headers:{'Content-Type':'text/plan'}})
38
+ let texts = await resdata.text();
39
+ let version = texts.split("\n")
40
+ res.json({'code':0,'version':version,'type':type})
41
+
42
+ })
43
+
44
+ app.post("/api/checkUniappVer",async (req,res)=>{
45
+ setResHeader(res)
46
+ // https://registry.npmjs.org/@dcloudio/uni-app
47
+ let resdata = await fetch(`https://mirrors.huaweicloud.com/repository/npm/@dcloudio/uni-app`,{method:'GET',headers:{'Content-Type':'text/plan'}})
48
+ let texts = await resdata.text();
49
+ let data = JSON.parse(texts)
50
+ let obj = {
51
+ dist:[
52
+ data['dist-tags'].alpha,
53
+ data['dist-tags'].next,
54
+ data['dist-tags'].vue3
55
+ ],
56
+ versions:[]
57
+
58
+ }
59
+ let lis = []
60
+ for(let i in data.versions){
61
+ lis.push(i)
62
+ }
63
+ lis.reverse()
64
+
65
+
66
+ lis = lis.slice(0,40)
67
+ lis = lis.filter(el=>el[0]!='2')
68
+ obj.versions = lis
69
+ res.json({'code':0,'data':obj})
70
+
71
+ })
72
+
73
+
74
+
75
+
76
+
77
+ export const createNet = ()=>{
78
+ app.listen(6170,()=>{
79
+ // open('http://localhost:6170')
80
+ })
81
+ }
82
+
83
+
84
+
85
+ // open('http://localhost:6170')
86
+
87
+ // const express = require('express');
88
+ // const fs = require('fs');
89
+ // const {spawn} = require('child_process');
90
+ // var iconv = require('iconv-lite');
91
+ // var BufferHelper = require('bufferhelper');
92
+ // const app = express();
93
+ // const {getJsonFiles} = require("./cmd/dirTool")
94
+ // const open = require('open');
95
+
96
+ // app.post("/api/dirlist",(req,res)=>{
97
+ // res.setHeader("Access-Control-Allow-Headers","*")
98
+ // res.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS")
99
+ // 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")
100
+
101
+ // const ls = getJsonFiles( __dirname )
102
+ // res.json(ls)
103
+
104
+ // })
105
+
106
+ // app.post("/api/cmd",(req,res)=>{
107
+ // res.setHeader("Access-Control-Allow-Headers","*")
108
+ // res.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS")
109
+ // 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")
110
+
111
+
112
+ // res.json(["响应中..."])
113
+
114
+ // })
115
+
116
+
117
+
118
+ // app.listen(6170)
119
+ // // open('http://localhost:6170')
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
@@ -0,0 +1,28 @@
1
+ import path from "path"
2
+ import fs from "fs"
3
+
4
+ import globalDirectories from "global-dirs"
5
+ import {
6
+ getJsonDir
7
+ } from "./dirTool.js"
8
+
9
+ /**读取项目目录 */
10
+ export async function selectedDir(cb, end, pathStr) {
11
+ try {
12
+ let dirpath = globalDirectories.npm.prefix
13
+ if (pathStr) {
14
+ dirpath = path.normalize(pathStr);
15
+ }
16
+ let str = getJsonDir(dirpath);
17
+ cb(str)
18
+ end('end')
19
+ } catch (error) {
20
+ console.log(error, '---')
21
+ if (end) {
22
+ cb(error)
23
+ end('end')
24
+ }
25
+ }
26
+ }
27
+
28
+