Skip to content

Commit 53b4810

Browse files
authored
stdio dbg 2 (#822)
- **add uuid dep** - **add: writing an empty course for no-import static** - **add helper info**
2 parents bbe75a0 + 9722924 commit 53b4810

File tree

4 files changed

+108
-10
lines changed

4 files changed

+108
-10
lines changed

dev.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# test db courseIDs
2+
3+
2aeb8315ef78f3e89ca386992d00825b Go (Programming Language)
4+
4a3bf3a147365a47ab8ab097b300028d Ethereum
5+
641e9a99d9d21303c9a0b0fa24000b82 Linux Command Line
6+
787bc0d25821da0abb503a3b8b027f8d JavaScript
7+
a9fae15687220aa6ce6201800502a3fd TypeScript
8+
a9fae15687220aa6ce62018005040a8f HTTP Status Codes
9+
a9fae15687220aa6ce62018005087c95 Emily
10+
e833171dd37e2945964962457700fb72 Word Work
11+
e92135c6c3ba6fba79367e7f26001ef3 Anatomy
12+
ed1d504ee2aa71872a7088db6c01fa6f Piano (by ear)

packages/cli/src/utils/template.ts

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { promises as fs, existsSync } from 'fs';
22
import path from 'path';
33
import { fileURLToPath } from 'url';
4+
import { randomUUID } from 'crypto';
45
import chalk from 'chalk';
56
import { ProjectConfig, SkuilderConfig } from '../types.js';
7+
import { CourseConfig } from '@vue-skuilder/common';
68

79
const __filename = fileURLToPath(import.meta.url);
810
const __dirname = path.dirname(__filename);
@@ -182,7 +184,8 @@ export default defineConfig({
182184
*/
183185
export async function generateSkuilderConfig(
184186
configPath: string,
185-
config: ProjectConfig
187+
config: ProjectConfig,
188+
outputPath?: string
186189
): Promise<void> {
187190
const skuilderConfig: SkuilderConfig = {
188191
title: config.title,
@@ -194,13 +197,14 @@ export async function generateSkuilderConfig(
194197
skuilderConfig.course = config.course;
195198
}
196199

197-
// For static data layer with imported courses, use the first course as primary
198-
if (
199-
config.dataLayerType === 'static' &&
200-
config.importCourseIds &&
201-
config.importCourseIds.length > 0
202-
) {
203-
skuilderConfig.course = config.importCourseIds[0];
200+
// For static data layer, use imported course ID or generate new one
201+
if (config.dataLayerType === 'static') {
202+
if (config.importCourseIds && config.importCourseIds.length > 0) {
203+
skuilderConfig.course = config.importCourseIds[0];
204+
} else {
205+
// Generate UUID for new static courses without imports
206+
skuilderConfig.course = randomUUID();
207+
}
204208
}
205209

206210
if (config.couchdbUrl) {
@@ -212,6 +216,11 @@ export async function generateSkuilderConfig(
212216
}
213217

214218
await fs.writeFile(configPath, JSON.stringify(skuilderConfig, null, 2));
219+
220+
// For static data layer without imports, create empty course structure
221+
if (config.dataLayerType === 'static' && (!config.importCourseIds || config.importCourseIds.length === 0) && outputPath) {
222+
await createEmptyCourseStructure(outputPath, skuilderConfig.course!, config.title);
223+
}
215224
}
216225

217226
/**
@@ -250,6 +259,72 @@ export async function transformTsConfig(tsconfigPath: string): Promise<void> {
250259
await fs.writeFile(tsconfigPath, JSON.stringify(tsconfig, null, 2));
251260
}
252261

262+
/**
263+
* Create empty course structure for new static courses
264+
*/
265+
async function createEmptyCourseStructure(
266+
projectPath: string,
267+
courseId: string,
268+
title: string
269+
): Promise<void> {
270+
const staticCoursesPath = path.join(projectPath, 'public', 'static-courses');
271+
const coursePath = path.join(staticCoursesPath, courseId);
272+
273+
// Create directory structure
274+
await fs.mkdir(coursePath, { recursive: true });
275+
await fs.mkdir(path.join(coursePath, 'chunks'), { recursive: true });
276+
await fs.mkdir(path.join(coursePath, 'indices'), { recursive: true });
277+
278+
// Create minimal CourseConfig
279+
const courseConfig: CourseConfig = {
280+
courseID: courseId,
281+
name: title,
282+
description: '',
283+
public: false,
284+
deleted: false,
285+
creator: 'system',
286+
admins: [],
287+
moderators: [],
288+
dataShapes: [],
289+
questionTypes: []
290+
};
291+
292+
// Create manifest.json with proper structure
293+
const manifest = {
294+
version: '1.0.0',
295+
courseId,
296+
courseName: title,
297+
courseConfig,
298+
lastUpdated: new Date().toISOString(),
299+
documentCount: 0,
300+
chunks: [],
301+
indices: [],
302+
designDocs: []
303+
};
304+
305+
await fs.writeFile(
306+
path.join(coursePath, 'manifest.json'),
307+
JSON.stringify(manifest, null, 2)
308+
);
309+
310+
// Create empty tags index
311+
await fs.writeFile(
312+
path.join(coursePath, 'indices', 'tags.json'),
313+
JSON.stringify({ tags: [] }, null, 2)
314+
);
315+
316+
// Create CourseConfig chunk
317+
await fs.writeFile(
318+
path.join(coursePath, 'chunks', 'CourseConfig.json'),
319+
JSON.stringify([{
320+
_id: 'CourseConfig',
321+
...courseConfig
322+
}], null, 2)
323+
);
324+
325+
console.log(chalk.green(`✅ Created empty course structure for ${courseId}`));
326+
}
327+
253328
/**
254329
* Generate .gitignore file for the project
255330
*/
@@ -540,7 +615,7 @@ export async function processTemplate(
540615

541616
console.log(chalk.blue('🔧 Generating configuration...'));
542617
const configPath = path.join(projectPath, 'skuilder.config.json');
543-
await generateSkuilderConfig(configPath, config);
618+
await generateSkuilderConfig(configPath, config, projectPath);
544619

545620
console.log(chalk.blue('📝 Creating README...'));
546621
const readmePath = path.join(projectPath, 'README.md');

packages/db/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"@vue-skuilder/common": "workspace:*",
4949
"moment": "^2.29.4",
5050
"pouchdb": "^9.0.0",
51-
"pouchdb-find": "^9.0.0"
51+
"pouchdb-find": "^9.0.0",
52+
"uuid": "^11.1.0"
5253
},
5354
"devDependencies": {
5455
"@types/uuid": "^10.0.0",

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5400,6 +5400,7 @@ __metadata:
54005400
pouchdb-find: "npm:^9.0.0"
54015401
tsup: "npm:^8.0.2"
54025402
typescript: "npm:~5.7.2"
5403+
uuid: "npm:^11.1.0"
54035404
languageName: unknown
54045405
linkType: soft
54055406

@@ -16425,6 +16426,15 @@ __metadata:
1642516426
languageName: node
1642616427
linkType: hard
1642716428

16429+
"uuid@npm:^11.1.0":
16430+
version: 11.1.0
16431+
resolution: "uuid@npm:11.1.0"
16432+
bin:
16433+
uuid: dist/esm/bin/uuid
16434+
checksum: 10c0/34aa51b9874ae398c2b799c88a127701408cd581ee89ec3baa53509dd8728cbb25826f2a038f9465f8b7be446f0fbf11558862965b18d21c993684297628d4d3
16435+
languageName: node
16436+
linkType: hard
16437+
1642816438
"v8-compile-cache-lib@npm:^3.0.1":
1642916439
version: 3.0.1
1643016440
resolution: "v8-compile-cache-lib@npm:3.0.1"

0 commit comments

Comments
 (0)