const util = require("./Util"); const vscode = require("vscode"); import fsProvider from './FsProvider' export const Confirmation = { 'Yes': () => `Yes`, 'No': () => `No`, } class VueHandler{ static async initProject(){ const projectName = await vscode.window.showInputBox({ placeHolder: "Enter project name: " }); if (!projectName){ vscode.window.showInformationMessage('Thế thì chịu rồi, không có tên thì gọi bằng gì !!!'); return; } const projectNameTypes = util.getFullTextType(projectName); try { fsProvider.copyFile('vue/init/src', 'src'); fsProvider.copyFile('vue/init/public', 'public'); fsProvider.copyFile('vue/init/.gitignore', '.gitignore'); fsProvider.copyFile('vue/init/babel.config.js', 'babel.config.js'); fsProvider.copyFile('vue/init/deploy.sh', 'deploy.sh'); fsProvider.copyFile('vue/init/vue.config.js', 'vue.config.js'); fsProvider.copyAndReplaceFile('vue/init/package.json', 'package.json', [{ regex: /{{project_name}}/g, value: projectNameTypes.kebabCase }]); } catch (error) { console.log(error); } } static async createComponent(fsPath: string | string[], assetPath: any){ if (!fsPath.includes('component')) return vscode.window.showErrorMessage("Please select subfolder in 'components'"); let componentName = await vscode.window.showInputBox({ placeHolder: "Enter component name: " }); if (!componentName){ vscode.window.showInformationMessage('Thế thì chịu rồi, không có tên thì gọi bằng gì !!!'); return; } componentName = componentName.replace('component', '').replace('Component', ''); const currentFolder = fsProvider.getPathFromRoot(fsPath); const componentTextTypes = util.getFullTextType(componentName); const distPath = `${currentFolder}/${componentTextTypes.classifyCase}Component.vue`; if (fsProvider.checkExist(distPath)) { const confirm = await vscode.window.showQuickPick([Confirmation.Yes, Confirmation.No], { placeHolder: "This file already exist in this folder. Do you want to replace it." }); if (confirm != Confirmation.Yes) return; } fsProvider.copyAndReplaceFile(assetPath, distPath, [ { regex: /{{snake}}/g, value: componentTextTypes.snakeCase }, { regex: /{{kebabCase}}/g, value: componentTextTypes.kebabCase }, { regex: /{{classify}}/g, value: componentTextTypes.classifyCase }, { regex: /{{camel}}/g, value: componentTextTypes.camelCase } ]); } static async createComponentNormal(fsPath: string | string[]) { return await this.createComponent(fsPath, 'vue/components/ExampleComponent.vue'); } } export default VueHandler;