adapt-authoring-ui 1.9.1 → 2.0.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,3 +1,4 @@
1
+ import { escapeRegExp } from 'adapt-authoring-core'
1
2
  import CacheManager from './CacheManager.js'
2
3
  import path from 'upath'
3
4
  import fs from 'fs-extra'
@@ -71,10 +72,6 @@ export default class JavaScriptTask {
71
72
  if (this.isDisableCache) this.log('info', 'Cache disabled')
72
73
  }
73
74
 
74
- escapeRegExp (string) {
75
- return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string
76
- }
77
-
78
75
  async restoreCache (cachePath, basePath) {
79
76
  if (this.isFirstRun || this.isDisableCache || this.cache || !fs.existsSync(cachePath)) return
80
77
  await new Promise((resolve, reject) => {
@@ -131,7 +128,7 @@ export default class JavaScriptTask {
131
128
  await new Promise((resolve, reject) => {
132
129
  let str = JSON.stringify(bundleCache)
133
130
  // Make cache location agnostic by stripping current basePath
134
- str = str.replace(new RegExp(this.escapeRegExp(basePath), 'g'), '%%basePath%%')
131
+ str = str.replace(new RegExp(escapeRegExp(basePath), 'g'), '%%basePath%%')
135
132
  deflate(str, { level: constants.Z_BEST_SPEED }, (err, buffer) => {
136
133
  if (err) {
137
134
  this.log('error', 'An error occurred saving rollup cache:', err)
package/lib/UiBuild.js CHANGED
@@ -7,6 +7,7 @@ import less from 'less'
7
7
  import { Gaze } from 'gaze'
8
8
  import chalk from 'chalk'
9
9
  import JavaScriptTask from './JavaScriptTask.js'
10
+ import { collate } from './utils/collate.js'
10
11
 
11
12
  class UiBuild {
12
13
  constructor ({ app, log, isDev, buildDir, enableWatch, uiPlugins }) {
@@ -63,16 +64,6 @@ class UiBuild {
63
64
  this.jsTask = new JavaScriptTask(this.Paths.Output, this.log, this.uiPlugins, path.join(this.app.getConfig('tempDir'), 'ui-build-cache'))
64
65
  }
65
66
 
66
- collate (collateAtFolderName, destFolder, srcFileName) {
67
- // ignore if the srcFileName ends with the collateAtFolderName
68
- const nameParts = srcFileName.split('/')
69
- if (nameParts[nameParts.length - 1] === collateAtFolderName) {
70
- return destFolder
71
- }
72
- const startOfCollatePath = srcFileName.indexOf(collateAtFolderName) + collateAtFolderName.length + 1
73
- return path.join(destFolder, srcFileName.substr(startOfCollatePath))
74
- }
75
-
76
67
  logCopy (event, dest, src) {
77
68
  this.log('verbose', `file ${event} ${chalk.cyan(src)} => ${chalk.green(dest)}`)
78
69
  }
@@ -226,7 +217,7 @@ class UiBuild {
226
217
  }
227
218
  try {
228
219
  const src = path.normalize(filepath)
229
- const dest = this.collate(type, dir, src)
220
+ const dest = collate(type, dir, src)
230
221
  await fs.cp(src, dest)
231
222
  this.logCopy(event, dest, src)
232
223
  } catch (e) {
@@ -0,0 +1,21 @@
1
+ import path from 'upath'
2
+
3
+ /**
4
+ * Determines the output file path when collating files by folder name.
5
+ * Returns destFolder if srcFileName ends with collateAtFolderName,
6
+ * otherwise joins destFolder with the portion of srcFileName after the folder name.
7
+ * @param {string} collateAtFolderName The folder name to collate at
8
+ * @param {string} destFolder The destination folder path
9
+ * @param {string} srcFileName The source file path
10
+ * @returns {string} The resolved output path
11
+ * @memberof ui
12
+ */
13
+ export function collate (collateAtFolderName, destFolder, srcFileName) {
14
+ // ignore if the srcFileName ends with the collateAtFolderName
15
+ const nameParts = srcFileName.split('/')
16
+ if (nameParts[nameParts.length - 1] === collateAtFolderName) {
17
+ return destFolder
18
+ }
19
+ const startOfCollatePath = srcFileName.indexOf(collateAtFolderName) + collateAtFolderName.length + 1
20
+ return path.join(destFolder, srcFileName.substr(startOfCollatePath))
21
+ }
package/lib/utils.js ADDED
@@ -0,0 +1 @@
1
+ export { collate } from './utils/collate.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adapt-authoring-ui",
3
- "version": "1.9.1",
3
+ "version": "2.0.0",
4
4
  "description": "Front-end application for the Adapt authoring tool",
5
5
  "homepage": "https://github.com/adapt-security/adapt-authoring-ui",
6
6
  "license": "GPL-3.0",
@@ -21,7 +21,7 @@
21
21
  "@rollup/plugin-commonjs": "^29.0.0",
22
22
  "@rollup/plugin-node-resolve": "^16.0.3",
23
23
  "@rollup/plugin-terser": "^0.4.0",
24
- "adapt-authoring-core": "^1.7.0",
24
+ "adapt-authoring-core": "^2.0.0",
25
25
  "babel-plugin-transform-amd-to-es6": "^1.0.2",
26
26
  "cpy": "^13.0.0",
27
27
  "fs-extra": "^11.2.0",
@@ -37,8 +37,8 @@
37
37
  "upath": "^2.0.1"
38
38
  },
39
39
  "peerDependencies": {
40
- "adapt-authoring-adaptframework": "^1.9.4",
41
- "adapt-authoring-server": "^1.2.1"
40
+ "adapt-authoring-adaptframework": "^2.0.0",
41
+ "adapt-authoring-server": "^2.0.0"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "adapt-authoring-adaptframework": {
@@ -0,0 +1,53 @@
1
+ import { describe, it } from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import { collate } from '../lib/utils/collate.js'
4
+
5
+ describe('collate()', () => {
6
+ it('should return destFolder when srcFileName ends with collateAtFolderName', () => {
7
+ const result = collate('assets', '/output/css/assets', 'some/path/assets')
8
+ assert.equal(result, '/output/css/assets')
9
+ })
10
+
11
+ it('should join destFolder with path after collateAtFolderName', () => {
12
+ const result = collate('assets', '/output/css/assets', 'node_modules/plugin/assets/image.png')
13
+ assert.equal(result, '/output/css/assets/image.png')
14
+ })
15
+
16
+ it('should handle nested paths after collateAtFolderName', () => {
17
+ const result = collate('assets', '/output/css/assets', 'node_modules/plugin/assets/fonts/bold.woff')
18
+ assert.equal(result, '/output/css/assets/fonts/bold.woff')
19
+ })
20
+
21
+ it('should handle libraries folder type', () => {
22
+ const result = collate('libraries', '/output/libraries', 'node_modules/adapt-authoring-ui/app/libraries/jquery.js')
23
+ assert.equal(result, '/output/libraries/jquery.js')
24
+ })
25
+
26
+ it('should handle required folder type', () => {
27
+ const result = collate('required', '/output', 'node_modules/adapt-authoring-ui/app/core/required/config.json')
28
+ assert.equal(result, '/output/config.json')
29
+ })
30
+
31
+ it('should handle srcFileName that exactly matches collateAtFolderName', () => {
32
+ const result = collate('assets', '/dest', 'assets')
33
+ assert.equal(result, '/dest')
34
+ })
35
+
36
+ it('should handle multiple occurrences of collateAtFolderName (uses first)', () => {
37
+ const result = collate('assets', '/dest', 'path/assets/sub/assets/file.png')
38
+ assert.equal(result, '/dest/sub/assets/file.png')
39
+ })
40
+
41
+ it('should handle paths with no content after collateAtFolderName marker', () => {
42
+ const result = collate('assets', '/dest', 'some/path/assets/')
43
+ // srcFileName ends with '/' not 'assets', so it enters the path calculation
44
+ // indexOf('assets') + 'assets'.length + 1 = past the slash, substr returns empty string
45
+ const expected = '/dest'
46
+ assert.equal(result, expected)
47
+ })
48
+
49
+ it('should return a string', () => {
50
+ const result = collate('assets', '/output', 'some/assets/file.txt')
51
+ assert.equal(typeof result, 'string')
52
+ })
53
+ })