adapt-authoring-contentplugin 1.0.0 → 1.0.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.
@@ -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,23 +145,27 @@ class ContentPluginModule extends AbstractApiModule {
145
145
  * @return {Promise}
146
146
  */
147
147
  async initPlugins () {
148
- await this.syncPluginData()
149
-
148
+ this.log('verbose', 'INIT_PLUGINS')
150
149
  const missing = await this.getMissingPlugins()
151
150
  if (missing.length) { // note we're using CLI directly, as plugins already exist in the DB
152
151
  this.log('debug', 'MISSING', missing)
153
152
  await this.framework.runCliCommand('installPlugins', { plugins: missing })
154
153
  }
155
- await this.processPluginSchemas()
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))
156
159
  }
157
160
 
158
161
  /**
159
162
  * Makes sure the database plugin data is in sync with the currently installed framework plugins
160
163
  */
161
- async syncPluginData() {
164
+ async syncPluginData () {
165
+ this.log('verbose', 'SYNC_PLUGINS')
162
166
  const dbInfo = (await this.find()).reduce((memo, info) => Object.assign(memo, { [info.name]: info }), {})
163
167
  for (const i of await this.framework.runCliCommand('getPluginUpdateInfos')) {
164
- if(dbInfo[i.name]?.version !== i.matchedVersion) {
168
+ if (dbInfo[i.name]?.version !== i.matchedVersion) {
165
169
  this.log('debug', 'SYNC', i.name, 'local:', dbInfo[i.name]?.version, 'fw:', i.matchedVersion)
166
170
  await this.insertOrUpdate({ ...(await i.getInfo()), type: await i.getType(), isLocalInstall: i.isLocalSource })
167
171
  }
@@ -170,10 +174,14 @@ class ContentPluginModule extends AbstractApiModule {
170
174
 
171
175
  /**
172
176
  * Returns a list of plugins defined in the database but not installed in the framework
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()
182
+ if (!dbPlugins.length) {
183
+ return (await this.framework.getManifestPlugins()).map(([name, version]) => `${name}@${version}`)
184
+ }
177
185
  const fwPlugins = await this.framework.getInstalledPlugins()
178
186
  return dbPlugins
179
187
  .filter(dbP => !fwPlugins.find(fwP => dbP.name === fwP.name))
@@ -289,7 +297,7 @@ class ContentPluginModule extends AbstractApiModule {
289
297
  async installPlugin (pluginName, versionOrPath, options = { strict: false, force: false }) {
290
298
  const [pluginData] = await this.find({ name: String(pluginName) }, { includeUpdateInfo: true })
291
299
  const { name, version, sourcePath, isLocalInstall } = await this.processPluginFiles({ ...pluginData, sourcePath: versionOrPath })
292
- const [ existingPlugin ] = await this.find({ name })
300
+ const [existingPlugin] = await this.find({ name })
293
301
 
294
302
  if (existingPlugin) {
295
303
  if (!options.force && semver.lte(version, existingPlugin.version)) {
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "adapt-authoring-contentplugin",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Module for managing framework plugins",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-contentplugin",
6
6
  "main": "index.js",
7
7
  "type": "module",
8
8
  "dependencies": {
9
- "adapt-cli": "github:adaptlearning/adapt-cli#v3.3.2",
9
+ "adapt-cli": "github:adaptlearning/adapt-cli#v3.3.3",
10
10
  "glob": "^11.0.0",
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
package/.eslintrc DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "env": {
3
- "browser": false,
4
- "node": true,
5
- "commonjs": false,
6
- "es2020": true
7
- },
8
- "extends": [
9
- "standard"
10
- ],
11
- "parserOptions": {
12
- "ecmaVersion": 2020
13
- }
14
- }