-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathrun_demo.js
66 lines (56 loc) · 1.76 KB
/
run_demo.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const child_process = require("child_process");
const fs = require("fs");
const path = require("path");
const testData = require("../../../resources/.test/test_data.json");
const availableLanguages = testData["tests"]["language_tests"].map(
(x) => x["language"],
);
const language = process.argv.slice(2)[0];
if (!language) {
console.error(
`Choose the language you would like to run the demo in with "yarn start [language]".\nAvailable languages are ${availableLanguages.join(
", ",
)}`,
);
process.exit(1);
}
if (!availableLanguages.includes(language)) {
console.error(
`'${language}' is not an available demo language.\nAvailable languages are ${availableLanguages.join(
", ",
)}`,
);
process.exit(1);
}
const suffix = language === "en" ? "" : `_${language}`;
const rootDir = path.join(__dirname, "..", "..", "..");
let outputDirectory = path.join(__dirname, "..", "models");
if (fs.existsSync(outputDirectory)) {
fs.readdirSync(outputDirectory).forEach((f) => {
fs.unlinkSync(path.join(outputDirectory, f));
});
} else {
fs.mkdirSync(outputDirectory, { recursive: true });
}
const modelDir = path.join(rootDir, "lib", "common");
const modelName = `leopard_params${suffix}.pv`;
fs.copyFileSync(
path.join(modelDir, modelName),
path.join(outputDirectory, modelName),
);
fs.writeFileSync(
path.join(outputDirectory, "leopardModel.js"),
`const leopardModel = {
publicPath: "models/${modelName}",
forceWrite: true,
};
(function () {
if (typeof module !== "undefined" && typeof module.exports !== "undefined")
module.exports = leopardModel;
})();`,
);
const command = process.platform === "win32" ? "npx.cmd" : "npx";
child_process.execSync(`${command} http-server -a localhost -p 5000`, {
shell: true,
stdio: "inherit",
});