-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.js
More file actions
58 lines (55 loc) · 1.71 KB
/
ui.js
File metadata and controls
58 lines (55 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @file 插件配置
* @author Lohoyo <824591872@qq.com>
*
*/
module.exports = api => {
if (process.env.SAN_CLI_UI_DEV) {
api.registerAddon({
id: 'san.widgets.client-addon.dev3',
url: 'http://localhost:8893/index.js'
});
} else {
api.registerAddon({
id: 'san.widgets.webhint.client-addon',
path: 'san-cli-ui-widget-webhint/dist'
});
}
api.registerWidget({
id: 'san.widgets.webhint',
title: 'san-cli-ui-widget-webhint.title',
description: 'san-cli-ui-widget-webhint.description',
icon: 'check-circle',
component: 'san.widgets.components.webhint',
minWidth: 2,
minHeight: 1,
maxWidth: 2,
maxHeight: 1,
maxCount: 1
});
api.onAction('san-cli-ui-widget-webhint.actions.lint', url => {
const {execSync} = require('child_process');
let lintRes;
try {
const res = execSync('npx hint ' + url, {encoding: 'utf8'})
} catch (err) {
if (err.stderr.indexOf('not an existing file nor a valid URL') !== -1) {
return {
errorCode: 1,
errorMessage: '检查失败,请输入有效的 URL。'
};
}
if (err.stderr.indexOf('AnalyzerError: Unable to parse axe results null') !== -1) {
return {
errorCode: 2,
errorMessage: '检查失败,请不要关闭弹出的窗口。'
};
}
lintRes = /".+"/.exec(err.stdout)[0];
}
execSync('open ' + lintRes);
return {
errorCode: 0
};
});
}