Skip to content

Commit 80567ca

Browse files
authored
Add skuilder.json generation to pack operations (#957)
Completes the work from PR #950 by ensuring all pack operations (CLI pack command, Express pack endpoint, and CLI pack-courses utility) generate course-level skuilder.json files. Previously only the pack-courses utility (used by skuilder init) created skuilder.json. This caused inconsistencies where courses packed via: - studio-ui flush button (Express endpoint) - missing skuilder.json - skuilder pack command (CLI) - missing skuilder.json Now all pack operations consistently create skuilder.json with the hierarchical manifest structure introduced in PR #950. Changes: - packages/express/src/client-requests/pack-requests.ts: Add skuilder.json generation after packing - packages/cli/src/commands/pack.ts: Add skuilder.json generation after packing Fixes: Packed courses now match the expected structure for StaticDataLayerProvider
2 parents 0cbb957 + 52ff966 commit 80567ca

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

packages/cli/src/commands/pack.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ export async function packCourse(courseId: string, options: PackOptions) {
8888
// Write files
8989
await writePackedData(packedData, outputDir);
9090

91+
// Create course-level skuilder.json for the packed course
92+
const courseTitle = packedData.manifest.courseName || packedData.manifest.courseId || courseId;
93+
const courseSkuilderJson = {
94+
name: `@skuilder/course-${courseId}`,
95+
version: '1.0.0',
96+
description: courseTitle,
97+
content: {
98+
type: 'static',
99+
manifest: './manifest.json',
100+
},
101+
};
102+
103+
await fs.writeJson(
104+
path.join(outputDir, 'skuilder.json'),
105+
courseSkuilderJson,
106+
{ spaces: 2 }
107+
);
108+
console.log(chalk.gray(`📄 Created skuilder.json`));
109+
91110
// Success summary
92111
console.log(chalk.green('\n✅ Successfully packed course!'));
93112
console.log(chalk.white(`📊 Course: ${packedData.manifest.courseName}`));

packages/express/src/client-requests/pack-requests.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,51 @@ export async function packCourse(data: PackCourseData): Promise<PackCourseRespon
170170
logger.info(`Using originalCourseId "${originalCourseId}" for manifest (extracted from "${data.courseId}")`);
171171

172172
const packResult = await packer.packCourseToFiles(courseDb, originalCourseId, outputPath, fsAdapter);
173-
173+
174+
// Create course-level skuilder.json for the packed course
175+
const pathModule = await import('path');
176+
const path = pathModule.default || pathModule;
177+
const manifestPath = path.join(outputPath, 'manifest.json');
178+
179+
// Read the manifest to get course title
180+
let courseTitle = originalCourseId;
181+
try {
182+
const manifestContent = await fsAdapter.readFile(manifestPath);
183+
const manifest = JSON.parse(manifestContent);
184+
courseTitle = manifest.courseName || manifest.courseConfig?.name || originalCourseId;
185+
} catch (error) {
186+
logger.warn(`Could not read manifest for course title, using courseId: ${error}`);
187+
}
188+
189+
// Create course-level skuilder.json
190+
const courseSkuilderJson = {
191+
name: `@skuilder/course-${originalCourseId}`,
192+
version: '1.0.0',
193+
description: courseTitle,
194+
content: {
195+
type: 'static',
196+
manifest: './manifest.json',
197+
},
198+
};
199+
200+
const skuilderJsonPath = path.join(outputPath, 'skuilder.json');
201+
await fsAdapter.writeJson(skuilderJsonPath, courseSkuilderJson, { spaces: 2 });
202+
logger.info(`Created skuilder.json for course: ${originalCourseId}`);
203+
174204
const duration = Date.now() - startTime;
175-
205+
176206
const response: PackCourseResponse = {
177207
status: Status.ok,
178208
ok: true,
179209
outputPath: outputPath,
180210
attachmentsFound: packResult.attachmentsFound,
181-
filesWritten: packResult.filesWritten,
182-
totalFiles: packResult.filesWritten, // Updated to reflect actual files written
211+
filesWritten: packResult.filesWritten + 1, // +1 for skuilder.json
212+
totalFiles: packResult.filesWritten + 1, // Updated to reflect actual files written including skuilder.json
183213
duration: duration
184214
};
185-
215+
186216
logger.info(`Pack completed in ${duration}ms. Attachments: ${response.attachmentsFound}, Files written: ${response.filesWritten}`);
187-
217+
188218
return response;
189219
} catch (error) {
190220
logger.error('Pack operation failed:', error);

0 commit comments

Comments
 (0)