-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy.js
53 lines (45 loc) · 1.32 KB
/
copy.js
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
const vscode = require("vscode");
const path = require("path");
const { run: jscodeshift } = require("jscodeshift/src/Runner");
const options = {
dry: false, // 是否对文件进行修改 true 不修改 false 修改
print: true, // 是否将转换后的信息打印出来
verbose: 2, // 格式化信息
};
function replace() {
const transformPath = path.resolve(__dirname, "./transform.js");
const filePath = vscode.window.activeTextEditor.document.fileName;
if (!filePath) return false;
jscodeshift(transformPath, [filePath], options).then((res, options) => {
const { ok, nochange } = res;
if (ok === 1) {
vscode.window.showInformationMessage("格式化成功");
return false;
}
if (nochange === 1) {
vscode.window.showInformationMessage("没有可以修改的内容");
return false;
}
vscode.window.showInformationMessage("操作失败");
});
}
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
let disposable = vscode.commands.registerCommand("toAntd", function () {
replace();
});
let menu = vscode.commands.registerTextEditorCommand(
"menuToAntd",
function (options) {
replace();
}
);
context.subscriptions.push(disposable, menu);
}
function deactivate() {}
module.exports = {
activate,
deactivate,
};