adapt-authoring-adaptframework 2.4.0 → 2.5.1
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/lib/AdaptFrameworkBuild.js +31 -12
- package/package.json +1 -1
|
@@ -40,11 +40,12 @@ class AdaptFrameworkBuild {
|
|
|
40
40
|
* @property {String} userId The user executing the build
|
|
41
41
|
* @property {String} expiresAt When the build expires
|
|
42
42
|
* @property {Boolean} compress Whether output files should be compressed into an archive file
|
|
43
|
+
* @property {String} outputDir If set, uses this as the build root. If the directory already exists, only content data and assets are written (framework copy and compilation are skipped)
|
|
43
44
|
*
|
|
44
45
|
* @constructor
|
|
45
46
|
* @param {AdaptFrameworkBuildOptions} options
|
|
46
47
|
*/
|
|
47
|
-
constructor ({ action, courseId, userId, expiresAt, compress }) {
|
|
48
|
+
constructor ({ action, courseId, userId, expiresAt, compress, outputDir }) {
|
|
48
49
|
/**
|
|
49
50
|
* The MongoDB collection name
|
|
50
51
|
* @type {String}
|
|
@@ -150,6 +151,11 @@ class AdaptFrameworkBuild {
|
|
|
150
151
|
* @type {Hook}
|
|
151
152
|
*/
|
|
152
153
|
this.postBuildHook = new Hook({ mutable: true })
|
|
154
|
+
/**
|
|
155
|
+
* Custom output directory. If the directory already exists, only content and assets are written
|
|
156
|
+
* @type {String}
|
|
157
|
+
*/
|
|
158
|
+
this.outputDir = outputDir ?? null
|
|
153
159
|
}
|
|
154
160
|
|
|
155
161
|
/**
|
|
@@ -158,23 +164,34 @@ class AdaptFrameworkBuild {
|
|
|
158
164
|
* @return {Promise} Resolves with the output directory
|
|
159
165
|
*/
|
|
160
166
|
async build () {
|
|
161
|
-
|
|
167
|
+
if (!this.outputDir) {
|
|
168
|
+
await this.removeOldBuilds()
|
|
169
|
+
}
|
|
162
170
|
|
|
163
171
|
const framework = await App.instance.waitForModule('adaptframework')
|
|
164
172
|
if (!this.expiresAt) {
|
|
165
173
|
this.expiresAt = await AdaptFrameworkBuild.getBuildExpiry()
|
|
166
174
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
if (this.outputDir) {
|
|
176
|
+
this.dir = this.outputDir
|
|
177
|
+
} else {
|
|
178
|
+
// random suffix to account for parallel builds executed at exactly the same millisecond
|
|
179
|
+
const randomSuffix = `_${Math.floor(Math.random() * 1000).toString().padStart(4, '0')}`
|
|
180
|
+
this.dir = path.resolve(framework.getConfig('buildDir'), Date.now() + randomSuffix)
|
|
181
|
+
}
|
|
170
182
|
this.buildDir = path.join(this.dir, 'build')
|
|
171
183
|
this.courseDir = path.join(this.buildDir, 'course')
|
|
172
184
|
|
|
185
|
+
const dirExists = await fs.access(this.dir).then(() => true, () => false)
|
|
186
|
+
const contentOnly = this.outputDir && dirExists
|
|
187
|
+
|
|
173
188
|
const cacheDir = path.join(framework.getConfig('buildDir'), 'cache')
|
|
174
189
|
|
|
175
190
|
await ensureDir(this.dir)
|
|
176
191
|
await ensureDir(this.buildDir)
|
|
177
|
-
|
|
192
|
+
if (!contentOnly) {
|
|
193
|
+
await ensureDir(cacheDir)
|
|
194
|
+
}
|
|
178
195
|
|
|
179
196
|
logDir('dir', this.dir)
|
|
180
197
|
logDir('buildDir', this.buildDir)
|
|
@@ -182,21 +199,23 @@ class AdaptFrameworkBuild {
|
|
|
182
199
|
|
|
183
200
|
await this.loadCourseData()
|
|
184
201
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
copyFrameworkSource({
|
|
202
|
+
const tasks = [this.copyAssets()]
|
|
203
|
+
if (!contentOnly) {
|
|
204
|
+
tasks.push(copyFrameworkSource({
|
|
188
205
|
destDir: this.dir,
|
|
189
206
|
enabledPlugins: this.enabledPlugins.map(p => p.name),
|
|
190
207
|
linkNodeModules: !this.isExport
|
|
191
|
-
})
|
|
192
|
-
|
|
208
|
+
}))
|
|
209
|
+
}
|
|
210
|
+
await Promise.all(tasks)
|
|
211
|
+
|
|
193
212
|
await this.preBuildHook.invoke(this)
|
|
194
213
|
|
|
195
214
|
await this.writeContentJson()
|
|
196
215
|
|
|
197
216
|
logDir('courseDir', this.courseDir)
|
|
198
217
|
|
|
199
|
-
if (!this.isExport) {
|
|
218
|
+
if (!contentOnly && !this.isExport) {
|
|
200
219
|
try {
|
|
201
220
|
logMemory()
|
|
202
221
|
await AdaptCli.buildCourse({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-adaptframework",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Adapt framework integration for the Adapt authoring tool",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-adaptframework",
|
|
6
6
|
"license": "GPL-3.0",
|