188 lines
8.7 KiB
JavaScript
188 lines
8.7 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.default = grabDirNames;
|
|
const path_1 = __importDefault(require("path"));
|
|
function grabDirNames(param) {
|
|
var _a;
|
|
const appDir = (param === null || param === void 0 ? void 0 : param.appDir) || process.env.DSQL_APP_DIR;
|
|
const DATA_DIR = (param === null || param === void 0 ? void 0 : param.dataDir) || process.env.DSQL_DATA_DIR || "/data";
|
|
const finalUserId = ((_a = param === null || param === void 0 ? void 0 : param.user) === null || _a === void 0 ? void 0 : _a.id) || (param === null || param === void 0 ? void 0 : param.userId);
|
|
if (!appDir)
|
|
throw new Error("Please provide the `DSQL_APP_DIR` env variable.");
|
|
if (!DATA_DIR)
|
|
throw new Error("Please provide the `DATA_DIR` env variable.");
|
|
const STATIC_ROOT = path_1.default.join(DATA_DIR, "static");
|
|
const publicImagesDir = path_1.default.join(STATIC_ROOT, `images`);
|
|
const publicDir = path_1.default.join(appDir, "public");
|
|
const publicSSLDir = path_1.default.join(publicDir, "documents", "ssl");
|
|
const appSSLDir = path_1.default.join(appDir, "ssl");
|
|
const mainSSLDir = path_1.default.join(DATA_DIR, "ssl");
|
|
const maxscaleSSLDir = path_1.default.join(mainSSLDir, "maxscale");
|
|
const mainDBSSLDir = path_1.default.join(mainSSLDir, "main");
|
|
const replica1DBSSLDir = path_1.default.join(mainSSLDir, "replica-1");
|
|
const replica2DBSSLDir = path_1.default.join(mainSSLDir, "replica-2");
|
|
const privateDataDir = path_1.default.join(DATA_DIR, "private");
|
|
/**
|
|
* # DB Dir names
|
|
* @description Database related Directories
|
|
*/
|
|
const mainDbDataDir = path_1.default.join(DATA_DIR, "db");
|
|
const mainDbGrastateDatFile = path_1.default.join(mainDbDataDir, "grastate.dat");
|
|
const replica1DbDataDir = path_1.default.join(DATA_DIR, "replica-1");
|
|
const mariadbMainConfigDir = path_1.default.join(DATA_DIR, "db-config", "main");
|
|
const mariadbReplicaConfigDir = path_1.default.join(DATA_DIR, "db-config", "replica");
|
|
const maxscaleConfigDir = path_1.default.join(DATA_DIR, "db-config", "maxscale");
|
|
const mariadbMainConfigFile = path_1.default.join(mariadbMainConfigDir, "default.cnf");
|
|
const mariadbReplicaConfigFile = path_1.default.join(mariadbReplicaConfigDir, "default.cnf");
|
|
const galeraConfigFile = path_1.default.join(mariadbMainConfigDir, "galera.cnf");
|
|
const galeraReplicaConfigFile = path_1.default.join(mariadbReplicaConfigDir, "galera.cnf");
|
|
const maxscaleConfigFile = path_1.default.join(maxscaleConfigDir, "maxscale.cnf");
|
|
/**
|
|
* # Schema Dir names
|
|
* @description
|
|
*/
|
|
const oldSchemasDir = path_1.default.join(appDir, "jsonData", "dbSchemas");
|
|
const appSchemaJSONFile = path_1.default.join(oldSchemasDir, "1.json");
|
|
const tempDirName = ".tmp";
|
|
const appConfigDir = path_1.default.join(appDir, "jsonData", "config");
|
|
const appConfigJSONFile = path_1.default.join(appConfigDir, "app-config.json");
|
|
if (!privateDataDir)
|
|
throw new Error("Please provide the `DSQL_DB_SCHEMA_DIR` env variable.");
|
|
const pakageSharedDir = path_1.default.join(appDir, `package-shared`);
|
|
const mainDbTypeDefFile = path_1.default.join(pakageSharedDir, `types/dsql.ts`);
|
|
const mainShemaJSONFilePath = path_1.default.join(oldSchemasDir, `main.json`);
|
|
const defaultTableFieldsJSONFilePath = path_1.default.join(pakageSharedDir, `data/defaultFields.json`);
|
|
const usersSchemaDir = path_1.default.join(privateDataDir, `users`);
|
|
const targetUserPrivateDir = finalUserId
|
|
? path_1.default.join(usersSchemaDir, `user-${finalUserId}`)
|
|
: undefined;
|
|
const userTempSQLFilePath = targetUserPrivateDir
|
|
? path_1.default.join(targetUserPrivateDir, `tmp.sql`)
|
|
: undefined;
|
|
const userMainShemaJSONFilePath = targetUserPrivateDir
|
|
? path_1.default.join(targetUserPrivateDir, `main.json`)
|
|
: undefined;
|
|
const userConfigJSONFilePath = targetUserPrivateDir
|
|
? path_1.default.join(targetUserPrivateDir, `config.json`)
|
|
: undefined;
|
|
const userSchemaMainJSONFilePath = targetUserPrivateDir
|
|
? path_1.default.join(targetUserPrivateDir, `main.json`)
|
|
: undefined;
|
|
const userPrivateMediaDir = targetUserPrivateDir
|
|
? path_1.default.join(targetUserPrivateDir, `media`)
|
|
: undefined;
|
|
const userPrivateExportsDir = targetUserPrivateDir
|
|
? path_1.default.join(targetUserPrivateDir, `export`)
|
|
: undefined;
|
|
const userPrivateSQLExportsDir = userPrivateExportsDir
|
|
? path_1.default.join(userPrivateExportsDir, `sql`)
|
|
: undefined;
|
|
const userPrivateTempSQLExportsDir = userPrivateSQLExportsDir
|
|
? path_1.default.join(userPrivateSQLExportsDir, tempDirName)
|
|
: undefined;
|
|
const userPrivateTempJSONSchemaFilePath = userPrivateTempSQLExportsDir
|
|
? path_1.default.join(userPrivateTempSQLExportsDir, `schema.json`)
|
|
: undefined;
|
|
const userPrivateDbExportZipFileName = `db-export.zip`;
|
|
const userPrivateDbExportZipFilePath = userPrivateSQLExportsDir
|
|
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
|
: undefined;
|
|
const userPublicMediaDir = finalUserId
|
|
? path_1.default.join(publicImagesDir, `user-images/user-${finalUserId}`)
|
|
: undefined;
|
|
const userPrivateDbImportZipFileName = `db-export.zip`;
|
|
const userPrivateDbImportZipFilePath = userPrivateSQLExportsDir
|
|
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
|
|
: undefined;
|
|
const dbNginxLoadBalancerConfigFile = path_1.default.join(appDir, "docker/services/mariadb/load-balancer/config/template/nginx.conf");
|
|
let dockerComposeFile = path_1.default.join(appDir, "docker-compose.yml");
|
|
let dockerComposeFileAlt = path_1.default.join(appDir, "docker-compose.yaml");
|
|
const testDockerComposeFile = path_1.default.join(appDir, "test.docker-compose.yml");
|
|
const testDockerComposeFileAlt = path_1.default.join(appDir, "test.docker-compose.yaml");
|
|
const dbDockerComposeFile = path_1.default.join(appDir, "db.docker-compose.yml");
|
|
const dbDockerComposeFileAlt = path_1.default.join(appDir, "db.docker-compose.yaml");
|
|
const extraDockerComposeFile = path_1.default.join(appDir, "extra.docker-compose.yml");
|
|
const extraDockerComposeFileAlt = path_1.default.join(appDir, "extra.docker-compose.yaml");
|
|
const siteSetupFile = path_1.default.join(appDir, "site-setup.json");
|
|
const envFile = path_1.default.join(appDir, ".env");
|
|
const testEnvFile = path_1.default.join(appDir, "test.env");
|
|
/**
|
|
* # Backup Dir names
|
|
* @description
|
|
*/
|
|
const mainBackupDir = path_1.default.join(DATA_DIR, "backups");
|
|
const userBackupDir = targetUserPrivateDir
|
|
? path_1.default.join(targetUserPrivateDir, `backups`)
|
|
: undefined;
|
|
const sqlBackupDirName = `sql`;
|
|
const schemasBackupDirName = `schema`;
|
|
return {
|
|
appDir,
|
|
privateDataDir,
|
|
oldSchemasDir,
|
|
userConfigJSONFilePath,
|
|
mainShemaJSONFilePath,
|
|
mainDbTypeDefFile,
|
|
tempDirName,
|
|
defaultTableFieldsJSONFilePath,
|
|
usersSchemaDir,
|
|
targetUserPrivateDir,
|
|
userSchemaMainJSONFilePath,
|
|
userPrivateMediaDir,
|
|
userPrivateExportsDir,
|
|
userPrivateSQLExportsDir,
|
|
userPrivateTempSQLExportsDir,
|
|
userPrivateTempJSONSchemaFilePath,
|
|
userPrivateDbExportZipFileName,
|
|
userPrivateDbExportZipFilePath,
|
|
userPrivateDbImportZipFileName,
|
|
userPrivateDbImportZipFilePath,
|
|
dbNginxLoadBalancerConfigFile,
|
|
dockerComposeFile,
|
|
dockerComposeFileAlt,
|
|
testDockerComposeFile,
|
|
testDockerComposeFileAlt,
|
|
extraDockerComposeFile,
|
|
extraDockerComposeFileAlt,
|
|
siteSetupFile,
|
|
envFile,
|
|
testEnvFile,
|
|
userPublicMediaDir,
|
|
userTempSQLFilePath,
|
|
STATIC_ROOT,
|
|
appConfigJSONFile,
|
|
appConfigDir,
|
|
mariadbMainConfigDir,
|
|
mariadbMainConfigFile,
|
|
maxscaleConfigDir,
|
|
mariadbReplicaConfigDir,
|
|
DATA_DIR,
|
|
publicDir,
|
|
publicSSLDir,
|
|
appSSLDir,
|
|
maxscaleConfigFile,
|
|
mariadbReplicaConfigFile,
|
|
mainSSLDir,
|
|
mainDbDataDir,
|
|
replica1DbDataDir,
|
|
galeraConfigFile,
|
|
galeraReplicaConfigFile,
|
|
dbDockerComposeFile,
|
|
dbDockerComposeFileAlt,
|
|
mainDbGrastateDatFile,
|
|
appSchemaJSONFile,
|
|
mainBackupDir,
|
|
userBackupDir,
|
|
sqlBackupDirName,
|
|
schemasBackupDirName,
|
|
userMainShemaJSONFilePath,
|
|
maxscaleSSLDir,
|
|
mainDBSSLDir,
|
|
replica1DBSSLDir,
|
|
replica2DBSSLDir,
|
|
};
|
|
}
|