@liascript/exporter 2.5.8--0.10.30 → 2.6.0--0.10.31
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.
- package/README.md +162 -0
- package/dist/assets/capacitor/{Browser.2af01b1f.js → Browser.5082dda8.js} +1 -1
- package/dist/assets/capacitor/index.3881155a.js +2 -0
- package/dist/assets/capacitor/index.bf88b71e.js +1 -0
- package/dist/assets/capacitor/index.html +1 -1
- package/dist/assets/indexeddb/{Browser.6b8ed70b.js → Browser.649e16ad.js} +1 -1
- package/dist/assets/indexeddb/{Browser.1b782839.js → Browser.d375e114.js} +1 -1
- package/dist/assets/indexeddb/index.a0cf34b4.js +1 -0
- package/dist/assets/indexeddb/index.b213d7fb.js +1 -0
- package/dist/assets/{scorm1.2/index.3f87aa11.js → indexeddb/index.c239bf26.js} +1 -1
- package/dist/assets/indexeddb/index.eb14aca6.js +1 -0
- package/dist/assets/indexeddb/index.html +1 -1
- package/dist/assets/pdf/Base.dfce8330.js +1 -0
- package/dist/assets/pdf/index.1a4303bf.js +1 -0
- package/dist/assets/pdf/index.40f97d1a.js +1 -0
- package/dist/assets/pdf/index.html +1 -1
- package/dist/assets/scorm1.2/index.1a43c3cf.js +1 -0
- package/dist/assets/scorm1.2/index.697f72c7.js +1 -0
- package/dist/assets/scorm1.2/index.a0cf34b4.js +1 -0
- package/dist/assets/{scorm2004/index.3f87aa11.js → scorm1.2/index.c239bf26.js} +1 -1
- package/dist/assets/scorm1.2/index.html +1 -1
- package/dist/assets/scorm2004/index.42ca750d.js +1 -0
- package/dist/assets/scorm2004/index.a0cf34b4.js +1 -0
- package/dist/assets/scorm2004/index.c239bf26.js +1 -0
- package/dist/assets/scorm2004/index.d364acfd.js +1 -0
- package/dist/assets/scorm2004/index.html +1 -1
- package/dist/assets/web/Base.54729a0c.js +1 -0
- package/dist/assets/web/Base.74505e58.js +1 -0
- package/dist/assets/web/index.a0cf34b4.js +1 -0
- package/dist/assets/web/index.a1534295.js +1 -0
- package/dist/assets/web/index.ade7f70f.js +1 -0
- package/dist/assets/web/index.c239bf26.js +1 -0
- package/dist/assets/web/index.html +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -1
- package/src/export/helper.ts +23 -0
- package/src/export/rdf.ts +227 -0
- package/src/index.ts +27 -3
- package/dist/assets/capacitor/index.6418b617.js +0 -1
- package/dist/assets/capacitor/index.9cc0286d.js +0 -2
- package/dist/assets/indexeddb/index.1a32b3c6.js +0 -1
- package/dist/assets/indexeddb/index.4890a134.js +0 -1
- package/dist/assets/indexeddb/index.907e0468.js +0 -1
- package/dist/assets/indexeddb/index.f7bddd51.js +0 -1
- package/dist/assets/pdf/Base.1408401d.js +0 -1
- package/dist/assets/pdf/index.ba366374.js +0 -1
- package/dist/assets/pdf/index.ff442846.js +0 -1
- package/dist/assets/scorm1.2/index.4a92e335.js +0 -1
- package/dist/assets/scorm1.2/index.607bde0c.js +0 -1
- package/dist/assets/scorm1.2/index.c71d23fb.js +0 -1
- package/dist/assets/scorm2004/index.250ec73b.js +0 -1
- package/dist/assets/scorm2004/index.2ed9b743.js +0 -1
- package/dist/assets/scorm2004/index.c71d23fb.js +0 -1
- package/dist/assets/web/Base.1b8501a4.js +0 -1
- package/dist/assets/web/Base.ec3f3075.js +0 -1
- package/dist/assets/web/index.1021a2ea.js +0 -1
- package/dist/assets/web/index.47a12822.js +0 -1
- package/dist/assets/web/index.4890a134.js +0 -1
- package/dist/assets/web/index.f7bddd51.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liascript/exporter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0--0.10.31",
|
|
4
4
|
"description": "A generic exporter for LiaScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -47,7 +47,9 @@
|
|
|
47
47
|
"@liascript/simple-scorm-packager": "^0.3.0",
|
|
48
48
|
"archiver": "^5.3.0",
|
|
49
49
|
"fs-extra": "^9.1.0",
|
|
50
|
+
"jsonld": "^8.1.1",
|
|
50
51
|
"minimist": "^1.2.5",
|
|
52
|
+
"node-fetch": "^2.6.9",
|
|
51
53
|
"path": "^0.12.7",
|
|
52
54
|
"puppeteer": "^19.2.2",
|
|
53
55
|
"temp": "^0.9.4",
|
package/src/export/helper.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
import fetch from 'node-fetch'
|
|
3
4
|
const temp = require('temp')
|
|
4
5
|
const fs = require('fs-extra')
|
|
5
6
|
const path = require('path')
|
|
@@ -180,3 +181,25 @@ export function getRepository(raw_url: string) {
|
|
|
180
181
|
|
|
181
182
|
return null
|
|
182
183
|
}
|
|
184
|
+
|
|
185
|
+
export async function checkLicense(baseURL: string) {
|
|
186
|
+
const url = new URL('LICENSE', baseURL).href
|
|
187
|
+
|
|
188
|
+
return await checkFileExists(url)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function baseURL(url: string) {
|
|
192
|
+
const path = url.split('/')
|
|
193
|
+
path.pop()
|
|
194
|
+
return path.join('/')
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function checkFileExists(fileUrl: string) {
|
|
198
|
+
try {
|
|
199
|
+
const response = await fetch(fileUrl, { method: 'HEAD' })
|
|
200
|
+
return response.status === 200
|
|
201
|
+
} catch (error) {
|
|
202
|
+
console.warn(`Error checking if file exists: ${error}`)
|
|
203
|
+
return false
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as helper from './helper'
|
|
2
|
+
|
|
3
|
+
const jsonld = require('jsonld')
|
|
4
|
+
const fs = require('fs-extra')
|
|
5
|
+
|
|
6
|
+
export function help() {
|
|
7
|
+
console.log('\nRDF settings:')
|
|
8
|
+
console.log('')
|
|
9
|
+
|
|
10
|
+
console.log(
|
|
11
|
+
'--rdf-format Output format n-quads, json-ld (defaults to json-ld).'
|
|
12
|
+
)
|
|
13
|
+
console.log('--rdf-preview Output the result to the console.')
|
|
14
|
+
console.log(
|
|
15
|
+
'--rdf-url Refer to an external URL when parsing a local project.'
|
|
16
|
+
)
|
|
17
|
+
console.log(
|
|
18
|
+
'--rdf-type Course frm schmema.org is applied as default, overwrite this with EducationalResource, etc.'
|
|
19
|
+
)
|
|
20
|
+
console.log(
|
|
21
|
+
'--rdf-license Add a license-URL, otherwise if url was provided as input, this will check for an existing LICENSE file.'
|
|
22
|
+
)
|
|
23
|
+
console.log(
|
|
24
|
+
'--rdf-educationalLevel Typically beginner, intermediate or advanced, and formal sets of level indicators.'
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function exporter(
|
|
29
|
+
argument: {
|
|
30
|
+
input: string
|
|
31
|
+
readme: string
|
|
32
|
+
output: string
|
|
33
|
+
format: string
|
|
34
|
+
path: string
|
|
35
|
+
key?: string
|
|
36
|
+
style?: string
|
|
37
|
+
|
|
38
|
+
// special cases for RDF
|
|
39
|
+
'rdf-format'?: string
|
|
40
|
+
'rdf-preview'?: string
|
|
41
|
+
'rdf-url'?: string
|
|
42
|
+
'rdf-type'?: string
|
|
43
|
+
//'rdf-input'?: string
|
|
44
|
+
'rdf-license'?: string
|
|
45
|
+
'rdf-educationalLevel'?: string
|
|
46
|
+
},
|
|
47
|
+
json
|
|
48
|
+
) {
|
|
49
|
+
let doc = {}
|
|
50
|
+
|
|
51
|
+
doc = {
|
|
52
|
+
'http://schema.org/name': json.lia.str_title,
|
|
53
|
+
'http://schema.org/@type': argument['rdf-type'] || 'Course',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let baseURL: string | null = null
|
|
57
|
+
|
|
58
|
+
// If a Url is defined, this Url is used as the key and to generate
|
|
59
|
+
if (helper.isURL(argument.input) || argument['rdf-url']) {
|
|
60
|
+
doc['http://schema.org/@id'] = argument['rdf-url'] || argument.input
|
|
61
|
+
doc['http://schema.org/url'] =
|
|
62
|
+
'https://LiaScript.github.io/course/?' +
|
|
63
|
+
(argument['rdf-url'] || argument.input)
|
|
64
|
+
|
|
65
|
+
baseURL = helper.baseURL(argument['rdf-url'] || argument.input)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (argument['rdf-educationalLevel']) {
|
|
69
|
+
doc['http://schema.org/educationalLevel'] = argument['rdf-educationalLevel']
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
doc = baseInformation(doc, json.lia.definition)
|
|
73
|
+
doc = langInformation(doc, json.lia.definition)
|
|
74
|
+
doc = logoInformation(doc, json.lia.definition, baseURL)
|
|
75
|
+
doc = await licenseInformation(doc, argument, baseURL)
|
|
76
|
+
doc = await jsonld.compact(doc, 'http://schema.org')
|
|
77
|
+
|
|
78
|
+
if (argument['rdf-format'] === 'n-quads') {
|
|
79
|
+
const nquads = await jsonld.toRDF(doc, { format: 'application/n-quads' })
|
|
80
|
+
if (argument['rdf-preview']) {
|
|
81
|
+
console.log(nquads)
|
|
82
|
+
} else {
|
|
83
|
+
fs.writeFile(argument.output + '.nq', nquads, function (err) {
|
|
84
|
+
if (err) console.error(err)
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
doc = clean(doc)
|
|
89
|
+
if (argument['rdf-preview']) {
|
|
90
|
+
console.log(JSON.stringify(doc, null, 2))
|
|
91
|
+
} else {
|
|
92
|
+
fs.writeFile(
|
|
93
|
+
argument.output + '.jsonld',
|
|
94
|
+
JSON.stringify(doc, null, 2),
|
|
95
|
+
function (err) {
|
|
96
|
+
if (err) console.error(err)
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Adds the following information, if they exist:
|
|
105
|
+
*
|
|
106
|
+
* - author:
|
|
107
|
+
* - name
|
|
108
|
+
* - email
|
|
109
|
+
* - description
|
|
110
|
+
* - keywords
|
|
111
|
+
* - version
|
|
112
|
+
*/
|
|
113
|
+
function baseInformation(doc: any, definition: any) {
|
|
114
|
+
if (definition?.author || definition?.email) {
|
|
115
|
+
const author = { 'http://schema.org/@type': 'Person' }
|
|
116
|
+
|
|
117
|
+
if (definition?.author) {
|
|
118
|
+
author['http://schema.org/name'] = definition?.author
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (definition?.email) {
|
|
122
|
+
author['http://schema.org/email'] = definition?.email
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
doc['http://schema.org/author'] = author
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (definition.macro?.comment) {
|
|
129
|
+
doc['http://schema.org/description'] = definition.macro?.comment
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (definition.macro?.tags) {
|
|
133
|
+
doc['http://schema.org/keywords'] = definition.macro.tags
|
|
134
|
+
.split(',')
|
|
135
|
+
.map((e: string) => e.trim())
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (definition?.version) {
|
|
139
|
+
doc['http://schema.org/version'] = definition?.version
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return doc
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Adds language information:
|
|
147
|
+
*
|
|
148
|
+
* - inLanguage
|
|
149
|
+
* - TODO: Translations
|
|
150
|
+
* @returns
|
|
151
|
+
*/
|
|
152
|
+
function langInformation(doc: any, definition: any) {
|
|
153
|
+
if (definition?.language) {
|
|
154
|
+
doc['http://schema.org/inLanguage'] = definition.language
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return doc
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Adds the image information.
|
|
162
|
+
*
|
|
163
|
+
* - image: from LiaScript logo
|
|
164
|
+
* - TODO: thumbnailUrl: from LiaScript icon
|
|
165
|
+
*/
|
|
166
|
+
function logoInformation(doc: any, definition: any, baseURL: null | string) {
|
|
167
|
+
if (definition?.logo) {
|
|
168
|
+
let imageUrl: string | null = null
|
|
169
|
+
|
|
170
|
+
if (helper.isURL(definition?.logo)) {
|
|
171
|
+
imageUrl = definition?.logo
|
|
172
|
+
} else if (baseURL) {
|
|
173
|
+
imageUrl = new URL(definition?.logo, baseURL).href
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (imageUrl) {
|
|
177
|
+
doc['http://schema.org/image'] = {
|
|
178
|
+
'http://schema.org/@type': 'ImageObject',
|
|
179
|
+
'http://schema.org/url': imageUrl,
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return doc
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function licenseInformation(
|
|
188
|
+
doc: any,
|
|
189
|
+
argument: any,
|
|
190
|
+
baseURL: null | string
|
|
191
|
+
) {
|
|
192
|
+
let licenseUrl: string | null = null
|
|
193
|
+
|
|
194
|
+
if (argument['rdf-license']) {
|
|
195
|
+
licenseUrl = argument['rdf-license']
|
|
196
|
+
} else if (baseURL && (await helper.checkLicense(baseURL))) {
|
|
197
|
+
licenseUrl = new URL(baseURL, 'LICENSE').href
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (licenseUrl) {
|
|
201
|
+
doc['http://schema.org/license'] = licenseUrl
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return doc
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* For some reason, jsonld puts to all keys with a "Url" a "schema:"
|
|
209
|
+
* to the front. This functions replaces all "schema:.*" by ".*".
|
|
210
|
+
*/
|
|
211
|
+
function clean(obj: Object) {
|
|
212
|
+
if (!obj || typeof obj !== 'object') {
|
|
213
|
+
return obj
|
|
214
|
+
}
|
|
215
|
+
if (Array.isArray(obj)) {
|
|
216
|
+
return obj.map((item) => clean(item))
|
|
217
|
+
}
|
|
218
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
219
|
+
const value = obj[key]
|
|
220
|
+
if (key.startsWith('schema:')) {
|
|
221
|
+
acc[key.split(':').pop() || key] = value
|
|
222
|
+
} else {
|
|
223
|
+
acc[key] = clean(value)
|
|
224
|
+
}
|
|
225
|
+
return acc
|
|
226
|
+
}, {})
|
|
227
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import * as IMS from './export/ims'
|
|
|
10
10
|
import * as ANDROID from './export/android'
|
|
11
11
|
// import * as IOS from './export/ios'
|
|
12
12
|
import * as PROJECT from './export/project'
|
|
13
|
+
import * as RDF from './export/rdf'
|
|
13
14
|
|
|
14
15
|
global.XMLHttpRequest = require('xhr2')
|
|
15
16
|
|
|
@@ -17,10 +18,11 @@ import YAML from 'yaml'
|
|
|
17
18
|
const path = require('path')
|
|
18
19
|
const fs = require('fs-extra')
|
|
19
20
|
const argv = require('minimist')(process.argv.slice(2))
|
|
21
|
+
import fetch from 'node-fetch'
|
|
20
22
|
|
|
21
23
|
// -------------------------------Main Execution-------------------------------
|
|
22
24
|
if (argv.v || argv.version) {
|
|
23
|
-
console.log('version: 2.
|
|
25
|
+
console.log('version: 2.6.0--0.10.31')
|
|
24
26
|
} else if (argv.h || argv.help) {
|
|
25
27
|
help()
|
|
26
28
|
} else if (argv.i || argv.input) {
|
|
@@ -33,7 +35,7 @@ if (argv.v || argv.version) {
|
|
|
33
35
|
|
|
34
36
|
var collection: any
|
|
35
37
|
|
|
36
|
-
function run(argument) {
|
|
38
|
+
async function run(argument) {
|
|
37
39
|
var app = Elm.Worker.init({ flags: { cmd: '' } })
|
|
38
40
|
app.ports.output.subscribe(function (event) {
|
|
39
41
|
let [ok, string] = event
|
|
@@ -52,6 +54,10 @@ function run(argument) {
|
|
|
52
54
|
})
|
|
53
55
|
break
|
|
54
56
|
}
|
|
57
|
+
case 'rdf': {
|
|
58
|
+
RDF.exporter(argument, JSON.parse(string))
|
|
59
|
+
break
|
|
60
|
+
}
|
|
55
61
|
case 'scorm1.2': {
|
|
56
62
|
SCORM12.exporter(argument, JSON.parse(string))
|
|
57
63
|
break
|
|
@@ -118,6 +124,7 @@ function run(argument) {
|
|
|
118
124
|
argument.format == 'ims' ||
|
|
119
125
|
argument.format == 'android' ||
|
|
120
126
|
argument.format == 'ios' ||
|
|
127
|
+
argument.format == 'rdf' ||
|
|
121
128
|
argument.format == 'project'
|
|
122
129
|
? 'fulljson'
|
|
123
130
|
: argument.format
|
|
@@ -136,6 +143,13 @@ function run(argument) {
|
|
|
136
143
|
app.ports.input.send([format, data])
|
|
137
144
|
} else if (argument.format === 'pdf') {
|
|
138
145
|
PDF.exporter(argument, {})
|
|
146
|
+
} else if (argument.format === 'rdf') {
|
|
147
|
+
const resp = await fetch(argument.input)
|
|
148
|
+
const data = await resp.text()
|
|
149
|
+
|
|
150
|
+
if (data) {
|
|
151
|
+
app.ports.input.send([format, data])
|
|
152
|
+
}
|
|
139
153
|
} else {
|
|
140
154
|
console.warn('URLs are not allowed as input')
|
|
141
155
|
}
|
|
@@ -167,7 +181,7 @@ function help() {
|
|
|
167
181
|
console.log(
|
|
168
182
|
'-f',
|
|
169
183
|
'--format',
|
|
170
|
-
' scorm1.2, scorm2004, json, fullJson, web, ims, pdf, android (default is json)'
|
|
184
|
+
' scorm1.2, scorm2004, json, fullJson, web, ims, pdf, android, linkedData (default is json)'
|
|
171
185
|
)
|
|
172
186
|
console.log('-v', '--version', ' output the current version')
|
|
173
187
|
|
|
@@ -326,6 +340,8 @@ function help() {
|
|
|
326
340
|
console.log(
|
|
327
341
|
'--project-generate-cache Only generate new files, if they do not exist.'
|
|
328
342
|
)
|
|
343
|
+
|
|
344
|
+
RDF.help()
|
|
329
345
|
}
|
|
330
346
|
|
|
331
347
|
function escapeBackslash(path?: string) {
|
|
@@ -400,6 +416,14 @@ function parseArguments() {
|
|
|
400
416
|
'project-generate-scorm2004': argv['project-generate-scorm2004'],
|
|
401
417
|
'project-generate-android': argv['project-generate-android'],
|
|
402
418
|
'project-generate-cache': argv['project-generate-cache'],
|
|
419
|
+
|
|
420
|
+
// RDF settngs
|
|
421
|
+
'rdf-format': argv['rdf-format'],
|
|
422
|
+
'rdf-preview': argv['rdf-preview'],
|
|
423
|
+
'rdf-url': argv['rdf-url'],
|
|
424
|
+
'rdf-type': argv['rdf-type'],
|
|
425
|
+
'rdf-license': argv['rdf-license'],
|
|
426
|
+
'rdf-educationalLevel': argv['rdf-educationalLevel'],
|
|
403
427
|
}
|
|
404
428
|
|
|
405
429
|
argument.format = argument.format.toLowerCase()
|