Skip to content

Commit b72b1cb

Browse files
fixed multiple errors in server vs. cli
1 parent 588bd64 commit b72b1cb

11 files changed

Lines changed: 749 additions & 132 deletions

File tree

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/server/presets.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ presets:
2323
- id: ilias
2424
name: ILIAS
2525
logo: 📚
26-
format: scorm12
26+
format: scorm1.2
2727
subtitle: SCORM 1.2
2828
description: >
2929
ILIAS ist ein leistungsstarkes Open-Source-LMS aus Deutschland.
@@ -38,7 +38,7 @@ presets:
3838
typicalDuration: "PT0H5M0S"
3939
scormIframe: true # Oft besser für ILIAS
4040
scormEmbed: false
41-
format: scorm12
41+
format: scorm1.2
4242

4343
- id: opal
4444
name: OPAL

dist/server/public/app.js

Lines changed: 542 additions & 1 deletion
Large diffs are not rendered by default.

dist/server/public/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="de">
33
<head>
44
<meta charset="UTF-8" />
@@ -151,7 +151,7 @@ <h2>2. Export-Ziel</h2>
151151
<input
152152
type="radio"
153153
name="format"
154-
value="scorm12"
154+
value="scorm1.2"
155155
data-description="E-Learning-Standard für Lernmanagementsysteme. Weit verbreitet, aber älter. Geeignet für ältere LMS-Plattformen. <a href='https://de.wikipedia.org/wiki/Sharable_Content_Object_Reference_Model' target='_blank'>Mehr erfahren</a>"
156156
/>
157157
<div class="preset-content">
@@ -317,7 +317,7 @@ <h2>
317317
<!-- SCORM Settings -->
318318
<div
319319
class="settings-group"
320-
data-formats="scorm12,scorm2004,moodle,ilias,opal,generic,openolat,openedx"
320+
data-formats="scorm1.2,scorm2004,moodle,ilias,opal,generic,openolat,openedx"
321321
>
322322
<h3 class="settings-heading">SCORM Einstellungen</h3>
323323

src/export/rdf.ts

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ interface LiaDefinition {
3535
}
3636
}
3737

38-
interface LiaJSON {
39-
lia: {
40-
str_title: string
41-
definition: LiaDefinition
42-
}
43-
}
44-
4538
interface SchemaDoc {
4639
[key: string]: any
4740
}
@@ -82,7 +75,7 @@ export function help() {
8275
console.log(COLOR.heading('RDF settings:'), '\n')
8376

8477
COLOR.info(
85-
'RDF (Resource Description Framework) export generates structured metadata for your LiaScript course or your project-yaml in standard linked data formats. This helps with course discovery and enables semantic web applications to understand your content. Available output formats are n-quads and JSON-LD.'
78+
'RDF (Resource Description Framework) export generates structured metadata for your LiaScript course or your project-yaml in standard linked data formats. This helps with course discovery and enables semantic web applications to understand your content. Available output formats are n-quads and JSON-LD.',
8679
)
8780

8881
console.log('\nLearn more:')
@@ -94,37 +87,37 @@ export function help() {
9487
COLOR.command(
9588
null,
9689
'--rdf-format',
97-
' Output format n-quads, json-ld (defaults to json-ld).'
90+
' Output format n-quads, json-ld (defaults to json-ld).',
9891
)
9992
COLOR.command(
10093
null,
10194
'--rdf-preview',
102-
' Output the result to the console.'
95+
' Output the result to the console.',
10396
)
10497
COLOR.command(
10598
null,
10699
'--rdf-url',
107-
' Refer to an external URL when parsing a local project.'
100+
' Refer to an external URL when parsing a local project.',
108101
)
109102
COLOR.command(
110103
null,
111104
'--rdf-type',
112-
' Course from schema.org is applied as default, overwrite this with EducationalResource, etc.'
105+
' Course from schema.org is applied as default, overwrite this with EducationalResource, etc.',
113106
)
114107
COLOR.command(
115108
null,
116109
'--rdf-license',
117-
' Add a license-URL, otherwise if url was provided as input, this will check for an existing LICENSE file.'
110+
' Add a license-URL, otherwise if url was provided as input, this will check for an existing LICENSE file.',
118111
)
119112
COLOR.command(
120113
null,
121114
'--rdf-educationalLevel',
122-
' Typically beginner, intermediate or advanced, and formal sets of level indicators.'
115+
' Typically beginner, intermediate or advanced, and formal sets of level indicators.',
123116
)
124117
COLOR.command(
125118
null,
126119
'--rdf-template',
127-
' Use a URL or json-file as a template.'
120+
' Use a URL or json-file as a template.',
128121
)
129122
}
130123

@@ -147,7 +140,7 @@ export const format = 'rdf'
147140
*/
148141
export async function exporter(
149142
argument: RDFArguments,
150-
json: LiaJSON
143+
json: any,
151144
): Promise<void> {
152145
try {
153146
let doc = await parse(argument, json)
@@ -166,7 +159,7 @@ export async function exporter(
166159
} else {
167160
await fs.writeFile(
168161
argument.output + '.jsonld',
169-
JSON.stringify(doc, null, 2)
162+
JSON.stringify(doc, null, 2),
170163
)
171164
}
172165
}
@@ -191,10 +184,11 @@ export async function exporter(
191184
*/
192185
export async function script(
193186
argument: RDFArguments,
194-
json: LiaJSON
187+
json: LiaJSON,
195188
): Promise<string> {
196189
try {
197190
let doc = await parse(argument, json)
191+
198192
doc = await jsonld.compact(doc, SCHEMA_ORG_CONTEXT)
199193
doc = clean(doc)
200194

@@ -266,11 +260,7 @@ async function loadTemplate(templatePath?: string): Promise<SchemaDoc> {
266260
* @param json LiaScript JSON data
267261
* @param rdfType Optional type override from arguments
268262
*/
269-
function setCoreProperties(
270-
doc: SchemaDoc,
271-
json: LiaJSON,
272-
rdfType?: string
273-
): void {
263+
function setCoreProperties(doc: SchemaDoc, json: any, rdfType?: string): void {
274264
doc[SCHEMA_ORG_PROPS.NAME] = json.lia.str_title
275265
doc[SCHEMA_ORG_PROPS.TYPE] =
276266
doc[SCHEMA_ORG_PROPS.TYPE] || rdfType || SCHEMA_TYPES.COURSE
@@ -299,7 +289,7 @@ function resolveBaseURL(input: string, rdfUrl?: string): string | null {
299289
function setURLProperties(
300290
doc: SchemaDoc,
301291
input: string,
302-
rdfUrl?: string
292+
rdfUrl?: string,
303293
): string | null {
304294
if (helper.isURL(input) || rdfUrl) {
305295
const urlValue = rdfUrl || input
@@ -323,7 +313,7 @@ async function enrichMetadata(
323313
doc: SchemaDoc,
324314
definition: LiaDefinition,
325315
baseURL: string | null,
326-
argument: RDFArguments
316+
argument: RDFArguments,
327317
): Promise<SchemaDoc> {
328318
doc = baseInformation(doc, definition)
329319
doc = langInformation(doc, definition)
@@ -356,9 +346,12 @@ async function enrichMetadata(
356346
*/
357347
export async function parse(
358348
argument: RDFArguments,
359-
json: LiaJSON
349+
json: string,
360350
): Promise<SchemaDoc> {
361351
try {
352+
// fix: sometimes json is string
353+
if (typeof json === 'string') json = JSON.parse(json)
354+
362355
// Load template if provided
363356
let doc = await loadTemplate(argument['rdf-template'])
364357

@@ -467,7 +460,7 @@ function langInformation(doc: SchemaDoc, definition: LiaDefinition): SchemaDoc {
467460
function logoInformation(
468461
doc: SchemaDoc,
469462
definition: LiaDefinition,
470-
baseURL: null | string
463+
baseURL: null | string,
471464
): SchemaDoc {
472465
if (definition?.logo) {
473466
let imageUrl: string | null = null
@@ -503,7 +496,7 @@ function logoInformation(
503496
async function licenseInformation(
504497
doc: SchemaDoc,
505498
argument: RDFArguments,
506-
baseURL: null | string
499+
baseURL: null | string,
507500
): Promise<SchemaDoc> {
508501
let licenseUrl: string | null = null
509502

@@ -515,7 +508,7 @@ async function licenseInformation(
515508
} catch (error) {
516509
console.warn(
517510
'Could not create a URL for the LICENSE file, using base URL as license URL.',
518-
baseURL
511+
baseURL,
519512
)
520513
}
521514
}
@@ -546,13 +539,16 @@ function clean(obj: any): any {
546539
if (Array.isArray(obj)) {
547540
return obj.map((item: any) => clean(item))
548541
}
549-
return Object.keys(obj).reduce((acc: Record<string, any>, key: string) => {
550-
const value = obj[key]
551-
if (key.startsWith('schema:')) {
552-
acc[key.split(':').pop() || key] = value
553-
} else {
554-
acc[key] = clean(value)
555-
}
556-
return acc
557-
}, {} as Record<string, any>)
542+
return Object.keys(obj).reduce(
543+
(acc: Record<string, any>, key: string) => {
544+
const value = obj[key]
545+
if (key.startsWith('schema:')) {
546+
acc[key.split(':').pop() || key] = value
547+
} else {
548+
acc[key] = clean(value)
549+
}
550+
return acc
551+
},
552+
{} as Record<string, any>,
553+
)
558554
}

src/export/scorm12.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,39 @@ export function help() {
1111
console.log(COLOR.heading('SCORM settings:'), '\n')
1212

1313
COLOR.info(
14-
'SCORM (Sharable Content Object Reference Model) 1.2 & 2004 are standards for e-learning content that can be imported into LMS platforms like Moodle, Blackboard, and others.'
14+
'SCORM (Sharable Content Object Reference Model) 1.2 & 2004 are standards for e-learning content that can be imported into LMS platforms like Moodle, Blackboard, and others.',
1515
)
1616

1717
console.log('\nLearn more: https://scorm.com/scorm-explained/\n')
1818

1919
console.log(
20-
'Known SCORM configurations per LMS:\n https://www.npmjs.com/package/@liascript/exporter#scorm-examples\n'
20+
'Known SCORM configurations per LMS:\n https://www.npmjs.com/package/@liascript/exporter#scorm-examples\n',
2121
)
2222

2323
https: COLOR.command(
2424
null,
2525
'--scorm-organization',
26-
' set the organization title'
26+
' set the organization title',
2727
)
2828
COLOR.command(
2929
null,
3030
'--scorm-masteryScore',
31-
' set the scorm masteryScore (a value between 0 -- 100), default is 0'
31+
' set the scorm masteryScore (a value between 0 -- 100), default is 0',
3232
)
3333
COLOR.command(
3434
null,
3535
'--scorm-typicalDuration',
36-
' set the scorm duration, default is PT0H5M0S'
36+
' set the scorm duration, default is PT0H5M0S',
3737
)
3838
COLOR.command(
3939
null,
4040
'--scorm-iframe',
41-
' use an iframe, when a SCORM starting parameter is not working'
41+
' use an iframe, when a SCORM starting parameter is not working',
4242
)
4343
COLOR.command(
4444
null,
4545
'--scorm-embed',
46-
' embed the Markdown into the JS code, use in Moodle 4 to handle restrictions with dynamic loading'
46+
' embed the Markdown into the JS code, use in Moodle 4 to handle restrictions with dynamic loading',
4747
)
4848
}
4949

@@ -92,7 +92,7 @@ export async function exporter(argument: Scorm12ExportArguments, json: any) {
9292
quiz: json.quiz,
9393
survey: json.survey,
9494
}) +
95-
';'
95+
';',
9696
)
9797

9898
const jsonLD = await RDF.script(argument, json)
@@ -103,15 +103,15 @@ export async function exporter(argument: Scorm12ExportArguments, json: any) {
103103
'start.html',
104104
argument.readme,
105105
jsonLD,
106-
argument.style
106+
argument.style,
107107
)
108108
}
109109

110110
if (argument['scorm-embed']) {
111111
index = helper.inject('<script src="course.js"></script>', index, true)
112112
await helper.writeFile(
113113
path.join(tmpPath, 'course.js'),
114-
'window["liascript_course"] = ' + JSON.stringify(argument['scorm-embed'])
114+
'window["liascript_course"] = ' + JSON.stringify(argument['scorm-embed']),
115115
)
116116
}
117117

0 commit comments

Comments
 (0)