-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuilder.js
41 lines (34 loc) · 1.23 KB
/
builder.js
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
39
40
41
// This is not the most elegant way to import surveys from this module
// but we have trouble packaging dynamic imports
var glob = require("glob");
const fs = require("fs");
const capitalize = (string) => {
return string ? string.charAt(0).toUpperCase() + string.slice(1) : "";
};
function writeLines(surveyName) {
const uppercaseName = capitalize(surveyName);
return `
import ${surveyName}Json from "../surveys/${surveyName}/${surveyName}.json";
import ${surveyName}Sha from "../surveys/${surveyName}/sha.json";
import { default as ${surveyName}ScoreFunc } from "../surveys/${surveyName}/${surveyName}.score.js";
export const ${uppercaseName} = SurveyFactory("${surveyName}", ${surveyName}Json, ${surveyName}ScoreFunc, ${surveyName}Sha);
`;
}
glob("surveys/*/", function (er, dirs) {
const surveyNames = dirs.map((dir) => dir.split("/")[1]);
var lines = [
`// auto-generated by builder.js
// run "npm run build" to regenerate
// automatically rebuilt on push
import SurveyFactory from "./surveyFactory.jsx"
`,
];
lines.push(...surveyNames.map(writeLines));
const content = lines.join("");
console.log("building index.js");
fs.writeFile("src/index.js", content, (err) => {
if (err) {
console.error(err);
}
});
});