Roll Back compile version
This commit is contained in:
Vendored
+80
-63
@@ -1,13 +1,28 @@
|
||||
#! /usr/bin/env node
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = run;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), ".env"),
|
||||
path: path_1.default.resolve(process.cwd(), ".env"),
|
||||
});
|
||||
import datasquirel from "../index";
|
||||
import colors from "../console-colors";
|
||||
import createDbFromSchema from "../package-shared/shell/createDbFromSchema";
|
||||
if (!fs.existsSync(path.resolve(process.cwd(), ".env"))) {
|
||||
const index_1 = __importDefault(require("../index"));
|
||||
const console_colors_1 = __importDefault(require("../console-colors"));
|
||||
const createDbFromSchema_1 = __importDefault(require("../package-shared/shell/createDbFromSchema"));
|
||||
if (!fs_1.default.existsSync(path_1.default.resolve(process.cwd(), ".env"))) {
|
||||
console.log(".env file not found");
|
||||
process.exit();
|
||||
}
|
||||
@@ -24,74 +39,76 @@ if (!(DSQL_PASS === null || DSQL_PASS === void 0 ? void 0 : DSQL_PASS.match(/./)
|
||||
console.log("DSQL_PASS is required in your `.env` file");
|
||||
process.exit();
|
||||
}
|
||||
const dbSchemaLocalFilePath = path.resolve(process.cwd(), "dsql.schema.json");
|
||||
export default async function run() {
|
||||
let schemaData;
|
||||
if (DSQL_KEY && (DSQL_REF_DB_NAME === null || DSQL_REF_DB_NAME === void 0 ? void 0 : DSQL_REF_DB_NAME.match(/./))) {
|
||||
const dbSchemaDataResponse = await datasquirel.getSchema({
|
||||
key: DSQL_KEY,
|
||||
database: DSQL_REF_DB_NAME || undefined,
|
||||
});
|
||||
if (!dbSchemaDataResponse.payload ||
|
||||
Array.isArray(dbSchemaDataResponse.payload)) {
|
||||
console.log("DSQL_KEY+DSQL_REF_DB_NAME => Error in fetching DB schema");
|
||||
console.log(dbSchemaDataResponse);
|
||||
const dbSchemaLocalFilePath = path_1.default.resolve(process.cwd(), "dsql.schema.json");
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let schemaData;
|
||||
if (DSQL_KEY && (DSQL_REF_DB_NAME === null || DSQL_REF_DB_NAME === void 0 ? void 0 : DSQL_REF_DB_NAME.match(/./))) {
|
||||
const dbSchemaDataResponse = yield index_1.default.getSchema({
|
||||
key: DSQL_KEY,
|
||||
database: DSQL_REF_DB_NAME || undefined,
|
||||
});
|
||||
if (!dbSchemaDataResponse.payload ||
|
||||
Array.isArray(dbSchemaDataResponse.payload)) {
|
||||
console.log("DSQL_KEY+DSQL_REF_DB_NAME => Error in fetching DB schema");
|
||||
console.log(dbSchemaDataResponse);
|
||||
process.exit();
|
||||
}
|
||||
let fetchedDbSchemaObject = dbSchemaDataResponse.payload;
|
||||
if (DSQL_DB_NAME)
|
||||
fetchedDbSchemaObject.dbFullName = DSQL_DB_NAME;
|
||||
schemaData = [fetchedDbSchemaObject];
|
||||
}
|
||||
else if (DSQL_KEY) {
|
||||
const dbSchemaDataResponse = yield index_1.default.getSchema({
|
||||
key: DSQL_KEY,
|
||||
database: DSQL_REF_DB_NAME || undefined,
|
||||
});
|
||||
if (!dbSchemaDataResponse.payload ||
|
||||
!Array.isArray(dbSchemaDataResponse.payload)) {
|
||||
console.log("DSQL_KEY => Error in fetching DB schema");
|
||||
console.log(dbSchemaDataResponse);
|
||||
process.exit();
|
||||
}
|
||||
let fetchedDbSchemaObject = dbSchemaDataResponse.payload;
|
||||
// fetchedDbSchemaObject.forEach((db, index) => {
|
||||
// db.dbFullName = db.dbFullName?.replace(/^datasquirel_user_\d+_/, "");
|
||||
// });
|
||||
schemaData = fetchedDbSchemaObject;
|
||||
}
|
||||
else if (fs_1.default.existsSync(dbSchemaLocalFilePath)) {
|
||||
schemaData = [
|
||||
JSON.parse(fs_1.default.readFileSync(dbSchemaLocalFilePath, "utf8")),
|
||||
];
|
||||
}
|
||||
else {
|
||||
console.log("No source for DB Schema. Please provide a local `dsql.schema.json` file, or provide `DSQL_KEY` and `DSQL_REF_DB_NAME` environment variables.");
|
||||
process.exit();
|
||||
}
|
||||
let fetchedDbSchemaObject = dbSchemaDataResponse.payload;
|
||||
if (DSQL_DB_NAME)
|
||||
fetchedDbSchemaObject.dbFullName = DSQL_DB_NAME;
|
||||
schemaData = [fetchedDbSchemaObject];
|
||||
}
|
||||
else if (DSQL_KEY) {
|
||||
const dbSchemaDataResponse = await datasquirel.getSchema({
|
||||
key: DSQL_KEY,
|
||||
database: DSQL_REF_DB_NAME || undefined,
|
||||
});
|
||||
if (!dbSchemaDataResponse.payload ||
|
||||
!Array.isArray(dbSchemaDataResponse.payload)) {
|
||||
console.log("DSQL_KEY => Error in fetching DB schema");
|
||||
console.log(dbSchemaDataResponse);
|
||||
if (!schemaData) {
|
||||
console.log("No schema found");
|
||||
process.exit();
|
||||
}
|
||||
let fetchedDbSchemaObject = dbSchemaDataResponse.payload;
|
||||
// fetchedDbSchemaObject.forEach((db, index) => {
|
||||
// db.dbFullName = db.dbFullName?.replace(/^datasquirel_user_\d+_/, "");
|
||||
// });
|
||||
schemaData = fetchedDbSchemaObject;
|
||||
}
|
||||
else if (fs.existsSync(dbSchemaLocalFilePath)) {
|
||||
schemaData = [
|
||||
JSON.parse(fs.readFileSync(dbSchemaLocalFilePath, "utf8")),
|
||||
];
|
||||
}
|
||||
else {
|
||||
console.log("No source for DB Schema. Please provide a local `dsql.schema.json` file, or provide `DSQL_KEY` and `DSQL_REF_DB_NAME` environment variables.");
|
||||
process.exit();
|
||||
}
|
||||
if (!schemaData) {
|
||||
console.log("No schema found");
|
||||
process.exit();
|
||||
}
|
||||
if (DSQL_FULL_SYNC === null || DSQL_FULL_SYNC === void 0 ? void 0 : DSQL_FULL_SYNC.match(/true/i)) {
|
||||
fs.writeFileSync(dbSchemaLocalFilePath, JSON.stringify(schemaData[0], null, 4), "utf8");
|
||||
}
|
||||
console.log(` - ${colors.FgBlue}Info:${colors.Reset} Now generating and mapping databases ...`);
|
||||
await createDbFromSchema({
|
||||
dbSchemaData: schemaData,
|
||||
if (DSQL_FULL_SYNC === null || DSQL_FULL_SYNC === void 0 ? void 0 : DSQL_FULL_SYNC.match(/true/i)) {
|
||||
fs_1.default.writeFileSync(dbSchemaLocalFilePath, JSON.stringify(schemaData[0], null, 4), "utf8");
|
||||
}
|
||||
console.log(` - ${console_colors_1.default.FgBlue}Info:${console_colors_1.default.Reset} Now generating and mapping databases ...`);
|
||||
yield (0, createDbFromSchema_1.default)({
|
||||
dbSchemaData: schemaData,
|
||||
});
|
||||
console.log(` - ${console_colors_1.default.FgGreen}Success:${console_colors_1.default.Reset} Databases created Successfully!`);
|
||||
});
|
||||
console.log(` - ${colors.FgGreen}Success:${colors.Reset} Databases created Successfully!`);
|
||||
}
|
||||
let interval;
|
||||
if (fs.existsSync(dbSchemaLocalFilePath) && !(DSQL_KEY === null || DSQL_KEY === void 0 ? void 0 : DSQL_KEY.match(/....../))) {
|
||||
fs.watchFile(dbSchemaLocalFilePath, { interval: 1000 }, (curr, prev) => {
|
||||
console.log(` - ${colors.FgBlue}Info:${colors.Reset} Syncing Databases Locally ...`);
|
||||
if (fs_1.default.existsSync(dbSchemaLocalFilePath) && !(DSQL_KEY === null || DSQL_KEY === void 0 ? void 0 : DSQL_KEY.match(/....../))) {
|
||||
fs_1.default.watchFile(dbSchemaLocalFilePath, { interval: 1000 }, (curr, prev) => {
|
||||
console.log(` - ${console_colors_1.default.FgBlue}Info:${console_colors_1.default.Reset} Syncing Databases Locally ...`);
|
||||
run();
|
||||
});
|
||||
}
|
||||
else if (DSQL_KEY === null || DSQL_KEY === void 0 ? void 0 : DSQL_KEY.match(/....../)) {
|
||||
interval = setInterval(() => {
|
||||
console.log(` - ${colors.FgMagenta}Info:${colors.Reset} Syncing Databases from the cloud ...`);
|
||||
console.log(` - ${console_colors_1.default.FgMagenta}Info:${console_colors_1.default.Reset} Syncing Databases from the cloud ...`);
|
||||
run();
|
||||
}, 20000);
|
||||
}
|
||||
|
||||
Vendored
+9
-4
@@ -1,9 +1,14 @@
|
||||
#! /usr/bin/env node
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var _a, _b, _c;
|
||||
import path from "path";
|
||||
import { execSync } from "child_process";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const child_process_1 = require("child_process");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(process.cwd(), ".env"),
|
||||
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" + "'"
|
||||
@@ -34,7 +39,7 @@ try {
|
||||
cwd: process.cwd(),
|
||||
};
|
||||
// if (process.platform.match(/win/i)) execSyncOptions.shell = "bash.exe";
|
||||
const dump = execSync(`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbName} < ${dumpFilePath}`, execSyncOptions);
|
||||
const dump = (0, child_process_1.execSync)(`${mysqlPath} -u ${DSQL_USER} -p${DSQL_PASS} ${dbName} < ${dumpFilePath}`, execSyncOptions);
|
||||
console.log("Dumped successfully", dump.toString());
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
Vendored
+40
-26
@@ -1,12 +1,26 @@
|
||||
#! /usr/bin/env node
|
||||
import fs from "fs";
|
||||
import datasquirel from "..";
|
||||
import { parseArgs } from "util";
|
||||
import dbSchemaToType from "../package-shared/functions/dsql/db-schema-to-type";
|
||||
import path from "path";
|
||||
import debugLog from "../package-shared/utils/logging/debug-log";
|
||||
import parseEnv from "../package-shared/utils/parse-env";
|
||||
const args = parseArgs({
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const __1 = __importDefault(require(".."));
|
||||
const util_1 = require("util");
|
||||
const db_schema_to_type_1 = __importDefault(require("../package-shared/functions/dsql/db-schema-to-type"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const debug_log_1 = __importDefault(require("../package-shared/utils/logging/debug-log"));
|
||||
const parse_env_1 = __importDefault(require("../package-shared/utils/parse-env"));
|
||||
const args = (0, util_1.parseArgs)({
|
||||
args: process.argv,
|
||||
options: {
|
||||
apiKey: {
|
||||
@@ -41,12 +55,12 @@ const args = parseArgs({
|
||||
});
|
||||
let appendedEnv = {};
|
||||
if (args.values.envfile && typeof args.values.envfile == "string") {
|
||||
const finalEnvPath = path.resolve(process.cwd(), args.values.envfile);
|
||||
if (fs.existsSync(finalEnvPath)) {
|
||||
const parsedEnv = parseEnv(finalEnvPath);
|
||||
const finalEnvPath = path_1.default.resolve(process.cwd(), args.values.envfile);
|
||||
if (fs_1.default.existsSync(finalEnvPath)) {
|
||||
const parsedEnv = (0, parse_env_1.default)(finalEnvPath);
|
||||
appendedEnv = (parsedEnv || {});
|
||||
if (args.values.debug) {
|
||||
debugLog({
|
||||
(0, debug_log_1.default)({
|
||||
log: appendedEnv,
|
||||
label: "Appended env",
|
||||
title: "Schema to Typedef",
|
||||
@@ -57,25 +71,25 @@ if (args.values.envfile && typeof args.values.envfile == "string") {
|
||||
}
|
||||
const finalEnv = Object.assign(Object.assign({}, process.env), appendedEnv);
|
||||
process.env = Object.assign(Object.assign({}, process.env), appendedEnv);
|
||||
(async () => {
|
||||
(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||
try {
|
||||
const key = args.values.apiKey || finalEnv["DSQL_FULL_ACCESS_API_KEY"];
|
||||
const database = args.values.database || finalEnv["DSQL_DB_NAME"];
|
||||
const user_id = args.values.userid || finalEnv["DSQL_API_USER_ID"] || "1";
|
||||
if (args.values.debug) {
|
||||
debugLog({
|
||||
(0, debug_log_1.default)({
|
||||
log: args.values,
|
||||
label: "Arguments",
|
||||
title: "Schema to Typedef",
|
||||
addTime: true,
|
||||
});
|
||||
debugLog({
|
||||
(0, debug_log_1.default)({
|
||||
log: process.env.DSQL_FULL_ACCESS_API_KEY,
|
||||
label: "process.env.DSQL_FULL_ACCESS_API_KEY",
|
||||
title: "Schema to Typedef",
|
||||
addTime: true,
|
||||
});
|
||||
debugLog({
|
||||
(0, debug_log_1.default)({
|
||||
log: process.env.DSQL_DB_NAME,
|
||||
label: "process.env.DSQL_DB_NAME",
|
||||
title: "Schema to Typedef",
|
||||
@@ -90,7 +104,7 @@ process.env = Object.assign(Object.assign({}, process.env), appendedEnv);
|
||||
throw new Error("Outfile are required");
|
||||
if (!user_id || typeof user_id !== "string")
|
||||
throw new Error("Outfile are required");
|
||||
const schema = await datasquirel.getSchema({
|
||||
const schema = yield __1.default.getSchema({
|
||||
key,
|
||||
database,
|
||||
user_id,
|
||||
@@ -98,7 +112,7 @@ process.env = Object.assign(Object.assign({}, process.env), appendedEnv);
|
||||
});
|
||||
const dbSchema = schema.payload;
|
||||
if (args.values.debug) {
|
||||
debugLog({
|
||||
(0, debug_log_1.default)({
|
||||
log: schema,
|
||||
label: "schema",
|
||||
title: "Schema to Typedef",
|
||||
@@ -107,16 +121,16 @@ process.env = Object.assign(Object.assign({}, process.env), appendedEnv);
|
||||
}
|
||||
if (!dbSchema)
|
||||
throw new Error("No schema found");
|
||||
const definitions = dbSchemaToType({ dbSchema });
|
||||
const finalOutfile = path.resolve(process.cwd(), args.values.outfile);
|
||||
const ourfileDir = path.dirname(finalOutfile);
|
||||
if (!fs.existsSync(ourfileDir)) {
|
||||
fs.mkdirSync(ourfileDir, { recursive: true });
|
||||
const definitions = (0, db_schema_to_type_1.default)({ dbSchema });
|
||||
const finalOutfile = path_1.default.resolve(process.cwd(), args.values.outfile);
|
||||
const ourfileDir = path_1.default.dirname(finalOutfile);
|
||||
if (!fs_1.default.existsSync(ourfileDir)) {
|
||||
fs_1.default.mkdirSync(ourfileDir, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(finalOutfile, (definitions === null || definitions === void 0 ? void 0 : definitions.join("\n\n")) || "", "utf-8");
|
||||
fs_1.default.writeFileSync(finalOutfile, (definitions === null || definitions === void 0 ? void 0 : definitions.join("\n\n")) || "", "utf-8");
|
||||
}
|
||||
catch (error) {
|
||||
debugLog({
|
||||
(0, debug_log_1.default)({
|
||||
log: error.message,
|
||||
label: "Error",
|
||||
title: "Schema to Typedef",
|
||||
@@ -125,4 +139,4 @@ process.env = Object.assign(Object.assign({}, process.env), appendedEnv);
|
||||
});
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
||||
}))();
|
||||
|
||||
Reference in New Issue
Block a user