代码拉取完成,页面将自动刷新
const vscode = require("vscode");
const fs = require("fs");
const path = require("path");
const { moduleFile } = require("./template/module");
const { componentFile } = require("./template/component");
const { serviceFile } = require("./template/service");
const findDir = (filePath) => {
if (fs.statSync(filePath).isFile()) {
return path.dirname(filePath);
}
return filePath;
};
const makeDirSync = (dir) => {
if (fs.existsSync(dir)) {
return;
}
if (!fs.existsSync(path.dirname(dir))) {
makeDirSync(path.dirname(dir));
}
fs.mkdirSync(dir);
};
const makeFileSync = (filename, content) => {
if (!fs.existsSync(filename)) {
makeDirSync(path.dirname(filename));
fs.createWriteStream(filename).write(content);
}
};
exports.generateComponent = (file) => {
vscode.window
.showInputBox({
value: "",
prompt: "Component name",
ignoreFocusOut: true,
valueSelection: [-1, -1],
})
.then((name) => {
if (!name) {
return;
}
const componentName = name.charAt(0).toUpperCase() + name.slice(1);
const dir = findDir(file.fsPath);
makeFileSync(
`${dir}/${componentName}.vue`,
componentFile.replace(/{componentName}/g, componentName)
);
});
};
exports.generateService = (file) => {
vscode.window
.showInputBox({
value: "",
prompt: "service name",
ignoreFocusOut: true,
valueSelection: [-1, -1],
})
.then((name) => {
if (!name) {
return;
}
const dir = findDir(file.fsPath);
const targetPath = path.join(dir, name);
makeFileSync(
`${targetPath}/${name}.js`,
serviceFile.replace(/{serviceName}/g, name)
);
});
};
exports.generateModule = (file) => {
vscode.window
.showInputBox({
value: "",
prompt: "module name",
ignoreFocusOut: true,
valueSelection: [-1, -1],
})
.then((name) => {
if (!name) {
return;
}
const dir = findDir(file.fsPath);
makeFileSync(`${dir}/${name}.js`, moduleFile);
});
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。