Skip to content

Commit cf283f9

Browse files
André DietrichAndré Dietrich
authored andcommitted
upgraded project to build apk, epub, docx, xapi
1 parent 2d77237 commit cf283f9

3 files changed

Lines changed: 137 additions & 3 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,13 @@ collection:
824824
# or leave, so that no card-image is added to your preview-cards
825825
# logo:
826826
827+
# By default, formats that require the repository to be cloned (SCORM12/2004,
828+
# IMS, Android, xAPI - see --project-generate-* below) pack the entire cloned
829+
# repository. If your course only occupies a sub-folder of the repository,
830+
# set `path` to restrict packing to that folder, just like the `-p/--path`
831+
# command line option does for single-file exports.
832+
# path: some/sub-folder
833+
827834
# You can manually tag courses, if this has not been done within the main comment of the course.
828835
# By default, these tags will be treated as categories, which can be used to navigate through
829836
# your courses. To disable this, use the cmd-param --project-no-categories

src/export/project.ts

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import * as IMS from './ims'
44
import * as SCORM12 from './scorm12'
55
import * as SCORM2004 from './scorm2004'
66
import * as ANDROID from './android'
7+
import * as EPUB from './epub'
8+
import * as DOCX from './docx'
9+
import * as XAPI from './xapi'
710
import * as RDF from './rdf'
811
import * as COLOR from '../colorize'
912

@@ -121,6 +124,26 @@ export function help() {
121124
'--project-generate-pdf',
122125
' PDFs are automatically generated and added to every card.',
123126
)
127+
COLOR.command(
128+
null,
129+
'--project-generate-android',
130+
'Android APKs and pass additional android settings.',
131+
)
132+
COLOR.command(
133+
null,
134+
'--project-generate-epub',
135+
' EPUBs are automatically generated and added to every card.',
136+
)
137+
COLOR.command(
138+
null,
139+
'--project-generate-docx',
140+
' DOCX documents are automatically generated and added to every card.',
141+
)
142+
COLOR.command(
143+
null,
144+
'--project-generate-xapi',
145+
' xAPI packages and pass additional xAPI settings.',
146+
)
124147
COLOR.command(
125148
null,
126149
'--project-generate-cache',
@@ -150,6 +173,9 @@ export interface ProjectExportArguments {
150173
'project-generate-scorm12'?: boolean
151174
'project-generate-scorm2004'?: boolean
152175
'project-generate-android'?: boolean
176+
'project-generate-epub'?: boolean
177+
'project-generate-docx'?: boolean
178+
'project-generate-xapi'?: boolean
153179
'project-generate-cache'?: boolean
154180
'project-search'?: boolean
155181
}
@@ -933,6 +959,12 @@ async function toCard(
933959
downloads['scorm12'] = 'assets/scorm12/' + backupOutput + '.zip'
934960
if (argument['project-generate-scorm2004'])
935961
downloads['scorm2004'] = 'assets/scorm2004/' + backupOutput + '.zip'
962+
if (argument['project-generate-epub'])
963+
downloads['epub'] = 'assets/epub/' + backupOutput + '.epub'
964+
if (argument['project-generate-docx'])
965+
downloads['docx'] = 'assets/docx/' + backupOutput + '.docx'
966+
if (argument['project-generate-xapi'])
967+
downloads['xapi'] = 'assets/xapi/' + backupOutput + '.zip'
936968

937969
if (argument['project-generate-pdf']) {
938970
argument.input = course.data.lia.readme
@@ -956,20 +988,67 @@ async function toCard(
956988
}
957989
}
958990

991+
if (argument['project-generate-epub']) {
992+
argument.input = course.data.lia.readme
993+
argument.output = 'assets/epub/' + backupOutput
994+
995+
const file = argument.output + '.epub'
996+
997+
if (
998+
argument['project-generate-cache'] &&
999+
fs.existsSync(path.join(process.cwd(), file))
1000+
) {
1001+
console.log('using cached file of ', argument.input, ' -> ', file)
1002+
} else {
1003+
console.log('generate epub of', argument.input, ' -> ', file)
1004+
1005+
fs.ensureDirSync('assets/epub')
1006+
await EPUB.exporter(argument, course.data)
1007+
}
1008+
}
1009+
1010+
if (argument['project-generate-docx']) {
1011+
argument.input = course.data.lia.readme
1012+
argument.output = 'assets/docx/' + backupOutput
1013+
1014+
const file = argument.output + '.docx'
1015+
1016+
if (
1017+
argument['project-generate-cache'] &&
1018+
fs.existsSync(path.join(process.cwd(), file))
1019+
) {
1020+
console.log('using cached file of ', argument.input, ' -> ', file)
1021+
} else {
1022+
console.log('generate docx of', argument.input, ' -> ', file)
1023+
1024+
fs.ensureDirSync('assets/docx')
1025+
await DOCX.exporter(argument)
1026+
}
1027+
}
1028+
9591029
let repo
9601030
if (
9611031
argument['project-generate-ims'] ||
9621032
argument['project-generate-scorm12'] ||
9631033
argument['project-generate-scorm2004'] ||
964-
argument['project-generate-android']
1034+
argument['project-generate-android'] ||
1035+
argument['project-generate-xapi']
9651036
) {
9661037
repo = helper.getRepository(course.url)
9671038

9681039
if (repo) {
9691040
execSync(repo.cmd)
9701041
argument.input = path.join('tmp', repo.path)
971-
argument.path = 'tmp'
972-
argument.readme = path.join('./', repo.path)
1042+
1043+
if (course.path) {
1044+
// restrict packing to the sub-folder given in the yaml, instead of
1045+
// the whole cloned repository
1046+
argument.path = path.join('tmp', course.path)
1047+
argument.readme = path.relative(course.path, repo.path)
1048+
} else {
1049+
argument.path = 'tmp'
1050+
argument.readme = path.join('./', repo.path)
1051+
}
9731052

9741053
argument.output = backupOutput
9751054

@@ -1051,6 +1130,24 @@ async function toCard(
10511130
}
10521131
}
10531132

1133+
// xAPI
1134+
if (repo && argument['project-generate-xapi']) {
1135+
argument.output = 'assets/xapi/' + backupOutput
1136+
argument['xapi-zip'] = true
1137+
const asset = argument.output + '.zip'
1138+
1139+
fs.ensureDirSync('assets/xapi')
1140+
1141+
if (
1142+
argument['project-generate-cache'] &&
1143+
fs.existsSync(path.join(process.cwd(), asset))
1144+
) {
1145+
console.log('using cached file of ', argument.input, ' -> ', asset)
1146+
} else {
1147+
await XAPI.exporter(argument, course.data)
1148+
}
1149+
}
1150+
10541151
// clean up
10551152
if (repo) {
10561153
execSync('rm -rf tmp')
@@ -1087,6 +1184,9 @@ function card(
10871184
scorm2004?: string
10881185
ims?: string
10891186
apk?: string
1187+
epub?: string
1188+
docx?: string
1189+
xapi?: string
10901190
},
10911191
img_url?: string,
10921192
link?: string,
@@ -1173,6 +1273,27 @@ function card(
11731273
'">Android APK</a></li>'
11741274
: ''
11751275
}
1276+
${
1277+
download.epub
1278+
? '<li><a class="dropdown-item btn-sm" href="' +
1279+
download.epub +
1280+
'">EPUB</a></li>'
1281+
: ''
1282+
}
1283+
${
1284+
download.docx
1285+
? '<li><a class="dropdown-item btn-sm" href="' +
1286+
download.docx +
1287+
'">DOCX</a></li>'
1288+
: ''
1289+
}
1290+
${
1291+
download.xapi
1292+
? '<li><a class="dropdown-item btn-sm" href="' +
1293+
download.xapi +
1294+
'">xAPI Package</a></li>'
1295+
: ''
1296+
}
11761297
</ul>
11771298
</div>
11781299
</div>

src/parser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ export function parseArguments(): Arguments {
158158
'project-generate-scorm12': argv['project-generate-scorm12'],
159159
'project-generate-scorm2004': argv['project-generate-scorm2004'],
160160
'project-generate-android': argv['project-generate-android'],
161+
'project-generate-epub': argv['project-generate-epub'],
162+
'project-generate-docx': argv['project-generate-docx'],
163+
'project-generate-xapi': argv['project-generate-xapi'],
161164
'project-generate-cache': argv['project-generate-cache'],
162165

163166
// RDF settings
@@ -307,6 +310,9 @@ export function parsePresetsArguments(presetId: string): Arguments {
307310
'project-generate-scorm12': argv['project-generate-scorm12'],
308311
'project-generate-scorm2004': argv['project-generate-scorm2004'],
309312
'project-generate-android': argv['project-generate-android'],
313+
'project-generate-epub': argv['project-generate-epub'],
314+
'project-generate-docx': argv['project-generate-docx'],
315+
'project-generate-xapi': argv['project-generate-xapi'],
310316
'project-generate-cache': argv['project-generate-cache'],
311317

312318
// RDF settings

0 commit comments

Comments
 (0)