34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
const path = require("path");
|
|
const { readAreaConfig } = require("./lib/area-config");
|
|
const { compileArea: compileWithCli } = require("./lib/road-compiler-cli");
|
|
|
|
const repoRoot = path.resolve(__dirname, "..");
|
|
|
|
function parseArgs(argv) {
|
|
const result = {};
|
|
for (let index = 0; index < argv.length; index += 1) {
|
|
if (!argv[index].startsWith("--")) continue;
|
|
const key = argv[index].slice(2).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
result[key] = argv[index + 1] && !argv[index + 1].startsWith("--") ? argv[++index] : "true";
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function compileArea(configPath) {
|
|
const area = readAreaConfig(configPath, { repoRoot });
|
|
return { area, marker: compileWithCli(area) };
|
|
}
|
|
|
|
function main() {
|
|
const args = parseArgs(process.argv.slice(2));
|
|
const configPath = path.resolve(args.config || path.join(repoRoot, "config", "areas", "nantaizi-lake-innovation-valley.json"));
|
|
compileArea(configPath);
|
|
}
|
|
|
|
if (require.main === module) main();
|
|
|
|
module.exports = { compileArea, parseArgs };
|