aiot-toolkit 1.0.17-binary-beta.2 → 1.0.17-binary-beta.3

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.
@@ -1,121 +1,2 @@
1
- "use strict";
2
-
3
- /*
4
- * Copyright (C) 2017, hapjs.org. All rights reserved.
5
- */
6
-
7
- const webpack = require('webpack');
8
- const {
9
- setCustomConfig,
10
- colorconsole
11
- } = require('@aiot-toolkit/shared-utils');
12
- const genWebpackConf = require('../../gen-webpack-conf');
13
- const {
14
- summaryErrors,
15
- summaryWarnings
16
- } = require('./utils');
17
-
18
- // webpack watch 模式返回的watching实例
19
- let watching = null;
20
- function showVersion() {
21
- const toolkitVer = require('../../package.json').version;
22
- const babelVer = require('@babel/core/package.json').version;
23
- const webpackVer = require('webpack/package.json').version;
24
- colorconsole.info(`aiot-toolkit: ${toolkitVer}; babel: ${babelVer}; webpack: ${webpackVer};`);
25
- }
26
- showVersion();
27
-
28
- /**
29
- * 调用 webpack 进行编译
30
- *
31
- * @module compile
32
- * @param {String} platform - 目标平台: native
33
- * @param {dev|prod} mode - 编译模式: dev、prod
34
- * @param {Boolean} watch - 是否监听
35
- * @param {Object} [options={}] - 动态生成 webpack 配置项的参数对象
36
- * @param {String} [options.cwd] - 工作目录
37
- * @param {Writable} [options.log] - 日志输出流
38
- * @param {String} [options.originType] - 打包来源,ide|cmd
39
- * @param {Function} [options.onerror] - 错误回调函数
40
- * @param {String} [options.setPreviewPkgPath] - 预览包保存路径,由IDE传入
41
- * @returns {Promise} - 返回成功与否的信息
42
- */
43
- module.exports.compile = function compile(platform, mode, watch, options = {}) {
44
- const errCb = options.onerror;
45
- return new Promise((resolve, reject) => {
46
- colorconsole.attach(options.log);
47
- setCustomConfig(options.cwd);
48
- // IMPORTANT: set env variables before generating webpack config
49
- process.env.NODE_PLATFORM = platform;
50
- process.env.NODE_PHASE = mode;
51
- function compilationCallback(err, stats) {
52
- if (err) {
53
- errCb && errCb(err);
54
- colorconsole.error(err);
55
- }
56
- if (stats) {
57
- if (stats.hasErrors() || stats.hasWarnings()) {
58
- const message = summaryErrors(stats);
59
- const warningMsg = summaryWarnings(stats);
60
- errCb && errCb(message);
61
- colorconsole.error(message);
62
- colorconsole.warn(warningMsg);
63
- }
64
- if (stats.hasErrors()) {
65
- process.exitCode = 1;
66
- }
67
- }
68
- }
69
- const webpackMode = mode === 'prod' ? 'production' : 'development';
70
- try {
71
- const webpackConfig = genWebpackConf(options, webpackMode);
72
- if (watch) {
73
- const compiler = webpack(webpackConfig);
74
- watching = compiler.watch({
75
- aggregateTimeout: 300
76
- }, (err, stats) => {
77
- compilationCallback(err, stats);
78
- resolve({
79
- compileError: err,
80
- stats,
81
- watching
82
- });
83
- });
84
- } else {
85
- webpack(webpackConfig, (err, stats) => {
86
- compilationCallback(err, stats);
87
- resolve({
88
- compileError: err,
89
- stats
90
- });
91
- });
92
- }
93
- } catch (err) {
94
- reject(err);
95
- }
96
- });
97
- };
98
-
99
- /**
100
- * 停止 webpack watch监听
101
- *
102
- * @module stopWatch
103
- * @returns {Promise} - 返回成功与否的信息
104
- */
105
- module.exports.stopWatch = function () {
106
- return new Promise(resolve => {
107
- if (watching) {
108
- watching.close(() => {
109
- watching = null;
110
- resolve({
111
- stopWatchError: null
112
- });
113
- });
114
- return;
115
- }
116
- resolve({
117
- stopWatchError: 'no watching'
118
- });
119
- });
120
- };
1
+ "use strict";const webpack=require("webpack"),{setCustomConfig:setCustomConfig,colorconsole:colorconsole}=require("@aiot-toolkit/shared-utils"),genWebpackConf=require("../../gen-webpack-conf"),{summaryErrors:summaryErrors,summaryWarnings:summaryWarnings}=require("./utils");let watching=null;function showVersion(){const o=require("../../package.json").version,r=require("@babel/core/package.json").version,e=require("webpack/package.json").version;colorconsole.info(`aiot-toolkit: ${o}; babel: ${r}; webpack: ${e};`)}showVersion(),module.exports.compile=function(o,r,e,s={}){const n=s.onerror;return new Promise(((c,t)=>{function a(o,r){if(o&&(n&&n(o),colorconsole.error(o)),r){if(r.hasErrors()||r.hasWarnings()){const o=summaryErrors(r),e=summaryWarnings(r);n&&n(o),colorconsole.error(o),colorconsole.warn(e)}r.hasErrors()&&(process.exitCode=1)}}colorconsole.attach(s.log),setCustomConfig(s.cwd),process.env.NODE_PLATFORM=o,process.env.NODE_PHASE=r;const i="prod"===r?"production":"development";try{const o=genWebpackConf(s,i);if(e){const r=webpack(o);watching=r.watch({aggregateTimeout:300},((o,r)=>{a(o,r),c({compileError:o,stats:r,watching:watching})}))}else webpack(o,((o,r)=>{a(o,r),c({compileError:o,stats:r})}))}catch(o){t(o)}}))},module.exports.stopWatch=function(){return new Promise((o=>{watching?watching.close((()=>{watching=null,o({stopWatchError:null})})):o({stopWatchError:"no watching"})}))};
121
2
  //# sourceMappingURL=compile.js.map