Skip to content

Commit

Permalink
AutoCommit: Bump Repository (Update Repository Files)
Browse files Browse the repository at this point in the history
  • Loading branch information
thealternatedev committed Oct 20, 2023
1 parent 8c95728 commit bf22c4f
Show file tree
Hide file tree
Showing 18 changed files with 456 additions and 15 deletions.
17 changes: 17 additions & 0 deletions bin/CommandBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CommandBuilder {
constructor(name) {
this.name = name;
this.args = [];
this.options = [];
this.description = "";
this.callback = () => {};
}
Expand All @@ -21,6 +22,21 @@ class CommandBuilder {
return this;
}

addArgument(arg) {
this.args.push(arg);
return this;
}

addOption(opt) {
this.options.push(opt);
return this;
}

setOptions(opts) {
this.options = opts;
return this;
}

setDescription(description) {
this.description = description;
return this;
Expand All @@ -36,6 +52,7 @@ class CommandBuilder {
name: this.name,
args: this.args,
description: this.description,
options: this.options,
callback: this.callback
};
}
Expand Down
8 changes: 7 additions & 1 deletion bin/CommandsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { Collection } = require("discord.js");

function RegisterCommand(program, data) {

const { name, args, description, callback } = data;
const { name, args, description, options, callback } = data;


if (!description) {
Expand All @@ -22,6 +22,12 @@ function RegisterCommand(program, data) {
l.argument(arg);
}
}

if (options && options.length) {
for (const option of options) {
l.option(option);
}
}
}

function RegisterJSONCommand(program, builder) {
Expand Down
6 changes: 5 additions & 1 deletion bin/commands/InitCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Nanospinner = require("nanospinner");
const spinner = Nanospinner.createSpinner();
const InitializationTools = require('../../globals/InitializationUtils');

const maxSteps = 4;
const maxSteps = 5;
let currentStep = 1;

function startStep(text) {
Expand Down Expand Up @@ -51,6 +51,10 @@ module.exports = () => CommandBuilder.createBuilder("init")

InitializationTools.createConfigurationFiles();

step("Installing Required dependencies")

//InitializationTools.installRequired();

step("Done! Created All Files");

});
6 changes: 5 additions & 1 deletion bin/commands/RegisterCommands.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const { RegisterCommand, RegisterJSONCommand } = require("../CommandsHandler");
const InitCommand = require("./InitCommand");
const VersionCommand = require("./VersionCommand")
const RunCommand = require("./RunCommand");
const VersionCommand = require("./VersionCommand");
const WatchCommand = require("./WatchCommand");

module.exports = (program) => {
RegisterJSONCommand(program, VersionCommand());
RegisterJSONCommand(program, InitCommand());
RegisterJSONCommand(program, RunCommand());
RegisterJSONCommand(program, WatchCommand());
}
40 changes: 40 additions & 0 deletions bin/commands/RunCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const path = require("path");
const { loadCurrentRedactConfig } = require("../../globals/ConfigurationTools");
const CommandBuilder = require("../CommandBuilder");
const figlet = require("figlet");
const chalk = require("cli-color");
const packageJSON = require("../../package.json");
const { Logger } = require("../..");

let text = `
d8888b. d88888b d8888b. .d8b. .o88b. d888888b .o88b. .d88b. d8888b. d8888b.
88 \`8D 88' 88 \`8D d8' \`8b d8P Y8 \`oo88oo' d8P Y8 .8P Y8. 88 \`8D 88 \`8D
88oobY' 88ooooo 88 88 88ooo88 8P 88 8P 88 88 88oobY' 88 88
88\`8b 88ooooo 88 88 88ooo88 8b 88 8b 88 88 88\`8b 88 88
88 \`88. 88. 88 .8D 88 88 Y8b d8 88 Y8b d8 \`8b d8' 88 \`88. 88 .8D
88 YD Y88888P Y8888D' YP YP \`Y88P' YP \`Y88P' \`Y88P' 88 YD Y8888D\' v${packageJSON.version}
`

module.exports = () => {
return CommandBuilder.createBuilder("run")
.setDescription("Runs the current project")
.setCallback(() => {

const config = loadCurrentRedactConfig();
const main = config["main"];

const a = async () => {
console.log(`${chalk.redBright(text)}`);
}


a().then(() => {
if (!main || !main.length)
return Logger.getLogger().error("Cannot find main field or main field is empty. Please provide a main path to a javascript file.")
const p = path.join(process.cwd(), main);
require(p);
})

});
}
26 changes: 26 additions & 0 deletions bin/commands/WatchCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require("fs");
const watch = require("watch");
const _eval = require("eval");
const CommandBuilder = require("../CommandBuilder");
const path = require("path");

function HandleWatcher() {
watch.watchTree(process.cwd(), {
filter: (path, stat) => {
console.log(path);
return stat.isFile() && (path.endsWith(".js") || path.endsWith(".ts"))
}
}, (f, curr, prev) => {
const data = fs.readdirSync(curr, "utf-8");
_eval(data);
});
}

module.exports = () => {
return CommandBuilder.createBuilder("watch")
.setDescription("Watches all files in the main directory")
.setCallback((options) => {
console.log(`[${new Date().toUTCString()}]: Started Watching files in the current directory.`);
HandleWatcher();
});
}
11 changes: 11 additions & 0 deletions globals/ConfigurationTools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { readFileSync } = require("fs");
const path = require("path");
const { configName } = require("./InitializationUtils");

function loadCurrentRedactConfig() {
return JSON.parse(readFileSync(path.join(process.cwd(), configName), "utf-8"));
}

module.exports = {
loadCurrentRedactConfig
};
31 changes: 28 additions & 3 deletions globals/InitializationUtils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { execSync } = require("child_process");
const { writeFileSync, mkdirSync } = require("fs");
const path = require("path");

const configName = "redact.config.json";
const configName = "redactcord.config.json";
const environmentName = ".redact.env";
const files = [
environmentName,
Expand All @@ -12,6 +13,9 @@ const directories = [
"commands",
"events",
];
const requiredDependencies = [
"redactcord",
]

const packageConfig = {
name: path.basename(path.dirname(process.cwd())),
Expand Down Expand Up @@ -43,7 +47,7 @@ function toJson(data) {

function createConfigurationFiles() {
writeFileSync(path.join(process.cwd(), "package.json"), toJson(packageConfig));
writeFileSync(path.join(process.cwd(), "redactcord.config.json"), toJson(redactconfig));
writeFileSync(path.join(process.cwd(), configName), toJson(redactconfig));
}

function writeFiles() {
Expand All @@ -58,9 +62,30 @@ function makeDirectories() {
}
}

function executeNpm(command) {
execSync("npm " + command);
}

function install(dependency) {
executeNpm("install " + dependency);
}

function installMultiple(...dependencies) {
executeNpm("install " + dependencies.join(" "));
}

function installRequired() {
installMultiple(...requiredDependencies);
}

module.exports = {
createConfigurationFiles,
writeFiles,
toJson,
makeDirectories
makeDirectories,
configName,
install,
executeNpm,
installMultiple,
installRequired
}
Loading

0 comments on commit bf22c4f

Please sign in to comment.