tess-framework
Version:
Lightweight TypeScript/Rust full-stack framework with Vue 3 + Vite
115 lines • 5.12 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initCommand = initCommand;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
const ora_1 = __importDefault(require("ora"));
const inquirer_1 = __importDefault(require("inquirer"));
const scaffold_1 = require("../utils/scaffold");
const install_1 = require("../utils/install");
async function initCommand(projectName, options) {
const isCurrentDir = projectName === '.' || projectName === '';
const actualProjectName = isCurrentDir ? path_1.default.basename(process.cwd()) : projectName;
const targetDir = isCurrentDir ? process.cwd() : path_1.default.join(process.cwd(), projectName);
if (!isCurrentDir && await fs_extra_1.default.pathExists(targetDir)) {
const { overwrite } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'overwrite',
message: `Directory ${projectName} already exists. Overwrite?`,
default: false
}
]);
if (!overwrite) {
console.log(chalk_1.default.red('Operation cancelled'));
process.exit(1);
}
await fs_extra_1.default.remove(targetDir);
}
if (isCurrentDir) {
const files = await fs_extra_1.default.readdir(targetDir);
const nonHiddenFiles = files.filter(f => !f.startsWith('.'));
if (nonHiddenFiles.length > 0) {
const { proceed } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'proceed',
message: 'Current directory is not empty. Initialize Tess project here anyway?',
default: false
}
]);
if (!proceed) {
console.log(chalk_1.default.red('Operation cancelled'));
process.exit(1);
}
}
}
const projectOptions = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'includeBackend',
message: 'Do you want to include a backend/API?',
default: true
},
{
type: 'list',
name: 'backendType',
message: 'Which backend language do you prefer?',
choices: [
{ name: 'TypeScript', value: 'typescript' },
{ name: 'Rust', value: 'rust' },
{ name: 'Both TypeScript and Rust', value: 'both' }
],
default: 'typescript',
when: (answers) => answers.includeBackend
}
]);
console.log(chalk_1.default.cyan(`\nCreating Tess project: ${actualProjectName}`));
console.log(chalk_1.default.gray(`Frontend: Vue 3 + TypeScript + Tailwind -tess.v`));
if (projectOptions.includeBackend) {
const backendText = projectOptions.backendType === 'both'
? 'TypeScript + Rust APIs'
: `${projectOptions.backendType === 'typescript' ? 'TypeScript' : 'Rust'} API`;
console.log(chalk_1.default.gray(`Backend: ${backendText}`));
}
else {
console.log(chalk_1.default.gray(`Backend: None (frontend only)`));
}
console.log(chalk_1.default.gray(`Dev Server Port: 8000 (frontend + API)`));
console.log();
const spinner = (0, ora_1.default)('Scaffolding project structure...').start();
try {
if (!isCurrentDir) {
await fs_extra_1.default.ensureDir(targetDir);
}
await (0, scaffold_1.createProjectStructure)(targetDir, actualProjectName, projectOptions);
spinner.succeed('Project structure created');
spinner.start('Installing dependencies...');
await (0, install_1.installDependencies)(targetDir);
spinner.succeed('Dependencies installed');
if (projectOptions.includeBackend && (projectOptions.backendType === 'rust' || projectOptions.backendType === 'both')) {
console.log(chalk_1.default.yellow('\nRust backend requires Rust and Cargo to be installed'));
console.log(chalk_1.default.white(' Install from: https://rustup.rs/\n'));
}
console.log(chalk_1.default.green('\nProject created successfully!\n'));
console.log(chalk_1.default.cyan('Get started with:'));
if (!isCurrentDir) {
console.log(chalk_1.default.white(` cd ${projectName}`));
}
console.log(chalk_1.default.white(' tess dev\n'));
if (projectOptions.includeBackend) {
console.log(chalk_1.default.yellow('API endpoints available at:'));
console.log(chalk_1.default.white(' http://localhost:8000/api/*\n'));
}
}
catch (error) {
spinner.fail('Failed to create project');
console.error(chalk_1.default.red(error));
process.exit(1);
}
}
//# sourceMappingURL=init.js.map