adapt-authoring-docs 1.4.0 → 1.4.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.
package/bin/docgen.js CHANGED
@@ -77,7 +77,7 @@ async function copyRootFiles () {
77
77
  async function docs () {
78
78
  const dependencies = await loadDependencies(rootDir)
79
79
  const pkg = { ...await readJson(path.join(rootDir, 'package.json')), ...await readJson(path.join(rootDir, 'adapt-authoring.json')) }
80
- const config = await loadConfigDefaults(dependencies)
80
+ const config = await loadConfigDefaults(rootDir, dependencies)
81
81
  const schemas = await loadSchemas(dependencies)
82
82
  const errors = await loadErrors(dependencies)
83
83
  const routerTree = await buildRouterTree(dependencies)
@@ -105,7 +105,7 @@ async function docs () {
105
105
 
106
106
  try {
107
107
  await fs.rm(outputdir, { recursive: true, force: true })
108
- await fs.mkdir(outputdir)
108
+ await fs.mkdir(outputdir, { recursive: true })
109
109
  await copyRootFiles()
110
110
  await jsdoc3(appData, cachedConfigs, outputdir, defaultPages)
111
111
  await docsify(appData, cachedConfigs, outputdir, defaultPages)
package/lib/docsData.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { loadDependencyFiles, readJson } from 'adapt-authoring-core'
2
2
  import { glob } from 'glob'
3
- import os from 'os'
4
3
  import path from 'path'
5
4
  import { pathToRegexp } from 'path-to-regexp'
6
5
 
@@ -35,11 +34,13 @@ export async function loadDependencies (rootDir) {
35
34
 
36
35
  /**
37
36
  * Reads conf/config.schema.json from each dependency, extracts default values,
38
- * and returns a { get(key) } object. Resolves $TEMP to os.tmpdir().
37
+ * and returns a { get(key) } object. Resolves $ROOT, $DATA and $TEMP to match
38
+ * the real app config (see JsonSchemaModule's isDirectory keyword).
39
+ * @param {string} rootDir Absolute path to the app root
39
40
  * @param {Object} dependencies Dependencies map from loadDependencies
40
41
  * @returns {Promise<Object>}
41
42
  */
42
- export async function loadConfigDefaults (dependencies) {
43
+ export async function loadConfigDefaults (rootDir, dependencies) {
43
44
  const allConfigs = await loadDependencyFiles('conf/config.schema.json', {
44
45
  parse: true,
45
46
  dependencies
@@ -53,6 +54,16 @@ export async function loadConfigDefaults (dependencies) {
53
54
  }
54
55
  if (Object.keys(modDefaults).length) defaults[depName] = modDefaults
55
56
  }
57
+ const coreDefaults = defaults['adapt-authoring-core'] || {}
58
+ const resolveVar = (value, varName, replacement) => {
59
+ return value.startsWith(varName) ? path.resolve(replacement, value.slice(varName.length + 1)) : value
60
+ }
61
+ const dataDir = typeof coreDefaults.dataDir === 'string'
62
+ ? resolveVar(coreDefaults.dataDir, '$ROOT', rootDir)
63
+ : path.join(rootDir, 'APP_DATA', 'data')
64
+ const tempDir = typeof coreDefaults.tempDir === 'string'
65
+ ? resolveVar(coreDefaults.tempDir, '$ROOT', rootDir)
66
+ : path.join(rootDir, 'APP_DATA', 'temp')
56
67
  return {
57
68
  get: (key) => {
58
69
  const dotIdx = key.indexOf('.')
@@ -60,8 +71,9 @@ export async function loadConfigDefaults (dependencies) {
60
71
  const modName = key.slice(0, dotIdx)
61
72
  const propKey = key.slice(dotIdx + 1)
62
73
  const val = defaults[modName]?.[propKey]
63
- if (typeof val === 'string') return val.replace('$TEMP', os.tmpdir())
64
- return val
74
+ if (typeof val !== 'string') return val
75
+ return [['$ROOT', rootDir], ['$DATA', dataDir], ['$TEMP', tempDir]]
76
+ .reduce((v, [k, r]) => resolveVar(v, k, r), val)
65
77
  }
66
78
  }
67
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-docs",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Tools for auto-generating documentation for the Adapt authoring tool",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-docs",
6
6
  "license": "GPL-3.0",
@@ -1,7 +1,7 @@
1
1
  import assert from 'node:assert/strict'
2
2
  import { describe, it, before, after } from 'node:test'
3
3
  import fs from 'fs/promises'
4
- import os from 'os'
4
+ import os from 'node:os'
5
5
  import path from 'path'
6
6
 
7
7
  /* eslint-disable no-template-curly-in-string */
@@ -150,6 +150,24 @@ async function createFixture () {
150
150
  }
151
151
  }))
152
152
 
153
+ // --- fake core module with dataDir/tempDir config ---
154
+ const coreDir = path.join(root, 'node_modules', 'adapt-authoring-core')
155
+ await fs.mkdir(path.join(coreDir, 'conf'), { recursive: true })
156
+ await fs.writeFile(path.join(coreDir, 'package.json'), JSON.stringify({
157
+ name: 'adapt-authoring-core',
158
+ version: '1.0.0'
159
+ }))
160
+ await fs.writeFile(path.join(coreDir, 'adapt-authoring.json'), JSON.stringify({
161
+ module: false
162
+ }))
163
+ await fs.writeFile(path.join(coreDir, 'conf', 'config.schema.json'), JSON.stringify({
164
+ type: 'object',
165
+ properties: {
166
+ dataDir: { type: 'string', isDirectory: true, default: '$ROOT/APP_DATA/data' },
167
+ tempDir: { type: 'string', isDirectory: true, default: '$ROOT/APP_DATA/temp' }
168
+ }
169
+ }))
170
+
153
171
  // --- fake docs module with config ---
154
172
  const docsDir = path.join(root, 'node_modules', 'adapt-authoring-docs')
155
173
  await fs.mkdir(path.join(docsDir, 'conf'), { recursive: true })
@@ -259,17 +277,18 @@ describe('docsData', () => {
259
277
  })
260
278
 
261
279
  describe('loadConfigDefaults', () => {
262
- it('should resolve $TEMP to os.tmpdir()', async () => {
280
+ it('should resolve $TEMP to the app temp directory', async () => {
263
281
  const { loadConfigDefaults } = await import('../lib/docsData.js')
264
- const config = await loadConfigDefaults(dependencies)
282
+ const config = await loadConfigDefaults(fixtureDir, dependencies)
265
283
  const outputDir = config.get('adapt-authoring-docs.outputDir')
266
- assert.ok(outputDir.startsWith(os.tmpdir()), `expected ${outputDir} to start with ${os.tmpdir()}`)
284
+ const expectedTemp = path.join(fixtureDir, 'APP_DATA', 'temp')
285
+ assert.ok(outputDir.startsWith(expectedTemp), `expected ${outputDir} to start with ${expectedTemp}`)
267
286
  assert.ok(outputDir.endsWith('/docs-build'))
268
287
  })
269
288
 
270
289
  it('should return object defaults', async () => {
271
290
  const { loadConfigDefaults } = await import('../lib/docsData.js')
272
- const config = await loadConfigDefaults(dependencies)
291
+ const config = await loadConfigDefaults(fixtureDir, dependencies)
273
292
  const sections = config.get('adapt-authoring-docs.manualSections')
274
293
  assert.ok(sections)
275
294
  assert.ok(sections['getting-started'] !== undefined)
@@ -278,15 +297,16 @@ describe('docsData', () => {
278
297
 
279
298
  it('should return undefined for unknown config keys', async () => {
280
299
  const { loadConfigDefaults } = await import('../lib/docsData.js')
281
- const config = await loadConfigDefaults(dependencies)
300
+ const config = await loadConfigDefaults(fixtureDir, dependencies)
282
301
  assert.equal(config.get('nonexistent.key'), undefined)
283
302
  })
284
303
 
285
304
  it('should resolve $TEMP in non-docs modules', async () => {
286
305
  const { loadConfigDefaults } = await import('../lib/docsData.js')
287
- const config = await loadConfigDefaults(dependencies)
306
+ const config = await loadConfigDefaults(fixtureDir, dependencies)
288
307
  const cacheDir = config.get('adapt-authoring-content.cacheDir')
289
- assert.ok(cacheDir.startsWith(os.tmpdir()))
308
+ const expectedTemp = path.join(fixtureDir, 'APP_DATA', 'temp')
309
+ assert.ok(cacheDir.startsWith(expectedTemp))
290
310
  assert.ok(cacheDir.endsWith('/content-cache'))
291
311
  })
292
312
  })