y3-app
Version:
CLI to add your project structure
126 lines (125 loc) • 6.09 kB
JavaScript
#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const inquirer_1 = __importDefault(require("inquirer"));
const path_1 = require("path");
const promises_1 = require("fs/promises");
const displayBanner_1 = require("./utils/displayBanner");
const createStructure_1 = require("./utils/createStructure");
const reactTsStructure_1 = require("./structures/reactTsStructure");
const nodeTsStructure_1 = require("./structures/nodeTsStructure");
const fullstackTsStructure_1 = require("./structures/fullstackTsStructure");
const index_1 = require("./config/index");
const program = new commander_1.Command();
program
.name('create-y3-app')
.description('CLI to add your project structure')
.version('1.0.0');
program
.argument('[projectName]', 'Name of the project')
.action(async (inputProjectName) => {
(0, displayBanner_1.displayBanner)();
const answers = await inquirer_1.default.prompt([
{
type: 'input',
name: 'projectName',
message: 'What will your project be called ?',
default: inputProjectName || 'my-app',
when: !inputProjectName,
},
{
type: 'list',
name: 'template',
message: 'Select a template:',
choices: ['react-ts', 'node-ts', 'fullstack-ts'],
},
]);
const projectName = inputProjectName || answers.projectName || 'my-app';
const projectType = answers.template === 'react-ts'
? 'react'
: answers.template === 'node-ts'
? 'node'
: 'fullstack';
const projectStructure = projectType === 'react'
? reactTsStructure_1.reactTsStructure
: projectType === 'node'
? nodeTsStructure_1.nodeTsStructure
: fullstackTsStructure_1.fullstackTsStructure;
console.log(`Adding project structure to: ${projectName} with template: ${answers.template}`);
try {
// Create project directory
await (0, promises_1.mkdir)(projectName, { recursive: true });
// Create package.json
const packageJson = (0, index_1.getPackageJson)(projectName, projectType);
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'package.json'), JSON.stringify(packageJson, null, 2));
// Create tsconfig.json
const tsconfig = (0, index_1.getTsConfig)(projectType);
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'tsconfig.json'), JSON.stringify(tsconfig, null, 2));
if (projectType === 'react' || projectType === 'fullstack') {
// Create tsconfig.node.json
const tsconfigNode = (0, index_1.getTsConfigNode)();
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'tsconfig.node.json'), JSON.stringify(tsconfigNode, null, 2));
// Create vite.config.ts
const viteConfig = (0, index_1.getViteConfig)(projectType);
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'vite.config.ts'), viteConfig);
// Create tailwind.config.ts
const tailwindConfig = (0, index_1.getTailwindConfig)(projectType);
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'tailwind.config.ts'), tailwindConfig);
// Create index.html
const indexHtml = (0, index_1.getIndexHtml)(projectName, projectType);
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'index.html'), indexHtml);
// Create tsconfig.app.json
const tsconfigApp = (0, index_1.getTsConfigApp)(projectType);
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'tsconfig.app.json'), JSON.stringify(tsconfigApp, null, 2));
}
if (projectType === 'fullstack') {
// Create tsconfig.backend.json
const tsconfigBackend = {
compilerOptions: {
target: 'ES2022',
module: 'ESNext',
lib: ['ES2023'],
skipLibCheck: true,
moduleResolution: 'node',
outDir: './backend/dist',
rootDir: './backend',
strict: true,
esModuleInterop: true,
noUnusedLocals: true,
noUnusedParameters: true,
noFallthroughCasesInSwitch: true,
},
include: ['backend'],
};
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'tsconfig.backend.json'), JSON.stringify(tsconfigBackend, null, 2));
}
// Create .gitignore
const gitignore = (0, index_1.getGitignore)();
await (0, promises_1.writeFile)((0, path_1.join)(projectName, '.gitignore'), gitignore);
// Create .env
const env = (0, index_1.getEnv)(projectName, projectType);
await (0, promises_1.writeFile)((0, path_1.join)(projectName, '.env'), env);
// Create eslint.config.ts
const eslintConfig = (0, index_1.getEslintConfig)(projectType);
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'eslint.config.ts'), eslintConfig);
// Create README.md
const readme = (0, index_1.getReadme)(projectName, projectType);
await (0, promises_1.writeFile)((0, path_1.join)(projectName, 'README.md'), readme);
// Create project structure
await (0, createStructure_1.createStructure)(projectStructure, projectName);
console.log('Project structure added successfully!');
console.log('\nNext steps:');
console.log(` cd ${projectName}`);
console.log(' pnpm install');
console.log(' pnpm run dev');
}
catch (error) {
console.error('Error adding project structure:', error);
process.exit(1);
}
});
program.parse();