tmui-cli 1.2.2 → 1.2.4

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,13 +1,12 @@
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"
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
+
11
10
 
12
11
 
13
12
  function detectEncoding(str) {
@@ -25,12 +24,12 @@ function detectEncoding(str) {
25
24
 
26
25
 
27
26
  function send(ws, arg) {
28
- ws.forEach(el => {
27
+ ws.forEach(function(el){
29
28
  el.send(arg)
30
29
  })
31
30
  }
32
31
 
33
- export function execCmd(cb, end, command) {
32
+ function execCmd(cb, end, command) {
34
33
  try {
35
34
  // const npmPath = path.join(process.env.APPDATA, 'npm', 'npm.cmd');
36
35
  const spawnObj = exec(command, {
@@ -52,7 +51,7 @@ export function execCmd(cb, end, command) {
52
51
  cb(cleanStr, spawnObj.pid || 0)
53
52
  }
54
53
  });
55
- spawnObj.addListener('error', (err) => {
54
+ spawnObj.addListener('error', function(err) {
56
55
  if (end) {
57
56
  cb(err)
58
57
  end('error')
@@ -64,7 +63,7 @@ export function execCmd(cb, end, command) {
64
63
  end('end')
65
64
  }
66
65
  })
67
- spawnObj.on('exit', (code) => {
66
+ spawnObj.on('exit', function(code){
68
67
  // console.log('exit code : ' + code);
69
68
  if (end) {
70
69
  end('end')
@@ -81,12 +80,12 @@ export function execCmd(cb, end, command) {
81
80
  }
82
81
  }
83
82
  // 杀死子进程及其所有子孙进程
84
- export function killChildAndGrandChildren(pid) {
83
+ function killChildAndGrandChildren(pid) {
85
84
 
86
85
  if (process.platform === 'win32') {
87
86
  // 在 Windows 系统上执行的代码
88
87
  const command = `taskkill /T /F /PID ${pid}`;
89
- exec(command, (err, stdout, stderr) => {
88
+ exec(command, function(err, stdout, stderr){
90
89
  if (err) {
91
90
  console.error(`服务进程退出失败!不要担心,当你关闭主进程时,未退出的子进程会一并关闭哦`);
92
91
  }
@@ -95,16 +94,16 @@ export function killChildAndGrandChildren(pid) {
95
94
  });
96
95
  } else {
97
96
  // 在 Linux/Unix/Mac 系统上执行的代码
98
- psTree(pid, (err, children) => {
97
+ psTree(pid, function(err, children){
99
98
  // 使用 kill 命令杀死所有子孙进程
100
99
  console.log(5555)
101
- exec(`kill -TERM ${pid} ${children.map(c => c.PID).join(' ')}`);
100
+ exec(`kill -TERM ${pid} ${children.map(function(c) {return c.PID}).join(' ')}`);
102
101
  });
103
102
  }
104
103
 
105
104
  }
106
105
 
107
- export function devRunApp(ws, obj) {
106
+ function devRunApp(ws, obj) {
108
107
 
109
108
  const nowcd = process.cwd();
110
109
  process.chdir(path.normalize(obj.data.path));
@@ -172,7 +171,7 @@ export function devRunApp(ws, obj) {
172
171
  return childreProcess;
173
172
  }
174
173
 
175
- export function buildApp(ws, obj, end) {
174
+ function buildApp(ws, obj, end) {
176
175
 
177
176
  const nowcd = process.cwd();
178
177
  process.chdir(path.normalize(obj.data.path));
@@ -220,4 +219,11 @@ export function buildApp(ws, obj, end) {
220
219
  return childreProcess;
221
220
  }
222
221
 
222
+ module.exports = {
223
+ execCmd,
224
+ killChildAndGrandChildren,
225
+ devRunApp,
226
+ buildApp
227
+ }
228
+
223
229
 
package/bin/createTmui.js CHANGED
@@ -1,7 +1,9 @@
1
- import path from "path";
2
- import fs from "fs"
3
- import compressing from "compressing"
4
- import { execCmd } from "./cmdTool.js";
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")
5
7
 
6
8
 
7
9
  const uniappDevListVer = [
@@ -74,10 +76,10 @@ function writePackageJson(filepath, str) {
74
76
  /**
75
77
  * 更新项目.
76
78
  * @param {{path,type,uvue,tmui,uniappver}} arg
77
- * @param {(str)=>{}} call
78
- * @param {()=>{}} end
79
79
  */
80
- export async function UpdateTmui(arg, call, end) {
80
+ async function UpdateTmui(arg, call, end) {
81
+ const fetch = (await Fetch).default;
82
+
81
83
  let rootdir = path.normalize(arg.path)
82
84
  call('检测目录...')
83
85
  if (!fs.existsSync(rootdir)) {
@@ -169,7 +171,7 @@ export async function UpdateTmui(arg, call, end) {
169
171
  let initjson = readPackageJson(packjsonDir)
170
172
  if (initjson['dependencies']['@dcloudio/uni-app'] != arg.uniappver) {
171
173
  call(`检测到cli版本与你选中的不一样,正在设置你选中的版本号`)
172
- uniappDevListVer.forEach(el => {
174
+ uniappDevListVer.forEach( function(el) {
173
175
  if (initjson['dependencies'][el]) {
174
176
  initjson['dependencies'][el] = arg.uniappver
175
177
  }
@@ -181,9 +183,9 @@ export async function UpdateTmui(arg, call, end) {
181
183
 
182
184
  writePackageJson(packjsonDir, JSON.stringify(initjson, null, 4))
183
185
 
184
- execCmd((datastr) => {
186
+ execCmd(function (datastr){
185
187
  call(datastr)
186
- }, () => {
188
+ }, function () {
187
189
  end()
188
190
  }, 'npm install --save --registry=https://registry.npmmirror.com/')
189
191
 
@@ -201,10 +203,10 @@ export async function UpdateTmui(arg, call, end) {
201
203
  /**
202
204
  *
203
205
  * @param {{name,rootDir,type,ver,uniappver,uniappBuildType,machine}} arg
204
- * @param {(str)=>{}} call
205
- * @param {(str?:string)=>{}} end
206
206
  */
207
- export async function createTmui(arg, call, end) {
207
+ async function createTmui(arg, call, end) {
208
+ const fetch = (await Fetch).default;
209
+
208
210
  let rootdir = path.normalize(arg.rootDir)
209
211
  call('检测目录...')
210
212
  if (!fs.existsSync(rootdir)) {
@@ -341,7 +343,7 @@ export async function createTmui(arg, call, end) {
341
343
  let initjson = readPackageJson(packjsonDir)
342
344
 
343
345
 
344
- uniappDevListVer.forEach(el => {
346
+ uniappDevListVer.forEach(function (el) {
345
347
  if (initjson['dependencies'][el]) {
346
348
  initjson['dependencies'][el] = arg.uniappver
347
349
  }
@@ -359,9 +361,9 @@ export async function createTmui(arg, call, end) {
359
361
 
360
362
  writePackageJson(packjsonDir, JSON.stringify(initjson, null, 4))
361
363
 
362
- execCmd((datastr) => {
364
+ execCmd(function (datastr) {
363
365
  call(datastr)
364
- }, () => {
366
+ }, function () {
365
367
  end(rootdir)
366
368
  }, 'npm install --save --registry=https://registry.npmmirror.com/')
367
369
 
@@ -372,4 +374,10 @@ export async function createTmui(arg, call, end) {
372
374
 
373
375
  end(rootdir)
374
376
 
377
+ }
378
+
379
+ module.exports = {
380
+ createTmui,
381
+ UpdateTmui,
382
+ delFile
375
383
  }
package/bin/dirTool.js CHANGED
@@ -1,14 +1,7 @@
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"
1
+ const path = require("path")
2
+ const fs = require("fs")
9
3
 
10
-
11
- export function getJsonFiles(jsonPath) {
4
+ function getJsonFiles(jsonPath) {
12
5
  let jsonFiles = [];
13
6
 
14
7
  function findJsonFile(www) {
@@ -28,7 +21,7 @@ export function getJsonFiles(jsonPath) {
28
21
  return jsonFiles;
29
22
  }
30
23
 
31
- export function getJsonDir(basePath = './') {
24
+ function getJsonDir(basePath = './') {
32
25
  const dirPath = basePath;
33
26
  const root = {
34
27
  name: '',
@@ -71,6 +64,7 @@ export function getJsonDir(basePath = './') {
71
64
  }
72
65
 
73
66
  }
67
+ // @ts-ignore
74
68
  root.children = tree;
75
69
 
76
70
 
@@ -78,7 +72,7 @@ export function getJsonDir(basePath = './') {
78
72
  }
79
73
 
80
74
  /**读取项目信息根据提供的路径。 */
81
- export function checkProject(obj) {
75
+ function checkProject(obj) {
82
76
 
83
77
  // const {id,path,type} = obj;
84
78
  let mainsetStrPath = "";
@@ -150,3 +144,9 @@ export function checkProject(obj) {
150
144
  }
151
145
  }
152
146
 
147
+
148
+ module.exports = {
149
+ getJsonFiles,
150
+ getJsonDir,
151
+ checkProject
152
+ }
package/bin/hooks.js CHANGED
@@ -1,13 +1,14 @@
1
+ const chalks = import("chalk")
2
+
3
+ const {createTmui,UpdateTmui} = require("./createTmui.js")
4
+ const {checkProject} = require("./dirTool.js")
5
+ const {selectedDir} = require("./selectedDir.js")
6
+ const osUtils = require("node-os-utils")
7
+ const {WebSocketServer} = require("ws")
8
+ const {execCmd, devRunApp, killChildAndGrandChildren, buildApp} = require("./cmdTool.js")
9
+
1
10
 
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'
9
11
 
10
- let chalk = new Chalk()
11
12
 
12
13
 
13
14
 
@@ -44,17 +45,18 @@ function uuid(len = 24, radix) {
44
45
  return uuid.join('');
45
46
  }
46
47
  function removeWs(id) {
47
- const index = wslist.findIndex(el => el.uuid == id)
48
+ const index = wslist.findIndex(function(el) {return el.uuid == id})
48
49
  if (index > -1) {
49
50
  wslist.splice(index, 1)
50
51
  }
51
52
  }
52
53
  function send(arg) {
53
- wslist.forEach(el => {
54
+ wslist.forEach(function(el) {
54
55
  el.send(arg)
55
56
  })
56
57
  }
57
- wss.on('connection', function connection(ws) {
58
+ wss.on('connection', async function connection(ws) {
59
+ const chalk = (await chalks).default;
58
60
 
59
61
  ws.uuid = uuid();
60
62
  wslist.push(ws)
@@ -98,7 +100,7 @@ wss.on('connection', function connection(ws) {
98
100
  // 查询目录项目的信息
99
101
  } else if (obj.event == '17') {
100
102
  let result = checkProject(obj.command)
101
- let runfl = runAppInfoList.filter(el => el.id == result.id)
103
+ let runfl = runAppInfoList.filter(function(el){ return el.id == result.id})
102
104
  send(JSON.stringify({
103
105
  event: '17',
104
106
  data: result,
@@ -124,12 +126,12 @@ wss.on('connection', function connection(ws) {
124
126
  if (!obj.command) return;
125
127
  // process.kill(Number(obj.command||0))
126
128
  const pid = Number(obj.command || 0);
127
- const index = processList.findIndex(el => el.pid == pid)
129
+ const index = processList.findIndex(function(el){ return el.pid == pid})
128
130
  if (index > -1) {
129
131
  // process.kill(sflit[0].pid)
130
132
  killChildAndGrandChildren(processList[index].pid)
131
133
  processList.splice(index, 1)
132
- const index2 = runAppInfoList.findIndex(el => el.pid == pid)
134
+ const index2 = runAppInfoList.findIndex(function(el){ return el.pid == pid})
133
135
  runAppInfoList.splice(index2, 1)
134
136
  }
135
137
  } catch (error) {
@@ -138,8 +140,8 @@ wss.on('connection', function connection(ws) {
138
140
  /**编译应用build:xx */
139
141
  } else if (obj.event == '3') {
140
142
  const id = obj.command.data.id;
141
- const childrenProcess = buildApp(wslist, obj.command, () => {
142
- const index2 = runAppInfoList.findIndex(el => el.id == id)
143
+ const childrenProcess = buildApp(wslist, obj.command, function() {
144
+ const index2 = runAppInfoList.findIndex(function(el){ return el.id == id})
143
145
  console.log("编译结束")
144
146
  if (index2 > -1) {
145
147
  runAppInfoList.splice(index2, 1)
@@ -147,7 +149,7 @@ wss.on('connection', function connection(ws) {
147
149
  })
148
150
  /**保存当前运行的用户信息。 */
149
151
  } else if (obj.event == 'saveRunInfo') {
150
- const index2 = runAppInfoList.findIndex(el => el.id == obj.command.id)
152
+ const index2 = runAppInfoList.findIndex(function(el){return el.id == obj.command.id})
151
153
  if (index2 > -1) {
152
154
  runAppInfoList.splice(index2, 1, obj.command)
153
155
  } else {
@@ -157,7 +159,7 @@ wss.on('connection', function connection(ws) {
157
159
  } else if (obj.event == 'getCpu') {
158
160
 
159
161
  Promise.all([osUtils.mem.info(),osUtils.cpu.usage()])
160
- .then(arg=>{
162
+ .then(function(arg){
161
163
  send(JSON.stringify({
162
164
  event: 'getCpu',
163
165
  data: {
@@ -168,13 +170,13 @@ wss.on('connection', function connection(ws) {
168
170
  })
169
171
  }else if(obj.event=='21'){
170
172
  // npm view @dcloudio/uni-app versions --json
171
- UpdateTmui(obj.command,(str)=>{
173
+ UpdateTmui(obj.command,function(str){
172
174
  send(JSON.stringify({
173
175
  event: 'info',
174
176
  flag:'',
175
177
  data: str
176
178
  }))
177
- },()=>{
179
+ },function(){
178
180
  send(JSON.stringify({
179
181
  event: '21',
180
182
  flag:'end',
@@ -184,13 +186,13 @@ wss.on('connection', function connection(ws) {
184
186
  // 创建项目.
185
187
  }else if(obj.event=='22'){
186
188
  // npm view @dcloudio/uni-app versions --json
187
- createTmui(obj.command,(str)=>{
189
+ createTmui(obj.command,function(str){
188
190
  send(JSON.stringify({
189
191
  event: 'info',
190
192
  flag:'',
191
193
  data: str
192
194
  }))
193
- },(prejectdir)=>{
195
+ },function(prejectdir){
194
196
  send(JSON.stringify({
195
197
  event: '22',
196
198
  flag:'end',
@@ -205,7 +207,7 @@ wss.on('connection', function connection(ws) {
205
207
  console.log(chalk.red(error))
206
208
  }
207
209
  });
208
- ws.on('close', () => {
210
+ ws.on('close', function() {
209
211
  removeWs(ws.uuid)
210
212
  })
211
213
  send('something');
package/bin/net.js CHANGED
@@ -1,17 +1,11 @@
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"
1
+ const Open = import("open")
2
+ const bodyParserS = import("body-parser")
3
+ const Fetch = import("node-fetch")
4
+ const express = require("express")
5
+
9
6
  const app = express();
10
7
 
11
- var jsonParser = bodyParser.json()
12
- var urlencodedParser = bodyParser.urlencoded({ extended: false })
13
- app.use(urlencodedParser)
14
- app.use(jsonParser)
8
+
15
9
  function setResHeader(res){
16
10
  res.setHeader("Access-Control-Allow-Headers","*")
17
11
  res.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS")
@@ -22,7 +16,7 @@ function setResHeader(res){
22
16
  app.use(express.static('website'))
23
17
  app.use('/store', express.static('websitemod'))
24
18
 
25
- app.all("/api/dirlist",(req,res)=>{
19
+ app.all("/api/dirlist",function (req,res){
26
20
  setResHeader(res)
27
21
  // const ls = getJsonFiles( __dirname )
28
22
  // res.json(ls)
@@ -30,7 +24,9 @@ app.all("/api/dirlist",(req,res)=>{
30
24
  res.json({'code':0})
31
25
  })
32
26
  //获取tmui版本
33
- app.post("/api/cehckTmuiVer",async (req,res)=>{
27
+ app.post("/api/cehckTmuiVer",async function (req,res){
28
+ const fetch = (await Fetch).default;
29
+
34
30
  setResHeader(res)
35
31
  let type = req.body?.type??'uniapp'
36
32
 
@@ -41,7 +37,9 @@ app.post("/api/cehckTmuiVer",async (req,res)=>{
41
37
 
42
38
  })
43
39
 
44
- app.post("/api/checkUniappVer",async (req,res)=>{
40
+ app.post("/api/checkUniappVer",async function (req,res){
41
+ const fetch = (await Fetch).default;
42
+
45
43
  setResHeader(res)
46
44
  // https://registry.npmjs.org/@dcloudio/uni-app
47
45
  let resdata = await fetch(`https://mirrors.huaweicloud.com/repository/npm/@dcloudio/uni-app`,{method:'GET',headers:{'Content-Type':'text/plan'}})
@@ -64,7 +62,7 @@ app.post("/api/checkUniappVer",async (req,res)=>{
64
62
 
65
63
 
66
64
  lis = lis.slice(0,40)
67
- lis = lis.filter(el=>el[0]!='2')
65
+ lis = lis.filter(function(el){ return el[0]!='2'})
68
66
  obj.versions = lis
69
67
  res.json({'code':0,'data':obj})
70
68
 
@@ -74,12 +72,23 @@ app.post("/api/checkUniappVer",async (req,res)=>{
74
72
 
75
73
 
76
74
 
77
- export const createNet = ()=>{
78
- app.listen(6170,()=>{
75
+ async function createNet (){
76
+ const bodyParser = (await bodyParserS).default;
77
+ var jsonParser = bodyParser.json()
78
+ var urlencodedParser = bodyParser.urlencoded({ extended: false })
79
+ app.use(urlencodedParser)
80
+ app.use(jsonParser)
81
+
82
+ app.listen(6170,async function (){
83
+ const open = (await Open).default;
79
84
  open('http://localhost:6170')
85
+
80
86
  })
81
87
  }
82
88
 
89
+ module.exports = {
90
+ createNet
91
+ }
83
92
 
84
93
 
85
94
  // open('http://localhost:6170')
@@ -1,13 +1,9 @@
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"
1
+ const path = require("path")
2
+ const globalDirectories = require("global-dirs")
3
+ const { getJsonDir } = require("./dirTool.js")
8
4
 
9
5
  /**读取项目目录 */
10
- export async function selectedDir(cb, end, pathStr) {
6
+ function selectedDir(cb, end, pathStr) {
11
7
  try {
12
8
  let dirpath = globalDirectories.npm.prefix
13
9
  if (pathStr) {
@@ -26,3 +22,7 @@ export async function selectedDir(cb, end, pathStr) {
26
22
  }
27
23
 
28
24
 
25
+ module.exports = {
26
+ selectedDir
27
+ }
28
+
package/bin/tmui.js CHANGED
@@ -1,11 +1,17 @@
1
- import { Chalk } from "chalk";
2
- import figlet from "figlet"
3
- import { createNet } from "./net.js";
4
- import "./hooks.js";
1
+ #!/usr/bin/env node
5
2
 
6
- let chalk = new Chalk()
7
- const main = ()=>{
8
- figlet('TMUI for UniApp',function(err,d){
3
+ process.title = 'tmui-cli';
4
+
5
+ var figletS = import("figlet");
6
+ const chalks = import("chalk")
7
+ const {createNet} = require("./net.js")
8
+ require("./hooks.js")
9
+
10
+ const main = async ()=>{
11
+ const chalk = (await chalks).default;
12
+ const figlet = (await figletS).default;
13
+
14
+ figlet('TMUI for UniApp', { font: 'Standard' }, function(err,d){
9
15
  if(err){
10
16
  console.log(chalk.red(err))
11
17
  console.dir(err)
package/dist/tmui.js CHANGED
@@ -1 +1 @@
1
- (()=>{var e,t,o={895:e=>{"use strict";e.exports=require("chalk")},679:e=>{"use strict";e.exports=require("figlet")}},r={};function n(e){var t=r[e];if(void 0!==t)return t.exports;var l=r[e]={exports:{}};return o[e](l,l.exports,n),l.exports}t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,n.t=function(o,r){if(1&r&&(o=this(o)),8&r)return o;if("object"==typeof o&&o){if(4&r&&o.__esModule)return o;if(16&r&&"function"==typeof o.then)return o}var l=Object.create(null);n.r(l);var i={};e=e||[null,t({}),t([]),t(t)];for(var c=2&r&&o;"object"==typeof c&&!~e.indexOf(c);c=t(c))Object.getOwnPropertyNames(c).forEach((e=>i[e]=()=>o[e]));return i.default=()=>o,n.d(l,i),l},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};const l=n(679);Promise.resolve().then(n.t.bind(n,895,23)).then((e=>{const t=new e.Chalk;l("TMUI for UniApp",(function(e,o){if(e)return console.log(t.red(e)),void console.dir(e);console.log(t.green(o)),console.log(t.yellow("请注意浏览器打开状态,如果打开失败")),console.log(t.yellow("请访问:http://localhost:6170"))}))}))})();
1
+ (()=>{var e,t,i={25:(e,t,i)=>{const n=i(928),{spawn:r,exec:o}=(i(896),i(317)),s=i(932),c=i(199),a=i(344);function u(e,t){e.forEach((function(e){e.send(t)}))}function d(e,t,i){try{const n=o(i,{encoding:"binary"});return n.stdout?.on("data",(function(t){if(e){Buffer.from(t,"binary").toString("utf8");const i=c(function(e){const t=Buffer.from(e);return t[0]<128?"ascii":t[0]<224?"utf8":t[0]<240?"utf16le":"utf32le"}(t)).decode(Buffer.from(t,"binary")).toString("utf-8").replace(/[\u001B\u009B][[\]()#;?]*(?:(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[A-PR-Za-z~])/g,"");e(i,n.pid||0)}})),n.addListener("error",(function(i){t&&(e(i),t("error"))})),n.on("close",(function(e){t&&t("end")})),n.on("exit",(function(e){t&&t("end")})),n}catch(i){return t&&(e(i),t("end")),null}}e.exports={execCmd:d,killChildAndGrandChildren:function(e){"win32"===s.platform?o(`taskkill /T /F /PID ${e}`,(function(e,t,i){e&&console.error("服务进程退出失败!不要担心,当你关闭主进程时,未退出的子进程会一并关闭哦")})):a(e,(function(t,i){console.log(5555),o(`kill -TERM ${e} ${i.map((function(e){return e.PID})).join(" ")}`)}))},devRunApp:function(e,t){return s.cwd(),s.chdir(n.normalize(t.data.path)),d((function(i,n){u(e,JSON.stringify({event:"info",data:i}));const r=/http:\/\/localhost(:\d+)?(\/[^\s]*)?/g,o=/http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?(\/[^\s]*)?/g;r.test(i)&&u(e,JSON.stringify({event:"1",data:{id:t.data.id,msg:i.match(r)[0],pid:n}})),o.test(i)&&u(e,JSON.stringify({event:"1",data:{id:t.data.id,msg:i.match(o)[0],pid:n}})),i.indexOf("ready")>-1&&u(e,JSON.stringify({event:"ready",data:{id:t.data.id,pid:n}}))}),(function(i){u(e,"end"==i?JSON.stringify({event:"end",data:{id:t.data.id}}):JSON.stringify({event:"error",data:{id:t.data.id}}))}),t.command)},buildApp:function(e,t,i){return s.cwd(),s.chdir(n.normalize(t.data.path)),d((function(i,n){u(e,JSON.stringify({event:"info",data:i})),i.indexOf("DONE")>-1&&u(e,JSON.stringify({event:"buildSucess",data:{id:t.data.id,pid:n}}))}),(function(n){"end"==n?(u(e,JSON.stringify({event:"end",data:{id:t.data.id}})),console.log("编译完成")):u(e,JSON.stringify({event:"error",data:{id:t.data.id}})),i&&i()}),t.command)}}},802:(e,t,i)=>{const n=i(928),{execCmd:r}=i(25),o=i(896),s=i(988),c=Promise.resolve().then(i.t.bind(i,229,23)),a=["@dcloudio/uni-app","@dcloudio/uni-app-plus","@dcloudio/uni-components","@dcloudio/uni-h5","@dcloudio/uni-mp-alipay","@dcloudio/uni-mp-baidu","@dcloudio/uni-mp-kuaishou","@dcloudio/uni-mp-lark","@dcloudio/uni-mp-qq","@dcloudio/uni-mp-toutiao","@dcloudio/uni-mp-weixin","@dcloudio/uni-quickapp-webview","@dcloudio/uni-automator","@dcloudio/uni-cli-shared","@dcloudio/vite-plugin-uni"];function u(e,t){if(o.existsSync(e))if(o.statSync(e).isDirectory()){var i=o.readdirSync(e),n=i.length,r=0;n>0?(i.forEach((function(t){r++,o.statSync(e+"/"+t);var i=e+"/"+t;o.statSync(i).isDirectory()?u(i,!0):o.unlinkSync(i)})),n==r&&t&&o.rmdirSync(e)):0==n&&t&&o.rmdirSync(e)}else o.unlinkSync(e),console.log("删除文件"+e+"成功")}function d(e){let t=o.readFileSync(e).toString("utf-8");return t=t.replace(/("([^\\\"]*(\\.)?)*")|('([^\\\']*(\\.)?)*')|(\/{2,}.*?(\r|\n|$))|(\/\*(\n|.)*?\*\/)/g,(function(e){return/^\/{2,}/.test(e)||/^\/\*/.test(e)?"":e})),JSON.parse(t)}function l(e,t){o.writeFileSync(e,t,{encoding:"utf-8"})}e.exports={createTmui:async function(e,t,i){const u=(await c).default;let p=n.normalize(e.rootDir);if(t("检测目录..."),!o.existsSync(p))return t("目录有误..."),void i();if(p=n.join(p,e.name),o.existsSync(p)||o.mkdirSync(p),"uniappx"==e.type){t("暂不支持uniappx更新sdk及下载更新tmui库,请联系作者授权,当前仅是创建一个空项目."),t("开始创建项目中...");let e="https://cdn.tmui.design/tmui4.0/tmui4.0xhbxModel.zip",r=await u(e),c=await r.arrayBuffer(),a=n.join(p,"tmui.zip");return o.existsSync(a)&&o.rmSync(a),o.writeFileSync(a,Buffer.from(c)),t("正在解压处理中..."),await s.zip.uncompress(a,p),t("创建uniAppx tmui4.0x 项目成功"),t("正在清理缓存文件..."),o.existsSync(a)&&o.rmSync(a),t("恭喜成功!!!"),void i(p)}process.chdir(p);let f=parseFloat(e.ver.replace(".",""))>=32,m=`https://cdn.tmui.design/public/static/${f?"tmuiHBX32":"tmuiHBX"}.zip`,y=`https://cdn.tmui.design/public/static/${f?"cli32":"cli"}.zip`,S="uniapp"==e.type&&"cli"==e.uniappBuildType?y:m,g=await u(S),h=await g.arrayBuffer(),x=n.join(p,"tmuimode.zip");o.existsSync(x)&&o.rmSync(x),o.writeFileSync(x,Buffer.from(h)),t("正在创建项目模板"),await s.zip.uncompress(x,p),t("tmui模板创建成功,正在下载tmuiUi库"),o.existsSync(x)&&o.rmSync(x);let v="";if("hbx"==e.uniappBuildType)if(f){let e=n.join(p,"uni_modules");o.existsSync(e)||o.mkdirSync(e),e=n.join(e,"tm-ui"),o.existsSync(e)||o.mkdirSync(e),v=e}else{let e=n.join(p,"tmui");o.existsSync(e)||o.mkdirSync(e),v=e}else if("cli"==e.uniappBuildType)if(f){let e=n.join(p,"src","uni_modules");o.existsSync(e)||o.mkdirSync(e),e=n.join(e,"tm-ui"),o.existsSync(e)||o.mkdirSync(e),v=e}else{let e=n.join(p,"src","tmui");o.existsSync(e)||o.mkdirSync(e),v=e}t("下载tmui中,版本号为:"+e.ver);let j=`https://cdn.tmui.design/public/static/tmui${e.ver}.zip`,w=await u(j),O=await w.arrayBuffer(),b=n.join(p,"tmui.zip");if(o.existsSync(b)&&o.rmSync(b),o.writeFileSync(b,Buffer.from(O)),t(`tmui${e.ver}下载完成,正在解压处理中...`),await s.zip.uncompress(b,v),t(`tmui${e.ver}安装成功`),t("正在清理缓存文件..."),o.existsSync(b)&&o.rmSync(b),t("恭喜安装tmui成功!!!"),e.uniappver&&"cli"==e.uniappBuildType){t("正在检查cli sdk 版本...");let o=n.join(p,"package.json"),s=d(o);return a.forEach((function(t){s.dependencies[t]&&(s.dependencies[t]=e.uniappver),s.devDependencies[t]&&(s.devDependencies[t]=e.uniappver)})),t("更新版本号完成,正在重新安装依赖,这个过程可能比较缓慢,如果失败,请手动在项目目录执行npm install或者重试"),"arm"==e.machine&&(s.dependencies["@esbuild/darwin-x64"]="^0.21.5",s.dependencies["@rollup/rollup-darwin-x64"]="^4.24.0"),l(o,JSON.stringify(s,null,4)),void r((function(e){t(e)}),(function(){i(p)}),"npm install --save --registry=https://registry.npmmirror.com/")}i(p)},UpdateTmui:async function(e,t,i){const p=(await c).default;let f=n.normalize(e.path);if(t("检测目录..."),!o.existsSync(f))return t("项目目录有误..."),void i();process.chdir(e.path);let m="",y=parseFloat(e.tmui.replace(".",""))>=32;if("hbx"==e.type)if(y){let e=n.join(f,"uni_modules");o.existsSync(e)||o.mkdirSync(e),e=n.join(e,"tm-ui"),o.existsSync(e)||o.mkdirSync(e),m=e}else{let e=n.join(f,"tmui");o.existsSync(e)||o.mkdirSync(e),m=e}else if("cli"==e.type)if(y){let e=n.join(f,"src","uni_modules");o.existsSync(e)||o.mkdirSync(e),e=n.join(e,"tm-ui"),o.existsSync(e)||o.mkdirSync(e),m=e}else{let e=n.join(f,"src","tmui");o.existsSync(e)||o.mkdirSync(e),m=e}if(t("已创建/检测/清除...tmui目录..."),!o.existsSync(m))return t("无法检测和创建目录,请检查权限..."),void i();u(m,!0),o.mkdirSync(m),t("下载tmui中,版本号为:"+e.tmui);let S=`https://cdn.tmui.design/public/static/tmui${e.tmui}.zip`,g=await p(S),h=await g.arrayBuffer(),x=n.join(f,"tmui.zip");if(o.existsSync(x)&&o.rmSync(x),o.writeFileSync(x,Buffer.from(h)),t(`tmui${e.tmui}下载完成,正在解压处理中...`),await s.zip.uncompress(x,m),t(`tmui${e.tmui}安装成功`),t("正在清理缓存文件..."),o.existsSync(x)&&o.rmSync(x),t("恭喜安装tmui成功!!!"),e.uniappver&&"cli"==e.type){t("正在检查cli sdk 版本...");let o=n.join(f,"package.json"),s=d(o);if(s.dependencies["@dcloudio/uni-app"]!=e.uniappver)return t("检测到cli版本与你选中的不一样,正在设置你选中的版本号"),a.forEach((function(t){s.dependencies[t]&&(s.dependencies[t]=e.uniappver),s.devDependencies[t]&&(s.devDependencies[t]=e.uniappver)})),t("更新版本号完成,正在重新安装依赖,这个过程可能比较缓慢,如果失败,请手动在项目目录执行npm install或者重试"),l(o,JSON.stringify(s,null,4)),void r((function(e){t(e)}),(function(){i()}),"npm install --save --registry=https://registry.npmmirror.com/");t("检测到cli版本与你选中的一样,跳过更新")}i()},delFile:u}},838:(e,t,i)=>{const n=i(928),r=i(896);e.exports={getJsonFiles:function(e){let t=[];return function e(i){r.readdirSync(i).forEach((function(o,s){let c=n.join(i,o),a=r.statSync(c);!0===a.isDirectory()&&e(c),!0===a.isFile()&&t.push(c)}))}(e),t},getJsonDir:function(e="./"){const t=e,i={name:"",type:"dir",parent:t,children:[]},o=r.readdirSync(t),s=[];for(let e=0;e<o.length;e++){const i=o[e],c=n.join(t,i),a=n.extname(i);try{if(-1==i.lastIndexOf(".tmp")&&-1==i.lastIndexOf(".sys")&&"."!=i[0]){const e=r.statSync(c);if(e.isFile()){const e={name:i,type:"file",parent:t,suffix:a};s.push(e)}else if(e.isDirectory()){const e={name:i,type:"dir",parent:t,suffix:"",children:[]};s.push(e)}}}catch(e){}}return i.children=s,i},checkProject:function(e){let t="",i="",o="",s="";"cli"==e.type?(t=n.join(e.path,"src","manifest.json"),i=n.join(e.path,"src","tmui","package.json"),r.existsSync(i)||(i=n.join(e.path,"src","uni_modules","tm-ui","package.json")),o=n.join(e.path,"package.json")):(t=n.join(e.path,"manifest.json"),i=n.join(e.path,"tmui","package.json"),r.existsSync(i)||(i=n.join(e.path,"uni_modules","tm-ui","package.json")),s=n.join(e.path,"uni_modules","tmx-ui","package.json"));let c=r.readFileSync(t).toString("utf-8");c=c.replace(/("([^\\\"]*(\\.)?)*")|('([^\\\']*(\\.)?)*')|(\/{2,}.*?(\r|\n|$))|(\/\*(\n|.)*?\*\/)/g,(function(e){return/^\/{2,}/.test(e)||/^\/\*/.test(e)?"":e}));const a=JSON.parse(c),u=a["uni-app-x"];let d="";if(u){if(r.existsSync(s)){let e=r.readFileSync(s).toString("utf-8");d=JSON.parse(e).version}}else if(r.existsSync(i)){let e=r.readFileSync(i).toString("utf-8");d=JSON.parse(e).version}let l="";if(r.existsSync(o)){let e=r.readFileSync(o).toString("utf-8");l=JSON.parse(e).scripts}return{name:a.name,appid:a.appid,versionName:a.versionName,tmui:d,unix:u,id:e.id,scripts:l}}}},487:(e,t,i)=>{const n=Promise.resolve().then(i.t.bind(i,895,23)),{createTmui:r,UpdateTmui:o}=i(802),{checkProject:s}=i(838),{selectedDir:c}=i(259),a=i(845),{WebSocketServer:u}=i(86),{execCmd:d,devRunApp:l,killChildAndGrandChildren:p,buildApp:f}=i(25),m=new u({port:6169});var y=[],S=[],g=[];function h(e){g.forEach((function(t){t.send(e)}))}m.on("connection",(async function(e){const t=(await n).default;e.uuid=function(e=24,t){var i,n,r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),o=[];if(t=t||r.length,e)for(i=0;i<e;i++)o[i]=r[0|Math.random()*t];else for(o[8]=o[13]=o[18]=o[23]="-",o[14]="4",i=0;i<36;i++)o[i]||(n=0|16*Math.random(),o[i]=r[19==i?3&n|8:n]);return o.join("")}(),g.push(e),e.on("error",console.error),e.on("message",(function(e){try{let i=JSON.parse(e);if("getCpu"!=i.event&&console.log(t.white(e)),"cmd"==i.event)d((function(e){h(JSON.stringify({event:"info",data:e}))}),(function(){h(JSON.stringify({event:"end",data:""}))}),i.command);else if("18"==i.event)c((function(e){h(JSON.stringify({event:"18",flag:"",data:e}))}),(function(){h(JSON.stringify({event:"18",flag:"end",data:""}))}),i.command);else if("17"==i.event){let e=s(i.command),t=S.filter((function(t){return t.id==e.id}));h(JSON.stringify({event:"17",data:e,flag:"",run:t})),h(JSON.stringify({event:"17",flag:"end",data:""}))}else if("1"==i.event){const e=l(g,i.command);e&&y.push(e)}else if("2"==i.event)try{if(!i.command)return;const e=Number(i.command||0),t=y.findIndex((function(t){return t.pid==e}));if(t>-1){p(y[t].pid),y.splice(t,1);const i=S.findIndex((function(t){return t.pid==e}));S.splice(i,1)}}catch(e){}else if("3"==i.event){const e=i.command.data.id;f(g,i.command,(function(){const t=S.findIndex((function(t){return t.id==e}));console.log("编译结束"),t>-1&&S.splice(t,1)}))}else if("saveRunInfo"==i.event){const e=S.findIndex((function(e){return e.id==i.command.id}));e>-1?S.splice(e,1,i.command):S.push(i.command)}else"getCpu"==i.event?Promise.all([a.mem.info(),a.cpu.usage()]).then((function(e){h(JSON.stringify({event:"getCpu",data:{memUsage:e[0].usedMemPercentage.toFixed(2),cpuUsage:e[1].toFixed(2)}}))})):"21"==i.event?o(i.command,(function(e){h(JSON.stringify({event:"info",flag:"",data:e}))}),(function(){h(JSON.stringify({event:"21",flag:"end",data:"完成"}))})):"22"==i.event&&r(i.command,(function(e){h(JSON.stringify({event:"info",flag:"",data:e}))}),(function(e){h(JSON.stringify({event:"22",flag:"end",data:e}))}))}catch(i){console.log(t.red(e)),console.log(t.red(i))}})),e.on("close",(function(){!function(e){const t=g.findIndex((function(t){return t.uuid==e}));t>-1&&g.splice(t,1)}(e.uuid)})),h("something")}))},628:(e,t,i)=>{const n=Promise.resolve().then(i.t.bind(i,80,23)),r=Promise.resolve().then(i.t.bind(i,268,23)),o=Promise.resolve().then(i.t.bind(i,229,23)),s=i(252),c=s();function a(e){e.setHeader("Access-Control-Allow-Headers","*"),e.setHeader("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS"),e.setHeader("Access-Control-Allow-Headers","DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization")}c.use(s.static("website")),c.use("/store",s.static("websitemod")),c.all("/api/dirlist",(function(e,t){a(t),t.json({code:0})})),c.post("/api/cehckTmuiVer",(async function(e,t){const i=(await o).default;a(t);let n=e.body?.type??"uniapp",r=await i(`https:cdn.tmui.design/${"uniapp"==n?"tmuiVer":"tmui4x"}.txt`,{method:"GET",headers:{"Content-Type":"text/plan"}}),s=(await r.text()).split("\n");t.json({code:0,version:s,type:n})})),c.post("/api/checkUniappVer",(async function(e,t){const i=(await o).default;a(t);let n=await i("https://mirrors.huaweicloud.com/repository/npm/@dcloudio/uni-app",{method:"GET",headers:{"Content-Type":"text/plan"}}),r=await n.text(),s=JSON.parse(r),c={dist:[s["dist-tags"].alpha,s["dist-tags"].next,s["dist-tags"].vue3],versions:[]},u=[];for(let e in s.versions)u.push(e);u.reverse(),u=u.slice(0,40),u=u.filter((function(e){return"2"!=e[0]})),c.versions=u,t.json({code:0,data:c})})),e.exports={createNet:async function(){const e=(await r).default;var t=e.json(),i=e.urlencoded({extended:!1});c.use(i),c.use(t),c.listen(6170,(async function(){(0,(await n).default)("http://localhost:6170")}))}}},259:(e,t,i)=>{const n=i(928),r=i(270),{getJsonDir:o}=i(838);e.exports={selectedDir:function(e,t,i){try{let s=r.npm.prefix;i&&(s=n.normalize(i)),e(o(s)),t("end")}catch(i){console.log(i,"---"),t&&(e(i),t("end"))}}}},268:e=>{"use strict";e.exports=require("body-parser")},895:e=>{"use strict";e.exports=require("chalk")},199:e=>{"use strict";e.exports=require("codecs")},988:e=>{"use strict";e.exports=require("compressing")},252:e=>{"use strict";e.exports=require("express")},679:e=>{"use strict";e.exports=require("figlet")},270:e=>{"use strict";e.exports=require("global-dirs")},229:e=>{"use strict";e.exports=require("node-fetch")},845:e=>{"use strict";e.exports=require("node-os-utils")},80:e=>{"use strict";e.exports=require("open")},344:e=>{"use strict";e.exports=require("ps-tree")},86:e=>{"use strict";e.exports=require("ws")},317:e=>{"use strict";e.exports=require("child_process")},896:e=>{"use strict";e.exports=require("fs")},928:e=>{"use strict";e.exports=require("path")},932:e=>{"use strict";e.exports=require("process")}},n={};function r(e){var t=n[e];if(void 0!==t)return t.exports;var o=n[e]={exports:{}};return i[e](o,o.exports,r),o.exports}t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,r.t=function(i,n){if(1&n&&(i=this(i)),8&n)return i;if("object"==typeof i&&i){if(4&n&&i.__esModule)return i;if(16&n&&"function"==typeof i.then)return i}var o=Object.create(null);r.r(o);var s={};e=e||[null,t({}),t([]),t(t)];for(var c=2&n&&i;"object"==typeof c&&!~e.indexOf(c);c=t(c))Object.getOwnPropertyNames(c).forEach((e=>s[e]=()=>i[e]));return s.default=()=>i,r.d(o,s),o},r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},process.title="tmui-cli";var o=Promise.resolve().then(r.t.bind(r,679,23));const s=Promise.resolve().then(r.t.bind(r,895,23)),{createNet:c}=r(628);r(487),(async()=>{const e=(await s).default;(0,(await o).default)("TMUI for UniApp",{font:"Standard"},(function(t,i){if(t)return console.log(e.red(t)),void console.dir(t);console.log(e.green(i)),console.log(e.yellow("请注意浏览器打开状态,如果打开失败")),console.log(e.yellow("请访问:http://localhost:6170")),c()}))})()})();
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "tmui-cli",
3
- "version": "1.2.2",
4
- "type": "module",
3
+ "version": "1.2.4",
5
4
  "description": "tmui2.0,3.0,4.0x,3.2",
6
5
  "main": "./bin/tmui.js",
7
6
  "scripts": {