mali-applet-ui 1.1.37 → 1.1.39

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/env/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
- // export function parseEnv(dirPath: string): Record<string, string>
2
- // export function initEnv(dirPath: string, defaultEnv: Record<string, string>): Record<string, string>
3
- // export function getSCSSAdditionalData(envConfig: any): string
1
+ export function getEnvCode(mode: string): string
2
+ export function getEnvName(mode: string): string
3
+ export function getCustomName(custom: string): string
4
+ export function getPlatformName(platform: string): string
5
+ export function getSubModuleName(module: string): string
6
+ export function parseEnv(dirPath: string): Record<string, string>
7
+ export function initEnv(dirPath: string, defaultEnv: Record<string, string>): Record<string, string>
8
+ export function initManifestEnv(dirPath: string, manifestJson: any): Record<string, string>
9
+ export function uploadWxMiniprogram(version: string): void
10
+ export function getSCSSAdditionalData(envConfig: any): string
4
11
  export function sendMail(options: {
5
12
  receivedBy: string | string[]
6
13
  subject: string
package/env/index.js CHANGED
@@ -1,6 +1,13 @@
1
+ const path = require('path')
2
+ const fs = require('fs')
3
+ const dotenv = require('dotenv')
1
4
  const axios = require('axios')
5
+ const XEUtils = require('xe-utils')
6
+ const compressing = require('compressing')
7
+ const ci = require('miniprogram-ci')
2
8
  const nodemailer = require('nodemailer')
3
9
  const smtpTransport = require('nodemailer-smtp-transport')
10
+ const pack = require('../package.json')
4
11
 
5
12
  const currTransporter = new Promise((resolve, reject) => {
6
13
  axios.get('http://192.168.10.217:3000/emai/getSmtpOptions').then(res => {
@@ -12,6 +19,225 @@ const currTransporter = new Promise((resolve, reject) => {
12
19
  })
13
20
  })
14
21
 
22
+ function getEnvCode (mode) {
23
+ const maps = {
24
+ dev: 'development',
25
+ test: 'testing',
26
+ demo: 'demo',
27
+ prod: 'production'
28
+ }
29
+ return maps[mode] || 'production'
30
+ }
31
+
32
+ function getEnvName (mode) {
33
+ const maps = {
34
+ dev: '开发环境',
35
+ test: '测试环境',
36
+ demo: '演示环境',
37
+ prod: '正式环境'
38
+ }
39
+ return maps[mode] || '正式环境'
40
+ }
41
+
42
+ function getPlatformName (platform) {
43
+ const maps = {
44
+ 'mp-weixin': '微信',
45
+ 'mp-qiwei': '企微',
46
+ 'mp-dingtalk': '钉钉'
47
+ }
48
+ return maps[platform] || platform
49
+ }
50
+
51
+ function getSubModuleName (module) {
52
+ const maps = {
53
+ default: '',
54
+ labour: '码里劳务',
55
+ smart: '码里智慧',
56
+ market: '码里营销',
57
+ design: '码里设计',
58
+ jicai: '码里集采'
59
+ }
60
+ return `${maps[module]}`
61
+ }
62
+
63
+ function getCustomName (custom) {
64
+ const maps = {
65
+ hengkun: '恒坤劳务',
66
+ beizhuang: '北装装饰',
67
+ zhongjian1: '中建一局',
68
+ guowenchuang: '国文创',
69
+ rongdu: '融都建设'
70
+ }
71
+ return `${maps[custom] || ''}`
72
+ }
73
+
74
+ function parseEnvFile (dirPath, name) {
75
+ const targetPath = path.resolve(dirPath, name)
76
+ if (fs.existsSync(targetPath)) {
77
+ const content = fs.readFileSync(targetPath, { encoding: 'utf8' })
78
+ return dotenv.parse(content)
79
+ }
80
+ return {}
81
+ }
82
+
83
+ function parseJSONFile (dirPath, name) {
84
+ const targetPath = path.resolve(dirPath, name)
85
+ if (fs.existsSync(targetPath)) {
86
+ const content = fs.readFileSync(targetPath, { encoding: 'utf8' })
87
+ return JSON.parse(content)
88
+ }
89
+ return {}
90
+ }
91
+
92
+ function getSCSSAdditionalData () {
93
+ const rest = [
94
+ '@import "./src/uni.scss";',
95
+ `@import "${pack.name}/style/variable.scss";`,
96
+ `$global-static-url: '${process.env.VUE_APP_PUBLIC_RESOURCES_URL}';`
97
+ ]
98
+ for (const name in process.env) {
99
+ if (/^VUE_SCSS_DEFINE_/.test(name)) {
100
+ const varName = name.replace('VUE_SCSS_DEFINE_', '').replace(/_/g, '-').toLowerCase()
101
+ rest.push(`$${varName}: ${process.env[name]};`)
102
+ }
103
+ }
104
+ return rest.join('\n')
105
+ }
106
+
107
+ function parseEnv (rootPath) {
108
+ const envConfig = {}
109
+ envConfig.VUE_APP_MODE = process.env.VUE_APP_MODE || 'prod'
110
+ envConfig.VUE_APP_CUSTOM_MODULE = process.env.VUE_APP_CUSTOM_MODULE || 'default'
111
+ envConfig.VUE_APP_SUB_MODULE = process.env.VUE_APP_SUB_MODULE || 'default'
112
+ envConfig.VUE_APP_PLATFORM_NAME = process.env.VUE_APP_PLATFORM_NAME || 'default'
113
+ envConfig.VUE_APP_PUBLISH_DATE = XEUtils.toDateString(new Date(), 'yyyyMMddHHmmss')
114
+
115
+ const cusName = `.env.${envConfig.VUE_APP_CUSTOM_MODULE || 'default'}`
116
+ const envName = `${cusName}.${envConfig.VUE_APP_SUB_MODULE || 'default'}.${envConfig.VUE_APP_PLATFORM_NAME || 'default'}.${getEnvCode(envConfig.VUE_APP_MODE)}`
117
+ const globalDev = parseEnvFile(rootPath, '.env')
118
+ const defDev = parseEnvFile(rootPath, cusName)
119
+ const appEnv = parseEnvFile(rootPath, envName)
120
+ const localEnv = parseEnvFile(rootPath, `${envName}.local`)
121
+
122
+ return Object.assign({}, globalDev, defDev, appEnv, localEnv, envConfig)
123
+ }
124
+
125
+ function initEnv (rootPath) {
126
+ const envConfig = parseEnv(rootPath)
127
+ const conf = Object.assign(process.env, envConfig)
128
+ console.log('\n环境配置:')
129
+ console.log(`版本:${conf.VUE_APP_CUSTOM_MODULE}\n模块:${conf.VUE_APP_SUB_MODULE}\n平台:${conf.VUE_APP_PLATFORM_NAME}\n环境:${conf.VUE_APP_MODE}\n`)
130
+ return conf
131
+ }
132
+
133
+ function initManifestEnv (rootPath, manifestJson) {
134
+ const envConfig = initEnv(rootPath)
135
+ if (process.env.VUE_APP_MP_APPID) {
136
+ const manifest = JSON.parse(fs.readFileSync(path.resolve(rootPath, 'src/manifest.json'), 'utf-8'))
137
+ manifest[process.env.UNI_PLATFORM] = {
138
+ ...manifestJson[process.env.UNI_PLATFORM],
139
+ appid: process.env.VUE_APP_MP_APPID
140
+ }
141
+ manifest.name = [
142
+ getCustomName(process.env.VUE_APP_CUSTOM_MODULE),
143
+ getSubModuleName(process.env.VUE_APP_SUB_MODULE) || manifestJson.name,
144
+ getPlatformName(process.env.VUE_APP_PLATFORM_NAME),
145
+ getEnvName(process.env.VUE_APP_MODE)
146
+ ].filter(v => v).join('-')
147
+ fs.writeFileSync(path.resolve(rootPath, 'src/manifest.json'), JSON.stringify(manifest, null, 2))
148
+ }
149
+ return envConfig
150
+ }
151
+
152
+ function deleteFolder (filePath) {
153
+ let files = []
154
+ if (fs.existsSync(filePath)) {
155
+ files = fs.readdirSync(filePath)
156
+ files.forEach((file, index) => {
157
+ const curPath = filePath + '/' + file
158
+ if (fs.statSync(curPath).isDirectory()) {
159
+ deleteFolder(curPath)
160
+ } else {
161
+ fs.unlinkSync(curPath)
162
+ }
163
+ })
164
+ fs.rmdirSync(filePath)
165
+ }
166
+ }
167
+
168
+ function uploadWxMiniprogram (rootPath, version) {
169
+ // 机器人编号
170
+ const robot = 1
171
+ const fixDesc = `自动发包机器人 ${XEUtils.toDateString(new Date(), 'yyyy-MM-dd HH:mm:ss')}`
172
+
173
+ const mainVersions = version.split('.')
174
+ return new Promise((resolve, reject) => {
175
+ if (['mp-weixin', 'mp-qiwei'].includes(process.env.VUE_APP_PLATFORM_NAME)) {
176
+ const projectConfig = parseJSONFile(rootPath, `${process.env.UNI_OUTPUT_DIR}/project.config.json`)
177
+ console.log('projectConfig', projectConfig)
178
+ console.log('projectPath=', path.resolve(rootPath, process.env.UNI_OUTPUT_DIR))
179
+ const options = {
180
+ appid: projectConfig.appid,
181
+ type: 'miniProgram',
182
+ projectPath: path.resolve(rootPath, process.env.UNI_OUTPUT_DIR),
183
+ privateKeyPath: `/applet/weixin/privatekey/private.${projectConfig.appid}.key`,
184
+ ignores: ['node_modules/**/*']
185
+ }
186
+ console.log(options)
187
+ const project = new ci.Project(options)
188
+ ci.getDevSourceMap({
189
+ project,
190
+ robot,
191
+ sourceMapSavePath: path.resolve(rootPath, 'sm.zip')
192
+ }).then((res) => {
193
+ console.log('sm==', path.resolve(rootPath, 'sm.zip'))
194
+ console.log('get success', res)
195
+ compressing.zip.uncompress(path.resolve(rootPath, 'sm.zip'), 'temp').then(() => {
196
+ const rest = JSON.parse(fs.readFileSync(path.resolve(rootPath, 'temp/__FULL__/app-service.js.map')))
197
+ const vArr = rest.wx.userVersion.match(/(\d+).(\d+).(\d+)/)
198
+ if (vArr) {
199
+ const newVersion = `${mainVersions[0]}.${mainVersions[1]}.${Number(mainVersions[1]) > Number(vArr[2]) ? 0 : (Number(vArr[3]) + 1)}.${XEUtils.toDateString(new Date(), 'yyMMdd')}`
200
+ ci.upload({
201
+ project,
202
+ version: newVersion,
203
+ desc: fixDesc,
204
+ robot
205
+ }).then((res) => {
206
+ console.log(res)
207
+ resolve()
208
+ })
209
+ } else {
210
+ const e = {}
211
+ console.error('version error')
212
+ reject(e)
213
+ }
214
+ deleteFolder(path.resolve(rootPath, 'temp'))
215
+ fs.unlinkSync(path.resolve(rootPath, 'sm.zip'))
216
+ resolve()
217
+ })
218
+ }).catch(e => {
219
+ if (e.message.indexOf('-80407') > -1) {
220
+ ci.upload({
221
+ project,
222
+ version: `${pack.version}.${XEUtils.toDateString(new Date(), 'yyMMdd')}`,
223
+ desc: '修复bug',
224
+ robot: 1
225
+ }).then((res) => {
226
+ console.log(res)
227
+ resolve()
228
+ })
229
+ } else {
230
+ console.log(e.message)
231
+ reject(e)
232
+ }
233
+ })
234
+ } else {
235
+ const e = {}
236
+ reject(e)
237
+ }
238
+ })
239
+ }
240
+
15
241
  function sendMail ({ receivedBy, subject, html }) {
16
242
  return new Promise((resolve, reject) => {
17
243
  currTransporter.then((transporter) => {
@@ -49,10 +275,30 @@ function sendQyWechatMsg (webhook, params) {
49
275
  })
50
276
  }
51
277
 
278
+ exports.getEnvCode = getEnvCode
279
+ exports.getEnvName = getEnvName
280
+ exports.getCustomName = getCustomName
281
+ exports.getPlatformName = getPlatformName
282
+ exports.getSubModuleName = getSubModuleName
283
+ exports.parseEnv = parseEnv
284
+ exports.initEnv = initEnv
285
+ exports.initManifestEnv = initManifestEnv
286
+ exports.uploadWxMiniprogram = uploadWxMiniprogram
287
+ exports.getSCSSAdditionalData = getSCSSAdditionalData
52
288
  exports.sendMail = sendMail
53
289
  exports.sendQyWechatMsg = sendQyWechatMsg
54
290
 
55
291
  module.exports = {
292
+ getEnvCode,
293
+ getEnvName,
294
+ getCustomName,
295
+ getPlatformName,
296
+ getSubModuleName,
297
+ parseEnv,
298
+ initEnv,
299
+ initManifestEnv,
300
+ uploadWxMiniprogram,
301
+ getSCSSAdditionalData,
56
302
  sendMail,
57
303
  sendQyWechatMsg
58
304
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "1.1.37",
3
+ "version": "1.1.39",
4
4
  "description": "码里UI-小程序组件库(vue2)",
5
5
  "files": [
6
6
  "lib",
@@ -37,6 +37,8 @@
37
37
  "axios": "^0.26.1",
38
38
  "nodemailer": "^6.9.4",
39
39
  "nodemailer-smtp-transport": "^2.7.4",
40
+ "compressing": "~1.6.3",
41
+ "miniprogram-ci": "~1.9.8",
40
42
  "xe-utils": "^3.5.11"
41
43
  },
42
44
  "devDependencies": {