UNPKG

1.66 kBJavaScriptView Raw
1"use strict";
2const fs = require("fs");
3const path = require("path");
4var program = require("commander");
5
6const solutionDir = path.join(__dirname, "..");
7
8const 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
17const 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
44program
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
53createConfiguration(program.directory, program.template);