create-sonicjs 2.3.3 → 2.3.5
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.
- package/package.json +1 -1
- package/src/cli.js +23 -18
- package/templates/starter/README.md +1 -3
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -418,7 +418,7 @@ async function copyTemplate(templateName, targetDir, options) {
|
|
|
418
418
|
|
|
419
419
|
// Add @sonicjs-cms/core dependency
|
|
420
420
|
packageJson.dependencies = {
|
|
421
|
-
'@sonicjs-cms/core': '^2.3.
|
|
421
|
+
'@sonicjs-cms/core': '^2.3.5',
|
|
422
422
|
...packageJson.dependencies
|
|
423
423
|
}
|
|
424
424
|
|
|
@@ -451,7 +451,8 @@ async function copyTemplate(templateName, targetDir, options) {
|
|
|
451
451
|
async function createAdminSeedScript(targetDir, { email, password }) {
|
|
452
452
|
const seedScriptContent = `import { createDb, users } from '@sonicjs-cms/core'
|
|
453
453
|
import { eq } from 'drizzle-orm'
|
|
454
|
-
import
|
|
454
|
+
import * as crypto from 'crypto'
|
|
455
|
+
import { getPlatformProxy } from 'wrangler'
|
|
455
456
|
|
|
456
457
|
/**
|
|
457
458
|
* Seed script to create initial admin user
|
|
@@ -465,17 +466,11 @@ import bcrypt from 'bcryptjs'
|
|
|
465
466
|
* Password: [as entered during setup]
|
|
466
467
|
*/
|
|
467
468
|
|
|
468
|
-
interface Env {
|
|
469
|
-
DB: D1Database
|
|
470
|
-
}
|
|
471
|
-
|
|
472
469
|
async function seed() {
|
|
473
|
-
// Get D1 database from Cloudflare environment
|
|
474
|
-
|
|
475
|
-
const { env } = await import('@cloudflare/workers-types/experimental')
|
|
476
|
-
const platform = (env as any).getPlatformProxy?.() || { env: {} }
|
|
470
|
+
// Get D1 database from Cloudflare environment using wrangler's getPlatformProxy
|
|
471
|
+
const { env, dispose } = await getPlatformProxy()
|
|
477
472
|
|
|
478
|
-
if (!
|
|
473
|
+
if (!env?.DB) {
|
|
479
474
|
console.error('❌ Error: DB binding not found')
|
|
480
475
|
console.error('')
|
|
481
476
|
console.error('Make sure you have:')
|
|
@@ -486,7 +481,7 @@ async function seed() {
|
|
|
486
481
|
process.exit(1)
|
|
487
482
|
}
|
|
488
483
|
|
|
489
|
-
const db = createDb(
|
|
484
|
+
const db = createDb(env.DB)
|
|
490
485
|
|
|
491
486
|
try {
|
|
492
487
|
// Check if admin user already exists
|
|
@@ -503,20 +498,26 @@ async function seed() {
|
|
|
503
498
|
return
|
|
504
499
|
}
|
|
505
500
|
|
|
506
|
-
// Hash password using
|
|
507
|
-
const
|
|
501
|
+
// Hash password using SHA-256 (same as SonicJS auth system)
|
|
502
|
+
const data = '${password}' + 'salt-change-in-production'
|
|
503
|
+
const passwordHash = crypto.createHash('sha256').update(data).digest('hex')
|
|
504
|
+
const now = Date.now()
|
|
505
|
+
const odid = \`admin-\${now}-\${Math.random().toString(36).substr(2, 9)}\`
|
|
508
506
|
|
|
509
507
|
// Create admin user
|
|
510
508
|
await db
|
|
511
509
|
.insert(users)
|
|
512
510
|
.values({
|
|
511
|
+
id: odid,
|
|
513
512
|
email: '${email}',
|
|
514
513
|
username: '${email.split('@')[0]}',
|
|
515
|
-
|
|
514
|
+
firstName: 'Admin',
|
|
515
|
+
lastName: 'User',
|
|
516
|
+
passwordHash: passwordHash,
|
|
516
517
|
role: 'admin',
|
|
517
|
-
isActive:
|
|
518
|
-
createdAt:
|
|
519
|
-
updatedAt:
|
|
518
|
+
isActive: true,
|
|
519
|
+
createdAt: now,
|
|
520
|
+
updatedAt: now
|
|
520
521
|
})
|
|
521
522
|
.run()
|
|
522
523
|
|
|
@@ -527,8 +528,12 @@ async function seed() {
|
|
|
527
528
|
console.log('You can now login at: http://localhost:8787/auth/login')
|
|
528
529
|
} catch (error) {
|
|
529
530
|
console.error('❌ Error creating admin user:', error)
|
|
531
|
+
await dispose()
|
|
530
532
|
process.exit(1)
|
|
531
533
|
}
|
|
534
|
+
|
|
535
|
+
// Clean up the platform proxy
|
|
536
|
+
await dispose()
|
|
532
537
|
}
|
|
533
538
|
|
|
534
539
|
// Run seed
|
|
@@ -42,9 +42,7 @@ A modern headless CMS built with [SonicJS](https://sonicjs.com) on Cloudflare's
|
|
|
42
42
|
6. **Open your browser:**
|
|
43
43
|
Navigate to `http://localhost:8787/admin` to access the admin interface.
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
- Email: `admin@sonicjs.com`
|
|
47
|
-
- Password: `admin`
|
|
45
|
+
Use the admin credentials you provided during project setup.
|
|
48
46
|
|
|
49
47
|
## Project Structure
|
|
50
48
|
|