aiot-toolkit 1.0.20-importfile-dev.2 → 2.0.1-alpha.10

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.
Files changed (57) hide show
  1. package/README.md +26 -192
  2. package/lib/bin.d.ts +2 -0
  3. package/lib/bin.js +148 -0
  4. package/lib/bin.js.map +1 -0
  5. package/lib/builder/IBuilder.d.ts +22 -0
  6. package/lib/builder/IBuilder.js +4 -0
  7. package/lib/builder/IBuilder.js.map +1 -0
  8. package/lib/builder/UxBuilder.d.ts +26 -0
  9. package/lib/builder/UxBuilder.js +102 -0
  10. package/lib/builder/UxBuilder.js.map +1 -0
  11. package/lib/builder/XtsBuilder.d.ts +16 -0
  12. package/lib/builder/XtsBuilder.js +100 -0
  13. package/lib/builder/XtsBuilder.js.map +1 -0
  14. package/lib/interface/CommandInterface.d.ts +15 -0
  15. package/lib/interface/CommandInterface.js +4 -0
  16. package/lib/interface/CommandInterface.js.map +1 -0
  17. package/lib/interface/VelaEmulatorInterface.d.ts +8 -0
  18. package/lib/interface/VelaEmulatorInterface.js +4 -0
  19. package/lib/interface/VelaEmulatorInterface.js.map +1 -0
  20. package/lib/starter/GoldfishStarter.d.ts +9 -0
  21. package/lib/starter/GoldfishStarter.js +108 -0
  22. package/lib/starter/GoldfishStarter.js.map +1 -0
  23. package/lib/utils/AdbUtils.d.ts +14 -0
  24. package/lib/utils/AdbUtils.js +103 -0
  25. package/lib/utils/AdbUtils.js.map +1 -0
  26. package/lib/utils/DeviceUtil.d.ts +62 -0
  27. package/lib/utils/DeviceUtil.js +366 -0
  28. package/lib/utils/DeviceUtil.js.map +1 -0
  29. package/lib/utils/RequestUtils.d.ts +11 -0
  30. package/lib/utils/RequestUtils.js +90 -0
  31. package/lib/utils/RequestUtils.js.map +1 -0
  32. package/lib/utils/VelaAvdUtils.d.ts +39 -0
  33. package/lib/utils/VelaAvdUtils.js +308 -0
  34. package/lib/utils/VelaAvdUtils.js.map +1 -0
  35. package/lib/waiter.d.ts +3 -0
  36. package/lib/waiter.js +39 -0
  37. package/lib/waiter.js.map +1 -0
  38. package/package.json +33 -47
  39. package/CHANGELOG.md +0 -353
  40. package/bin/index.js +0 -495
  41. package/gen-webpack-conf/get-devtool.js +0 -51
  42. package/gen-webpack-conf/helpers.js +0 -143
  43. package/gen-webpack-conf/index.js +0 -436
  44. package/gen-webpack-conf/manifest-schema.js +0 -284
  45. package/gen-webpack-conf/validate.js +0 -284
  46. package/lib/commands/compile.js +0 -2
  47. package/lib/commands/debug.js +0 -2
  48. package/lib/commands/init.js +0 -2
  49. package/lib/commands/packages.js +0 -2
  50. package/lib/commands/preview.js +0 -2
  51. package/lib/commands/report.js +0 -2
  52. package/lib/commands/resign.js +0 -2
  53. package/lib/commands/update.js +0 -2
  54. package/lib/commands/utils.js +0 -2
  55. package/lib/index.js +0 -2
  56. package/lib/plugins/manifest-watch-plugin.js +0 -2
  57. package/lib/utils.js +0 -2
@@ -1,436 +0,0 @@
1
- /*
2
- * Copyright (C) 2017, hapjs.org. All rights reserved.
3
- */
4
-
5
- const path = require('path')
6
- const fs = require('fs')
7
- const webpack = require('webpack')
8
- const {
9
- readJson,
10
- colorconsole,
11
- KnownError,
12
- getProjectDslName,
13
- getDefaultServerHost
14
- } = require('@aiot-toolkit/shared-utils')
15
- const globalConfig = require('@aiot-toolkit/shared-utils/config')
16
-
17
- const {
18
- compileOptionsMeta,
19
- compileOptionsObject,
20
- initCompileOptionsObject
21
- } = require('@aiot-toolkit/shared-utils/compilation-config')
22
- const { name } = require('@aiot-toolkit/packager/lib/common/info')
23
-
24
- const ManifestWatchPlugin = require('../lib/plugins/manifest-watch-plugin')
25
- const { resolveEntries } = require('../lib/utils')
26
- const getDevtool = require('./get-devtool')
27
- const {
28
- getConfigPath,
29
- cleanup,
30
- checkBuiltinModules,
31
- setAdaptForV8Version,
32
- checkBabelModulesExists
33
- } = require('./helpers')
34
-
35
- const {
36
- validateProject,
37
- validateManifest,
38
- valiedateSitemap,
39
- valiedateSkeleton
40
- } = require('./validate')
41
-
42
- const pathMap = {
43
- packager: require.resolve('@aiot-toolkit/packager/lib/webpack.post.js'),
44
- xvm: require.resolve(`@aiot-toolkit/dsl-xvm/lib/webpack.post.js`),
45
- vue: require.resolve(`@aiot-toolkit/dsl-vue/lib/webpack.post.js`)
46
- }
47
-
48
- const eventBus = require('@aiot-toolkit/shared-utils/event-bus')
49
- const lodash = require('lodash')
50
- const { PACKAGER_BUILD_PROGRESS } = eventBus
51
-
52
- // 能使用抽取公共js功能的调试器最低版本
53
- const SPLIT_CHUNKS_SUPPORT_VERSION_FROM = 1080
54
-
55
- /**
56
- * 动态生成 webpack 配置项
57
- *
58
- * @param {Object} launchOptions - 命令行参数对象
59
- * @param {String} [launchOptions.cwd] - 工作目录
60
- * @param {String} [launchOptions.originType] - 打包来源,ide|cmd
61
- * @param {String} [launchOptions.devtool=undefined] - devtool(sourcemap)配置
62
- * @param {boolean} [launchOptions.debug=false] - 是否开启调试
63
- * @param {boolean} [launchOptions.stats=false] - 是否开启分析
64
- * @param {boolean} [launchOptions.disableSubpackages=false] - 是否禁止分包
65
- * @param {boolean} [launchOptions.optimizeCssAttr=false] - 优化 css 属性
66
- * @param {boolean} [launchOptions.optimizeDescMeta=false] - 优化 css 描述数据
67
- * @param {boolean} [launchOptions.optimizeTemplateAttr=false] - 优化模板属性
68
- * @param {boolean} [launchOptions.optimizeStyleAppLevel=false] - 优化 app 样式等级
69
- * @param {boolean} [launchOptions.optimizeStylePageLevel=false] - 优化 app 样式等级
70
- * @param {boolean} [launchOptions.splitChunksMode=undefined] - 抽取公共JS
71
- * @param {production|development} mode - webpack mode
72
- * @returns {WebpackConfiguration}
73
- */
74
- module.exports = function genWebpackConf(launchOptions, mode) {
75
- // 项目目录
76
- if (launchOptions.cwd) {
77
- globalConfig.projectPath = launchOptions.cwd
78
- }
79
- const cwd = globalConfig.projectPath
80
-
81
- const hapConfigPath = getConfigPath(cwd)
82
- // 用于接受quickapp.config.js 或者 hap.config.js中的配置
83
- let quickappConfig
84
- // 接受命令行
85
- let cli = {}
86
- if (hapConfigPath) {
87
- try {
88
- quickappConfig = require(hapConfigPath)
89
- if (typeof quickappConfig.cli === 'object') {
90
- cli = quickappConfig.cli
91
- launchOptions = lodash.merge({}, launchOptions, cli)
92
- }
93
- } catch (err) {
94
- colorconsole.error(
95
- `Error loading webpack configuration file [${hapConfigPath}]:${err.message}`
96
- )
97
- }
98
- }
99
-
100
- // 是否需要设置全局的打包模式为mina-h5
101
- const manifestFileTemp = path.resolve(cwd, 'manifest.json')
102
- let isMinaH5 = false
103
- if (fs.existsSync(manifestFileTemp)) {
104
- const manifestTemp = readJson(manifestFileTemp)
105
- const { deviceTypeList } = manifestTemp
106
- const minaH5Type = ['tv', 'tv-h5']
107
- isMinaH5 = minaH5Type.some(item => deviceTypeList.includes(item))
108
- if (isMinaH5) {
109
- initCompileOptionsObject({ enableMinaH5: true })
110
- globalConfig.sourceRoot = './.src'
111
- }
112
- }
113
-
114
- // 源代码目录
115
- const SRC_DIR = path.resolve(cwd, globalConfig.sourceRoot)
116
- // 签名文件目录
117
- const SIGN_FOLDER = globalConfig.signRoot
118
- // 编译文件的目录
119
- const BUILD_DIR = path.resolve(cwd, globalConfig.outputPath)
120
- // 最终发布目录:setPreviewPkgPathDir为ide传入的路径,用来保存构建的临时预览包
121
- const DIST_DIR = launchOptions.setPreviewPkgPath || path.resolve(cwd, globalConfig.releasePath)
122
- // 打包配置文件
123
- const manifestFile = path.resolve(SRC_DIR, 'manifest.json')
124
-
125
- checkBabelModulesExists(cwd)
126
-
127
- // 合并launchOptions到全局
128
- initCompileOptionsObject(launchOptions)
129
-
130
- // 校验项目工程
131
- validateProject(manifestFile, SRC_DIR)
132
-
133
- // 清理 BUILD_DIR DIST_DIR
134
- cleanup(BUILD_DIR, DIST_DIR)
135
-
136
- let manifest
137
- try {
138
- manifest = readJson(manifestFile)
139
- } catch (e) {
140
- throw new KnownError('manifest.json parsing failed!')
141
- }
142
-
143
- validateManifest(SRC_DIR, manifest, compileOptionsObject)
144
-
145
- valiedateSitemap(SRC_DIR, manifest)
146
-
147
- valiedateSkeleton(SRC_DIR, manifest)
148
-
149
- // 是否需要设置全局的打包模式为Mirtos
150
- const { deviceTypeList } = manifest
151
- if (deviceTypeList && deviceTypeList.includes('watch')) {
152
- initCompileOptionsObject({ enableMirtos: true })
153
- }
154
-
155
- // 设置合适的v8版本
156
- setAdaptForV8Version(compileOptionsObject.disableScriptV8V65, manifest, cwd)
157
-
158
- // 页面文件
159
- const entries = resolveEntries(manifest, SRC_DIR, cwd)
160
-
161
- // 环境变量
162
- const env = {
163
- // 平台:native
164
- NODE_PLATFORM: process.env.NODE_PLATFORM,
165
- // 阶段: dev|test|release
166
- NODE_PHASE: process.env.NODE_PHASE
167
- }
168
- colorconsole.info(`Configuration environment:${JSON.stringify(env)}`)
169
-
170
- const webpackConf = {
171
- context: cwd,
172
- mode,
173
- entry: entries,
174
- output: {
175
- globalObject: 'window',
176
- path: BUILD_DIR,
177
- filename: '[name].js',
178
- publicPath: './'
179
- },
180
- module: {
181
- rules: []
182
- },
183
- externals: [checkBuiltinModules],
184
- plugins: [
185
- new webpack.ProgressPlugin(percentage => {
186
- const cb = launchOptions.callback
187
- if (cb && typeof cb === 'function') {
188
- const params = { action: 'progress', percentage }
189
- cb(params)
190
- }
191
- eventBus.emit(PACKAGER_BUILD_PROGRESS, { percentage })
192
- }),
193
- // 定义环境变量
194
- new webpack.DefinePlugin({
195
- // 平台:na
196
- ENV_PLATFORM: JSON.stringify(env.NODE_PLATFORM),
197
- // 阶段: dev|test|release
198
- ENV_PHASE: JSON.stringify(env.NODE_PHASE),
199
- ENV_PHASE_DV: env.NODE_PHASE === 'dev',
200
- ENV_PHASE_QA: env.NODE_PHASE === 'test',
201
- ENV_PHASE_OL: env.NODE_PHASE === 'prod',
202
- // 服务器地址
203
- QUICKAPP_SERVER_HOST: JSON.stringify(getDefaultServerHost()),
204
- QUICKAPP_TOOLKIT_VERSION: JSON.stringify(require('../package.json').version)
205
- }),
206
- // 编译耗时
207
- function BuildTimePlugin() {
208
- this.hooks.done.tapAsync('end', function(stats, callback) {
209
- if (!stats.compilation.errors.length) {
210
- const secs = (stats.endTime - stats.startTime) / 1000
211
- colorconsole.info(`Build Time Cost: ${secs}s`)
212
- }
213
- callback()
214
- })
215
- },
216
- new ManifestWatchPlugin({
217
- appRoot: cwd,
218
- root: SRC_DIR,
219
- isMinaH5
220
- })
221
- ],
222
- resolve: {
223
- modules: ['node_modules'],
224
- extensions: ['.webpack.js', '.web.js', '.js', '.json'].concat(name.extList)
225
- },
226
- stats: {
227
- builtAt: false,
228
- entrypoints: false,
229
- children: false,
230
- chunks: false,
231
- chunkModules: false,
232
- chunkOrigins: false,
233
- modules: false,
234
- version: false,
235
- assets: false
236
- },
237
- optimization: {}
238
- }
239
-
240
- // 设置抽取公共js
241
- if (compileOptionsObject.splitChunksMode === compileOptionsMeta.splitChunksModeEnum.SMART) {
242
- colorconsole.warn(
243
- `Enable splitChunksMode: SMART mode, please ensure that the platform version >= ${SPLIT_CHUNKS_SUPPORT_VERSION_FROM}`
244
- )
245
- // 当前仅smart模式才启用
246
- webpackConf.optimization.splitChunks = {
247
- minSize: 1,
248
- cacheGroups: {
249
- default: false,
250
- defaultVendors: {
251
- test: /[\\/]node_modules[\\/]/,
252
- chunks: 'all',
253
- minChunks: 2,
254
- name(module) {
255
- // 处理node_modules的chunk位置为node_modules下的路径,通过name来控制,如node_modules/vue/dist/vue.runtime.esm;
256
- const index = module.resource.indexOf('node_modules')
257
- const chunkPath = module.resource
258
- .slice(index)
259
- .replace(/(.+)\.\w\??(.+)?/, ($0, $1) => $1)
260
- // 兼容windows上的路径
261
- return chunkPath.split(path.sep).join('/')
262
- },
263
- priority: 2,
264
- reuseExistingChunk: true,
265
- enforce: true
266
- },
267
- // 用于抽离出app.ux引入的组件或者文件
268
- appPkg: {
269
- test(module, { chunkGraph }) {
270
- function isAppRequire(module, chunkGraph) {
271
- let result = false
272
- chunkGraph.getModuleChunksIterable(module).forEach(chunk => {
273
- if (chunk.name === 'app') {
274
- result = true
275
- return false
276
- }
277
- })
278
- return result
279
- }
280
-
281
- function isUxPath(module) {
282
- // require.context引入的是ContextModule不含有resource
283
- if (!module.resource) return false
284
- const queryStriped = module.resource.split('?').shift()
285
- return path.extname(queryStriped) === '.ux'
286
- }
287
-
288
- if (isAppRequire(module, chunkGraph) && isUxPath(module)) {
289
- return true
290
- }
291
-
292
- return false
293
- },
294
- chunks: 'all',
295
- name(module) {
296
- // 处理正常chunk的位置为相对src下的路径,通过name来控制,如Common/a;
297
- const sourcePath = path.join(globalConfig.projectPath, globalConfig.sourceRoot)
298
- const chunkPath = module.resource
299
- .slice(sourcePath.length + 1)
300
- .replace(/(.+)\.\w\??(.+)?/, ($0, $1) => $1)
301
- // 兼容windows上的路径
302
- return chunkPath.split(path.sep).join('/')
303
- },
304
- // 优先级最低
305
- priority: 1,
306
- // 只要app.ux引入即被抽离
307
- minChunks: 1,
308
- reuseExistingChunk: true,
309
- enforce: true
310
- },
311
- chunks: {
312
- test(module) {
313
- // 过滤掉自定义module,比如抽取css生成*.css.json使用的CssModule
314
- if (module.constructor.name !== 'NormalModule') {
315
- return false
316
- }
317
- return true
318
- },
319
- chunks: 'all',
320
- minChunks: 2,
321
- name(module) {
322
- // 处理正常chunk的位置为相对src下的路径,通过name来控制,如Common/a;
323
- const sourcePath = path.join(globalConfig.projectPath, globalConfig.sourceRoot)
324
- const chunkPath = module.resource
325
- .slice(sourcePath.length + 1)
326
- .replace(/(.+)\.\w\??(.+)?/, ($0, $1) => $1)
327
- // 兼容windows上的路径
328
- return chunkPath.split(path.sep).join('/')
329
- },
330
- priority: 1,
331
- reuseExistingChunk: true,
332
- enforce: true
333
- },
334
- async: {
335
- chunks: 'async',
336
- name(module) {
337
- const sourcePath = path.join(globalConfig.projectPath, globalConfig.sourceRoot)
338
- const chunkPath = module.resource
339
- .slice(sourcePath.length + 1)
340
- .replace(/(.+)\.\w\??(.+)?/, ($0, $1) => $1)
341
- // 兼容windows上的路径
342
- return chunkPath.split(path.sep).join('/')
343
- },
344
- priority: 3,
345
- enforce: true
346
- }
347
- }
348
- }
349
- }
350
-
351
- // 加载配置
352
- loadWebpackConfList()
353
-
354
- // 设置 sourcemap 类型
355
- webpackConf.devtool = getDevtool(webpackConf.mode, compileOptionsObject.devtool)
356
-
357
- /**
358
- * 尝试加载每个模块的webpack配置
359
- */
360
- function loadWebpackConfList() {
361
- const moduleList = [
362
- {
363
- name: 'packager',
364
- path: pathMap['packager']
365
- }
366
- ]
367
-
368
- const dslName = getProjectDslName(cwd)
369
-
370
- if (dslName === 'vue') {
371
- colorconsole.error(
372
- 'The current hap-toolkit version does not support Vue syntax project compilation, please use the old version first'
373
- )
374
- colorconsole.throw(
375
- 'Because the upgrade of Webpack5 makes the toolkit greatly changed the Vue syntax support, the Vue syntax will be supported in the next version'
376
- )
377
- }
378
-
379
- moduleList.push({
380
- name: `${dslName}-post`,
381
- path: pathMap[dslName]
382
- })
383
-
384
- const {
385
- package: appPackageName,
386
- icon: appIcon,
387
- versionName,
388
- versionCode,
389
- subpackages,
390
- workers,
391
- banner = ''
392
- } = manifest
393
- for (let i = 0, len = moduleList.length; i < len; i++) {
394
- const fileConf = moduleList[i].path
395
- if (fs.existsSync(fileConf)) {
396
- try {
397
- const moduleWebpackConf = require(fileConf)
398
- if (moduleWebpackConf.postHook) {
399
- moduleWebpackConf.postHook(
400
- webpackConf,
401
- {
402
- appPackageName,
403
- appIcon,
404
- banner,
405
- versionName,
406
- versionCode,
407
- nodeConf: env,
408
- pathDist: DIST_DIR,
409
- pathSrc: SRC_DIR,
410
- subpackages,
411
- pathBuild: BUILD_DIR,
412
- pathSignFolder: SIGN_FOLDER,
413
- workers,
414
- cwd,
415
- originType: compileOptionsObject.originType
416
- },
417
- quickappConfig
418
- )
419
- }
420
- } catch (err) {
421
- console.error(
422
- `Error loading webpack configuration file [${fileConf}]:${err.message}`,
423
- err
424
- )
425
- }
426
- }
427
- }
428
-
429
- // 增加项目目录的postHook机制
430
- if (quickappConfig && quickappConfig.postHook) {
431
- quickappConfig.postHook(webpackConf, compileOptionsObject)
432
- }
433
- }
434
-
435
- return webpackConf
436
- }