UNPKG

meocord

Version:

MeoCord is a lightweight and modular framework for building scalable Discord bots using TypeScript and Discord.js. It simplifies bot development with an extensible architecture, TypeScript-first approach, and powerful CLI tools.

33 lines 25.5 kB
#!/usr/bin/env node /** * MeoCord Framework * Copyright (C) 2025 Ukasyah Rahmatullah Zada * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(b,c){if(b){if("string"==typeof b)return _arrayLikeToArray(b,c);var a={}.toString.call(b).slice(8,-1);return"Object"===a&&b.constructor&&(a=b.constructor.name),"Map"===a||"Set"===a?Array.from(b):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?_arrayLikeToArray(b,c):void 0}}function _arrayLikeToArray(b,c){(null==c||c>b.length)&&(c=b.length);for(var d=0,f=Array(c);d<c;d++)f[d]=b[d];return f}function _iterableToArrayLimit(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d["return"]&&(k=d["return"](),Object(k)!==k))return}finally{if(m)throw h}}return l}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function define(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function wrap(b,d,e,f){var g=d&&d.prototype instanceof Generator?d:Generator,i=Object.create(g.prototype),a=new Context(f||[]);return h(i,"_invoke",{value:makeInvokeMethod(b,e,a)}),i}function tryCatch(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}function defineIteratorMethods(a){["next","throw","return"].forEach(function(b){define(a,b,function(a){return this._invoke(b,a)})})}function AsyncIterator(b,d){function invoke(e,f,g,i){var a=tryCatch(b[e],b,f);if("throw"!==a.type){var c=a.arg,k=c.value;return k&&"object"==_typeof(k)&&j.call(k,"__await")?d.resolve(k.__await).then(function(a){invoke("next",a,g,i)},function(a){invoke("throw",a,g,i)}):d.resolve(k).then(function(a){c.value=a,g(c)},function(a){return invoke("throw",a,g,i)})}i(a.arg)}var a;h(this,"_invoke",{value:function value(b,c){function callInvokeWithMethodAndArg(){return new d(function(a,d){invoke(b,c,a,d)})}return a=a?a.then(callInvokeWithMethodAndArg,callInvokeWithMethodAndArg):callInvokeWithMethodAndArg()}})}function makeInvokeMethod(a,d,e){var f="suspendedStart";return function(g,h){if(f==="executing")throw Error("Generator is already running");if("completed"===f){if("throw"===g)throw h;return{value:b,done:!0}}for(e.method=g,e.arg=h;;){var i=e.delegate;if(i){var j=maybeInvokeDelegate(i,e);if(j){if(j===m)continue;return j}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===f)throw f="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);f="executing";var k=tryCatch(a,d,e);if("normal"===k.type){if(f=e.done?"completed":"suspendedYield",k.arg===m)continue;return{value:k.arg,done:e.done}}"throw"===k.type&&(f="completed",e.method="throw",e.arg=k.arg)}}}function maybeInvokeDelegate(c,d){var e=d.method,f=c.iterator[e];if(f===b)return d.delegate=null,"throw"===e&&c.iterator["return"]&&(d.method="return",d.arg=b,maybeInvokeDelegate(c,d),"throw"===d.method)||"return"!==e&&(d.method="throw",d.arg=new TypeError("The iterator does not provide a '"+e+"' method")),m;var g=tryCatch(f,c.iterator,d.arg);if("throw"===g.type)return d.method="throw",d.arg=g.arg,d.delegate=null,m;var h=g.arg;return h?h.done?(d[c.resultName]=h.value,d.next=c.nextLoc,"return"!==d.method&&(d.method="next",d.arg=b),d.delegate=null,m):h:(d.method="throw",d.arg=new TypeError("iterator result is not an object"),d.delegate=null,m)}function pushTryEntry(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function resetTryEntry(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function Context(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(pushTryEntry,this),this.reset(!0)}function values(a){if(a||""===a){var c=a[l];if(c)return c.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var d=-1,e=function next(){for(;++d<a.length;)if(j.call(a,d))return next.value=a[d],next.done=!1,next;return next.value=b,next.done=!0,next};return e.next=e}}throw new TypeError(_typeof(a)+" is not iterable")}_regeneratorRuntime=function _regeneratorRuntime(){return f};var b,f={},e=Object.prototype,j=e.hasOwnProperty,h=Object.defineProperty||function(a,b,c){a[b]=c.value},k="function"==typeof Symbol?Symbol:{},l=k.iterator||"@@iterator",a=k.asyncIterator||"@@asyncIterator",c=k.toStringTag||"@@toStringTag";try{define({},"")}catch(a){define=function define(a,b,c){return a[b]=c}}f.wrap=wrap;var m={},i={};define(i,l,function(){return this});var n=Object.getPrototypeOf,d=n&&n(n(values([])));d&&d!==e&&j.call(d,l)&&(i=d);var o=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(i);return GeneratorFunction.prototype=GeneratorFunctionPrototype,h(o,"constructor",{value:GeneratorFunctionPrototype,configurable:!0}),h(GeneratorFunctionPrototype,"constructor",{value:GeneratorFunction,configurable:!0}),GeneratorFunction.displayName=define(GeneratorFunctionPrototype,c,"GeneratorFunction"),f.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===GeneratorFunction||"GeneratorFunction"===(b.displayName||b.name))},f.mark=function(a){return Object.setPrototypeOf?Object.setPrototypeOf(a,GeneratorFunctionPrototype):(a.__proto__=GeneratorFunctionPrototype,define(a,c,"GeneratorFunction")),a.prototype=Object.create(o),a},f.awrap=function(a){return{__await:a}},defineIteratorMethods(AsyncIterator.prototype),define(AsyncIterator.prototype,a,function(){return this}),f.AsyncIterator=AsyncIterator,f.async=function(b,c,d,e,g){void 0===g&&(g=Promise);var h=new AsyncIterator(wrap(b,c,d,e),g);return f.isGeneratorFunction(c)?h:h.next().then(function(a){return a.done?a.value:h.next()})},defineIteratorMethods(o),define(o,c,"Generator"),define(o,l,function(){return this}),define(o,"toString",function(){return"[object Generator]"}),f.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function next(){for(;c.length;){var a=c.pop();if(a in b)return next.value=a,next.done=!1,next}return next.done=!0,next}},f.values=values,Context.prototype={constructor:Context,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=b,this.done=!1,this.delegate=null,this.method="next",this.arg=b,this.tryEntries.forEach(resetTryEntry),!a)for(var c in this)"t"===c.charAt(0)&&j.call(this,c)&&!isNaN(+c.slice(1))&&(this[c]=b)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(d){function handle(a,c){return h.type="throw",h.arg=d,e.next=a,c&&(e.method="next",e.arg=b),!!c}if(this.done)throw d;for(var e=this,f=this.tryEntries.length-1;0<=f;--f){var g=this.tryEntries[f],h=g.completion;if("root"===g.tryLoc)return handle("end");if(g.tryLoc<=this.prev){var k=j.call(g,"catchLoc"),l=j.call(g,"finallyLoc");if(k&&l){if(this.prev<g.catchLoc)return handle(g.catchLoc,!0);if(this.prev<g.finallyLoc)return handle(g.finallyLoc)}else if(!k){if(!l)throw Error("try statement without catch or finally");if(this.prev<g.finallyLoc)return handle(g.finallyLoc)}else if(this.prev<g.catchLoc)return handle(g.catchLoc,!0)}}},abrupt:function abrupt(b,c){for(var d,e=this.tryEntries.length-1;0<=e;--e)if(d=this.tryEntries[e],d.tryLoc<=this.prev&&j.call(d,"finallyLoc")&&this.prev<d.finallyLoc){var f=d;break}f&&("break"===b||"continue"===b)&&f.tryLoc<=c&&c<=f.finallyLoc&&(f=null);var g=f?f.completion:{};return g.type=b,g.arg=c,f?(this.method="next",this.next=f.finallyLoc,m):this.complete(g)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),m},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),resetTryEntry(b),m},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var f=d.arg;resetTryEntry(b)}return f}throw Error("illegal catch attempt")},delegateYield:function delegateYield(a,c,d){return this.delegate={iterator:values(a),resultName:c,nextLoc:d},"next"===this.method&&(this.arg=b),m}},f}function asyncGeneratorStep(b,d,f,e,g,h,a){try{var c=b[h](a),i=c.value}catch(a){return void f(a)}c.done?d(i):Promise.resolve(i).then(e,g)}function _asyncToGenerator(b){return function(){var c=this,d=arguments;return new Promise(function(e,f){function _next(a){asyncGeneratorStep(g,e,f,_next,_throw,"next",a)}function _throw(a){asyncGeneratorStep(g,e,f,_next,_throw,"throw",a)}var g=b.apply(c,d);_next(void 0)})}}function _classCallCheck(b,a){if(!(b instanceof a))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!=_typeof(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}import path from"path";import webpack from"webpack";import{Logger}from"../common/index.js";import{spawn}from"node:child_process";import{capitalize}from"lodash-es";import wait from"../util/wait.util.js";import{GeneratorCLI}from"./generator.js";import*as fs from"node:fs";import{compileAndValidateConfig,setEnvironment}from"../util/common.util.js";import{Command}from"commander";import{compileMeoCordConfig}from"../util/meocord-config-loader.util.js";import{simpleGit}from"simple-git";import chalk from"chalk";import{execSync}from"child_process";import{configureCommandHelp,ensureReady}from"../util/meocord-cli.util.js";import packageJson from"../../package.json"with{type:"json"};import{fileURLToPath}from"url";var __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),MeoCordCLI=/*#__PURE__*/function(){function MeoCordCLI(){_classCallCheck(this,MeoCordCLI),_defineProperty(this,"appName","MeoCord"),_defineProperty(this,"logger",new Logger(this.appName)),_defineProperty(this,"projectRoot",process.cwd()),_defineProperty(this,"mainJSPath",path.join(this.projectRoot,"dist","main.js")),_defineProperty(this,"webpackConfigPath",path.resolve(__dirname,"..","..","webpack.config.js")),_defineProperty(this,"generatorCLI",new GeneratorCLI(this.appName)),_defineProperty(this,"version",packageJson.version)}return _createClass(MeoCordCLI,[{key:"run",value:(/** * Configures and runs the MeoCord CLI. */function(){function run(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(){var a,b=this;return _regeneratorRuntime().wrap(function _callee4$(c){for(;;)switch(c.prev=c.next){case 0:a=new Command,a.name(this.appName.toLowerCase()).description("CLI for managing the ".concat(this.appName," application")).version(this.version),a.command("show").description("Display information").option("-w, --warranty","Display warranty disclaimer").option("-c, --license","Display licensing conditions and usage rights").action(function(b){if(!b.warranty&&!b.license){var c;null===(c=a.commands.find(function(a){return"show"===a.name()}))||void 0===c||c.outputHelp(),process.exit(1)}b.warranty&&console.log("\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\nThe authors of this software are not responsible for damages caused\nby the usage, misuse, or inability to use the software.\n\nSee the GNU General Public License for full details:\n<https://www.gnu.org/licenses/>.\n "),b.license&&console.log("\nThis program is free software: you can redistribute it and/or\nmodify it under the terms of the GNU General Public License as\npublished by the Free Software Foundation, either version 3 of\nthe License, or (at your option) any later version.\n\nKey conditions of the GNU GPL v3:\n- You can use this software for personal, academic, or commercial purposes.\n- If you distribute modified versions, you must share the source code under the same GPL v3 license.\n- The original copyright must be retained.\n\nFor full license details, refer to:\n<https://www.gnu.org/licenses/gpl-3.0.txt>\n ")}),a.command("create <app-name>").description("Create a new MeoCord application").action(/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(a){return _regeneratorRuntime().wrap(function _callee$(c){for(;1;)switch(c.prev=c.next){case 0:return c.next=2,b.createApp(a);case 2:return c.abrupt("return",c.sent);case 3:case"end":return c.stop()}},_callee)}));return function(b){return a.apply(this,arguments)}}()),a.command("build").description("Build the application").option("-d, --dev","Build in development mode").option("-p, --prod","Build in production mode").action(/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(a){var c;return _regeneratorRuntime().wrap(function _callee2$(d){for(;1;)switch(d.prev=d.next){case 0:return d.next=2,ensureReady();case 2:return c=a.prod?"production":"development",setEnvironment(c),d.next=6,compileAndValidateConfig();case 6:return d.next=8,b.build(c);case 8:case"end":return d.stop()}},_callee2)}));return function(b){return a.apply(this,arguments)}}()),a.command("start").description("Start the application").option("-b, --build","Pre-build before starting").option("-d, --dev","Start in development mode").option("-p, --prod","Start in production mode").action(/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(a){var c;return _regeneratorRuntime().wrap(function _callee3$(d){for(;1;)switch(d.prev=d.next){case 0:return d.next=2,ensureReady();case 2:if(c=a.prod?"production":"development",setEnvironment(c),!(a.build||a.dev)){d.next=7;break}return d.next=7,compileAndValidateConfig();case 7:if(!a.build){d.next=10;break}return d.next=10,b.build(c);case 10:if(!a.prod){d.next=15;break}return d.next=13,b.startProd();case 13:d.next=17;break;case 15:return d.next=17,b.startDev();case 17:case"end":return d.stop()}},_callee3)}));return function(b){return a.apply(this,arguments)}}()),a=this.generatorCLI.register(a),configureCommandHelp(a),a.showHelpAfterError().parse(process.argv);case 9:case"end":return c.stop()}},_callee4,this)}));return run}())},{key:"createApp",value:function(){function createApp(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;return _regeneratorRuntime().wrap(function _callee5$(q){for(;1;)switch(q.prev=q.next){case 0:if(b=a.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),c=path.resolve(process.cwd(),b),d="https://github.com/l7aromeo/meocord-template.git",console.info(chalk.blueBright("\uD83D\uDE80 Creating a new MeoCord app: ".concat(chalk.bold(b)))),q.prev=4,!fs.existsSync(c)){q.next=10;break}return console.error(chalk.red("\u274C Directory \"".concat(chalk.bold(b),"\" already exists."))),q.next=9,wait(100);case 9:process.exit(1);case 10:if(e="22.14.0",f=process.version.slice(1).split(".").map(Number),g=_slicedToArray(f,3),h=g[0],i=g[1],j=g[2],k=e.split(".").map(Number),l=_slicedToArray(k,3),m=l[0],n=l[1],o=l[2],!(h<m||h===m&&i<n||h===m&&i===n&&j<o)){q.next=18;break}return console.error(chalk.red("\u274C Node.js v".concat(e," or higher is required. Current version: v").concat(process.version,"."))),q.next=17,wait(100);case 17:process.exit(1);case 18:return console.info(chalk.blueBright("\uD83D\uDCE6 Fetching template...")),q.next=21,simpleGit().clone(d,c);case 21:return console.log(chalk.green("\u2714 App successfully created at: ".concat(chalk.bold(c)))),fs.rmSync(path.join(c,".git"),{recursive:!0,force:!0}),console.info(chalk.blueBright("\uD83D\uDD27 Initializing Git repository...")),p=simpleGit(c),q.next=27,p.init();case 27:return q.next=29,p.add("./*");case 29:return q.next=31,p.commit("Initial commit");case 31:console.log(chalk.green("\u2714 Git repository initialized.")),console.info(chalk.blueBright("\uD83D\uDCE6 Installing dependencies...")),execSync("cd ".concat(b," && corepack enable && yarn install"),{stdio:"inherit"}),console.log(chalk.green("\u2714 Dependencies installed successfully.")),console.log(chalk.greenBright("\uD83C\uDF89 MeoCord app \"".concat(chalk.bold(b),"\" is ready!"))),q.next=44;break;case 38:return q.prev=38,q.t0=q["catch"](4),console.error(chalk.red("\u274C Failed to create app: ".concat(q.t0 instanceof Error?q.t0.message:q.t0+""))),q.next=43,wait(100);case 43:process.exit(1);case 44:case"end":return q.stop()}},_callee5,null,[[4,38]])}));return createApp}()/** * Builds the MeoCord application in the specified mode. * * @param mode - The build mode ('production' or 'development'). */},{key:"build",value:(function(){function build(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(a){var b,c,d=this;return _regeneratorRuntime().wrap(function _callee6$(e){for(;1;)switch(e.prev=e.next){case 0:return e.prev=0,this.clearConsole(),this.logger.info("Building ".concat(a," version...")),e.next=5,import(this.webpackConfigPath);case 5:return b=e.sent["default"],c=webpack(_objectSpread(_objectSpread({},b),{},{mode:a})),e.next=9,new Promise(function(b,e){c.run(function(f,g){return f?(d.logger.error("Build encountered an error: ".concat(f.message)),void e("Build encountered an error: ".concat(f.message))):void(null!==g&&void 0!==g&&g.hasErrors()?d.logger.error("Build failed due to errors in the compilation process:",g.compilation.errors):d.logger.info("".concat(capitalize(a)," build completed successfully.")),c.close(function(a){return a?(d.logger.error("Error occurred while closing the compiler: ".concat(a.message)),void e("Error occurred while closing the compiler: ".concat(a.message))):void b()}))})});case 9:e.next=17;break;case 11:return e.prev=11,e.t0=e["catch"](0),this.logger.error("Build process failed: ".concat(e.t0.message)),e.next=16,wait(100);case 16:process.exit(1);case 17:case"end":return e.stop()}},_callee6,this,[[0,11]])}));return build}()/** * Starts the MeoCord application in development mode with live updates. */)},{key:"startDev",value:(function(){function startDev(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(){var a,b,c,d,e,f,g,h=this;return _regeneratorRuntime().wrap(function _callee9$(i){for(;1;)switch(i.prev=i.next){case 0:return i.prev=0,this.clearConsole(),this.logger.log("Starting watch mode..."),i.next=5,import(this.webpackConfigPath);case 5:a=i.sent["default"],b=webpack(_objectSpread(_objectSpread({},a),{},{mode:"development"})),c=null,d=!1,e=function watch(){return b.watch({},function(a,b){return a?void h.logger.error("Webpack Error: ".concat(a.message)):void(null!==b&&void 0!==b&&b.hasErrors()?h.logger.error("Build failed due to errors in the compilation process:",b.compilation.errors):(c&&(c.kill(),c=null),c=spawn("npx -y nodemon",["-q",h.mainJSPath],{shell:!0,cwd:h.projectRoot,stdio:"inherit"}),d=!0))})},e(),g=fs.watch(path.resolve(process.cwd(),"meocord.config.ts"),function(){clearTimeout(f),f=setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(){return _regeneratorRuntime().wrap(function _callee7$(a){for(;1;)switch(a.prev=a.next){case 0:if(!(d&&c)){a.next=9;break}return d=!1,h.logger.log("MeoCord config change detected, recompiling config..."),c&&!c.killed&&(c.kill(),c=null),a.next=6,new Promise(function(a){return b.close(a)});case 6:return a.next=8,compileMeoCordConfig();case 8:e();case 9:case"end":return a.stop()}},_callee7)})),300)}),process.on("SIGINT",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(){return _regeneratorRuntime().wrap(function _callee8$(a){for(;1;)switch(a.prev=a.next){case 0:return a.next=2,wait(1e3);case 2:return c&&!c.killed&&c.kill(),a.next=5,new Promise(function(a){return b.close(a)});case 5:return g.close(),a.next=8,wait(100);case 8:process.exit(0);case 9:case"end":return a.stop()}},_callee8)}))),i.next=18;break;case 15:i.prev=15,i.t0=i["catch"](0),this.logger.error("Failed to start: ".concat(i.t0.message));case 18:case"end":return i.stop()}},_callee9,this,[[0,15]])}));return startDev}()/** * Starts the MeoCord application in production mode. */)},{key:"startProd",value:(function(){function startProd(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(){var a;return _regeneratorRuntime().wrap(function _callee11$(b){for(;1;)switch(b.prev=b.next){case 0:if(b.prev=0,fs.existsSync(this.mainJSPath)){b.next=6;break}return this.logger.error("Main entry file (main.js) not found! You might need to build before running in production mode."),b.next=5,wait(100);case 5:process.exit(1);case 6:this.clearConsole(),this.logger.log("Starting..."),a=spawn("node ".concat(this.mainJSPath),{shell:!0,cwd:this.projectRoot,stdio:"inherit"}).on("spawn",this.clearConsole),process.on("SIGINT",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(){return _regeneratorRuntime().wrap(function _callee10$(b){for(;1;)switch(b.prev=b.next){case 0:return b.next=2,wait(1e3);case 2:return a&&!a.killed&&a.kill(),b.next=5,wait(100);case 5:process.exit(0);case 6:case"end":return b.stop()}},_callee10)}))),b.next=18;break;case 12:return b.prev=12,b.t0=b["catch"](0),this.logger.error("Failed to start:",b.t0 instanceof Error?b.t0.message:b.t0+""),b.next=17,wait(100);case 17:process.exit(1);case 18:case"end":return b.stop()}},_callee11,this,[[0,12]])}));return startProd}()/** * Clears the console on all platforms. */)},{key:"clearConsole",value:function clearConsole(){process.stdout.write("\x1B[3J\x1B[2J\x1B[H")}}])}(),cli=new MeoCordCLI;/** * A Command Line Interface (CLI) for managing the MeoCord application. */// Create an instance of the CLI and run it cli.run()["catch"](/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12(a){return _regeneratorRuntime().wrap(function _callee12$(b){for(;1;)switch(b.prev=b.next){case 0:return cli.logger.error("Failed to initialize CLI:",(null===a||void 0===a?void 0:a.message)||a),b.next=3,wait(100);case 3:process.exit(1);case 4:case"end":return b.stop()}},_callee12)}));return function(b){return a.apply(this,arguments)}}());