kempo 4.2.13 → 4.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cli.js +32 -7
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -31,7 +31,7 @@ const projectName = basename(projectDir);
31
31
  */
32
32
 
33
33
  const generatePassword = () => {
34
- const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789!@#$%&*';
34
+ const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789-_';
35
35
  return Array.from(
36
36
  { length: 16 },
37
37
  () => chars[crypto.randomInt(chars.length)]
@@ -62,11 +62,11 @@ const getPostgresContainers = () => {
62
62
  }
63
63
  };
64
64
 
65
- const waitForPostgres = async (containerName) => {
65
+ const waitForPostgres = async (containerName, dbName = 'postgres') => {
66
66
  process.stdout.write('Waiting for Postgres to be ready');
67
67
  for(let i = 0; i < 30; i++){
68
68
  try {
69
- execSync(`docker exec ${containerName} pg_isready -U kempo -d kempo`, { stdio: 'ignore' });
69
+ execSync(`docker exec ${containerName} pg_isready -U kempo -d ${dbName}`, { stdio: 'ignore' });
70
70
  process.stdout.write(' ready!\n');
71
71
  return;
72
72
  } catch {
@@ -404,6 +404,21 @@ execSync('npm install kempo', { cwd: projectDir, stdio: 'inherit' });
404
404
  console.log('\n--- Starting database ---\n');
405
405
 
406
406
  if(containerMode === 'new'){
407
+ const volumeName = `${dbName}_postgres_data`;
408
+
409
+ try {
410
+ execSync(`docker stop ${containerName}`, { stdio: 'ignore' });
411
+ execSync(`docker rm ${containerName}`, { stdio: 'ignore' });
412
+ } catch {
413
+ // Container doesn't exist, that's fine
414
+ }
415
+
416
+ try {
417
+ execSync(`docker volume rm ${volumeName}`, { stdio: 'ignore' });
418
+ } catch {
419
+ // Volume doesn't exist, that's fine
420
+ }
421
+
407
422
  const compose = spawnSync('docker', ['compose', 'up', '-d'], {
408
423
  cwd: projectDir,
409
424
  stdio: 'inherit',
@@ -414,12 +429,12 @@ if(containerMode === 'new'){
414
429
  printManualSteps(databaseUrl);
415
430
  process.exit(1);
416
431
  }
417
- await waitForPostgres(containerName);
432
+ await waitForPostgres(containerName, 'postgres');
418
433
  } else {
419
434
  const container = existingContainers.find(c => c.name === containerName);
420
435
  if(container && !container.running){
421
436
  execSync(`docker start ${containerName}`, { stdio: 'inherit' });
422
- await waitForPostgres(containerName);
437
+ await waitForPostgres(containerName, 'postgres');
423
438
  }
424
439
  }
425
440
 
@@ -429,14 +444,24 @@ if(containerMode === 'new'){
429
444
 
430
445
  console.log('\n--- Initializing database ---\n');
431
446
 
447
+ // Give database plenty of time to fully initialize
448
+ await new Promise(r => setTimeout(r, 30000));
449
+
432
450
  // Clear migration snapshots so drizzle-kit push compares against the live DB only
433
451
  const migrationDir = join(projectDir, 'server', 'db', 'migrations');
434
452
  if(existsSync(migrationDir)){
435
453
  rmSync(migrationDir, { recursive: true, force: true });
436
454
  }
437
455
 
438
- execSync('npx drizzle-kit push --force', { cwd: projectDir, stdio: 'inherit' });
439
- execSync('node node_modules/kempo/scripts/init-db.js', { cwd: projectDir, stdio: 'inherit' });
456
+ const drizzleResult = spawnSync('npx', ['drizzle-kit', 'push', '--force'], { cwd: projectDir, stdio: 'inherit', env: { ...process.env, DATABASE_URL: databaseUrl }, shell: true });
457
+ if(drizzleResult.status !== 0){
458
+ console.error('\n❌ Drizzle push failed. DATABASE_URL: ' + databaseUrl);
459
+ console.error('Container: ' + containerName);
460
+ console.error('Check: docker logs ' + containerName + '\n');
461
+ process.exit(1);
462
+ }
463
+
464
+ execSync('node node_modules/kempo/scripts/init-db.js', { cwd: projectDir, stdio: 'inherit', env: { ...process.env, DATABASE_URL: databaseUrl } });
440
465
 
441
466
  /*
442
467
  Step 8: Create admin user
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kempo",
3
- "version": "4.2.13",
3
+ "version": "4.2.15",
4
4
  "type": "module",
5
5
  "description": "A fullstack CMS framework for creating websites with user authentication",
6
6
  "scripts": {