Skip to content

Commit ad7c9d6

Browse files
committed
add friendly info
1 parent 7926e37 commit ad7c9d6

File tree

2 files changed

+77
-74
lines changed

2 files changed

+77
-74
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "CreateVueClassComponent",
44
"description": "create vue class component",
55
"icon": "images/vue_logo.png",
6-
"version": "0.1.0",
6+
"version": "0.1.1",
77
"publisher": "pengfeiyuan",
88
"engines": {
99
"vscode": "^1.57.0"

src/checkDestinationVueFilename.ts

Lines changed: 76 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,98 +3,101 @@ import * as fs from "fs";
33
import convertWords2BigCamelCaseStyle from "./convertWords2BigCamelCaseStyle";
44

55
interface Data {
6-
oldPath: string;
7-
tempPath: string;
8-
newPath: string;
6+
oldPath: string;
7+
tempPath: string;
8+
newPath: string;
99
}
1010

1111
function readFilesOfDest(uri: vscode.Uri) {
12-
const _path = uri.path;
13-
if (fs.lstatSync(_path).isFile()) {
14-
if (_path.endsWith(".vue")) {
15-
const arr = _path.split("/");
16-
const filename = arr.pop();
17-
const dir = arr.join("/");
12+
const _path = uri.path;
13+
if (fs.lstatSync(_path).isFile()) {
14+
if (_path.endsWith(".vue")) {
15+
const arr = _path.split("/");
16+
const filename = arr.pop();
17+
const dir = arr.join("/");
1818

19-
return [handleFile(filename!, dir)];
20-
}
19+
return [handleFile(filename!, dir)];
20+
}
2121

22-
return [];
23-
}
22+
return [];
23+
}
2424

25-
const res: Data[] = [];
25+
const res: Data[] = [];
2626

27-
function handleFile(v: string, dir: string): Data {
28-
if (/\.vue$/.test(v) && !/[A-Z]/g.test(v[0])) {
29-
return {
30-
oldPath: `${dir}/${v}`,
31-
tempPath: `${dir}/${convertWords2BigCamelCaseStyle(v)}.temp`,
32-
newPath: `${dir}/${convertWords2BigCamelCaseStyle(v)}`,
33-
};
34-
}
27+
function handleFile(v: string, dir: string): Data {
28+
if (/\.vue$/.test(v) && !/[A-Z]/g.test(v[0])) {
29+
return {
30+
oldPath: `${dir}/${v}`,
31+
tempPath: `${dir}/${convertWords2BigCamelCaseStyle(v)}.temp`,
32+
newPath: `${dir}/${convertWords2BigCamelCaseStyle(v)}`,
33+
};
34+
}
3535

36-
return null as any as Data;
37-
}
36+
return null as any as Data;
37+
}
3838

39-
function read(dir: string) {
40-
const files = fs.readdirSync(dir);
41-
files.map((v) => {
42-
if (fs.lstatSync(`${dir}/${v}`).isFile()) {
43-
const d = handleFile(v, dir);
44-
res.push(d);
45-
} else {
46-
read(`${dir}/${v}`);
47-
}
48-
});
49-
}
39+
function read(dir: string) {
40+
const files = fs.readdirSync(dir);
41+
files.map((v) => {
42+
if (fs.lstatSync(`${dir}/${v}`).isFile()) {
43+
const d = handleFile(v, dir);
44+
d && res.push(d);
45+
} else {
46+
read(`${dir}/${v}`);
47+
}
48+
});
49+
}
5050

51-
read(_path);
51+
read(_path);
5252

53-
return res;
53+
return res;
5454
}
5555

5656
function rename({ oldPath, tempPath, newPath }: Data) {
57-
fs.copyFileSync(oldPath, tempPath);
58-
fs.unlinkSync(oldPath);
59-
fs.copyFileSync(tempPath, newPath);
60-
fs.unlinkSync(tempPath);
57+
fs.copyFileSync(oldPath, tempPath);
58+
fs.unlinkSync(oldPath);
59+
fs.copyFileSync(tempPath, newPath);
60+
fs.unlinkSync(tempPath);
6161
}
6262

6363
function checkDestinationVueFilename(context: vscode.ExtensionContext) {
64-
context.subscriptions.push(
65-
vscode.commands.registerCommand(
66-
"createvueclasscomponent.check",
67-
async (uri: vscode.Uri) => {
68-
const files = readFilesOfDest(uri);
69-
if (!files.length) {
70-
vscode.window.showInformationMessage(
71-
"Congratulations, your vue filenames are all regularly!"
72-
);
73-
return;
74-
}
75-
vscode.window
76-
.showInformationMessage(
77-
`You have some files that are not named irregularly,\n
78-
do you want me to rename them for you?\n
64+
const win = vscode.window;
65+
context.subscriptions.push(
66+
vscode.commands.registerCommand(
67+
"createvueclasscomponent.check",
68+
async (uri: vscode.Uri) => {
69+
const files = readFilesOfDest(uri);
70+
if (!files.length) {
71+
win.showInformationMessage(
72+
"Congratulations, your vue filenames are all regularly!"
73+
);
74+
return;
75+
}
76+
win
77+
.showInformationMessage(
78+
`You have some files that are not named irregularly,\n
79+
do you want me to rename them?\n
7980
If you choose yes, I'll automatically rename them for you\n
8081
or I'll show you where they are.`,
81-
"Yes",
82-
"No"
83-
)
84-
.then((v) => {
85-
if (v === "Yes") {
86-
files.forEach((v) => rename(v));
87-
} else {
88-
const str = files.map((v) => v.oldPath).join("\n");
89-
const terminal =
90-
vscode.window.createTerminal("File Details");
91-
terminal.sendText(str, true);
92-
terminal.show();
93-
}
94-
});
95-
}
96-
)
97-
);
82+
"Yes",
83+
"No"
84+
)
85+
.then((v) => {
86+
if (v === "Yes") {
87+
files.forEach((v) => rename(v));
88+
win.showInformationMessage(
89+
"Already renamed for you, please refresh editor to check."
90+
);
91+
} else {
92+
const str = files.map((v) => v.oldPath).join("\n");
93+
const terminal = win.createTerminal("File Details");
94+
terminal.sendText(str, true);
95+
terminal.show();
96+
}
97+
});
98+
}
99+
)
100+
);
98101
}
99102

100103
export default checkDestinationVueFilename;

0 commit comments

Comments
 (0)