forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjspec_env.js
More file actions
38 lines (32 loc) · 1.02 KB
/
Copy pathjspec_env.js
File metadata and controls
38 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require('fs')
const path = require('path')
const config = {
__SPEC_FILE: null,
__SPEC_DIR: null,
}
const printErr = (...args) => {
// wrap err output in red
console.error('\033[31m\n', ...args, '\033[37m')
}
// make sure JSPEC env was set properly
if (process.env.JSPEC_WD && process.env.JSPEC_PATH) {
const specPath = path.join(process.env.JSPEC_WD, process.env.JSPEC_PATH)
try {
const pathInfo = fs.statSync(specPath)
if (pathInfo.isFile()) {
config.__SPEC_FILE = specPath
} else if (pathInfo.isDirectory()) {
config.__SPEC_DIR = specPath
}
} catch (e) {
// most likely ENOENT (file not found)
// print error and exit so we don't continue with the webpack build
printErr('Error reading spec path:', e.code, specPath)
process.exit(1)
}
}
// JSON.stringify config values since webpack plugin does a hard search-replace
module.exports = Object.keys(config).reduce((outputConfig, key) => {
outputConfig[key] = JSON.stringify(config[key])
return outputConfig
}, {})