adapt-authoring-contentplugin 1.5.4 → 1.6.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.
|
@@ -1,32 +1,16 @@
|
|
|
1
1
|
name: Release
|
|
2
|
+
|
|
2
3
|
on:
|
|
3
4
|
push:
|
|
4
5
|
branches:
|
|
5
6
|
- master
|
|
6
7
|
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
issues: write
|
|
11
|
+
pull-requests: write
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
7
14
|
jobs:
|
|
8
15
|
release:
|
|
9
|
-
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
permissions:
|
|
12
|
-
contents: write # to be able to publish a GitHub release
|
|
13
|
-
issues: write # to be able to comment on released issues
|
|
14
|
-
pull-requests: write # to be able to comment on released pull requests
|
|
15
|
-
id-token: write # to enable use of OIDC for trusted publishing and npm provenance
|
|
16
|
-
steps:
|
|
17
|
-
- name: Checkout
|
|
18
|
-
uses: actions/checkout@v3
|
|
19
|
-
with:
|
|
20
|
-
fetch-depth: 0
|
|
21
|
-
- name: Setup Node.js
|
|
22
|
-
uses: actions/setup-node@v3
|
|
23
|
-
with:
|
|
24
|
-
node-version: 'lts/*'
|
|
25
|
-
- name: Update npm
|
|
26
|
-
run: npm install -g npm@latest
|
|
27
|
-
- name: Install dependencies
|
|
28
|
-
run: npm install
|
|
29
|
-
- name: Release
|
|
30
|
-
env:
|
|
31
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
32
|
-
run: npx semantic-release
|
|
16
|
+
uses: adaptlearning/semantic-release-config/.github/workflows/release.yml@master
|
|
@@ -4,6 +4,7 @@ import path from 'node:path'
|
|
|
4
4
|
import { readJson } from 'adapt-authoring-core'
|
|
5
5
|
import { loadRouteConfig } from 'adapt-authoring-server'
|
|
6
6
|
import {
|
|
7
|
+
addDefaultPlugins,
|
|
7
8
|
backupPluginVersion,
|
|
8
9
|
getMostRecentBackup,
|
|
9
10
|
cleanupOldPluginBackups,
|
|
@@ -44,7 +45,7 @@ class ContentPluginModule extends AbstractApiModule {
|
|
|
44
45
|
if (!process.env.ADAPT_ALLOW_PRERELEASE) {
|
|
45
46
|
process.env.ADAPT_ALLOW_PRERELEASE = 'true'
|
|
46
47
|
}
|
|
47
|
-
const [framework, mongodb] = await this.app.waitForModule('adaptframework', 'mongodb')
|
|
48
|
+
const [framework, mongodb, content] = await this.app.waitForModule('adaptframework', 'mongodb', 'content')
|
|
48
49
|
|
|
49
50
|
await mongodb.setIndex(this.collectionName, 'name', { unique: true })
|
|
50
51
|
await mongodb.setIndex(this.collectionName, 'displayName', { unique: true })
|
|
@@ -60,6 +61,7 @@ class ContentPluginModule extends AbstractApiModule {
|
|
|
60
61
|
} catch (e) {
|
|
61
62
|
this.log('error', e)
|
|
62
63
|
}
|
|
64
|
+
content.preInsertHook.tap((...args) => addDefaultPlugins(this, ...args))
|
|
63
65
|
this.framework.postInstallHook.tap(this.syncPluginData.bind(this))
|
|
64
66
|
this.framework.postUpdateHook.tap(this.syncPluginData.bind(this))
|
|
65
67
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds default plugins to a course config's _enabledPlugins list.
|
|
3
|
+
* Intended to be tapped into the content module's preInsertHook.
|
|
4
|
+
* @param {Object} contentplugin The contentplugin module instance
|
|
5
|
+
* @param {Object} data The insert data (mutated in place)
|
|
6
|
+
* @param {Object} options
|
|
7
|
+
* @param {String} options.schemaName The schema name for the insert
|
|
8
|
+
*/
|
|
9
|
+
async function addDefaultPlugins (contentplugin, data, { schemaName }) {
|
|
10
|
+
if (schemaName !== 'config') {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
const defaultPlugins = await contentplugin.find({ isAddedByDefault: true })
|
|
14
|
+
if (!defaultPlugins.length) {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
if (!data._enabledPlugins) data._enabledPlugins = []
|
|
18
|
+
defaultPlugins.forEach(({ name }) => !data._enabledPlugins.includes(name) && data._enabledPlugins.push(name))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { addDefaultPlugins }
|
package/lib/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { addDefaultPlugins } from './utils/addDefaultPlugins.js'
|
|
1
2
|
export { backupPluginVersion } from './utils/backupPluginVersion.js'
|
|
2
3
|
export { getMostRecentBackup } from './utils/getMostRecentBackup.js'
|
|
3
4
|
export { cleanupOldPluginBackups } from './utils/cleanupOldPluginBackups.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-contentplugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Module for managing framework plugins",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-contentplugin",
|
|
6
6
|
"repository": "github:adapt-security/adapt-authoring-contentplugin",
|
|
@@ -24,36 +24,10 @@
|
|
|
24
24
|
"adapt-authoring-server": "^2.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@semantic-release
|
|
28
|
-
"conventional-changelog-eslint": "^6.0.0",
|
|
29
|
-
"semantic-release": "^25.0.2",
|
|
27
|
+
"@adaptlearning/semantic-release-config": "^1.0.0",
|
|
30
28
|
"standard": "^17.1.0"
|
|
31
29
|
},
|
|
32
30
|
"release": {
|
|
33
|
-
"
|
|
34
|
-
[
|
|
35
|
-
"@semantic-release/commit-analyzer",
|
|
36
|
-
{
|
|
37
|
-
"preset": "eslint"
|
|
38
|
-
}
|
|
39
|
-
],
|
|
40
|
-
[
|
|
41
|
-
"@semantic-release/release-notes-generator",
|
|
42
|
-
{
|
|
43
|
-
"preset": "eslint"
|
|
44
|
-
}
|
|
45
|
-
],
|
|
46
|
-
"@semantic-release/npm",
|
|
47
|
-
"@semantic-release/github",
|
|
48
|
-
[
|
|
49
|
-
"@semantic-release/git",
|
|
50
|
-
{
|
|
51
|
-
"assets": [
|
|
52
|
-
"package.json"
|
|
53
|
-
],
|
|
54
|
-
"message": "Chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
]
|
|
31
|
+
"extends": "@adaptlearning/semantic-release-config"
|
|
58
32
|
}
|
|
59
33
|
}
|
|
@@ -55,6 +55,11 @@
|
|
|
55
55
|
"latestCompatibleVersion" : {
|
|
56
56
|
"type": "boolean",
|
|
57
57
|
"isReadOnly": true
|
|
58
|
+
},
|
|
59
|
+
"isAddedByDefault": {
|
|
60
|
+
"description": "Whether the plugin should be added by default for new courses",
|
|
61
|
+
"type": "boolean",
|
|
62
|
+
"default": false
|
|
58
63
|
}
|
|
59
64
|
},
|
|
60
65
|
"required": ["framework", "name", "type", "version", "isLocalInstall"]
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { describe, it } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { addDefaultPlugins } from '../lib/utils/addDefaultPlugins.js'
|
|
4
|
+
|
|
5
|
+
function createMockContentplugin (plugins = []) {
|
|
6
|
+
return { find: async () => plugins }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('addDefaultPlugins', () => {
|
|
10
|
+
describe('when schemaName is not config', () => {
|
|
11
|
+
it('should not modify data for non-config schemas', async () => {
|
|
12
|
+
const contentplugin = createMockContentplugin([{ name: 'plugin-a' }])
|
|
13
|
+
const data = {}
|
|
14
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'course' })
|
|
15
|
+
assert.equal(data._enabledPlugins, undefined)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('should not modify data for article schema', async () => {
|
|
19
|
+
const contentplugin = createMockContentplugin([{ name: 'plugin-a' }])
|
|
20
|
+
const data = { _enabledPlugins: ['existing'] }
|
|
21
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'article' })
|
|
22
|
+
assert.deepEqual(data._enabledPlugins, ['existing'])
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
describe('when schemaName is config', () => {
|
|
27
|
+
it('should add default plugins to _enabledPlugins', async () => {
|
|
28
|
+
const contentplugin = createMockContentplugin([{ name: 'plugin-a' }, { name: 'plugin-b' }])
|
|
29
|
+
const data = {}
|
|
30
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
31
|
+
assert.deepEqual(data._enabledPlugins, ['plugin-a', 'plugin-b'])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('should create _enabledPlugins array if it does not exist', async () => {
|
|
35
|
+
const contentplugin = createMockContentplugin([{ name: 'plugin-a' }])
|
|
36
|
+
const data = {}
|
|
37
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
38
|
+
assert.ok(Array.isArray(data._enabledPlugins))
|
|
39
|
+
assert.deepEqual(data._enabledPlugins, ['plugin-a'])
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should append to existing _enabledPlugins', async () => {
|
|
43
|
+
const contentplugin = createMockContentplugin([{ name: 'plugin-b' }])
|
|
44
|
+
const data = { _enabledPlugins: ['plugin-a'] }
|
|
45
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
46
|
+
assert.deepEqual(data._enabledPlugins, ['plugin-a', 'plugin-b'])
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('should not duplicate plugins already in _enabledPlugins', async () => {
|
|
50
|
+
const contentplugin = createMockContentplugin([{ name: 'plugin-a' }, { name: 'plugin-b' }])
|
|
51
|
+
const data = { _enabledPlugins: ['plugin-a'] }
|
|
52
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
53
|
+
assert.deepEqual(data._enabledPlugins, ['plugin-a', 'plugin-b'])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('should not modify _enabledPlugins when no default plugins found', async () => {
|
|
57
|
+
const contentplugin = createMockContentplugin([])
|
|
58
|
+
const data = { _enabledPlugins: ['existing'] }
|
|
59
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
60
|
+
assert.deepEqual(data._enabledPlugins, ['existing'])
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should not create _enabledPlugins when no default plugins found', async () => {
|
|
64
|
+
const contentplugin = createMockContentplugin([])
|
|
65
|
+
const data = {}
|
|
66
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
67
|
+
assert.equal(data._enabledPlugins, undefined)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('should call find with isAddedByDefault true', async () => {
|
|
71
|
+
let findQuery
|
|
72
|
+
const contentplugin = {
|
|
73
|
+
find: async (query) => {
|
|
74
|
+
findQuery = query
|
|
75
|
+
return []
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
await addDefaultPlugins(contentplugin, {}, { schemaName: 'config' })
|
|
79
|
+
assert.deepEqual(findQuery, { isAddedByDefault: true })
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('should handle a single default plugin', async () => {
|
|
83
|
+
const contentplugin = createMockContentplugin([{ name: 'only-plugin' }])
|
|
84
|
+
const data = {}
|
|
85
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
86
|
+
assert.deepEqual(data._enabledPlugins, ['only-plugin'])
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('should handle many default plugins', async () => {
|
|
90
|
+
const plugins = Array.from({ length: 10 }, (_, i) => ({ name: `plugin-${i}` }))
|
|
91
|
+
const contentplugin = createMockContentplugin(plugins)
|
|
92
|
+
const data = {}
|
|
93
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
94
|
+
assert.equal(data._enabledPlugins.length, 10)
|
|
95
|
+
plugins.forEach((p, i) => {
|
|
96
|
+
assert.equal(data._enabledPlugins[i], p.name)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('should handle all plugins already enabled', async () => {
|
|
101
|
+
const contentplugin = createMockContentplugin([{ name: 'plugin-a' }, { name: 'plugin-b' }])
|
|
102
|
+
const data = { _enabledPlugins: ['plugin-a', 'plugin-b'] }
|
|
103
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
104
|
+
assert.deepEqual(data._enabledPlugins, ['plugin-a', 'plugin-b'])
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('should preserve order of existing plugins', async () => {
|
|
108
|
+
const contentplugin = createMockContentplugin([{ name: 'plugin-c' }])
|
|
109
|
+
const data = { _enabledPlugins: ['plugin-b', 'plugin-a'] }
|
|
110
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
111
|
+
assert.deepEqual(data._enabledPlugins, ['plugin-b', 'plugin-a', 'plugin-c'])
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('should handle _enabledPlugins as empty array', async () => {
|
|
115
|
+
const contentplugin = createMockContentplugin([{ name: 'plugin-a' }])
|
|
116
|
+
const data = { _enabledPlugins: [] }
|
|
117
|
+
await addDefaultPlugins(contentplugin, data, { schemaName: 'config' })
|
|
118
|
+
assert.deepEqual(data._enabledPlugins, ['plugin-a'])
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
})
|