From 71ef33c24162bc9ab07e24dca842d6c0e00c69b5 Mon Sep 17 00:00:00 2001 From: Tben Date: Fri, 25 Aug 2023 09:28:22 +0100 Subject: [PATCH] Updates --- console-colors.js | 31 +++++++++++++++++++++++++++++++ engine/dsql.js | 34 ++++++++++++++++------------------ package.json | 2 +- 3 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 console-colors.js diff --git a/console-colors.js b/console-colors.js new file mode 100644 index 0000000..bec5d22 --- /dev/null +++ b/console-colors.js @@ -0,0 +1,31 @@ +const colors = { + Reset: "\x1b[0m", + Bright: "\x1b[1m", + Dim: "\x1b[2m", + Underscore: "\x1b[4m", + Blink: "\x1b[5m", + Reverse: "\x1b[7m", + Hidden: "\x1b[8m", + + FgBlack: "\x1b[30m", + FgRed: "\x1b[31m", + FgGreen: "\x1b[32m", + FgYellow: "\x1b[33m", + FgBlue: "\x1b[34m", + FgMagenta: "\x1b[35m", + FgCyan: "\x1b[36m", + FgWhite: "\x1b[37m", + FgGray: "\x1b[90m", + + BgBlack: "\x1b[40m", + BgRed: "\x1b[41m", + BgGreen: "\x1b[42m", + BgYellow: "\x1b[43m", + BgBlue: "\x1b[44m", + BgMagenta: "\x1b[45m", + BgCyan: "\x1b[46m", + BgWhite: "\x1b[47m", + BgGray: "\x1b[100m", +}; + +module.exports = colors; diff --git a/engine/dsql.js b/engine/dsql.js index 3d7f96d..aa1ba20 100644 --- a/engine/dsql.js +++ b/engine/dsql.js @@ -11,6 +11,7 @@ require("dotenv").config({ const datasquirel = require("../index"); const createDbFromSchema = require("./engine/createDbFromSchema"); +const colors = require("../console-colors"); if (!fs.existsSync(path.resolve(process.cwd(), ".env"))) { console.log(".env file not found"); @@ -89,30 +90,27 @@ async function run() { fs.writeFileSync(dbSchemaLocalFilePath, JSON.stringify(schemaData[0], null, 4), "utf8"); } - console.log("Now generating and mapping databases ..."); - // console.log("Db Schema =>", schemaData); + console.log(` - ${colors.FgBlue}Info:${colors.Reset} Now generating and mapping databases ...`); + // deepcode ignore reDOS: await createDbFromSchema(schemaData); - console.log("Databases created Successfully!"); + console.log(` - ${colors.FgGreen}Success:${colors.Reset} Databases created Successfully!`); } // let timeout; -// if (fs.existsSync(dbSchemaLocalFilePath)) { -// fs.watchFile(dbSchemaLocalFilePath, { interval: 1000 }, (curr, prev) => { -// clearTimeout(timeout); - -// timeout = setTimeout(() => { -// console.log("`dsql.schema.json` file changed. Now syncing databases ..."); -// run(); -// }, 5000); -// }); -// } - let interval; -interval = setInterval(() => { - console.log("Syncing Databases ..."); - run(); -}, 20000); + +if (fs.existsSync(dbSchemaLocalFilePath) && !DSQL_KEY?.match(/....../)) { + fs.watchFile(dbSchemaLocalFilePath, { interval: 1000 }, (curr, prev) => { + console.log(` - ${colors.FgBlue}Info:${colors.Reset} Syncing Databases Locally ...`); + run(); + }); +} else if (DSQL_KEY?.match(/....../)) { + interval = setInterval(() => { + console.log(` - ${colors.FgMagenta}Info:${colors.Reset} Syncing Databases from the cloud ...`); + run(); + }, 20000); +} run(); diff --git a/package.json b/package.json index a5632d8..87e5526 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "1.8.4", + "version": "1.8.5", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": {