@autobest-ui/scripts 0.0.3 → 0.1.0

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,97 +1,97 @@
1
- const friendlySyntaxErrorLabel = 'Syntax error:';
2
-
3
- function isLikelyASyntaxError(message) {
4
- return message.indexOf(friendlySyntaxErrorLabel) !== -1;
5
- }
6
-
7
- function formatMessage(message) {
8
- let lines = [];
9
-
10
- if (typeof message === 'string') {
11
- lines = message.split('\n');
12
- } else if ('message' in message) {
13
- lines = message.message.split('\n');
14
- } else if (Array.isArray(message)) {
15
- message.forEach(message => {
16
- if ('message' in message) {
17
- lines = message.message.split('\n');
18
- }
19
- });
20
- }
21
-
22
- lines = lines.filter(line => !/Module [A-z ]+\(from/.test(line));
23
-
24
- lines = lines.map(line => {
25
- const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
26
- if (!parsingError) {
27
- return line;
28
- }
29
- const [, errorLine, errorColumn, errorMessage] = parsingError;
30
- return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
31
- });
32
-
33
- message = lines.join('\n');
34
- message = message.replace(
35
- /SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
36
- `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`
37
- );
38
-
39
- message = message.replace(
40
- /^.*export '(.+?)' was not found in '(.+?)'.*$/gm,
41
- "Attempted import error: '$1' is not exported from '$2'."
42
- );
43
- message = message.replace(
44
- /^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
45
- "Attempted import error: '$2' does not contain a default export (imported as '$1')."
46
- );
47
- message = message.replace(
48
- /^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
49
- "Attempted import error: '$1' is not exported from '$3' (imported as '$2')."
50
- );
51
- lines = message.split('\n');
52
-
53
- if (lines.length > 2 && lines[1].trim() === '') {
54
- lines.splice(1, 1);
55
- }
56
- lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
57
-
58
- if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
59
- lines = [
60
- lines[0],
61
- lines[1]
62
- .replace('Error: ', '')
63
- .replace('Module not found: Cannot find file:', 'Cannot find file:')
64
- ];
65
- }
66
-
67
- if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
68
- lines[1] = 'To import Sass files, you first need to install sass.\n';
69
- lines[1] += 'Run `npm install sass` or `yarn add sass` inside your workspace.';
70
- }
71
-
72
- message = lines.join('\n');
73
-
74
- message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, ''); // at ... ...:x:y
75
- message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
76
- lines = message.split('\n');
77
-
78
- lines = lines.filter(
79
- (line, index, arr) => index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim()
80
- );
81
-
82
- // 重新组装message
83
- message = lines.join('\n');
84
- return message.trim();
85
- }
86
-
87
- function formatWebpackMessages(json) {
88
- const formattedErrors = json.errors.map(formatMessage);
89
- const formattedWarnings = json.warnings.map(formatMessage);
90
- const result = { errors: formattedErrors, warnings: formattedWarnings };
91
- if (result.errors.some(isLikelyASyntaxError)) {
92
- result.errors = result.errors.filter(isLikelyASyntaxError);
93
- }
94
- return result;
95
- }
96
-
97
- module.exports = formatWebpackMessages;
1
+ const friendlySyntaxErrorLabel = 'Syntax error:';
2
+
3
+ function isLikelyASyntaxError(message) {
4
+ return message.indexOf(friendlySyntaxErrorLabel) !== -1;
5
+ }
6
+
7
+ function formatMessage(message) {
8
+ let lines = [];
9
+
10
+ if (typeof message === 'string') {
11
+ lines = message.split('\n');
12
+ } else if ('message' in message) {
13
+ lines = message.message.split('\n');
14
+ } else if (Array.isArray(message)) {
15
+ message.forEach(message => {
16
+ if ('message' in message) {
17
+ lines = message.message.split('\n');
18
+ }
19
+ });
20
+ }
21
+
22
+ lines = lines.filter(line => !/Module [A-z ]+\(from/.test(line));
23
+
24
+ lines = lines.map(line => {
25
+ const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
26
+ if (!parsingError) {
27
+ return line;
28
+ }
29
+ const [, errorLine, errorColumn, errorMessage] = parsingError;
30
+ return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
31
+ });
32
+
33
+ message = lines.join('\n');
34
+ message = message.replace(
35
+ /SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
36
+ `${friendlySyntaxErrorLabel} $3 ($1:$2)\n`
37
+ );
38
+
39
+ message = message.replace(
40
+ /^.*export '(.+?)' was not found in '(.+?)'.*$/gm,
41
+ "Attempted import error: '$1' is not exported from '$2'."
42
+ );
43
+ message = message.replace(
44
+ /^.*export 'default' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
45
+ "Attempted import error: '$2' does not contain a default export (imported as '$1')."
46
+ );
47
+ message = message.replace(
48
+ /^.*export '(.+?)' \(imported as '(.+?)'\) was not found in '(.+?)'.*$/gm,
49
+ "Attempted import error: '$1' is not exported from '$3' (imported as '$2')."
50
+ );
51
+ lines = message.split('\n');
52
+
53
+ if (lines.length > 2 && lines[1].trim() === '') {
54
+ lines.splice(1, 1);
55
+ }
56
+ lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
57
+
58
+ if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
59
+ lines = [
60
+ lines[0],
61
+ lines[1]
62
+ .replace('Error: ', '')
63
+ .replace('Module not found: Cannot find file:', 'Cannot find file:')
64
+ ];
65
+ }
66
+
67
+ if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
68
+ lines[1] = 'To import Sass files, you first need to install sass.\n';
69
+ lines[1] += 'Run `npm install sass` or `yarn add sass` inside your workspace.';
70
+ }
71
+
72
+ message = lines.join('\n');
73
+
74
+ message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, ''); // at ... ...:x:y
75
+ message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
76
+ lines = message.split('\n');
77
+
78
+ lines = lines.filter(
79
+ (line, index, arr) => index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim()
80
+ );
81
+
82
+ // 重新组装message
83
+ message = lines.join('\n');
84
+ return message.trim();
85
+ }
86
+
87
+ function formatWebpackMessages(json) {
88
+ const formattedErrors = json.errors.map(formatMessage);
89
+ const formattedWarnings = json.warnings.map(formatMessage);
90
+ const result = { errors: formattedErrors, warnings: formattedWarnings };
91
+ if (result.errors.some(isLikelyASyntaxError)) {
92
+ result.errors = result.errors.filter(isLikelyASyntaxError);
93
+ }
94
+ return result;
95
+ }
96
+
97
+ module.exports = formatWebpackMessages;
@@ -1,14 +1,14 @@
1
- const loaderUtils = require('loader-utils');
2
-
3
- module.exports = function getLocalIdent(context, localIdentName, localName, options) {
4
- const fileNameOrFolder = context.resourcePath.match(/index\.module\.(css|scss|sass)$/)
5
- ? '[folder]'
6
- : '[name]';
7
- const hash = loaderUtils.getHashDigest(context.resourcePath + localName, 'md5', 'base64', 5);
8
- const className = loaderUtils.interpolateName(
9
- context,
10
- `${fileNameOrFolder}_${localName}_${hash}`,
11
- options
12
- );
13
- return className.replace('.module_', '_');
14
- };
1
+ const loaderUtils = require('loader-utils');
2
+
3
+ module.exports = function getLocalIdent(context, localIdentName, localName, options) {
4
+ const fileNameOrFolder = context.resourcePath.match(/index\.module\.(css|scss|sass)$/)
5
+ ? '[folder]'
6
+ : '[name]';
7
+ const hash = loaderUtils.getHashDigest(context.resourcePath + localName, 'md5', 'base64', 5);
8
+ const className = loaderUtils.interpolateName(
9
+ context,
10
+ `${fileNameOrFolder}_${localName}_${hash}`,
11
+ options
12
+ );
13
+ return className.replace('.module_', '_');
14
+ };
package/common/start.js CHANGED
@@ -1,71 +1,71 @@
1
- const webpackDevServer = require('webpack-dev-server');
2
- const webpack = require('webpack');
3
- const open = require('open');
4
- const appConfig = require('./appConfig');
5
- const getEnvironmentInfo = require('./extendEnv');
6
- const { parseArgsToJson, getProjectPath } = require('./utils');
7
-
8
- function openStartRun(webpackFactory) {
9
- process.env.BABEL_ENV = 'development';
10
- process.env.NODE_ENV = 'development';
11
-
12
- const PORT = process.env.PORT || parseArgsToJson.port || appConfig.startDefaultPort;
13
- const HOST = process.env.HOST || '0.0.0.0';
14
-
15
- const extendEnv = getEnvironmentInfo();
16
-
17
- const options = {
18
- contentBase: getProjectPath(appConfig.startOutput.path),
19
- hot: true,
20
- host: HOST,
21
- quiet: true,
22
- publicPath: appConfig.startOutput.publicPath || '/',
23
- compress: true,
24
- overlay: false,
25
- historyApiFallback: {
26
- // https://github.com/facebook/create-react-app/issues/387.
27
- disableDotRule: true
28
- },
29
- watchOptions: {
30
- aggregateTimeout: 300,
31
- poll: 1000,
32
- ignored: /node_modules/
33
- },
34
- disableHostCheck: true
35
- };
36
-
37
- const startOpenPath = appConfig.startOpenPath ? appConfig.startOpenPath : '';
38
-
39
- try {
40
- const config = webpackFactory({ ...appConfig, port: PORT, startOpenPath }, extendEnv);
41
-
42
- webpackDevServer.addDevServerEntrypoints(config, options);
43
- const compiler = webpack(config);
44
- // eslint-disable-next-line new-cap
45
- const server = new webpackDevServer(compiler, options);
46
-
47
- server.listen(PORT, HOST, err => {
48
- if (err) {
49
- // eslint-disable-next-line no-console
50
- console.log(err);
51
- return;
52
- }
53
- open(`http://localhost:${PORT}${startOpenPath}`);
54
- });
55
-
56
- ['SIGINT', 'SIGTERM'].forEach(sig => {
57
- process.on(sig, () => {
58
- server.close();
59
- process.exit();
60
- });
61
- });
62
- } catch (err) {
63
- if (err && err.message) {
64
- // eslint-disable-next-line no-console
65
- console.log(err.message);
66
- }
67
- process.exit(1);
68
- }
69
- }
70
-
71
- module.exports = openStartRun;
1
+ const webpackDevServer = require('webpack-dev-server');
2
+ const webpack = require('webpack');
3
+ const open = require('open');
4
+ const appConfig = require('./appConfig');
5
+ const getEnvironmentInfo = require('./extendEnv');
6
+ const { parseArgsToJson, getProjectPath } = require('./utils');
7
+
8
+ function openStartRun(webpackFactory) {
9
+ process.env.BABEL_ENV = 'development';
10
+ process.env.NODE_ENV = 'development';
11
+
12
+ const PORT = process.env.PORT || parseArgsToJson.port || appConfig.startDefaultPort;
13
+ const HOST = process.env.HOST || '0.0.0.0';
14
+
15
+ const extendEnv = getEnvironmentInfo();
16
+
17
+ const options = {
18
+ contentBase: getProjectPath(appConfig.startOutput.path),
19
+ hot: true,
20
+ host: HOST,
21
+ quiet: true,
22
+ publicPath: appConfig.startOutput.publicPath || '/',
23
+ compress: true,
24
+ overlay: false,
25
+ historyApiFallback: {
26
+ // https://github.com/facebook/create-react-app/issues/387.
27
+ disableDotRule: true
28
+ },
29
+ watchOptions: {
30
+ aggregateTimeout: 300,
31
+ poll: 1000,
32
+ ignored: /node_modules/
33
+ },
34
+ disableHostCheck: true
35
+ };
36
+
37
+ const startOpenPath = appConfig.startOpenPath ? appConfig.startOpenPath : '';
38
+
39
+ try {
40
+ const config = webpackFactory({ ...appConfig, port: PORT, startOpenPath }, extendEnv);
41
+
42
+ webpackDevServer.addDevServerEntrypoints(config, options);
43
+ const compiler = webpack(config);
44
+ // eslint-disable-next-line new-cap
45
+ const server = new webpackDevServer(compiler, options);
46
+
47
+ server.listen(PORT, HOST, err => {
48
+ if (err) {
49
+ // eslint-disable-next-line no-console
50
+ console.log(err);
51
+ return;
52
+ }
53
+ open(`http://localhost:${PORT}${startOpenPath}`);
54
+ });
55
+
56
+ ['SIGINT', 'SIGTERM'].forEach(sig => {
57
+ process.on(sig, () => {
58
+ server.close();
59
+ process.exit();
60
+ });
61
+ });
62
+ } catch (err) {
63
+ if (err && err.message) {
64
+ // eslint-disable-next-line no-console
65
+ console.log(err.message);
66
+ }
67
+ process.exit(1);
68
+ }
69
+ }
70
+
71
+ module.exports = openStartRun;
package/common/utils.js CHANGED
@@ -1,59 +1,64 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
-
4
- // 执行node命令时候的文件绝对路径
5
- const root = process.cwd();
6
-
7
- /**
8
- * 从根目录开始获取文件绝对地址路径
9
- * @param filePath 文件参数
10
- * @returns {string} 返回绝对路径
11
- */
12
- function getProjectPath(...filePath) {
13
- return path.join(root, ...filePath);
14
- }
15
-
16
- function getParseArgsToJson() {
17
- const args = process.argv.slice(2);
18
- const length = args.length - 1;
19
- const result = {};
20
- let count = 0;
21
- while (count <= length) {
22
- if (!/^--[0-9a-z]+$/.test(args[count])) {
23
- throw Error('Run args error, example: --port 3030');
24
- }
25
- const key = args[count].substring(2);
26
- count++;
27
- if (count > length) {
28
- result[key] = '';
29
- break;
30
- }
31
- result[key] = isNaN(Number(args[count])) ? args[count] : Number(args[count]);
32
- count++;
33
- }
34
- return result;
35
- }
36
-
37
- const parseArgsToJson = getParseArgsToJson();
38
-
39
- function deleteFolders(path) {
40
- let files = [];
41
- if (fs.existsSync(path)) {
42
- files = fs.readdirSync(path);
43
- files.forEach(file => {
44
- const curPath = `${path}/${file}`;
45
- if (fs.statSync(curPath).isDirectory()) {
46
- deleteFolders(curPath);
47
- } else {
48
- fs.unlinkSync(curPath);
49
- }
50
- });
51
- fs.rmdirSync(path);
52
- }
53
- }
54
-
55
- module.exports = {
56
- getProjectPath,
57
- parseArgsToJson,
58
- deleteFolders
59
- };
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+
4
+ // 执行node命令时候的文件绝对路径
5
+ const root = process.cwd();
6
+
7
+ /**
8
+ * 从根目录开始获取文件绝对地址路径
9
+ * @param filePath 文件参数
10
+ * @returns {string} 返回绝对路径
11
+ */
12
+ function getProjectPath(...filePath) {
13
+ return path.join(root, ...filePath);
14
+ }
15
+
16
+ function getParseArgsToJson() {
17
+ const args = process.argv.slice(2);
18
+ const length = args.length - 1;
19
+ const result = {};
20
+ let count = 0;
21
+ while (count <= length) {
22
+ if (!/^--[0-9a-z]+$/.test(args[count])) {
23
+ throw Error('Run args error, example: --port 3030');
24
+ }
25
+ const key = args[count].substring(2);
26
+ count++;
27
+ if (count > length) {
28
+ result[key] = '';
29
+ break;
30
+ }
31
+ result[key] = isNaN(Number(args[count])) ? args[count] : Number(args[count]);
32
+ count++;
33
+ }
34
+ return result;
35
+ }
36
+
37
+ function isExistsSyncFile(path) {
38
+ return fs.existsSync(path);
39
+ }
40
+
41
+ const parseArgsToJson = getParseArgsToJson();
42
+
43
+ function deleteFolders(path) {
44
+ let files = [];
45
+ if (isExistsSyncFile(path)) {
46
+ files = fs.readdirSync(path);
47
+ files.forEach(file => {
48
+ const curPath = `${path}/${file}`;
49
+ if (fs.statSync(curPath).isDirectory()) {
50
+ deleteFolders(curPath);
51
+ } else {
52
+ fs.unlinkSync(curPath);
53
+ }
54
+ });
55
+ fs.rmdirSync(path);
56
+ }
57
+ }
58
+
59
+ module.exports = {
60
+ getProjectPath,
61
+ parseArgsToJson,
62
+ deleteFolders,
63
+ isExistsSyncFile
64
+ };
package/common/version.js CHANGED
@@ -1,23 +1,23 @@
1
- /**
2
- * 根据 当前时间组装版本号,”年月日时“的形式
3
- * @returns {string}
4
- */
5
- function getCurrentVersion() {
6
- const date = new Date();
7
- const year = date.getFullYear();
8
- const month = date.getMonth() + 1;
9
- const day = date.getDate();
10
- const hour = date.getHours();
11
- return `${year}${getCompleteVal(month)}${getCompleteVal(day)}${getCompleteVal(hour)}`;
12
- }
13
-
14
- /**
15
- * 补全小于10的数字,例如: 9 =》 09
16
- * @param val
17
- * @returns {string}
18
- */
19
- function getCompleteVal(val) {
20
- return val < 10 ? `0${val}` : val;
21
- }
22
-
23
- module.exports = getCurrentVersion;
1
+ /**
2
+ * 根据 当前时间组装版本号,”年月日时“的形式
3
+ * @returns {string}
4
+ */
5
+ function getCurrentVersion() {
6
+ const date = new Date();
7
+ const year = date.getFullYear();
8
+ const month = date.getMonth() + 1;
9
+ const day = date.getDate();
10
+ const hour = date.getHours();
11
+ return `${year}${getCompleteVal(month)}${getCompleteVal(day)}${getCompleteVal(hour)}`;
12
+ }
13
+
14
+ /**
15
+ * 补全小于10的数字,例如: 9 =》 09
16
+ * @param val
17
+ * @returns {string}
18
+ */
19
+ function getCompleteVal(val) {
20
+ return val < 10 ? `0${val}` : val;
21
+ }
22
+
23
+ module.exports = getCurrentVersion;