UNPKG

create-sekiban-app

Version:

Create a new Sekiban application with Dapr

75 lines (60 loc) 2.38 kB
#!/usr/bin/env node import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; import { promises as fs } from 'fs'; import { execSync } from 'child_process'; const __dirname = dirname(fileURLToPath(import.meta.url)); async function createApp(projectName) { const targetDir = join(process.cwd(), projectName); console.log(`Creating a new Sekiban app in ${targetDir}...`); // Create target directory await fs.mkdir(targetDir, { recursive: true }); // Copy template files const templateDir = join(__dirname, 'template'); await copyDir(templateDir, targetDir); // Update package.json with project name const packageJsonPath = join(targetDir, 'package.json'); const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8')); packageJson.name = projectName; await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)); console.log('\nInstalling dependencies...'); execSync('pnpm install', { cwd: targetDir, stdio: 'inherit' }); console.log('\n✅ Success! Created', projectName, 'at', targetDir); console.log('\nInside that directory, you can run several commands:'); console.log('\n pnpm build'); console.log(' Builds all packages'); console.log('\n pnpm dev'); console.log(' Starts the development server'); console.log('\n pnpm dapr:start'); console.log(' Starts all services with Dapr'); console.log('\n pnpm test'); console.log(' Runs the test suite'); console.log('\nWe suggest that you begin by typing:'); console.log(`\n cd ${projectName}`); console.log(' pnpm build'); console.log(' pnpm dev'); } async function copyDir(src, dest) { await fs.mkdir(dest, { recursive: true }); const entries = await fs.readdir(src, { withFileTypes: true }); for (const entry of entries) { const srcPath = join(src, entry.name); const destPath = join(dest, entry.name); if (entry.isDirectory()) { await copyDir(srcPath, destPath); } else { await fs.copyFile(srcPath, destPath); } } } // Main execution const projectName = process.argv[2]; if (!projectName) { console.error('Please specify the project directory:'); console.error(' npx create-sekiban-app my-app'); process.exit(1); } createApp(projectName).catch((error) => { console.error('Error creating app:', error); process.exit(1); });