UNPKG

nhb-express

Version:

Minimal Express + TypeScript scaffolder with modular structure and flexible stack choices.

67 lines (60 loc) 2.07 kB
// @ts-check import { defineScriptConfig, parsePackageJson, runExeca } from 'nhb-scripts'; import { expressPrismaPostgresTemplate } from './scripts/moduleTemplate.mjs'; import { updatePrismaSchema } from './scripts/updateSchema.mjs'; import { updateCollection, updateRoutes } from './scripts/updateTemplate.mjs'; export default defineScriptConfig({ format: { args: ['--write'], files: ['src', 'nhb.scripts.config.mjs'], ignorePath: '.prettierignore', }, lint: { folders: ['src'], patterns: ['**/*.ts'] }, fix: { folders: ['src'], patterns: ['**/*.ts'] }, commit: { runFormatter: !!parsePackageJson()?.devDependencies?.prettier, emojiBeforePrefix: true, wrapPrefixWith: '`', }, build: { distFolder: 'dist', commands: [{ cmd: 'tsc' }, { cmd: 'tsc-alias' }], waitingMessage: ' 📦 Building Your Express Application...', }, count: { defaultPath: 'src', excludePaths: ['node_modules', 'dist', 'generated', 'prisma', 'public'], }, module: { force: false, destination: 'src/app/modules', defaultTemplate: 'express-prisma-postgres', templates: { 'express-prisma-postgres': { createFolder: true, destination: 'src/app/modules', files: expressPrismaPostgresTemplate, onComplete: async (moduleName) => { updatePrismaSchema(moduleName); updateCollection(moduleName); updateRoutes(moduleName, true); await runPrismaMigration(moduleName); }, }, }, }, }); /** * * Run Prisma migration related commands. * @param {string} schemaName Name of the schema to append with the migration filename. */ async function runPrismaMigration(schemaName) { /** @type {{ stdout: 'inherit', stderr: 'inherit', stdin: 'inherit' }} */ const options = { stdout: 'inherit', stderr: 'inherit', stdin: 'inherit' }; // Regenerate Prisma Client await runExeca('prisma', ['generate'], options); // Reset DB & migration history await runExeca('prisma', ['migrate', 'reset', '--force'], options); // Create new baseline migration await runExeca('prisma', ['migrate', 'dev', '--name', schemaName], options); }