adapt-authoring-adaptframework 1.4.0 → 1.5.0
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.
|
@@ -198,7 +198,6 @@ class AdaptFrameworkBuild {
|
|
|
198
198
|
this.copySource()
|
|
199
199
|
])
|
|
200
200
|
await this.preBuildHook.invoke(this)
|
|
201
|
-
await framework.preBuildHook.invoke(this)
|
|
202
201
|
|
|
203
202
|
await this.writeContentJson()
|
|
204
203
|
|
|
@@ -227,7 +226,6 @@ class AdaptFrameworkBuild {
|
|
|
227
226
|
this.location = this.isPreview ? path.join(this.dir, 'build') : this.dir
|
|
228
227
|
}
|
|
229
228
|
await this.postBuildHook.invoke(this)
|
|
230
|
-
await framework.postBuildHook.invoke(this)
|
|
231
229
|
|
|
232
230
|
this.buildData = await this.recordBuildAttempt()
|
|
233
231
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { App } from 'adapt-authoring-core'
|
|
1
|
+
import { App, Hook } from 'adapt-authoring-core'
|
|
2
2
|
import fs from 'fs/promises'
|
|
3
3
|
import { glob } from 'glob'
|
|
4
4
|
import octopus from 'adapt-octopus'
|
|
@@ -70,7 +70,7 @@ class AdaptFrameworkImport {
|
|
|
70
70
|
* @constructor
|
|
71
71
|
* @param {AdaptFrameworkImportOptions} options
|
|
72
72
|
*/
|
|
73
|
-
constructor ({ unzipPath, userId, assetFolders, tags, isDryRun, importContent = true, importPlugins = true, migrateContent = true, updatePlugins = false }) {
|
|
73
|
+
constructor ({ unzipPath, userId, assetFolders, tags, isDryRun, importContent = true, importPlugins = true, migrateContent = true, updatePlugins = false, removeSource = true }) {
|
|
74
74
|
try {
|
|
75
75
|
if (!unzipPath || !userId) throw new Error()
|
|
76
76
|
/**
|
|
@@ -163,8 +163,17 @@ class AdaptFrameworkImport {
|
|
|
163
163
|
importContent,
|
|
164
164
|
importPlugins,
|
|
165
165
|
migrateContent,
|
|
166
|
-
updatePlugins
|
|
166
|
+
updatePlugins,
|
|
167
|
+
removeSource
|
|
167
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Invoked before the import process has started
|
|
171
|
+
*/
|
|
172
|
+
this.preImportHook = new Hook()
|
|
173
|
+
/**
|
|
174
|
+
* Invoked once the import process has completed
|
|
175
|
+
*/
|
|
176
|
+
this.postImportHook = new Hook()
|
|
168
177
|
|
|
169
178
|
/**
|
|
170
179
|
* plugins on import that are of a lower version than the installed version
|
|
@@ -231,6 +240,7 @@ class AdaptFrameworkImport {
|
|
|
231
240
|
[this.prepare],
|
|
232
241
|
[this.loadAssetData],
|
|
233
242
|
[this.loadPluginData],
|
|
243
|
+
[() => this.preImportHook.invoke(this), true],
|
|
234
244
|
[this.importTags, importContent],
|
|
235
245
|
[this.importCourseAssets, importContent],
|
|
236
246
|
[this.importCoursePlugins, isDryRun && importPlugins],
|
|
@@ -243,6 +253,7 @@ class AdaptFrameworkImport {
|
|
|
243
253
|
for (const [func, test] of tasks) {
|
|
244
254
|
if (test === true || test === undefined) await func.call(this)
|
|
245
255
|
}
|
|
256
|
+
await this.postImportHook.invoke(this)
|
|
246
257
|
} catch (e) {
|
|
247
258
|
error = e
|
|
248
259
|
}
|
|
@@ -764,7 +775,7 @@ class AdaptFrameworkImport {
|
|
|
764
775
|
data[key].forEach(d => this.extractAssets(val.items.properties, d))
|
|
765
776
|
} else if (val?._backboneForms?.type === 'Asset' || val?._backboneForms === 'Asset') {
|
|
766
777
|
data[key] !== ''
|
|
767
|
-
? data[key] = this.assetMap[data[key]]
|
|
778
|
+
? data[key] = this.assetMap[data[key]] ?? data[key]
|
|
768
779
|
: delete data[key]
|
|
769
780
|
}
|
|
770
781
|
})
|
|
@@ -776,6 +787,9 @@ class AdaptFrameworkImport {
|
|
|
776
787
|
* @return {Promise}
|
|
777
788
|
*/
|
|
778
789
|
async cleanUp (error) {
|
|
790
|
+
if (!this.settings.removeSource) {
|
|
791
|
+
return
|
|
792
|
+
}
|
|
779
793
|
try {
|
|
780
794
|
const tasks = [
|
|
781
795
|
fs.rm(this.unzipPath, { recursive: true })
|
|
@@ -32,6 +32,16 @@ class AdaptFrameworkModule extends AbstractModule {
|
|
|
32
32
|
*/
|
|
33
33
|
this.postUpdateHook = new Hook()
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Invoked prior to a course being imported. The AdaptFrameworkImport instance is passed to any observers.
|
|
37
|
+
* @type {Hook}
|
|
38
|
+
*/
|
|
39
|
+
this.preImportHook = new Hook({ mutable: true })
|
|
40
|
+
/**
|
|
41
|
+
* Invoked after a course has been imported. The AdaptFrameworkImport instance is passed to any observers.
|
|
42
|
+
* @type {Hook}
|
|
43
|
+
*/
|
|
44
|
+
this.postImportHook = new Hook()
|
|
35
45
|
/**
|
|
36
46
|
* Invoked prior to a course being built. The AdaptFrameworkBuild instance is passed to any observers.
|
|
37
47
|
* @type {Hook}
|
|
@@ -299,22 +309,25 @@ class AdaptFrameworkModule extends AbstractModule {
|
|
|
299
309
|
* @return {AdaptFrameworkBuild}
|
|
300
310
|
*/
|
|
301
311
|
async buildCourse (options) {
|
|
302
|
-
|
|
312
|
+
const builder = AdaptFrameworkBuild.run(options)
|
|
313
|
+
builder.preBuildHook.tap(() => this.preBuildHook.invoke(builder))
|
|
314
|
+
builder.postBuildHook.tap(() => this.postBuildHook.invoke(builder))
|
|
303
315
|
}
|
|
304
316
|
|
|
305
317
|
/**
|
|
306
318
|
* Imports a single Adapt framework course
|
|
307
|
-
* @param {
|
|
308
|
-
* @param {String} userId _id of the new owner of the imported course
|
|
319
|
+
* @param {AdaptFrameworkImportOptions} options
|
|
309
320
|
* @return {AdaptFrameworkImportSummary}
|
|
310
321
|
*/
|
|
311
|
-
async importCourse (
|
|
312
|
-
let unzipPath = importPath
|
|
313
|
-
if (importPath.endsWith('.zip')) {
|
|
314
|
-
unzipPath = `${importPath}_unzip`
|
|
315
|
-
await unzip(importPath, unzipPath, { removeSource: true })
|
|
322
|
+
async importCourse (options) {
|
|
323
|
+
let unzipPath = options.importPath
|
|
324
|
+
if (options.importPath.endsWith('.zip')) {
|
|
325
|
+
unzipPath = `${options.importPath}_unzip`
|
|
326
|
+
await unzip(options.importPath, unzipPath, { removeSource: true })
|
|
316
327
|
}
|
|
317
|
-
const importer = await AdaptFrameworkImport.run(
|
|
328
|
+
const importer = await AdaptFrameworkImport.run(options)
|
|
329
|
+
importer.preImportHook.tap(() => this.preImportHook.invoke(importer))
|
|
330
|
+
importer.postImportHook.tap(() => this.postImportHook.invoke(importer))
|
|
318
331
|
return await FWUtils.getImportSummary(importer)
|
|
319
332
|
}
|
|
320
333
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-adaptframework",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Adapt framework integration for the Adapt authoring tool",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-adaptframework",
|
|
6
6
|
"license": "GPL-3.0",
|