sx-cli-tool
Version:
Laravel va Vue frameworklaridagi monolith arxitektura loyihalarni boshqarish uchun mo'ljallangan CLI tool
91 lines (90 loc) • 5.51 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.laravelVueSetup = laravelVueSetup;
// import { PackageManager } from "../types/index";
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const inquirer_1 = __importDefault(require("inquirer"));
const child_process_1 = require("child_process");
const vite_1 = require("./mock/vite");
const vue_1 = require("./mock/vue");
const folder_1 = require("../utils/folder");
function laravelVueSetup(projectPath) {
return __awaiter(this, void 0, void 0, function* () {
try {
console.log("Installing Vue 3 and Vite...");
const { packageManager } = yield inquirer_1.default
.prompt([{ type: "list", name: "packageManager", message: "Package managerni tanlang:", choices: ["npm", "yarn", "pnpm"] }]);
// install vue
const installTemplate = packageManager === "yarn" ? "yarn add vue vue-router ant-design-vue pinia vue-i18n@10" : packageManager === "pnpm" ? "pnpm add vue vue-router ant-design-vue pinia vue-i18n@10" : "npm install vue vue-router ant-design-vue pinia vue-i18n@10";
(0, child_process_1.execSync)(installTemplate, { stdio: "inherit", cwd: projectPath });
// install vite as dev dependency
const installTemplate2 = packageManager === "yarn" ? "yarn add -D vite" : packageManager === "pnpm" ? "pnpm add --save-dev vite" : "npm install vite --save-dev";
(0, child_process_1.execSync)(installTemplate2, { stdio: "inherit", cwd: projectPath });
// install vite vue plugin
const installTemplate3 = packageManager === "yarn" ? "yarn add -D @vitejs/plugin-vue laravel-vite-plugin" : packageManager === "pnpm" ? "pnpm add --save-dev @vitejs/plugin-vue laravel-vite-plugin" : "npm install --save-dev @vitejs/plugin-vue laravel-vite-plugin";
(0, child_process_1.execSync)(installTemplate3, { stdio: "inherit", cwd: projectPath });
// create vite config
fs_1.default.writeFileSync(`${projectPath}/vite.config.js`, vite_1.viteVueConfig);
console.log("Vite configuration created.");
(0, folder_1.ensureDirectoryExists)(`${projectPath}/resources/vue/shims-vue.d.ts`);
// create shim-vue.d.ts
fs_1.default.writeFileSync(`${projectPath}/resources/vue/shims-vue.d.ts`, vue_1.shimsContent);
console.log("shims-vue.d.ts created.");
// create ts config
fs_1.default.writeFileSync(`${projectPath}/tsconfig.json`, vue_1.tsConfig);
console.log("tsconfig.json created.");
// create vue entry point
fs_1.default.writeFileSync(`${projectPath}/resources/vue/main.ts`, vue_1.appTsContent);
console.log("Vue entry point setup in resources/vue/main.ts");
// create vue component
fs_1.default.writeFileSync(`${projectPath}/resources/vue/App.vue`, vue_1.appVueContent);
console.log("Basic Vue component (App.vue) created.");
// create app.blade.php
const bladePath = `${projectPath}/resources/views/app.blade.php`;
fs_1.default.writeFileSync(bladePath, vue_1.bladeContent);
console.log("app.blade.php modified to include Vue component.");
// update routes/web.php
const routeConfig = `Route::get('{any?}', fn() => view("app"))->where("any", ".*");`;
// add route config
try {
// Path to web.php
const webRoutesPath = path_1.default.join(projectPath, "routes", "web.php");
// Check if web.php exists
if (fs_1.default.existsSync(webRoutesPath)) {
const currentRoutes = fs_1.default.readFileSync(webRoutesPath, "utf-8");
// Check if the routeConfig is already in the file
if (!currentRoutes.includes(routeConfig)) {
// Append the routeConfig to web.php
fs_1.default.appendFileSync(webRoutesPath, `\n${routeConfig}\n`);
console.log("Vue route added to routes/web.php.");
}
else {
console.log("Vue route already exists in routes/web.php.");
}
}
else {
console.error("web.php file not found.");
}
}
catch (error) {
console.error("Error updating routes/web.php:", error);
}
}
catch (e) {
console.error(e);
}
});
}