tmui-cli 1.2.0 → 1.2.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.
package/bin/cmdTool.js CHANGED
@@ -1,12 +1,13 @@
1
-
2
- const path = require("path")
3
- const fs = require("fs")
4
- const {spawn,exec} = require("child_process")
5
- const process = require("process")
6
- const codecs = require("codecs")
7
- const psTree = require("ps-tree")
8
-
9
-
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 codecs from "codecs"
9
+ import psTree from "ps-tree"
10
+ import iconv from "iconv-lite"
10
11
 
11
12
 
12
13
  function detectEncoding(str) {
@@ -24,12 +25,12 @@ function detectEncoding(str) {
24
25
 
25
26
 
26
27
  function send(ws, arg) {
27
- ws.forEach(function(el){
28
+ ws.forEach(el => {
28
29
  el.send(arg)
29
30
  })
30
31
  }
31
32
 
32
- function execCmd(cb, end, command) {
33
+ export function execCmd(cb, end, command) {
33
34
  try {
34
35
  // const npmPath = path.join(process.env.APPDATA, 'npm', 'npm.cmd');
35
36
  const spawnObj = exec(command, {
@@ -51,7 +52,7 @@ function execCmd(cb, end, command) {
51
52
  cb(cleanStr, spawnObj.pid || 0)
52
53
  }
53
54
  });
54
- spawnObj.addListener('error', function(err) {
55
+ spawnObj.addListener('error', (err) => {
55
56
  if (end) {
56
57
  cb(err)
57
58
  end('error')
@@ -63,7 +64,7 @@ function execCmd(cb, end, command) {
63
64
  end('end')
64
65
  }
65
66
  })
66
- spawnObj.on('exit', function(code){
67
+ spawnObj.on('exit', (code) => {
67
68
  // console.log('exit code : ' + code);
68
69
  if (end) {
69
70
  end('end')
@@ -80,12 +81,12 @@ function execCmd(cb, end, command) {
80
81
  }
81
82
  }
82
83
  // 杀死子进程及其所有子孙进程
83
- function killChildAndGrandChildren(pid) {
84
+ export function killChildAndGrandChildren(pid) {
84
85
 
85
86
  if (process.platform === 'win32') {
86
87
  // 在 Windows 系统上执行的代码
87
88
  const command = `taskkill /T /F /PID ${pid}`;
88
- exec(command, function(err, stdout, stderr){
89
+ exec(command, (err, stdout, stderr) => {
89
90
  if (err) {
90
91
  console.error(`服务进程退出失败!不要担心,当你关闭主进程时,未退出的子进程会一并关闭哦`);
91
92
  }
@@ -94,16 +95,16 @@ function killChildAndGrandChildren(pid) {
94
95
  });
95
96
  } else {
96
97
  // 在 Linux/Unix/Mac 系统上执行的代码
97
- psTree(pid, function(err, children){
98
+ psTree(pid, (err, children) => {
98
99
  // 使用 kill 命令杀死所有子孙进程
99
100
  console.log(5555)
100
- exec(`kill -TERM ${pid} ${children.map(function(c) {return c.PID}).join(' ')}`);
101
+ exec(`kill -TERM ${pid} ${children.map(c => c.PID).join(' ')}`);
101
102
  });
102
103
  }
103
104
 
104
105
  }
105
106
 
106
- function devRunApp(ws, obj) {
107
+ export function devRunApp(ws, obj) {
107
108
 
108
109
  const nowcd = process.cwd();
109
110
  process.chdir(path.normalize(obj.data.path));
@@ -171,7 +172,7 @@ function devRunApp(ws, obj) {
171
172
  return childreProcess;
172
173
  }
173
174
 
174
- function buildApp(ws, obj, end) {
175
+ export function buildApp(ws, obj, end) {
175
176
 
176
177
  const nowcd = process.cwd();
177
178
  process.chdir(path.normalize(obj.data.path));
@@ -219,11 +220,4 @@ function buildApp(ws, obj, end) {
219
220
  return childreProcess;
220
221
  }
221
222
 
222
- module.exports = {
223
- execCmd,
224
- killChildAndGrandChildren,
225
- devRunApp,
226
- buildApp
227
- }
228
-
229
223
 
package/bin/createTmui.js CHANGED
@@ -1,9 +1,7 @@
1
-
2
- const path = require("path")
3
- const {execCmd} = require("./cmdTool.js")
4
- const fs = require("fs")
5
- const compressing = require("compressing")
6
- const Fetch = import("node-fetch")
1
+ import path from "path";
2
+ import fs from "fs"
3
+ import compressing from "compressing"
4
+ import { execCmd } from "./cmdTool.js";
7
5
 
8
6
 
9
7
  const uniappDevListVer = [
@@ -76,10 +74,10 @@ function writePackageJson(filepath, str) {
76
74
  /**
77
75
  * 更新项目.
78
76
  * @param {{path,type,uvue,tmui,uniappver}} arg
77
+ * @param {(str)=>{}} call
78
+ * @param {()=>{}} end
79
79
  */
80
- async function UpdateTmui(arg, call, end) {
81
- const fetch = (await Fetch).default;
82
-
80
+ export async function UpdateTmui(arg, call, end) {
83
81
  let rootdir = path.normalize(arg.path)
84
82
  call('检测目录...')
85
83
  if (!fs.existsSync(rootdir)) {
@@ -171,7 +169,7 @@ async function UpdateTmui(arg, call, end) {
171
169
  let initjson = readPackageJson(packjsonDir)
172
170
  if (initjson['dependencies']['@dcloudio/uni-app'] != arg.uniappver) {
173
171
  call(`检测到cli版本与你选中的不一样,正在设置你选中的版本号`)
174
- uniappDevListVer.forEach( function(el) {
172
+ uniappDevListVer.forEach(el => {
175
173
  if (initjson['dependencies'][el]) {
176
174
  initjson['dependencies'][el] = arg.uniappver
177
175
  }
@@ -183,9 +181,9 @@ async function UpdateTmui(arg, call, end) {
183
181
 
184
182
  writePackageJson(packjsonDir, JSON.stringify(initjson, null, 4))
185
183
 
186
- execCmd(function (datastr){
184
+ execCmd((datastr) => {
187
185
  call(datastr)
188
- }, function () {
186
+ }, () => {
189
187
  end()
190
188
  }, 'npm install --save --registry=https://registry.npmmirror.com/')
191
189
 
@@ -203,10 +201,10 @@ async function UpdateTmui(arg, call, end) {
203
201
  /**
204
202
  *
205
203
  * @param {{name,rootDir,type,ver,uniappver,uniappBuildType,machine}} arg
204
+ * @param {(str)=>{}} call
205
+ * @param {(str?:string)=>{}} end
206
206
  */
207
- async function createTmui(arg, call, end) {
208
- const fetch = (await Fetch).default;
209
-
207
+ export async function createTmui(arg, call, end) {
210
208
  let rootdir = path.normalize(arg.rootDir)
211
209
  call('检测目录...')
212
210
  if (!fs.existsSync(rootdir)) {
@@ -343,7 +341,7 @@ async function createTmui(arg, call, end) {
343
341
  let initjson = readPackageJson(packjsonDir)
344
342
 
345
343
 
346
- uniappDevListVer.forEach(function (el) {
344
+ uniappDevListVer.forEach(el => {
347
345
  if (initjson['dependencies'][el]) {
348
346
  initjson['dependencies'][el] = arg.uniappver
349
347
  }
@@ -361,9 +359,9 @@ async function createTmui(arg, call, end) {
361
359
 
362
360
  writePackageJson(packjsonDir, JSON.stringify(initjson, null, 4))
363
361
 
364
- execCmd(function (datastr) {
362
+ execCmd((datastr) => {
365
363
  call(datastr)
366
- }, function () {
364
+ }, () => {
367
365
  end(rootdir)
368
366
  }, 'npm install --save --registry=https://registry.npmmirror.com/')
369
367
 
@@ -374,10 +372,4 @@ async function createTmui(arg, call, end) {
374
372
 
375
373
  end(rootdir)
376
374
 
377
- }
378
-
379
- module.exports = {
380
- createTmui,
381
- UpdateTmui,
382
- delFile
383
375
  }
package/bin/dirTool.js CHANGED
@@ -1,7 +1,14 @@
1
- const path = require("path")
2
- const fs = require("fs")
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"
3
9
 
4
- function getJsonFiles(jsonPath) {
10
+
11
+ export function getJsonFiles(jsonPath) {
5
12
  let jsonFiles = [];
6
13
 
7
14
  function findJsonFile(www) {
@@ -21,7 +28,7 @@ function getJsonFiles(jsonPath) {
21
28
  return jsonFiles;
22
29
  }
23
30
 
24
- function getJsonDir(basePath = './') {
31
+ export function getJsonDir(basePath = './') {
25
32
  const dirPath = basePath;
26
33
  const root = {
27
34
  name: '',
@@ -64,7 +71,6 @@ function getJsonDir(basePath = './') {
64
71
  }
65
72
 
66
73
  }
67
- // @ts-ignore
68
74
  root.children = tree;
69
75
 
70
76
 
@@ -72,7 +78,7 @@ function getJsonDir(basePath = './') {
72
78
  }
73
79
 
74
80
  /**读取项目信息根据提供的路径。 */
75
- function checkProject(obj) {
81
+ export function checkProject(obj) {
76
82
 
77
83
  // const {id,path,type} = obj;
78
84
  let mainsetStrPath = "";
@@ -144,9 +150,3 @@ function checkProject(obj) {
144
150
  }
145
151
  }
146
152
 
147
-
148
- module.exports = {
149
- getJsonFiles,
150
- getJsonDir,
151
- checkProject
152
- }
package/bin/hooks.js CHANGED
@@ -1,15 +1,13 @@
1
- const figlet = require("figlet")
2
- const chalks = import("chalk")
3
-
4
- const {createTmui,UpdateTmui} = require("./createTmui.js")
5
- const {checkProject} = require("./dirTool.js")
6
- const {selectedDir} = require("./selectedDir.js")
7
- const osUtils = require("node-os-utils")
8
- const {WebSocketServer} = require("ws")
9
- const {execCmd, devRunApp, killChildAndGrandChildren, buildApp} = require("./cmdTool.js")
10
-
11
1
 
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'
12
9
 
10
+ let chalk = new Chalk()
13
11
 
14
12
 
15
13
 
@@ -46,18 +44,17 @@ function uuid(len = 24, radix) {
46
44
  return uuid.join('');
47
45
  }
48
46
  function removeWs(id) {
49
- const index = wslist.findIndex(function(el) {return el.uuid == id})
47
+ const index = wslist.findIndex(el => el.uuid == id)
50
48
  if (index > -1) {
51
49
  wslist.splice(index, 1)
52
50
  }
53
51
  }
54
52
  function send(arg) {
55
- wslist.forEach(function(el) {
53
+ wslist.forEach(el => {
56
54
  el.send(arg)
57
55
  })
58
56
  }
59
- wss.on('connection', async function connection(ws) {
60
- const chalk = (await chalks).default;
57
+ wss.on('connection', function connection(ws) {
61
58
 
62
59
  ws.uuid = uuid();
63
60
  wslist.push(ws)
@@ -101,7 +98,7 @@ wss.on('connection', async function connection(ws) {
101
98
  // 查询目录项目的信息
102
99
  } else if (obj.event == '17') {
103
100
  let result = checkProject(obj.command)
104
- let runfl = runAppInfoList.filter(function(el){ return el.id == result.id})
101
+ let runfl = runAppInfoList.filter(el => el.id == result.id)
105
102
  send(JSON.stringify({
106
103
  event: '17',
107
104
  data: result,
@@ -127,12 +124,12 @@ wss.on('connection', async function connection(ws) {
127
124
  if (!obj.command) return;
128
125
  // process.kill(Number(obj.command||0))
129
126
  const pid = Number(obj.command || 0);
130
- const index = processList.findIndex(function(el){ return el.pid == pid})
127
+ const index = processList.findIndex(el => el.pid == pid)
131
128
  if (index > -1) {
132
129
  // process.kill(sflit[0].pid)
133
130
  killChildAndGrandChildren(processList[index].pid)
134
131
  processList.splice(index, 1)
135
- const index2 = runAppInfoList.findIndex(function(el){ return el.pid == pid})
132
+ const index2 = runAppInfoList.findIndex(el => el.pid == pid)
136
133
  runAppInfoList.splice(index2, 1)
137
134
  }
138
135
  } catch (error) {
@@ -141,8 +138,8 @@ wss.on('connection', async function connection(ws) {
141
138
  /**编译应用build:xx */
142
139
  } else if (obj.event == '3') {
143
140
  const id = obj.command.data.id;
144
- const childrenProcess = buildApp(wslist, obj.command, function() {
145
- const index2 = runAppInfoList.findIndex(function(el){ return el.id == id})
141
+ const childrenProcess = buildApp(wslist, obj.command, () => {
142
+ const index2 = runAppInfoList.findIndex(el => el.id == id)
146
143
  console.log("编译结束")
147
144
  if (index2 > -1) {
148
145
  runAppInfoList.splice(index2, 1)
@@ -150,7 +147,7 @@ wss.on('connection', async function connection(ws) {
150
147
  })
151
148
  /**保存当前运行的用户信息。 */
152
149
  } else if (obj.event == 'saveRunInfo') {
153
- const index2 = runAppInfoList.findIndex(function(el){return el.id == obj.command.id})
150
+ const index2 = runAppInfoList.findIndex(el => el.id == obj.command.id)
154
151
  if (index2 > -1) {
155
152
  runAppInfoList.splice(index2, 1, obj.command)
156
153
  } else {
@@ -160,7 +157,7 @@ wss.on('connection', async function connection(ws) {
160
157
  } else if (obj.event == 'getCpu') {
161
158
 
162
159
  Promise.all([osUtils.mem.info(),osUtils.cpu.usage()])
163
- .then(function(arg){
160
+ .then(arg=>{
164
161
  send(JSON.stringify({
165
162
  event: 'getCpu',
166
163
  data: {
@@ -171,13 +168,13 @@ wss.on('connection', async function connection(ws) {
171
168
  })
172
169
  }else if(obj.event=='21'){
173
170
  // npm view @dcloudio/uni-app versions --json
174
- UpdateTmui(obj.command,function(str){
171
+ UpdateTmui(obj.command,(str)=>{
175
172
  send(JSON.stringify({
176
173
  event: 'info',
177
174
  flag:'',
178
175
  data: str
179
176
  }))
180
- },function(){
177
+ },()=>{
181
178
  send(JSON.stringify({
182
179
  event: '21',
183
180
  flag:'end',
@@ -187,13 +184,13 @@ wss.on('connection', async function connection(ws) {
187
184
  // 创建项目.
188
185
  }else if(obj.event=='22'){
189
186
  // npm view @dcloudio/uni-app versions --json
190
- createTmui(obj.command,function(str){
187
+ createTmui(obj.command,(str)=>{
191
188
  send(JSON.stringify({
192
189
  event: 'info',
193
190
  flag:'',
194
191
  data: str
195
192
  }))
196
- },function(prejectdir){
193
+ },(prejectdir)=>{
197
194
  send(JSON.stringify({
198
195
  event: '22',
199
196
  flag:'end',
@@ -208,7 +205,7 @@ wss.on('connection', async function connection(ws) {
208
205
  console.log(chalk.red(error))
209
206
  }
210
207
  });
211
- ws.on('close', function() {
208
+ ws.on('close', () => {
212
209
  removeWs(ws.uuid)
213
210
  })
214
211
  send('something');
package/bin/net.js CHANGED
@@ -1,8 +1,11 @@
1
- const Open = import("open")
2
- const bodyParser = require("body-parser")
3
- const Fetch = import("node-fetch")
4
- const express = require("express")
5
-
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"
6
9
  const app = express();
7
10
 
8
11
  var jsonParser = bodyParser.json()
@@ -19,7 +22,7 @@ function setResHeader(res){
19
22
  app.use(express.static('website'))
20
23
  app.use('/store', express.static('websitemod'))
21
24
 
22
- app.all("/api/dirlist",function (req,res){
25
+ app.all("/api/dirlist",(req,res)=>{
23
26
  setResHeader(res)
24
27
  // const ls = getJsonFiles( __dirname )
25
28
  // res.json(ls)
@@ -27,9 +30,7 @@ app.all("/api/dirlist",function (req,res){
27
30
  res.json({'code':0})
28
31
  })
29
32
  //获取tmui版本
30
- app.post("/api/cehckTmuiVer",async function (req,res){
31
- const fetch = (await Fetch).default;
32
-
33
+ app.post("/api/cehckTmuiVer",async (req,res)=>{
33
34
  setResHeader(res)
34
35
  let type = req.body?.type??'uniapp'
35
36
 
@@ -40,9 +41,7 @@ app.post("/api/cehckTmuiVer",async function (req,res){
40
41
 
41
42
  })
42
43
 
43
- app.post("/api/checkUniappVer",async function (req,res){
44
- const fetch = (await Fetch).default;
45
-
44
+ app.post("/api/checkUniappVer",async (req,res)=>{
46
45
  setResHeader(res)
47
46
  // https://registry.npmjs.org/@dcloudio/uni-app
48
47
  let resdata = await fetch(`https://mirrors.huaweicloud.com/repository/npm/@dcloudio/uni-app`,{method:'GET',headers:{'Content-Type':'text/plan'}})
@@ -65,7 +64,7 @@ app.post("/api/checkUniappVer",async function (req,res){
65
64
 
66
65
 
67
66
  lis = lis.slice(0,40)
68
- lis = lis.filter(function(el){ return el[0]!='2'})
67
+ lis = lis.filter(el=>el[0]!='2')
69
68
  obj.versions = lis
70
69
  res.json({'code':0,'data':obj})
71
70
 
@@ -75,19 +74,12 @@ app.post("/api/checkUniappVer",async function (req,res){
75
74
 
76
75
 
77
76
 
78
- function createNet (){
79
-
80
-
81
- app.listen(6170,async function (){
82
- const open = (await Open).default;
77
+ export const createNet = ()=>{
78
+ app.listen(6170,()=>{
83
79
  open('http://localhost:6170')
84
-
85
80
  })
86
81
  }
87
82
 
88
- module.exports = {
89
- createNet
90
- }
91
83
 
92
84
 
93
85
  // open('http://localhost:6170')
@@ -1,9 +1,13 @@
1
- const path = require("path")
2
- const globalDirectories = require("global-dirs")
3
- const { getJsonDir } = require("./dirTool.js")
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"
4
8
 
5
9
  /**读取项目目录 */
6
- function selectedDir(cb, end, pathStr) {
10
+ export async function selectedDir(cb, end, pathStr) {
7
11
  try {
8
12
  let dirpath = globalDirectories.npm.prefix
9
13
  if (pathStr) {
@@ -22,7 +26,3 @@ function selectedDir(cb, end, pathStr) {
22
26
  }
23
27
 
24
28
 
25
- module.exports = {
26
- selectedDir
27
- }
28
-
package/bin/tmui.js CHANGED
@@ -1,12 +1,12 @@
1
- const figlet = require("figlet")
2
- const chalks = import("chalk")
3
- const {createNet} = require("./net.js")
4
- require("./hooks.js")
1
+ import { Chalk } from "chalk";
2
+ import figlet from "figlet"
3
+ import { createNet } from "./net.js";
4
+ import "./hooks.js";
5
5
 
6
- chalks.then(v => {
7
- const chalk = new v.Chalk()
8
- figlet('TMUI for UniApp', function (err, d) {
9
- if (err) {
6
+ let chalk = new Chalk()
7
+ const main = ()=>{
8
+ figlet('TMUI for UniApp',function(err,d){
9
+ if(err){
10
10
  console.log(chalk.red(err))
11
11
  console.dir(err)
12
12
  return
@@ -16,4 +16,7 @@ chalks.then(v => {
16
16
  console.log(chalk.yellow('请访问:http://localhost:6170'))
17
17
  createNet()
18
18
  })
19
- })
19
+ }
20
+
21
+ main();
22
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tmui-cli",
3
- "version": "1.2.0",
4
- "type": "commonjs",
3
+ "version": "1.2.2",
4
+ "type": "module",
5
5
  "description": "tmui2.0,3.0,4.0x,3.2",
6
6
  "main": "./bin/tmui.js",
7
7
  "scripts": {
@@ -12,7 +12,12 @@
12
12
  "keywords": [
13
13
  "tmui"
14
14
  ],
15
- "author": "tmzdy",
15
+ "author": {
16
+ "name": "tmzdy"
17
+ },
18
+ "bin": {
19
+ "tmui": "bin/tmui.js"
20
+ },
16
21
  "license": "MIT",
17
22
  "dependencies": {
18
23
  "@babel/runtime": "^7.25.7",