adapt-authoring-adaptframework 2.3.0 → 2.3.2

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.
@@ -1,5 +1,5 @@
1
1
  import _ from 'lodash'
2
- import { App, ensureDir, writeJson } from 'adapt-authoring-core'
2
+ import { App, Hook, ensureDir, writeJson } from 'adapt-authoring-core'
3
3
  import { parseObjectId } from 'adapt-authoring-mongodb'
4
4
  import { createWriteStream } from 'node:fs'
5
5
  import AdaptCli from 'adapt-cli'
@@ -140,6 +140,16 @@ class AdaptFrameworkBuild {
140
140
  * @type {Array<Object>}
141
141
  */
142
142
  this.disabledPlugins = []
143
+ /**
144
+ * Invoked prior to a course being built.
145
+ * @type {Hook}
146
+ */
147
+ this.preBuildHook = new Hook({ mutable: true })
148
+ /**
149
+ * Invoked after a course has been built.
150
+ * @type {Hook}
151
+ */
152
+ this.postBuildHook = new Hook({ mutable: true })
143
153
  }
144
154
 
145
155
  /**
@@ -180,6 +190,8 @@ class AdaptFrameworkBuild {
180
190
  linkNodeModules: !this.isExport
181
191
  })
182
192
  ])
193
+ await this.preBuildHook.invoke(this)
194
+
183
195
  await this.writeContentJson()
184
196
 
185
197
  logDir('courseDir', this.courseDir)
@@ -206,6 +218,8 @@ class AdaptFrameworkBuild {
206
218
  } else {
207
219
  this.location = this.isPreview ? path.join(this.dir, 'build') : this.dir
208
220
  }
221
+ await this.postBuildHook.invoke(this)
222
+
209
223
  this.buildData = await this.recordBuildAttempt()
210
224
 
211
225
  return this
@@ -1,4 +1,4 @@
1
- import { App, spawn, readJson, writeJson } from 'adapt-authoring-core'
1
+ import { App, Hook, spawn, readJson, writeJson } from 'adapt-authoring-core'
2
2
  import { parseObjectId } from 'adapt-authoring-mongodb'
3
3
  import fs from 'node:fs/promises'
4
4
  import { glob } from 'glob'
@@ -194,6 +194,15 @@ class AdaptFrameworkImport {
194
194
  updatePlugins,
195
195
  removeSource
196
196
  }
197
+ /**
198
+ * Invoked before the import process has started
199
+ */
200
+ this.preImportHook = new Hook()
201
+ /**
202
+ * Invoked once the import process has completed
203
+ */
204
+ this.postImportHook = new Hook()
205
+
197
206
  /**
198
207
  * plugins on import that are of a lower version than the installed version
199
208
  * @type {Array}
@@ -255,6 +264,7 @@ class AdaptFrameworkImport {
255
264
  [this.prepare],
256
265
  [this.loadAssetData],
257
266
  [this.loadPluginData],
267
+ [() => this.preImportHook.invoke(this)],
258
268
  [this.importTags, importContent],
259
269
  [this.importCourseAssets, importContent],
260
270
  [this.importCoursePlugins, isDryRun && importPlugins],
@@ -268,6 +278,7 @@ class AdaptFrameworkImport {
268
278
  for (const task of tasks) {
269
279
  if (task.length < 2 || task[1]) await task[0].call(this)
270
280
  }
281
+ await this.postImportHook.invoke(this)
271
282
  } catch (e) {
272
283
  error = e
273
284
  }
@@ -262,16 +262,12 @@ class AdaptFrameworkModule extends AbstractModule {
262
262
  */
263
263
  async buildCourse (options) {
264
264
  const builder = new AdaptFrameworkBuild(options)
265
- const core = async () => {
266
- await this.preBuildHook.invoke(builder)
267
- await builder.build()
268
- await this.postBuildHook.invoke(builder)
269
- return builder
270
- }
265
+ builder.preBuildHook.tap(() => this.preBuildHook.invoke(builder))
266
+ builder.postBuildHook.tap(() => this.postBuildHook.invoke(builder))
271
267
  if (this.buildHook.hasObservers) {
272
- return this.buildHook.invoke(core, builder)
268
+ return this.buildHook.invoke(async () => builder.build(), builder)
273
269
  }
274
- return core()
270
+ return builder.build()
275
271
  }
276
272
 
277
273
  /**
@@ -281,16 +277,12 @@ class AdaptFrameworkModule extends AbstractModule {
281
277
  */
282
278
  async importCourse (options) {
283
279
  const importer = new AdaptFrameworkImport(options)
284
- const core = async () => {
285
- await this.preImportHook.invoke(importer)
286
- await importer.import()
287
- await this.postImportHook.invoke(importer)
288
- return importer
289
- }
280
+ importer.preImportHook.tap(() => this.preImportHook.invoke(importer))
281
+ importer.postImportHook.tap(() => this.postImportHook.invoke(importer))
290
282
  if (this.importHook.hasObservers) {
291
- return this.importHook.invoke(core, importer)
283
+ return this.importHook.invoke(async () => importer.import(), importer)
292
284
  }
293
- return core()
285
+ return importer.import()
294
286
  }
295
287
  }
296
288
 
@@ -7,7 +7,7 @@ import { App } from 'adapt-authoring-core'
7
7
  */
8
8
  export async function slugifyTitle (buildData) {
9
9
  const content = await App.instance.waitForModule('content')
10
- const [course] = await content.find({ _id: buildData.courseId })
10
+ const course = await content.findOne({ _id: buildData.courseId })
11
11
  const sanitisedTitle = course.title
12
12
  .toLowerCase()
13
13
  .trim()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-adaptframework",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
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",