spine-framework 0.1.45 → 0.1.46
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.
|
@@ -28,9 +28,10 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import type { Command } from 'commander'
|
|
31
|
-
import { existsSync, readFileSync, readdirSync } from 'fs'
|
|
31
|
+
import { existsSync, readFileSync, readdirSync, cpSync, mkdirSync } from 'fs'
|
|
32
32
|
import { resolve, dirname } from 'path'
|
|
33
33
|
import { fileURLToPath } from 'url'
|
|
34
|
+
import { execSync } from 'child_process'
|
|
34
35
|
import { adminDb } from '../../functions/_shared/index.ts'
|
|
35
36
|
|
|
36
37
|
const __filename = fileURLToPath(import.meta.url)
|
|
@@ -286,14 +287,120 @@ async function recordInstallation(appSlug: string, accountId: string | null, dry
|
|
|
286
287
|
}
|
|
287
288
|
}
|
|
288
289
|
|
|
290
|
+
function isNpmPackage(slug: string): boolean {
|
|
291
|
+
return slug.includes('/') || slug.startsWith('spine-framework-') || slug.startsWith('@')
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function resolveSlugFromPackage(pkg: string): string {
|
|
295
|
+
const manifest = resolve(PROJECT_ROOT, `node_modules/${pkg}/spine-manifest.json`)
|
|
296
|
+
if (existsSync(manifest)) {
|
|
297
|
+
try {
|
|
298
|
+
return JSON.parse(readFileSync(manifest, 'utf8')).slug
|
|
299
|
+
} catch { /* fall through */ }
|
|
300
|
+
}
|
|
301
|
+
const pkgJson = resolve(PROJECT_ROOT, `node_modules/${pkg}/package.json`)
|
|
302
|
+
if (existsSync(pkgJson)) {
|
|
303
|
+
try {
|
|
304
|
+
const meta = JSON.parse(readFileSync(pkgJson, 'utf8'))
|
|
305
|
+
if (meta.spine?.slug) return meta.spine.slug
|
|
306
|
+
} catch { /* fall through */ }
|
|
307
|
+
}
|
|
308
|
+
return pkg.replace(/^spine-framework-/, '').replace(/^@[^/]+\//, '')
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async function checkPrerequisites(slug: string): Promise<void> {
|
|
312
|
+
const PREREQS: Record<string, string[]> = {
|
|
313
|
+
'customer-portal': ['cortex'],
|
|
314
|
+
}
|
|
315
|
+
const required = PREREQS[slug]
|
|
316
|
+
if (!required || required.length === 0) return
|
|
317
|
+
|
|
318
|
+
for (const prereq of required) {
|
|
319
|
+
const { data } = await adminDb
|
|
320
|
+
.from('app_installations')
|
|
321
|
+
.select('id')
|
|
322
|
+
.eq('app_slug', prereq)
|
|
323
|
+
.eq('is_enabled', true)
|
|
324
|
+
.maybeSingle()
|
|
325
|
+
|
|
326
|
+
if (!data) {
|
|
327
|
+
console.error(` ❌ Prerequisite not installed: '${prereq}'`)
|
|
328
|
+
console.error(` Run: spine-framework install-app spine-framework-${prereq}`)
|
|
329
|
+
process.exit(1)
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function copyAppFiles(pkg: string, slug: string): void {
|
|
335
|
+
const pkgDir = resolve(PROJECT_ROOT, `node_modules/${pkg}`)
|
|
336
|
+
const appDirs = ['pages', 'components', 'seed', 'api']
|
|
337
|
+
const appFiles = ['index.tsx', 'manifest.json', 'package.json']
|
|
338
|
+
const targetAppDir = resolve(PROJECT_ROOT, `custom/apps/${slug}`)
|
|
339
|
+
const targetFunctionsDir = resolve(PROJECT_ROOT, 'custom/functions')
|
|
340
|
+
|
|
341
|
+
mkdirSync(targetAppDir, { recursive: true })
|
|
342
|
+
mkdirSync(targetFunctionsDir, { recursive: true })
|
|
343
|
+
|
|
344
|
+
for (const file of appFiles) {
|
|
345
|
+
const src = resolve(pkgDir, file)
|
|
346
|
+
if (existsSync(src)) {
|
|
347
|
+
cpSync(src, resolve(targetAppDir, file), { force: true })
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
for (const dir of appDirs) {
|
|
352
|
+
const src = resolve(pkgDir, dir)
|
|
353
|
+
if (existsSync(src)) {
|
|
354
|
+
cpSync(src, resolve(targetAppDir, dir), { recursive: true, force: true })
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const functionsDir = resolve(pkgDir, 'functions')
|
|
359
|
+
if (existsSync(functionsDir)) {
|
|
360
|
+
cpSync(functionsDir, targetFunctionsDir, { recursive: true, force: true })
|
|
361
|
+
const count = readdirSync(targetFunctionsDir).filter(f => f.endsWith('.ts')).length
|
|
362
|
+
console.log(` ✓ Copied functions (${count} files) → custom/functions/`)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
console.log(` ✓ Ejected app files → custom/apps/${slug}/`)
|
|
366
|
+
}
|
|
367
|
+
|
|
289
368
|
async function installApp(slug: string, options: InstallOptions): Promise<void> {
|
|
290
369
|
console.log(`\n📦 Installing app '${slug}'...\n`)
|
|
291
370
|
|
|
292
|
-
|
|
293
|
-
|
|
371
|
+
let resolvedSlug = slug
|
|
372
|
+
let packageName: string | null = null
|
|
373
|
+
|
|
374
|
+
if (isNpmPackage(slug)) {
|
|
375
|
+
packageName = slug
|
|
376
|
+
console.log(`📥 Step 1: Installing npm package...`)
|
|
377
|
+
const pkgDir = resolve(PROJECT_ROOT, `node_modules/${slug}`)
|
|
378
|
+
if (!existsSync(pkgDir)) {
|
|
379
|
+
try {
|
|
380
|
+
console.log(` Running: npm install ${slug}`)
|
|
381
|
+
execSync(`npm install ${slug}`, { cwd: PROJECT_ROOT, stdio: 'inherit' })
|
|
382
|
+
console.log(` ✓ Package installed`)
|
|
383
|
+
} catch (err: any) {
|
|
384
|
+
console.error(` ❌ npm install failed: ${err.message}`)
|
|
385
|
+
process.exit(1)
|
|
386
|
+
}
|
|
387
|
+
} else {
|
|
388
|
+
console.log(` ⏭️ Package already in node_modules`)
|
|
389
|
+
}
|
|
390
|
+
resolvedSlug = resolveSlugFromPackage(slug)
|
|
391
|
+
console.log(` ✓ App slug: ${resolvedSlug}`)
|
|
392
|
+
|
|
393
|
+
console.log(`\n📁 Step 2: Ejecting app files...`)
|
|
394
|
+
copyAppFiles(slug, resolvedSlug)
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Check prerequisites (e.g. portal requires cortex)
|
|
398
|
+
await checkPrerequisites(resolvedSlug)
|
|
399
|
+
|
|
400
|
+
const appDir = resolve(PROJECT_ROOT, `custom/apps/${resolvedSlug}`)
|
|
294
401
|
if (!existsSync(appDir)) {
|
|
295
|
-
console.error(` ❌ App directory not found: custom/apps/${
|
|
296
|
-
console.error(` Install the npm package first or create the app with 'spine-framework create-app ${
|
|
402
|
+
console.error(` ❌ App directory not found: custom/apps/${resolvedSlug}`)
|
|
403
|
+
console.error(` Install the npm package first or create the app with 'spine-framework create-app ${resolvedSlug}'`)
|
|
297
404
|
process.exit(1)
|
|
298
405
|
}
|
|
299
406
|
|
|
@@ -313,7 +420,7 @@ async function installApp(slug: string, options: InstallOptions): Promise<void>
|
|
|
313
420
|
}
|
|
314
421
|
|
|
315
422
|
// 3. Ensure app record in DB
|
|
316
|
-
const appId = await ensureAppRecord(
|
|
423
|
+
const appId = await ensureAppRecord(resolvedSlug, appName)
|
|
317
424
|
|
|
318
425
|
// 4. Process seed files
|
|
319
426
|
const seedDir = resolve(appDir, 'seed')
|
|
@@ -364,12 +471,12 @@ async function installApp(slug: string, options: InstallOptions): Promise<void>
|
|
|
364
471
|
|
|
365
472
|
// 5. Record installation
|
|
366
473
|
console.log(`\n📝 Recording installation...`)
|
|
367
|
-
await recordInstallation(
|
|
474
|
+
await recordInstallation(resolvedSlug, options.account || null, options.dryRun)
|
|
368
475
|
|
|
369
476
|
console.log(`\n✅ App '${appName}' installed successfully!`)
|
|
370
477
|
console.log(`\n Next steps:`)
|
|
371
478
|
console.log(` 1. npm run assemble && netlify dev`)
|
|
372
|
-
console.log(` 2. Navigate to /${
|
|
479
|
+
console.log(` 2. Navigate to /${resolvedSlug} in your browser`)
|
|
373
480
|
}
|
|
374
481
|
|
|
375
482
|
export function registerInstallAppCommands(program: Command) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install-app.d.ts","sourceRoot":"","sources":["../../../.framework/cli/commands/install-app.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"install-app.d.ts","sourceRoot":"","sources":["../../../.framework/cli/commands/install-app.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAocxC,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,QAgB1D"}
|