|
1 | 1 | import chalk from 'chalk'; |
2 | 2 | import path from 'path'; |
| 3 | +import { promises as fs } from 'fs'; |
3 | 4 |
|
4 | 5 | export interface PackCoursesOptions { |
5 | 6 | server: string; |
@@ -39,6 +40,38 @@ export async function packCourses(options: PackCoursesOptions): Promise<void> { |
39 | 40 | }); |
40 | 41 |
|
41 | 42 | console.log(chalk.green(`✅ Successfully packed course: ${courseId}`)); |
| 43 | + |
| 44 | + // Create course-level skuilder.json for the packed course |
| 45 | + const coursePath = path.join(outputDir, courseId); |
| 46 | + const manifestPath = path.join(coursePath, 'manifest.json'); |
| 47 | + |
| 48 | + // Read the manifest to get course title |
| 49 | + let courseTitle = courseId; |
| 50 | + try { |
| 51 | + const manifestContent = await fs.readFile(manifestPath, 'utf-8'); |
| 52 | + const manifest = JSON.parse(manifestContent); |
| 53 | + courseTitle = manifest.courseName || manifest.courseConfig?.name || courseId; |
| 54 | + } catch (error) { |
| 55 | + console.warn(chalk.yellow(`⚠️ Could not read manifest for course title, using courseId`)); |
| 56 | + } |
| 57 | + |
| 58 | + // Create course-level skuilder.json |
| 59 | + const courseSkuilderJson = { |
| 60 | + name: `@skuilder/course-${courseId}`, |
| 61 | + version: '1.0.0', |
| 62 | + description: courseTitle, |
| 63 | + content: { |
| 64 | + type: 'static', |
| 65 | + manifest: './manifest.json', |
| 66 | + }, |
| 67 | + }; |
| 68 | + |
| 69 | + await fs.writeFile( |
| 70 | + path.join(coursePath, 'skuilder.json'), |
| 71 | + JSON.stringify(courseSkuilderJson, null, 2) |
| 72 | + ); |
| 73 | + |
| 74 | + console.log(chalk.gray(`📄 Created skuilder.json for course: ${courseId}`)); |
42 | 75 | } catch (error: unknown) { |
43 | 76 | console.error(chalk.red(`❌ Failed to pack course ${courseId}:`)); |
44 | 77 | console.error(chalk.red(error instanceof Error ? error.message : String(error))); |
|
0 commit comments