adapt-authoring-adaptframework 2.0.2 → 2.0.4

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,6 @@
1
1
  import _ from 'lodash'
2
2
  import { App, Hook, ensureDir, writeJson } from 'adapt-authoring-core'
3
+ import { parse as parseObjectId } from 'adapt-authoring-mongodb'
3
4
  import { createWriteStream } from 'fs'
4
5
  import AdaptCli from 'adapt-cli'
5
6
  import { log, logDir, logMemory, copyFrameworkSource } from './utils.js'
@@ -254,10 +255,10 @@ class AdaptFrameworkBuild {
254
255
  * @return {Promise}
255
256
  */
256
257
  async loadAssetData () {
257
- const [assets, courseassets, mongodb, tags] = await App.instance.waitForModule('assets', 'courseassets', 'mongodb', 'tags')
258
+ const [assets, courseassets, tags] = await App.instance.waitForModule('assets', 'courseassets', 'tags')
258
259
 
259
260
  const caRecs = await courseassets.find({ courseId: this.courseId })
260
- const uniqueAssetIds = new Set(caRecs.map(c => mongodb.ObjectId.parse(c.assetId)))
261
+ const uniqueAssetIds = new Set(caRecs.map(c => parseObjectId(c.assetId)))
261
262
  const usedAssets = await assets.find({ _id: { $in: [...uniqueAssetIds] } })
262
263
 
263
264
  const usedTagIds = new Set(usedAssets.reduce((m, a) => [...m, ...(a.tags ?? [])], []))
@@ -1,4 +1,5 @@
1
1
  import { App, Hook, spawn, readJson, writeJson } from 'adapt-authoring-core'
2
+ import { parse as parseObjectId } from 'adapt-authoring-mongodb'
2
3
  import fs from 'fs/promises'
3
4
  import { glob } from 'glob'
4
5
  import octopus from 'adapt-octopus'
@@ -660,40 +661,41 @@ class AdaptFrameworkImport {
660
661
  throw App.instance.errors.FW_IMPORT_MISSING_PLUGINS
661
662
  .setData({ plugins: pluginsToInstall.join(', ') })
662
663
  }
663
- const errors = []
664
- await Promise.all([...pluginsToInstall, ...pluginsToUpdate].map(async p => {
664
+ const allPlugins = [...pluginsToInstall, ...pluginsToUpdate]
665
+ // pre-process: store update metadata and fix missing targetAttributes
666
+ for (const p of allPlugins) {
667
+ const isUpdate = pluginsToUpdate.includes(p)
668
+ if (isUpdate && this.installedPlugins[p]) {
669
+ this.updatedContentPlugins[p] = this.installedPlugins[p]
670
+ }
671
+ const pluginBowerPath = path.join(this.usedContentPlugins[p].path, 'bower.json')
672
+ const bowerJson = await readJson(pluginBowerPath)
673
+ if (!bowerJson.targetAttribute) {
674
+ bowerJson.targetAttribute = `_${bowerJson.component || bowerJson.extension || bowerJson.menu || bowerJson.theme}`
675
+ await writeJson(pluginBowerPath, bowerJson)
676
+ }
677
+ this.statusReport.info.push({ code: 'INSTALL_PLUGIN', data: { name: p, version: bowerJson.version } })
678
+ }
679
+ if (!this.settings.isDryRun) {
665
680
  try {
666
- // Store original plugin metadata for updates before overwriting
667
- const isUpdate = pluginsToUpdate.includes(p)
668
- if (isUpdate && this.installedPlugins[p]) {
669
- this.updatedContentPlugins[p] = this.installedPlugins[p]
670
- }
671
- // try and infer a targetAttribute if there isn't one
672
- const pluginBowerPath = path.join(this.usedContentPlugins[p].path, 'bower.json')
673
- const bowerJson = await readJson(pluginBowerPath)
674
- if (!bowerJson.targetAttribute) {
675
- bowerJson.targetAttribute = `_${bowerJson.component || bowerJson.extension || bowerJson.menu || bowerJson.theme}`
676
- await writeJson(pluginBowerPath, bowerJson)
677
- }
678
- if (!this.settings.isDryRun) {
679
- const [pluginData] = await this.contentplugin.installPlugins([[p, this.usedContentPlugins[p].path]], { strict: true })
680
- if (!isUpdate) {
681
- this.newContentPlugins[p] = pluginData
681
+ const installed = await this.contentplugin.installPlugins(
682
+ allPlugins.map(p => [p, this.usedContentPlugins[p].path]),
683
+ { strict: true }
684
+ )
685
+ installed.forEach(pluginData => {
686
+ if (!pluginsToUpdate.includes(pluginData.name)) {
687
+ this.newContentPlugins[pluginData.name] = pluginData
682
688
  }
683
- }
684
- this.statusReport.info.push({ code: 'INSTALL_PLUGIN', data: { name: p, version: bowerJson.version } })
689
+ })
685
690
  } catch (e) {
686
- if (e.code === 'EEXIST') {
687
- log('warn', 'PLUGIN_ALREADY_EXISTS', p)
688
- } else {
689
- log('error', 'PLUGIN_IMPORT_FAILED', p, e)
690
- errors.push({ plugin: p, error: e.data?.errors?.[0] ?? e })
691
- }
691
+ const errors = e.data?.errors?.map(err => ({
692
+ plugin: err.data?.name ?? 'unknown',
693
+ error: err.data?.errors?.[0] ?? err
694
+ })) ?? [{ plugin: 'unknown', error: e }]
695
+ errors.forEach(err => log('error', 'PLUGIN_IMPORT_FAILED', err.plugin, err.error))
696
+ throw App.instance.errors.FW_IMPORT_PLUGINS_FAILED
697
+ .setData({ errors: errors.map(e => App.instance.lang.translate(undefined, e)).join(', ') })
692
698
  }
693
- }))
694
- if (errors.length) {
695
- throw App.instance.errors.FW_IMPORT_PLUGINS_FAILED
696
- .setData({ errors: errors.map(e => App.instance.lang.translate(undefined, e)).join(', ') })
697
699
  }
698
700
  }
699
701
  this.componentNameMap = Object.values({ ...this.installedPlugins, ...this.newContentPlugins }).reduce((m, v) => {
@@ -877,8 +879,7 @@ class AdaptFrameworkImport {
877
879
  }
878
880
  let _courseId
879
881
  try {
880
- const { ObjectId } = await App.instance.waitForModule('mongodb')
881
- _courseId = ObjectId.parse(this.idMap[this.contentJson.course._id])
882
+ _courseId = parseObjectId(this.idMap[this.contentJson.course._id])
882
883
  } catch (e) {}
883
884
  if (_courseId) {
884
885
  tasks.push(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-adaptframework",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
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",