1 | "use strict";
|
2 | const fs = require("fs");
|
3 | const path = require("path");
|
4 | var program = require("commander");
|
5 |
|
6 | const solutionDir = path.join(__dirname, "..");
|
7 |
|
8 | const resolvePathToAbsolute = (baseDir, targetPath) => {
|
9 | if (path.isAbsolute(targetPath)) return targetPath;
|
10 | else if (baseDir) return path.join(baseDir, targetPath);
|
11 | else
|
12 | throw new Error(
|
13 | "Can't resolve relative path without base dir: " + relativePath
|
14 | );
|
15 | };
|
16 |
|
17 | const createConfiguration = (backendDirectory, templateFilePath) => {
|
18 | if (!backendDirectory)
|
19 | throw new Error("Backend directory is not specified");
|
20 |
|
21 | const absoluteBackendDirectory = resolvePathToAbsolute(
|
22 | solutionDir,
|
23 | backendDirectory
|
24 | );
|
25 | if (!fs.existsSync(absoluteBackendDirectory))
|
26 | throw new Error("Backend directory does not exists");
|
27 |
|
28 | const absoluteTemplateFile = resolvePathToAbsolute(
|
29 | solutionDir,
|
30 | templateFilePath
|
31 | );
|
32 | const generalConfiguration = require(absoluteTemplateFile);
|
33 |
|
34 | console.log("Template:", absoluteTemplateFile);
|
35 | console.log("Backend directory:", absoluteBackendDirectory);
|
36 |
|
37 | generalConfiguration.baseDir = absoluteBackendDirectory;
|
38 | fs.writeFileSync(
|
39 | "./build/development-settings.json",
|
40 | JSON.stringify(generalConfiguration, null, 4)
|
41 | );
|
42 | };
|
43 |
|
44 | program
|
45 | .option("-d, --directory <dir>", "Backend directory")
|
46 | .option(
|
47 | "-t, --template [file]",
|
48 | "Template file path",
|
49 | "build/development-settings.template.json"
|
50 | )
|
51 | .parse(process.argv);
|
52 |
|
53 | createConfiguration(program.directory, program.template);
|