UNPKG

@quadnix/octo-build

Version:

Octo-Build is a CLI tool to build Octo projects.

122 lines 5.91 kB
import { readdir, stat } from 'fs/promises'; import { join, resolve } from 'path'; import Generator, {} from 'yeoman-generator'; export default class extends Generator { constructor(args, opts) { super(args, opts); this.appName = args[0]; this.appPath = args[1]; this.appTemplate = args[2]; } async initializing() { const targetPath = resolve(join(this.appPath, this.appName)); // Check if directory already exists and is not empty. let targetPathStat; try { targetPathStat = await stat(targetPath); } catch (error) { if (error.code !== 'ENOENT') { throw error; } } if (targetPathStat?.isDirectory()) { const files = await readdir(targetPath); if (files.length > 0) { throw new Error(`Directory '${targetPath}' already exists and is not empty! Please choose a different name or path.`); } } // Set the destination root to the app directory. this.destinationRoot(targetPath); } async writing() { // Create eslint.config.js (ESLint v9 flat config) this.fs.copyTpl(this.templatePath('eslint.config.js.ejs'), this.destinationPath('eslint.config.js')); // Create .gitignore this.fs.copyTpl(this.templatePath('gitignore.ejs'), this.destinationPath('.gitignore')); // Create package.json this.fs.copyTpl(this.templatePath('package.json.ejs'), this.destinationPath('package.json'), { description: `Infrastructure definition using Octo for ${this.appName}`, name: this.appName, version: '0.0.1', }); await this.addDependencies({ '@quadnix/octo': '0.0.x', '@quadnix/octo-aws-cdk': '0.0.x', '@quadnix/octo-event-listeners': '0.0.x', 'env-smart': '^2.3.2', }); await this.addDevDependencies({ '@eslint/js': '^9.33.0', '@types/jest': '^30.0.0', '@types/node': '^24.3.0', '@typescript-eslint/eslint-plugin': '^8.39.1', '@typescript-eslint/parser': '^8.39.1', eslint: '^9.33.0', 'eslint-config-prettier': '^10.1.8', 'eslint-import-resolver-typescript': '^4.4.4', 'eslint-plugin-import': '^2.32.0', 'eslint-plugin-jsonc': '^2.20.1', 'eslint-plugin-prettier': '^5.5.4', globals: '^16.3.0', jest: '^30.0.5', prettier: '^3.6.2', rimraf: '^6.0.1', 'source-map-support': '^0.5.21', 'ts-jest': '^29.4.1', 'ts-loader': '^9.5.2', 'ts-node': '^10.9.2', 'tsconfig-paths': '^4.2.0', typescript: '^5.9.2', }); // Create .prettierrc this.fs.copyTpl(this.templatePath('prettierrc.ejs'), this.destinationPath('.prettierrc')); // Create README.md this.fs.copyTpl(this.templatePath('README.md.ejs'), this.destinationPath('README.md'), { description: `Infrastructure definition using Octo for ${this.appName}`, name: this.appName, }); // Create tsconfig.json and tsconfig.build.json this.fs.copyTpl(this.templatePath('tsconfig.json.ejs'), this.destinationPath('tsconfig.json')); this.fs.copyTpl(this.templatePath('tsconfig.build.json.ejs'), this.destinationPath('tsconfig.build.json')); // Create .octo directory this.fs.copyTpl(this.templatePath(`gitkeep.ejs`), this.destinationPath('.octo/.gitkeep')); // Create src directory and main files if (this.appTemplate === 'aws-ecs-server') { const templatePath = `src/${this.appTemplate}`; this.fs.copyTpl(this.templatePath(`${templatePath}/app.config.ts.ejs`), this.destinationPath('src/app.config.ts')); this.fs.copyTpl(this.templatePath(`${templatePath}/env.ejs`), this.destinationPath('.env')); this.fs.copyTpl(this.templatePath(`${templatePath}/main.ts.ejs`), this.destinationPath('src/main.ts'), { name: this.appName, }); this.fs.copyTpl(this.templatePath(`${templatePath}/module-definitions.ts.ejs`), this.destinationPath('src/module-definitions.ts')); } else if (this.appTemplate === 'aws-s3-website') { const templatePath = `src/${this.appTemplate}`; this.fs.copyTpl(this.templatePath(`${templatePath}/website/error.html.ejs`), this.destinationPath('website/error.html'), { name: this.appName, }); this.fs.copyTpl(this.templatePath(`${templatePath}/website/index.html.ejs`), this.destinationPath('website/index.html'), { name: this.appName, }); this.fs.copyTpl(this.templatePath(`${templatePath}/app.config.ts.ejs`), this.destinationPath('src/app.config.ts')); this.fs.copyTpl(this.templatePath(`${templatePath}/env.ejs`), this.destinationPath('.env')); this.fs.copyTpl(this.templatePath(`${templatePath}/main.ts.ejs`), this.destinationPath('src/main.ts')); this.fs.copyTpl(this.templatePath(`${templatePath}/module-definitions.ts.ejs`), this.destinationPath('src/module-definitions.ts')); } else { throw new Error(`Unsupported app template: ${this.appTemplate}`); } } end() { const targetPath = resolve(join(this.appPath, this.appName)); this.log('✅ Your TypeScript app has been generated successfully!'); this.log(`📁 App created at: ${targetPath}`); this.log('📦 Next steps:'); this.log(` cd ${targetPath}`); this.log(' npm install'); this.log(' npm run build'); this.log(' npm start'); } } //# sourceMappingURL=index.js.map