adapt-authoring-contentplugin 1.0.1 → 1.0.3
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.
- package/.github/workflows/standardjs.yml +13 -0
- package/lib/ContentPluginModule.js +19 -10
- package/package.json +1 -2
- package/.eslintignore +0 -1
- package/.eslintrc +0 -14
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
name: Standard.js formatting check
|
|
2
|
+
on: push
|
|
3
|
+
jobs:
|
|
4
|
+
default:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
steps:
|
|
7
|
+
- uses: actions/checkout@master
|
|
8
|
+
- uses: actions/setup-node@master
|
|
9
|
+
with:
|
|
10
|
+
node-version: 'lts/*'
|
|
11
|
+
cache: 'npm'
|
|
12
|
+
- run: npm ci
|
|
13
|
+
- run: npx standard
|
|
@@ -106,7 +106,7 @@ class ContentPluginModule extends AbstractApiModule {
|
|
|
106
106
|
return results
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
async readJson(filepath) {
|
|
109
|
+
async readJson (filepath) {
|
|
110
110
|
return JSON.parse(await fs.readFile(filepath))
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -145,22 +145,27 @@ class ContentPluginModule extends AbstractApiModule {
|
|
|
145
145
|
* @return {Promise}
|
|
146
146
|
*/
|
|
147
147
|
async initPlugins () {
|
|
148
|
+
this.log('verbose', 'INIT_PLUGINS')
|
|
148
149
|
const missing = await this.getMissingPlugins()
|
|
149
150
|
if (missing.length) { // note we're using CLI directly, as plugins already exist in the DB
|
|
150
151
|
this.log('debug', 'MISSING', missing)
|
|
151
152
|
await this.framework.runCliCommand('installPlugins', { plugins: missing })
|
|
152
153
|
}
|
|
153
|
-
await
|
|
154
|
-
|
|
154
|
+
const results = await Promise.allSettled([
|
|
155
|
+
this.syncPluginData(),
|
|
156
|
+
this.processPluginSchemas()
|
|
157
|
+
])
|
|
158
|
+
results.forEach(r => r.status === 'rejected' && this.log('error', r.reason))
|
|
155
159
|
}
|
|
156
160
|
|
|
157
161
|
/**
|
|
158
162
|
* Makes sure the database plugin data is in sync with the currently installed framework plugins
|
|
159
163
|
*/
|
|
160
|
-
async syncPluginData() {
|
|
164
|
+
async syncPluginData () {
|
|
165
|
+
this.log('verbose', 'SYNC_PLUGINS')
|
|
161
166
|
const dbInfo = (await this.find()).reduce((memo, info) => Object.assign(memo, { [info.name]: info }), {})
|
|
162
167
|
for (const i of await this.framework.runCliCommand('getPluginUpdateInfos')) {
|
|
163
|
-
if(dbInfo[i.name]?.version !== i.matchedVersion) {
|
|
168
|
+
if (dbInfo[i.name]?.version !== i.matchedVersion) {
|
|
164
169
|
this.log('debug', 'SYNC', i.name, 'local:', dbInfo[i.name]?.version, 'fw:', i.matchedVersion)
|
|
165
170
|
await this.insertOrUpdate({ ...(await i.getInfo()), type: await i.getType(), isLocalInstall: i.isLocalSource })
|
|
166
171
|
}
|
|
@@ -172,10 +177,11 @@ class ContentPluginModule extends AbstractApiModule {
|
|
|
172
177
|
* If no plugins are defined in the database, it returns all plugins defined in the framework manifest
|
|
173
178
|
* @return {Array} List of plugin names mapped to version/dir
|
|
174
179
|
*/
|
|
175
|
-
async getMissingPlugins() {
|
|
180
|
+
async getMissingPlugins () {
|
|
176
181
|
const dbPlugins = await this.find()
|
|
177
|
-
if (!dbPlugins.length)
|
|
182
|
+
if (!dbPlugins.length) {
|
|
178
183
|
return (await this.framework.getManifestPlugins()).map(([name, version]) => `${name}@${version}`)
|
|
184
|
+
}
|
|
179
185
|
const fwPlugins = await this.framework.getInstalledPlugins()
|
|
180
186
|
return dbPlugins
|
|
181
187
|
.filter(dbP => !fwPlugins.find(fwP => dbP.name === fwP.name))
|
|
@@ -184,13 +190,16 @@ class ContentPluginModule extends AbstractApiModule {
|
|
|
184
190
|
|
|
185
191
|
/**
|
|
186
192
|
* Loads and processes all installed content plugin schemas
|
|
187
|
-
* @param {Array} pluginInfo Plugin info data
|
|
193
|
+
* @param {Array|Object} pluginInfo Plugin info data
|
|
188
194
|
* @return {Promise}
|
|
189
195
|
*/
|
|
190
196
|
async processPluginSchemas (pluginInfo) {
|
|
191
197
|
if (!pluginInfo) {
|
|
192
198
|
pluginInfo = await this.framework.runCliCommand('getPluginUpdateInfos')
|
|
193
199
|
}
|
|
200
|
+
if (!Array.isArray(pluginInfo)) {
|
|
201
|
+
pluginInfo = [pluginInfo]
|
|
202
|
+
}
|
|
194
203
|
const jsonschema = await this.app.waitForModule('jsonschema')
|
|
195
204
|
return Promise.all(pluginInfo.map(async plugin => {
|
|
196
205
|
const name = plugin.name
|
|
@@ -291,7 +300,7 @@ class ContentPluginModule extends AbstractApiModule {
|
|
|
291
300
|
async installPlugin (pluginName, versionOrPath, options = { strict: false, force: false }) {
|
|
292
301
|
const [pluginData] = await this.find({ name: String(pluginName) }, { includeUpdateInfo: true })
|
|
293
302
|
const { name, version, sourcePath, isLocalInstall } = await this.processPluginFiles({ ...pluginData, sourcePath: versionOrPath })
|
|
294
|
-
const [
|
|
303
|
+
const [existingPlugin] = await this.find({ name })
|
|
295
304
|
|
|
296
305
|
if (existingPlugin) {
|
|
297
306
|
if (!options.force && semver.lte(version, existingPlugin.version)) {
|
|
@@ -313,7 +322,7 @@ class ContentPluginModule extends AbstractApiModule {
|
|
|
313
322
|
throw this.app.errors.CONTENTPLUGIN_ATTR_MISSING
|
|
314
323
|
.setData({ name })
|
|
315
324
|
}
|
|
316
|
-
await this.processPluginSchemas(
|
|
325
|
+
await this.processPluginSchemas(data)
|
|
317
326
|
return info
|
|
318
327
|
}
|
|
319
328
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-contentplugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Module for managing framework plugins",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-contentplugin",
|
|
6
6
|
"main": "index.js",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"semver": "^7.6.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"eslint": "^9.12.0",
|
|
15
14
|
"standard": "^17.1.0",
|
|
16
15
|
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
17
16
|
"@semantic-release/git": "^10.0.1",
|
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node_modules
|