datasquirel/dist/engine/dump.js
Benjamin Toby e9bb9fb07f Updates
2025-02-19 20:01:50 +01:00

52 lines
2.2 KiB
JavaScript

#! /usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a, _b, _c;
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const child_process_1 = require("child_process");
require("dotenv").config({
path: path_1.default.resolve(process.cwd(), ".env"),
});
const mysqlPath = ((_a = process.platform) === null || _a === void 0 ? void 0 : _a.match(/win/i))
? "'" + "C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe" + "'"
: "mysql";
const mysqlDumpPath = ((_b = process.platform) === null || _b === void 0 ? void 0 : _b.match(/win/i))
? "'" +
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
"'"
: "mysqldump";
const { DSQL_USER, DSQL_PASS, DSQL_DB_NAME } = process.env;
const dbName = DSQL_DB_NAME || "";
const dumpFilePathArg = process.argv.indexOf("--file");
if (dumpFilePathArg < 0) {
console.log("Please provide a dump file path using `--file` argument");
process.exit();
}
const dumpFilePath = process.argv[dumpFilePathArg + 1];
if (!(dbName === null || dbName === void 0 ? void 0 : dbName.match(/./))) {
console.log("DSQL_DB_NAME is required in your `.env` file");
process.exit();
}
if (!(DSQL_USER === null || DSQL_USER === void 0 ? void 0 : DSQL_USER.match(/./)) || !(DSQL_PASS === null || DSQL_PASS === void 0 ? void 0 : DSQL_PASS.match(/./))) {
console.log("DSQL_USER and DSQL_PASS are required in your `.env` file");
process.exit();
}
try {
let execSyncOptions = {
cwd: process.cwd(),
};
// if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
const dump = (0, child_process_1.execSync)(`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbName} < ${dumpFilePath}`, execSyncOptions);
console.log("Dumped successfully", dump.toString());
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
}
catch (error) {
(_c = global.ERROR_CALLBACK) === null || _c === void 0 ? void 0 : _c.call(global, `MariaDB Dump Error`, error);
console.log("Dump Error: ", error.message);
}