arkos 1.1.5-beta → 1.1.7-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/modules/error-handler/error-handler.controller.js +1 -5
- package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/cjs/server.js +1 -1
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +1 -1
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +49 -36
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/start.js +37 -28
- package/dist/cjs/utils/cli/start.js.map +1 -1
- package/dist/cjs/utils/helpers/prisma.helpers.js +7 -5
- package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/es2020/modules/error-handler/error-handler.controller.js +1 -5
- package/dist/es2020/modules/error-handler/error-handler.controller.js.map +1 -1
- package/dist/es2020/server.js +1 -1
- package/dist/es2020/server.js.map +1 -1
- package/dist/es2020/utils/cli/build.js +1 -1
- package/dist/es2020/utils/cli/build.js.map +1 -1
- package/dist/es2020/utils/cli/dev.js +49 -36
- package/dist/es2020/utils/cli/dev.js.map +1 -1
- package/dist/es2020/utils/cli/start.js +37 -28
- package/dist/es2020/utils/cli/start.js.map +1 -1
- package/dist/es2020/utils/helpers/prisma.helpers.js +7 -5
- package/dist/es2020/utils/helpers/prisma.helpers.js.map +1 -1
- package/dist/types/utils/cli/dev.d.ts +1 -1
- package/dist/types/utils/cli/start.d.ts +1 -1
- package/dist/types/utils/helpers/prisma.helpers.d.ts +1 -1
- package/package.json +3 -3
|
@@ -90,11 +90,7 @@ function errorHandler(err, req, res, next) {
|
|
|
90
90
|
function sendDevelopmentError(err, req, res) {
|
|
91
91
|
var _a;
|
|
92
92
|
if (req.originalUrl.startsWith("/api"))
|
|
93
|
-
res.status(err.statusCode).json({
|
|
94
|
-
message: err.message.split("\n")[err.message.split("\n").length - 1],
|
|
95
|
-
error: err,
|
|
96
|
-
stack: (_a = err.stack) === null || _a === void 0 ? void 0 : _a.split("\n"),
|
|
97
|
-
});
|
|
93
|
+
res.status(err.statusCode).json(Object.assign(Object.assign({}, err), { message: err.message.split("\n")[err.message.split("\n").length - 1], stack: (_a = err.stack) === null || _a === void 0 ? void 0 : _a.split("\n") }));
|
|
98
94
|
else
|
|
99
95
|
res.status(err.statusCode).json({
|
|
100
96
|
title: "Something went wrong!",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,+BAyEC;AA5FD,kEAAyC;AACzC,qFAAuE;AACvE,yCAAsC;AAiBtC,SAAwB,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;IAGnC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO;IACT,CAAC;IAGD,IAAI,KAAK,mCAAQ,GAAG,KAAE,OAAO,EAAE,GAAG,CAAC,OAAO,GAAE,CAAC;IAG7C,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,cAAc,EAAE,CAAC;IACjD,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,CAAC;IAGnD,IAAI,GAAG,CAAC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,CAAC,uBAAuB,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n // Handle general error types (e.g., syntax errors, type errors, etc.)\n // if (err.name === \"SyntaxError\")\n // error = errorControllerHelper.handleSchemaSyntaxError(err);\n // if (err.name === \"TypeError\")\n // error = errorControllerHelper.handleClientTypeError(err);\n // if (err.name === \"BinaryError\")\n // error = errorControllerHelper.handleBinaryError(err);\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n // if (err.name === \"UnhandledPromiseRejection\")\n // error = errorControllerHelper.handleUnhandledPromiseError(err);\n if (!err.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n error: err,\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n });\n }\n});\n"]}
|
|
1
|
+
{"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,+BAyEC;AA5FD,kEAAyC;AACzC,qFAAuE;AACvE,yCAAsC;AAiBtC,SAAwB,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,G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ACrB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QAC9B,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,yBAAyB;KACnC,CAAC,CAAC;AACL,CAAC;AAWD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,EAClC,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,eAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n // Handle general error types (e.g., syntax errors, type errors, etc.)\n // if (err.name === \"SyntaxError\")\n // error = errorControllerHelper.handleSchemaSyntaxError(err);\n // if (err.name === \"TypeError\")\n // error = errorControllerHelper.handleClientTypeError(err);\n // if (err.name === \"BinaryError\")\n // error = errorControllerHelper.handleBinaryError(err);\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n // if (err.name === \"UnhandledPromiseRejection\")\n // error = errorControllerHelper.handleUnhandledPromiseError(err);\n if (!err.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n });\n }\n});\n"]}
|
package/dist/cjs/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,
|
|
1
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(e,o,r,s){function l(n){return n instanceof r?n:new r(function(i){i(n)})}return new(r||(r=Promise))(function(n,i){function c(t){try{p(s.next(t))}catch(u){i(u)}}function a(t){try{p(s.throw(t))}catch(u){i(u)}}function p(t){t.done?n(t.value):l(t.value).then(c,a)}p((s=s.apply(e,o||[])).next())})},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.getArkosConfig=getArkosConfig,exports.getExpressApp=getExpressApp,exports.initApp=initApp;const app_1=require("./app"),deepmerge_helper_1=__importDefault(require("./utils/helpers/deepmerge.helper"));process.on("uncaughtException",e=>{console.error("UNCAUGHT EXCEPTION! SHUTTING DOWN..."),console.error(e.name,e.message),console.error(e),process.exit(1)});let server,_app,_arkosConfig={welcomeMessage:"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com",port:8e3,fileUpload:{baseUploadDir:"uploads",baseRoute:"/api/uploads"}};function initApp(){return __awaiter(this,arguments,void 0,function*(e={}){_arkosConfig=(0,deepmerge_helper_1.default)(_arkosConfig,e);const o=_arkosConfig.port;return _app=yield(0,app_1.bootstrap)(_arkosConfig),o&&(exports.server=server=_app.listen(e?.host?[o,e?.host]:o,()=>{const r=new Date().toTimeString().split(" ")[0]})),_app})}process.on("unhandledRejection",e=>{console.error("UNHANDLED REJECTION! SHUTTING DOWN..."),console.error(e.name,e.message),console.error(e),server?.close(()=>{process.exit(1)})});function getArkosConfig(){return _arkosConfig}function getExpressApp(){return _app}
|
package/dist/cjs/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAwEA,wCAEC;AAED,sCAEC;AAEgB,0BAAO;AA7ExB,+BAAkC;AAElC,wFAAyD;AAEzD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACtD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,IAAI,MAA6D,CAAC;AAClE,IAAI,IAAa,CAAC;AAElB,IAAI,YAAY,GAAgB;IAC9B,cAAc,EACZ,6FAA6F;IAC/F,IAAI,EAAE,IAAI;IACV,UAAU,EAAE;QACV,aAAa,EAAE,SAAS;QACxB,SAAS,EAAE,cAAc;KAC1B;CACF,CAAC;AAeF,SAAe,OAAO;yDAAC,cAA2B,EAAE;QAClD,YAAY,GAAG,IAAA,0BAAS,EAAC,YAAY,EAAE,WAAW,CAAC,CAAC;QAEpD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;QAC/B,IAAI,GAAG,MAAM,IAAA,eAAS,EAAC,YAAY,CAAC,CAAC;QAErC,IAAI,IAAI;YACN,iBAAA,MAAM,GAAG,IAAI,CAAC,MAAM,CAClB,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,IAAI,EAAC,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,IAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EACrD,GAAG,EAAE;g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AAC,CAAC,IAAI,EACrD,GAAG,EAAE;gBACH,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAOvD,CAAC,CACF,CAAC;QAEJ,OAAO,IAAI,CAAC;IACd,CAAC;CAAA;AAED,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,GAAa,EAAE,EAAE;IACjD,OAAO,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;IACvD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC,GAAG,EAAE;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,SAAgB,cAAc;IAC5B,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAgB,aAAa;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { IncomingMessage, Server, ServerResponse } from \"http\";\nimport AppError from \"./modules/error-handler/utils/app-error\";\nimport { Express } from \"express\";\nimport { bootstrap } from \"./app\";\nimport { ArkosConfig } from \"./types/arkos-config\";\nimport deepmerge from \"./utils/helpers/deepmerge.helper\";\n\nprocess.on(\"uncaughtException\", (err) => {\n console.error(\"UNCAUGHT EXCEPTION! SHUTTING DOWN...\");\n console.error(err.name, err.message);\n console.error(err);\n process.exit(1);\n});\n\nlet server: Server<typeof IncomingMessage, typeof ServerResponse>;\nlet _app: Express;\n\nlet _arkosConfig: ArkosConfig = {\n welcomeMessage:\n \"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com\",\n port: 8000,\n fileUpload: {\n baseUploadDir: \"uploads\",\n baseRoute: \"/api/uploads\",\n },\n};\n\n/**\n * Initializes the application server.\n *\n * This function starts the server by listening on a specified port.\n * The port is determined by the following order of precedence:\n * 1. The `port` argument passed to the function.\n * 2. Defaults to `8000` if neither is provided.\n *\n * @param {ArkosConfig} arkosConfig - initial configs for the api ( authentication, port).\n * @returns {Promise<Express>} This function returns the Express App after all middlewares configurations.\n * You can prevent it from listen py passing port as undefined\n *\n */\nasync function initApp(arkosConfig: ArkosConfig = {}): Promise<Express> {\n _arkosConfig = deepmerge(_arkosConfig, arkosConfig);\n\n const port = _arkosConfig.port;\n _app = await bootstrap(_arkosConfig);\n\n if (port)\n server = _app.listen(\n arkosConfig?.host ? [port, arkosConfig?.host!] : port,\n () => {\n const time = new Date().toTimeString().split(\" \")[0];\n // console.info(\n // `[\\x1b[32mREADY\\x1b[0m] \\x1b[90m${time}\\x1b[0m App running on port \\x1b[33m${port}\\x1b[0m, server waiting on http://localhost:${port}`\n // );\n\n // if (!!process.env.NODE_ENV)\n // console.info(`${`Environment: ${process.env.NODE_ENV}`}`);\n }\n );\n\n return _app;\n}\n\nprocess.on(\"unhandledRejection\", (err: AppError) => {\n console.error(\"UNHANDLED REJECTION! SHUTTING DOWN...\");\n console.error(err.name, err.message);\n console.error(err);\n server?.close(() => {\n process.exit(1);\n });\n});\n\nexport function getArkosConfig() {\n return _arkosConfig;\n}\n\nexport function getExpressApp() {\n return _app;\n}\n\nexport { server, initApp };\n"]}
|
|
@@ -12,7 +12,7 @@ const BUILD_DIR = ".build";
|
|
|
12
12
|
const MODULE_TYPES = ["cjs", "esm"];
|
|
13
13
|
function buildCommand(options = {}) {
|
|
14
14
|
try {
|
|
15
|
-
console.info(`🚀 Building project
|
|
15
|
+
console.info(`🚀 Building an optimized production ready project...\n`);
|
|
16
16
|
ensureBuildDir();
|
|
17
17
|
const fileExt = (0, fs_helpers_1.getUserFileExtension)();
|
|
18
18
|
if (fileExt === "ts") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sour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AAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAKD,SAAS,iBAAiB,CAAC,UAAkB;IAC3C,IAAI,CAAC;QACH,IAAI,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;AACH,CAAC","sourcesContent":["// src/utils/cli/build.ts\nimport path from \"path\";\nimport fs from \"fs\";\nimport { execSync, spawn } from \"child_process\";\nimport { getUserFileExtension } from \"../helpers/fs.helpers\";\n\n// Constants\nconst BUILD_DIR = \".build\";\nconst MODULE_TYPES = [\"cjs\", \"esm\"] as const;\ntype ModuleType = (typeof MODULE_TYPES)[number];\n\ninterface BuildOptions {\n watch?: boolean;\n config?: string;\n module?: string;\n}\n\n/**\n * Main build function for the arkos CLI\n */\nexport function buildCommand(options: BuildOptions = {}) {\n try {\n console.info(`🚀 Building project...`);\n\n ensureBuildDir();\n\n // Detect project type\n const fileExt = getUserFileExtension();\n\n if (fileExt === \"ts\") {\n buildTypeScriptProject(options);\n } else {\n buildJavaScriptProject(options);\n }\n\n console.info(`✅ Build complete! \\n`);\n console.info(`Next step:\\n`);\n console.info(`Run the generated build with the start command.\\n`);\n } catch (error) {\n console.error(\"❌ Build failed:\", error);\n process.exit(1);\n }\n}\n\n/**\n * Validates and normalizes module type option\n */\nfunction validateModuleType(moduleType?: string): ModuleType {\n if (!moduleType) return \"cjs\";\n\n const normalizedType = moduleType.toLowerCase();\n\n // Map common terms to our module types\n if (normalizedType === \"cjs\" || normalizedType === \"commonjs\") {\n return \"cjs\";\n } else if (\n [\"esm\", \"es\", \"es2020\", \"esnext\", \"module\"].includes(normalizedType)\n ) {\n return \"esm\";\n }\n\n // Default to CJS if unrecognized\n console.warn(\n `⚠️ Unrecognized module type \"${moduleType}\", defaulting to \"cjs\"`\n );\n return \"cjs\";\n}\n\n/**\n * Ensure the build directory exists\n */\nfunction ensureBuildDir() {\n if (!fs.existsSync(BUILD_DIR)) {\n fs.mkdirSync(BUILD_DIR, { recursive: true });\n }\n\n // Create module-specific subdirectories\n for (const moduleType of MODULE_TYPES) {\n const moduleDir = path.join(BUILD_DIR, moduleType);\n if (!fs.existsSync(moduleDir)) {\n fs.mkdirSync(moduleDir, { recursive: true });\n }\n }\n}\n\n/**\n * Build a TypeScript project\n */\nfunction buildTypeScriptProject(options: BuildOptions) {\n // Read the user's tsconfig.json\n const tsconfigPath = path.join(\n process.cwd(),\n options.config || \"tsconfig.json\"\n );\n let tsconfig: any = {};\n\n try {\n if (fs.existsSync(tsconfigPath)) {\n const tsconfigContent = fs.readFileSync(tsconfigPath, \"utf8\");\n tsconfig = JSON.parse(tsconfigContent);\n }\n } catch (error) {\n console.error(\"❌ Error reading tsconfig.json:\", error);\n // Continue with default config\n }\n\n // Create a custom tsconfig that outputs to our .build directory\n const tempTsconfig = {\n ...tsconfig,\n compilerOptions: {\n ...(tsconfig.compilerOptions || {}),\n outDir: path.join(`./${BUILD_DIR}`),\n },\n };\n\n const tempTsconfigPath = path.join(\n process.cwd(),\n `tsconfig.arkos-build.json`\n );\n fs.writeFileSync(tempTsconfigPath, JSON.stringify(tempTsconfig, null, 2));\n\n try {\n // Run TypeScript compiler\n\n if (options.watch) {\n // For watch mode, spawn a process\n const tsc = spawn(\"npx\", [\"tsc\", \"-p\", tempTsconfigPath, \"--watch\"], {\n stdio: \"inherit\",\n shell: true,\n });\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n tsc.kill();\n cleanupTempConfig(tempTsconfigPath);\n process.exit(0);\n });\n } else {\n // For one-time build, use execSync\n execSync(`npx tsc -p ${tempTsconfigPath}`, {\n stdio: \"inherit\",\n cwd: process.cwd(),\n });\n\n // Copy non-TypeScript files\n // copyAssetFiles(moduleType);\n\n // Clean up temp config\n cleanupTempConfig(tempTsconfigPath);\n }\n } catch (error) {\n cleanupTempConfig(tempTsconfigPath);\n throw error;\n }\n}\n\n/**\n * Build a JavaScript project\n */\nfunction buildJavaScriptProject(options: BuildOptions) {\n // Target directory\n const targetDir = path.join(BUILD_DIR);\n\n try {\n // For JS projects, we need to handle module transformations if needed\n if (true) {\n // For ESM output, we might want to transform CJS to ESM if needed\n // This is a simplified approach - for production, consider using tools like Babel\n execSync(\n `npx copyfiles -u 0 \"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.mjs\" \"src/**/*.cjs\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n } else {\n // For CJS output, direct copy is usually fine\n execSync(\n `npx copyfiles -u 0 \"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.cjs\" \"src/**/*.mjs\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n }\n\n // Copy asset files\n copyAssetFiles();\n\n // Handle watch mode\n if (options.watch) {\n const patterns = `\"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.mjs\" \"src/**/*.cjs\"`;\n\n const watcher = spawn(\n \"npx\",\n [\"chokidar\", patterns, \"-c\", `npx copyfiles -u 0 {path} ${targetDir}`],\n {\n stdio: \"inherit\",\n shell: true,\n }\n );\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n watcher.kill();\n process.exit(0);\n });\n }\n } catch (error) {\n console.error(\"❌ Error building JavaScript project:\", error);\n throw error;\n }\n}\n\n/**\n * Copy asset files to the build directory\n */\nfunction copyAssetFiles() {\n const targetDir = path.join(BUILD_DIR);\n\n try {\n execSync(\n `npx copyfiles -u 0 \"src/**/*.json\" \"src/**/*.html\" \"src/**/*.css\" \"src/**/*.svg\" \"src/**/*.png\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n } catch (error) {\n console.warn(\"Warning: Error copying asset files:\", error);\n }\n}\n\n/**\n * Clean up temporary tsconfig\n */\nfunction cleanupTempConfig(configPath: string) {\n try {\n if (fs.existsSync(configPath)) {\n fs.unlinkSync(configPath);\n }\n } catch (error) {\n console.warn(\"Warning: Error cleaning up temporary config:\", error);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../../src/utils/cli/build.ts"],"names":[],"mappings":";;;;;AAoBA,oCAsBC;AAzCD,gDAAwB;AACxB,4CAAoB;AACpB,iDAAgD;AAChD,sDAA6D;AAG7D,MAAM,SAAS,GAAG,QAAQ,CAAC;AAC3B,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU,CAAC;AAY7C,SAAgB,YAAY,CAAC,UAAwB,EAAE;IACrD,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;QAEvE,cAAc,EAAE,CAAC;QAGjB,MAAM,OAAO,GAAG,IAAA,iCAAoB,GAAE,CAAC;QAEvC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAKD,SAAS,kBAAkB,CAAC,UAAmB;IAC7C,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CA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K,CAAC;IACd,CAAC;AACH,CAAC;AAKD,SAAS,cAAc;IACrB,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAEvC,IAAI,CAAC;QACH,IAAA,wBAAQ,EACN,mGAAmG,SAAS,EAAE,EAC9G;YACE,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;SACnB,CACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAKD,SAAS,iBAAiB,CAAC,UAAkB;IAC3C,IAAI,CAAC;QACH,IAAI,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;AACH,CAAC","sourcesContent":["// src/utils/cli/build.ts\nimport path from \"path\";\nimport fs from \"fs\";\nimport { execSync, spawn } from \"child_process\";\nimport { getUserFileExtension } from \"../helpers/fs.helpers\";\n\n// Constants\nconst BUILD_DIR = \".build\";\nconst MODULE_TYPES = [\"cjs\", \"esm\"] as const;\ntype ModuleType = (typeof MODULE_TYPES)[number];\n\ninterface BuildOptions {\n watch?: boolean;\n config?: string;\n module?: string;\n}\n\n/**\n * Main build function for the arkos CLI\n */\nexport function buildCommand(options: BuildOptions = {}) {\n try {\n console.info(`🚀 Building an optimized production ready project...\\n`);\n\n ensureBuildDir();\n\n // Detect project type\n const fileExt = getUserFileExtension();\n\n if (fileExt === \"ts\") {\n buildTypeScriptProject(options);\n } else {\n buildJavaScriptProject(options);\n }\n\n console.info(`✅ Build complete! \\n`);\n console.info(`Next step:\\n`);\n console.info(`Run the generated build with the start command.\\n`);\n } catch (error) {\n console.error(\"❌ Build failed:\", error);\n process.exit(1);\n }\n}\n\n/**\n * Validates and normalizes module type option\n */\nfunction validateModuleType(moduleType?: string): ModuleType {\n if (!moduleType) return \"cjs\";\n\n const normalizedType = moduleType.toLowerCase();\n\n // Map common terms to our module types\n if (normalizedType === \"cjs\" || normalizedType === \"commonjs\") {\n return \"cjs\";\n } else if (\n [\"esm\", \"es\", \"es2020\", \"esnext\", \"module\"].includes(normalizedType)\n ) {\n return \"esm\";\n }\n\n // Default to CJS if unrecognized\n console.warn(\n `⚠️ Unrecognized module type \"${moduleType}\", defaulting to \"cjs\"`\n );\n return \"cjs\";\n}\n\n/**\n * Ensure the build directory exists\n */\nfunction ensureBuildDir() {\n if (!fs.existsSync(BUILD_DIR)) {\n fs.mkdirSync(BUILD_DIR, { recursive: true });\n }\n\n // Create module-specific subdirectories\n for (const moduleType of MODULE_TYPES) {\n const moduleDir = path.join(BUILD_DIR, moduleType);\n if (!fs.existsSync(moduleDir)) {\n fs.mkdirSync(moduleDir, { recursive: true });\n }\n }\n}\n\n/**\n * Build a TypeScript project\n */\nfunction buildTypeScriptProject(options: BuildOptions) {\n // Read the user's tsconfig.json\n const tsconfigPath = path.join(\n process.cwd(),\n options.config || \"tsconfig.json\"\n );\n let tsconfig: any = {};\n\n try {\n if (fs.existsSync(tsconfigPath)) {\n const tsconfigContent = fs.readFileSync(tsconfigPath, \"utf8\");\n tsconfig = JSON.parse(tsconfigContent);\n }\n } catch (error) {\n console.error(\"❌ Error reading tsconfig.json:\", error);\n // Continue with default config\n }\n\n // Create a custom tsconfig that outputs to our .build directory\n const tempTsconfig = {\n ...tsconfig,\n compilerOptions: {\n ...(tsconfig.compilerOptions || {}),\n outDir: path.join(`./${BUILD_DIR}`),\n },\n };\n\n const tempTsconfigPath = path.join(\n process.cwd(),\n `tsconfig.arkos-build.json`\n );\n fs.writeFileSync(tempTsconfigPath, JSON.stringify(tempTsconfig, null, 2));\n\n try {\n // Run TypeScript compiler\n\n if (options.watch) {\n // For watch mode, spawn a process\n const tsc = spawn(\"npx\", [\"tsc\", \"-p\", tempTsconfigPath, \"--watch\"], {\n stdio: \"inherit\",\n shell: true,\n });\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n tsc.kill();\n cleanupTempConfig(tempTsconfigPath);\n process.exit(0);\n });\n } else {\n // For one-time build, use execSync\n execSync(`npx tsc -p ${tempTsconfigPath}`, {\n stdio: \"inherit\",\n cwd: process.cwd(),\n });\n\n // Copy non-TypeScript files\n // copyAssetFiles(moduleType);\n\n // Clean up temp config\n cleanupTempConfig(tempTsconfigPath);\n }\n } catch (error) {\n cleanupTempConfig(tempTsconfigPath);\n throw error;\n }\n}\n\n/**\n * Build a JavaScript project\n */\nfunction buildJavaScriptProject(options: BuildOptions) {\n // Target directory\n const targetDir = path.join(BUILD_DIR);\n\n try {\n // For JS projects, we need to handle module transformations if needed\n if (true) {\n // For ESM output, we might want to transform CJS to ESM if needed\n // This is a simplified approach - for production, consider using tools like Babel\n execSync(\n `npx copyfiles -u 0 \"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.mjs\" \"src/**/*.cjs\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n } else {\n // For CJS output, direct copy is usually fine\n execSync(\n `npx copyfiles -u 0 \"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.cjs\" \"src/**/*.mjs\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n }\n\n // Copy asset files\n copyAssetFiles();\n\n // Handle watch mode\n if (options.watch) {\n const patterns = `\"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.mjs\" \"src/**/*.cjs\"`;\n\n const watcher = spawn(\n \"npx\",\n [\"chokidar\", patterns, \"-c\", `npx copyfiles -u 0 {path} ${targetDir}`],\n {\n stdio: \"inherit\",\n shell: true,\n }\n );\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n watcher.kill();\n process.exit(0);\n });\n }\n } catch (error) {\n console.error(\"❌ Error building JavaScript project:\", error);\n throw error;\n }\n}\n\n/**\n * Copy asset files to the build directory\n */\nfunction copyAssetFiles() {\n const targetDir = path.join(BUILD_DIR);\n\n try {\n execSync(\n `npx copyfiles -u 0 \"src/**/*.json\" \"src/**/*.html\" \"src/**/*.css\" \"src/**/*.svg\" \"src/**/*.png\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n } catch (error) {\n console.warn(\"Warning: Error copying asset files:\", error);\n }\n}\n\n/**\n * Clean up temporary tsconfig\n */\nfunction cleanupTempConfig(configPath: string) {\n try {\n if (fs.existsSync(configPath)) {\n fs.unlinkSync(configPath);\n }\n } catch (error) {\n console.warn(\"Warning: Error cleaning up temporary config:\", error);\n }\n}\n"]}
|
|
@@ -1,47 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.devCommand = devCommand;
|
|
4
13
|
const child_process_1 = require("child_process");
|
|
5
14
|
const fs_helpers_1 = require("../helpers/fs.helpers");
|
|
6
15
|
const _1 = require(".");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
child
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const server_1 = require("../../server");
|
|
17
|
+
function devCommand() {
|
|
18
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
19
|
+
try {
|
|
20
|
+
const { port, host } = options;
|
|
21
|
+
const fileExt = (0, fs_helpers_1.getUserFileExtension)();
|
|
22
|
+
const entryPoint = `src/app.${fileExt}`;
|
|
23
|
+
if (!entryPoint) {
|
|
24
|
+
console.error("❌ Could not find application entry point.");
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
const env = Object.assign(Object.assign(Object.assign({ NODE_ENV: "development" }, process.env), (port && { PORT: port })), (host && { HOST: host }));
|
|
28
|
+
let child;
|
|
29
|
+
if (fileExt === "ts") {
|
|
30
|
+
child = (0, child_process_1.spawn)("npx", ["ts-node-dev", "--respawn", entryPoint], {
|
|
31
|
+
stdio: "inherit",
|
|
32
|
+
env,
|
|
33
|
+
shell: true,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
child = (0, child_process_1.spawn)("npx", ["nodemon", entryPoint], {
|
|
38
|
+
stdio: "inherit",
|
|
39
|
+
env,
|
|
40
|
+
shell: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
console.log((0, server_1.getArkosConfig)());
|
|
44
|
+
console.info(` \x1b[1m\x1b[36m Arkos.js ${(0, _1.getVersion)()}\x1b[0m`);
|
|
45
|
+
console.info(` - Local: http://${host}:${port}`);
|
|
46
|
+
console.info(` - Environments: development\n`);
|
|
47
|
+
process.on("SIGINT", () => {
|
|
48
|
+
if (child) {
|
|
49
|
+
child.kill();
|
|
50
|
+
}
|
|
51
|
+
process.exit(0);
|
|
23
52
|
});
|
|
24
53
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
env,
|
|
29
|
-
shell: true,
|
|
30
|
-
});
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error("❌ Development server failed to start:", error);
|
|
56
|
+
process.exit(1);
|
|
31
57
|
}
|
|
32
|
-
|
|
33
|
-
console.info(` - Local: http://${host}:${port}`);
|
|
34
|
-
console.info(` - Environments: development\n`);
|
|
35
|
-
process.on("SIGINT", () => {
|
|
36
|
-
if (child) {
|
|
37
|
-
child.kill();
|
|
38
|
-
}
|
|
39
|
-
process.exit(0);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
console.error("❌ Development server failed to start:", error);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
58
|
+
});
|
|
46
59
|
}
|
|
47
60
|
//# sourceMappingURL=dev.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../src/utils/cli/dev.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../src/utils/cli/dev.ts"],"names":[],"mappings":";;;;;;;;;;;AAcA,gCA0DC;AAvED,iDAAsC;AACtC,sDAA6D;AAC7D,wBAA+B;AAC/B,yCAA8C;AAU9C,SAAsB,UAAU;yDAAC,UAAsB,EAAE;QACvD,IAAI,CAAC;YACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;YAG/B,MAAM,OAAO,GAAG,IAAA,iCAAoB,GAAE,CAAC;YAGvC,MAAM,UAAU,GAAG,WAAW,OAAO,EAAE,CAAC;YAExC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;gBAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YAGD,MAAM,GAAG,+CACP,QAAQ,EAAE,aAAa,IACpB,OAAO,CAAC,GAAG,GACX,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,GAC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tension } from \"../helpers/fs.helpers\";\nimport { getVersion } from \".\";\nimport { getArkosConfig } from \"../../server\";\n\ninterface DevOptions {\n port?: string;\n host?: string;\n}\n\n/**\n * Dev server command for the arkos CLI\n */\nexport async function devCommand(options: DevOptions = {}) {\n try {\n const { port, host } = options;\n\n // Detect if project uses TypeScript or JavaScript\n const fileExt = getUserFileExtension();\n\n // Find the application entry point\n const entryPoint = `src/app.${fileExt}`;\n\n if (!entryPoint) {\n console.error(\"❌ Could not find application entry point.\");\n process.exit(1);\n }\n\n // Set environment variables\n const env = {\n NODE_ENV: \"development\",\n ...process.env,\n ...(port && { PORT: port }),\n ...(host && { HOST: host }),\n };\n\n // Start the application with the appropriate runner\n let child;\n\n // Setup file watching if enabled\n if (fileExt === \"ts\") {\n child = spawn(\"npx\", [\"ts-node-dev\", \"--respawn\", entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n } else {\n child = spawn(\"npx\", [\"nodemon\", entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n }\n\n console.log(getArkosConfig());\n\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(` - Local: http://${host}:${port}`);\n console.info(` - Environments: development\\n`);\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n if (child) {\n child.kill();\n }\n process.exit(0);\n });\n } catch (error) {\n console.error(\"❌ Development server failed to start:\", error);\n process.exit(1);\n }\n}\n"]}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -7,36 +16,36 @@ exports.startCommand = startCommand;
|
|
|
7
16
|
const path_1 = __importDefault(require("path"));
|
|
8
17
|
const fs_1 = __importDefault(require("fs"));
|
|
9
18
|
const child_process_1 = require("child_process");
|
|
10
|
-
const server_1 = require("../../server");
|
|
11
19
|
const _1 = require(".");
|
|
12
|
-
function startCommand(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
function startCommand() {
|
|
21
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
22
|
+
try {
|
|
23
|
+
const { port, host } = options;
|
|
24
|
+
const entryPoint = path_1.default.join(".build", "src", "app.js");
|
|
25
|
+
if (!fs_1.default.existsSync(path_1.default.join(process.cwd(), entryPoint))) {
|
|
26
|
+
console.error(`❌ Could not find built application entry point at ${entryPoint}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
const env = Object.assign(Object.assign(Object.assign(Object.assign({}, process.env), (port && { PORT: port })), (host && { HOST: host })), { NODE_ENV: "production", ARKOS_BUILD: "true" });
|
|
30
|
+
const child = (0, child_process_1.spawn)("node", [entryPoint], {
|
|
31
|
+
stdio: "inherit",
|
|
32
|
+
env,
|
|
33
|
+
shell: true,
|
|
34
|
+
});
|
|
35
|
+
process.on("SIGINT", () => {
|
|
36
|
+
if (child) {
|
|
37
|
+
child.kill();
|
|
38
|
+
}
|
|
39
|
+
process.exit(0);
|
|
40
|
+
});
|
|
41
|
+
console.info(` \x1b[1m\x1b[36m Arkos.js ${(0, _1.getVersion)()}\x1b[0m`);
|
|
42
|
+
console.info(` - Local: http://${host}:${port}`);
|
|
43
|
+
console.info(` - Environments: production\n`);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error("❌ Production server failed to start:", error);
|
|
19
47
|
process.exit(1);
|
|
20
48
|
}
|
|
21
|
-
|
|
22
|
-
const child = (0, child_process_1.spawn)("node", [entryPoint], {
|
|
23
|
-
stdio: "inherit",
|
|
24
|
-
env,
|
|
25
|
-
shell: true,
|
|
26
|
-
});
|
|
27
|
-
process.on("SIGINT", () => {
|
|
28
|
-
if (child) {
|
|
29
|
-
child.kill();
|
|
30
|
-
}
|
|
31
|
-
process.exit(0);
|
|
32
|
-
});
|
|
33
|
-
console.info(` \x1b[1m\x1b[36m♖ Arkos.js ${(0, _1.getVersion)()}\x1b[0m`);
|
|
34
|
-
console.info(` - Local: http://${host}:${port}`);
|
|
35
|
-
console.info(` - Environments: production\n`);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
console.error("❌ Production server failed to start:", error);
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
49
|
+
});
|
|
41
50
|
}
|
|
42
51
|
//# sourceMappingURL=start.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAeA,oCAiDC;AA/DD,gDAAwB;AACxB,4CAAoB;AACpB,iDAAsC;AAEtC,wBAA+B;AAU/B,SAAsB,YAAY;yDAAC,UAAwB,EAAE;QAG3D,IAAI,CAAC;YACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;YAG/B,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YAExD,IAAI,CAAC,YAAE,C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path\";\nimport fs from \"fs\";\nimport { spawn } from \"child_process\";\nimport { getArkosConfig } from \"../../server\";\nimport { getVersion } from \".\";\n\ninterface StartOptions {\n port?: string;\n host?: string;\n}\n\n/**\n * Production start command for the arkos CLI\n */\nexport async function startCommand(options: StartOptions = {}) {\n // const configs = getArkosConfig();\n // console.log(configs);\n try {\n const { port, host } = options;\n\n // Check for built app file\n const entryPoint = path.join(\".build\", \"src\", \"app.js\");\n\n if (!fs.existsSync(path.join(process.cwd(), entryPoint))) {\n console.error(\n `❌ Could not find built application entry point at ${entryPoint}`\n );\n process.exit(1);\n }\n\n // Set environment variables\n const env = {\n ...process.env,\n ...(port && { PORT: port }),\n ...(host && { HOST: host }),\n NODE_ENV: \"production\",\n ARKOS_BUILD: \"true\",\n };\n\n // Start the application\n const child = spawn(\"node\", [entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n if (child) {\n child.kill();\n }\n process.exit(0);\n });\n\n // console.log(getArkosConfig());\n\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(` - Local: http://${host}:${port}`);\n console.info(` - Environments: production\\n`);\n } catch (error) {\n console.error(\"❌ Production server failed to start:\", error);\n process.exit(1);\n }\n}\n"]}
|
|
@@ -21,7 +21,7 @@ const app_error_1 = __importDefault(require("../../modules/error-handler/utils/a
|
|
|
21
21
|
const fs_helpers_1 = require("./fs.helpers");
|
|
22
22
|
const global_helpers_1 = require("./global.helpers");
|
|
23
23
|
exports.prismaInstance = null;
|
|
24
|
-
function loadPrismaModule(
|
|
24
|
+
function loadPrismaModule() {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
if (!exports.prismaInstance) {
|
|
27
27
|
try {
|
|
@@ -32,12 +32,14 @@ function loadPrismaModule(a) {
|
|
|
32
32
|
const prismaModule = yield (0, global_helpers_1.importModule)(prismaPath);
|
|
33
33
|
exports.prismaInstance = prismaModule.default || prismaModule.prisma;
|
|
34
34
|
if (!exports.prismaInstance)
|
|
35
|
-
throw new Error("not found");
|
|
35
|
+
throw new Error("Prisma not found");
|
|
36
36
|
}
|
|
37
37
|
catch (error) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
if (error.message === "Prisma not found")
|
|
39
|
+
throw new app_error_1.default("Could not initialize Prisma module.", 500, {
|
|
40
|
+
tip: `Make sure your prisma instance is exported under src/utils/prisma.${(0, fs_helpers_1.getUserFileExtension)()} or src/utils/prisma/index.${(0, fs_helpers_1.getUserFileExtension)()}, read more about Arkos' Project Structure under https://www.arkosjs.com/docs/project-structure#root-structure`,
|
|
41
|
+
});
|
|
42
|
+
throw error;
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
return exports.prismaInstance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,
|
|
1
|
+
{"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,4CAsBC;AAED,8CAEC;AAnCD,4CAAoB;AAEpB,gGAAuE;AACvE,4FAAmE;AACnE,6CAAyD;AACzD,qDAAgD;AAErC,QAAA,cAAc,GAAQ,IAAI,CAAC;AAEtC,SAAsB,gBAAgB;;QACpC,IAAI,CAAC,sBAAc,EAAE,CAAC;YACpB,IAAI,CAAC;gBACH,IAAI,UAAU,GAAG,GAAG,IAAA,gBAAG,GAAE,qBAAqB,IAAA,iCAAoB,GAAE,EAAE,CAAC;gBAEvE,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC/B,UAAU,GAAG,GAAG,IAAA,gBAAG,GAAE,2BAA2B,IAAA,iCAAoB,GAAE,EAAE,CAAC;gBAC3E,CAAC;gBAED,MAAM,YAAY,GAAG,MAAM,IAAA,6BAAY,EAAC,UAAU,CAAC,CAAC;gBACpD,sBAAc,GAAG,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC;gBAE7D,IAAI,CAAC,sBAAc;oBAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAC3D,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAI,KAAK,CAAC,OAAO,KAAK,kBAAkB;oBACtC,MAAM,IAAI,mBAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;wBAC7D,GAAG,EAAE,qEAAqE,IAAA,iCAAoB,GAAE,8BAA8B,IAAA,iCAAoB,GAAE,gHAAgH;qBACrQ,CAAC,CAAC;gBACL,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,sBAAc,CAAC;IACxB,CAAC;CAAA;AAED,SAAgB,iBAAiB;IAC/B,OAAO,sBAAc,CAAC;AACxB,CAAC;AAEY,QAAA,uBAAuB,GAAG,IAAA,qBAAU,EAC/C,CAAO,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,MAAM,MAAM,GAAG,MAAM,gBAAgB,EAAE,CAAC;IACxC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,IAAI,EAAE,CAAC;IACT,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,mBAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;AACH,CAAC,CAAA,CACF,CAAC","sourcesContent":["import fs from \"fs\";\nimport { Request, Response, NextFunction } from \"express\";\nimport catchAsync from \"../../modules/error-handler/utils/catch-async\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { crd, getUserFileExtension } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\n\nexport let prismaInstance: any = null;\n\nexport async function loadPrismaModule() {\n if (!prismaInstance) {\n try {\n let prismaPath = `${crd()}/src/utils/prisma.${getUserFileExtension()}`;\n\n if (!fs.existsSync(prismaPath)) {\n prismaPath = `${crd()}/src/utils/prisma/index.${getUserFileExtension()}`;\n }\n\n const prismaModule = await importModule(prismaPath);\n prismaInstance = prismaModule.default || prismaModule.prisma;\n\n if (!prismaInstance) throw new Error(\"Prisma not found\");\n } catch (error: any) {\n if (error.message === \"Prisma not found\")\n throw new AppError(\"Could not initialize Prisma module.\", 500, {\n tip: `Make sure your prisma instance is exported under src/utils/prisma.${getUserFileExtension()} or src/utils/prisma/index.${getUserFileExtension()}, read more about Arkos' Project Structure under https://www.arkosjs.com/docs/project-structure#root-structure`,\n });\n throw error;\n }\n }\n return prismaInstance;\n}\n\nexport function getPrismaInstance() {\n return prismaInstance;\n}\n\nexport const checkDatabaseConnection = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const prisma = await loadPrismaModule();\n try {\n await prisma.$connect();\n next();\n } catch (error: any) {\n console.error(\"Database connection error\", error.message);\n next(new AppError(error.message, 503));\n }\n }\n);\n"]}
|
|
@@ -51,11 +51,7 @@ export default function errorHandler(err, req, res, next) {
|
|
|
51
51
|
function sendDevelopmentError(err, req, res) {
|
|
52
52
|
var _a;
|
|
53
53
|
if (req.originalUrl.startsWith("/api"))
|
|
54
|
-
res.status(err.statusCode).json({
|
|
55
|
-
message: err.message.split("\n")[err.message.split("\n").length - 1],
|
|
56
|
-
error: err,
|
|
57
|
-
stack: (_a = err.stack) === null || _a === void 0 ? void 0 : _a.split("\n"),
|
|
58
|
-
});
|
|
54
|
+
res.status(err.statusCode).json(Object.assign(Object.assign({}, err), { message: err.message.split("\n")[err.message.split("\n").length - 1], stack: (_a = err.stack) === null || _a === void 0 ? void 0 : _a.split("\n") }));
|
|
59
55
|
else
|
|
60
56
|
res.status(err.statusCode).json({
|
|
61
57
|
title: "Something went wrong!",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,qBAAqB,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;IAGnC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC1C,oBAAoB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO;IACT,CAAC;IAGD,IAAI,KAAK,mCAAQ,GAAG,KAAE,OAAO,EAAE,GAAG,CAAC,OAAO,GAAE,CAAC;IAG7C,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,cAAc,EAAE,CAAC;IACjD,IAAI,GAAG,CAAC,IAAI,KAAK,mBAAmB;QAClC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,EAAE,CAAC;IAGnD,IAAI,GAAG,CAAC,IAAI,KAAK,6BAA6B;QAC5C,KAAK,GAAG,qBAAqB,CAAC,iCAAiC,CAAC,GAAG,CAAC,CAAC;IAGvE,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;QACtB,KAAK,GAAG,qBAAqB,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC;IAC/D,IAAI,GAAG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AO,EAAE,GAAG,CAAC,OAAO;gBACpB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE;gBACpB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,SAAS;aAC5B,CAAC,CAAC;;YAEH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,uBAAuB;aACjC,CAAC,CAAC;QAEL,OAAO;IACT,CAAC;IAED,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACtB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;YAC9B,KAAK,EAAE,uBAAuB;YAC9B,OAAO,EAAE,GAAG,CAAC,OAAO;SACrB,CAAC,CAAC;QACH,OAAO;IACT,CAAC;IAED,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QAC9B,KAAK,EAAE,uBAAuB;QAC9B,OAAO,EAAE,yBAAyB;KACnC,CAAC,CAAC;AACL,CAAC;AAWD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,EAClC,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n // Handle general error types (e.g., syntax errors, type errors, etc.)\n // if (err.name === \"SyntaxError\")\n // error = errorControllerHelper.handleSchemaSyntaxError(err);\n // if (err.name === \"TypeError\")\n // error = errorControllerHelper.handleClientTypeError(err);\n // if (err.name === \"BinaryError\")\n // error = errorControllerHelper.handleBinaryError(err);\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n // if (err.name === \"UnhandledPromiseRejection\")\n // error = errorControllerHelper.handleUnhandledPromiseError(err);\n if (!err.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n error: err,\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n });\n }\n});\n"]}
|
|
1
|
+
{"version":3,"file":"error-handler.controller.js","sourceRoot":"","sources":["../../../../src/modules/error-handler/error-handler.controller.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,qBAAqB,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAiBtC,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAa,EACb,GAAY,EACZ,GAAa,EACb,IAAkB;IAElB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;IAE9C,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;IACvC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,OAAO,CAAC;IAGnC,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,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CAAC,CAAC;AACL,CAAC;AAWD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;IACzB,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACrC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,EAClC,CAAC;QACD,OAAO,CAAC,IAAI,EAAE,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAE3E,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { NextFunction, Request, Response } from \"express\";\nimport AppError from \"./utils/app-error\";\nimport * as errorControllerHelper from \"./utils/error-handler.helpers\";\nimport { server } from \"../../server\";\n\n/**\n * Error handling middleware for Express.\n *\n * This middleware function handles all errors in the Express application.\n * It checks for the environment (development or production) and sends appropriate error responses\n * based on whether the environment is production or not. It also maps specific errors such as\n * JWT errors, Prisma client errors, and database-related errors to specific helper functions for handling.\n *\n * @param {AppError} err - The error object thrown by the application.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n * @param {NextFunction} next - The next middleware function in the chain.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nexport default function errorHandler(\n err: AppError,\n req: Request,\n res: Response,\n next: NextFunction\n): void {\n console.error(\"[\\x1b[31mERROR\\x1b[0m]:\", err);\n // Default error status\n err.statusCode = err.statusCode || 500;\n err.status = err.status || \"error\";\n\n // If the environment is not production, send detailed error information\n if (process.env.NODE_ENV !== \"production\") {\n sendDevelopmentError(err, req, res);\n return;\n }\n\n // Prepare error object for response, copying the original error's properties\n let error = { ...err, message: err.message };\n\n // Handle specific error cases (JWT errors, Prisma validation errors, etc.)\n if (err.name === \"JsonWebTokenError\")\n error = errorControllerHelper.handleJWTError();\n if (err.name === \"TokenExpiredError\")\n error = errorControllerHelper.handleJWTExpired();\n\n // Handle specific Prisma client validation errors\n if (err.name === \"PrismaClientValidationError\")\n error = errorControllerHelper.handlePrismaClientValidationError(err);\n\n // Handle Prisma database-specific error codes (P1000 to P3005)\n if (err.code === \"P1000\")\n error = errorControllerHelper.handleAuthenticationError(err);\n if (err.code === \"P1001\")\n error = errorControllerHelper.handleServerNotReachableError(err);\n if (err.code === \"P1002\")\n error = errorControllerHelper.handleConnectionTimeoutError(err);\n if (err.code === \"P1003\")\n error = errorControllerHelper.handleDatabaseNotFoundError(err);\n if (err.code === \"P2000\")\n error = errorControllerHelper.handleFieldValueTooLargeError(err);\n if (err.code === \"P2001\")\n error = errorControllerHelper.handleRecordNotFoundError(err);\n if (err.code === \"P2002\")\n error = errorControllerHelper.handleUniqueConstraintError(err);\n if (err.code === \"P2003\")\n error = errorControllerHelper.handleForeignKeyConstraintError(err);\n if (err.code === \"P2004\")\n error = errorControllerHelper.handleConstraintFailedError(err);\n if (err.code === \"P3000\")\n error = errorControllerHelper.handleSchemaCreationFailedError(err);\n if (err.code === \"P3001\")\n error = errorControllerHelper.handleMigrationAlreadyAppliedError(err);\n if (err.code === \"P3002\")\n error = errorControllerHelper.handleMigrationScriptFailedError(err);\n if (err.code === \"P3003\")\n error = errorControllerHelper.handleVersionMismatchError(err);\n\n // Handle general error types (e.g., syntax errors, type errors, etc.)\n // if (err.name === \"SyntaxError\")\n // error = errorControllerHelper.handleSchemaSyntaxError(err);\n // if (err.name === \"TypeError\")\n // error = errorControllerHelper.handleClientTypeError(err);\n // if (err.name === \"BinaryError\")\n // error = errorControllerHelper.handleBinaryError(err);\n if (err.name === \"NetworkError\")\n error = errorControllerHelper.handleNetworkError(err);\n // if (err.name === \"UnhandledPromiseRejection\")\n // error = errorControllerHelper.handleUnhandledPromiseError(err);\n if (!err.isOperational) error = new AppError(\"Something went wrong!\", 500);\n\n // Send the error response for production environment\n sendProductionError(error, req, res);\n}\n\n/**\n * Sends a detailed error response in development mode.\n *\n * In development, the error response includes full error details, including\n * the stack trace and the complete error message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendDevelopmentError(\n err: AppError,\n req: Request,\n res: Response\n): void {\n if (req.originalUrl.startsWith(\"/api\"))\n res.status(err.statusCode).json({\n ...err,\n message: err.message.split(\"\\n\")[err.message.split(\"\\n\").length - 1],\n stack: err.stack?.split(\"\\n\"),\n });\n else\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n}\n\n/**\n * Sends a generic error response in production mode.\n *\n * In production, sensitive error details (such as stack traces) are not exposed\n * to the client. Only operational errors are shown with a generic message.\n *\n * @param {AppError} err - The error object.\n * @param {Request} req - The Express request object.\n * @param {Response} res - The Express response object.\n *\n * @returns {void} - Sends the response with the error details to the client.\n */\nfunction sendProductionError(err: AppError, req: Request, res: Response): void {\n if (req.originalUrl.startsWith(\"/api\")) {\n if (err.isOperational)\n res.status(err.statusCode).json({\n status: err.status,\n message: err.message,\n meta: err.meta || {},\n code: err.code || \"unknown\",\n });\n else\n res.status(500).json({\n status: \"error\",\n message: \"Something went wrong!\",\n });\n\n return;\n }\n\n if (err.isOperational) {\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: err.message,\n });\n return;\n }\n\n res.status(err.statusCode).json({\n title: \"Something went wrong!\",\n message: \"Please try again later.\",\n });\n}\n\n/**\n * Gracefully handles process termination by listening for SIGTERM signal.\n *\n * - In production and staging environments, it will log a shutdown message\n * and attempt to close the server gracefully.\n * - In development or non-production environments, it will immediately exit the process.\n *\n * @returns {void}\n */\nprocess.on(\"SIGTERM\", () => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n process.env.NODE_ENV !== \"staging\"\n ) {\n process.exit();\n } else {\n console.error(\"SIGTERM RECEIVED in Production. Shutting down gracefully!\");\n\n server.close(() => {\n console.error(\"Process terminated!!!\");\n });\n }\n});\n"]}
|
package/dist/es2020/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=function(e,t,n,c){function d(r){return r instanceof n?r:new n(function(p){p(r)})}return new(n||(n=Promise))(function(r,p){function m(o){try{u(c.next(o))}catch(a){p(a)}}function f(o){try{u(c.throw(o))}catch(a){p(a)}}function u(o){o.done?r(o.value):d(o.value).then(m,f)}u((c=c.apply(e,t||[])).next())})};import{bootstrap as w}from"./app";import v from"./utils/helpers/deepmerge.helper";process.on("uncaughtException",e=>{console.error("UNCAUGHT EXCEPTION! SHUTTING DOWN..."),console.error(e.name,e.message),console.error(e),process.exit(1)});let i,l,s={welcomeMessage:"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com",port:8e3,fileUpload:{baseUploadDir:"uploads",baseRoute:"/api/uploads"}};function x(){return h(this,arguments,void 0,function*(e={}){s=v(s,e);const t=s.port;return l=yield w(s),t&&(i=l.listen(e?.host?[t,e?.host]:t,()=>{const n=new Date().toTimeString().split(" ")[0]})),l})}process.on("unhandledRejection",e=>{console.error("UNHANDLED REJECTION! SHUTTING DOWN..."),console.error(e.name,e.message),console.error(e),i?.close(()=>{process.exit(1)})});export function getArkosConfig(){return s}export function getExpressApp(){return l}export{i as server,x as initApp};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,SAAS,MAAM,kCAAkC,CAAC;AAEzD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;IACtD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO,CAAC,KAAK,CAAC,G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E,KAAK,CAAC,GAAG,EAAE;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,cAAc;IAC5B,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC","sourcesContent":["import { IncomingMessage, Server, ServerResponse } from \"http\";\nimport AppError from \"./modules/error-handler/utils/app-error\";\nimport { Express } from \"express\";\nimport { bootstrap } from \"./app\";\nimport { ArkosConfig } from \"./types/arkos-config\";\nimport deepmerge from \"./utils/helpers/deepmerge.helper\";\n\nprocess.on(\"uncaughtException\", (err) => {\n console.error(\"UNCAUGHT EXCEPTION! SHUTTING DOWN...\");\n console.error(err.name, err.message);\n console.error(err);\n process.exit(1);\n});\n\nlet server: Server<typeof IncomingMessage, typeof ServerResponse>;\nlet _app: Express;\n\nlet _arkosConfig: ArkosConfig = {\n welcomeMessage:\n \"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com\",\n port: 8000,\n fileUpload: {\n baseUploadDir: \"uploads\",\n baseRoute: \"/api/uploads\",\n },\n};\n\n/**\n * Initializes the application server.\n *\n * This function starts the server by listening on a specified port.\n * The port is determined by the following order of precedence:\n * 1. The `port` argument passed to the function.\n * 2. Defaults to `8000` if neither is provided.\n *\n * @param {ArkosConfig} arkosConfig - initial configs for the api ( authentication, port).\n * @returns {Promise<Express>} This function returns the Express App after all middlewares configurations.\n * You can prevent it from listen py passing port as undefined\n *\n */\nasync function initApp(arkosConfig: ArkosConfig = {}): Promise<Express> {\n _arkosConfig = deepmerge(_arkosConfig, arkosConfig);\n\n const port = _arkosConfig.port;\n _app = await bootstrap(_arkosConfig);\n\n if (port)\n server = _app.listen(\n arkosConfig?.host ? [port, arkosConfig?.host!] : port,\n () => {\n const time = new Date().toTimeString().split(\" \")[0];\n // console.info(\n // `[\\x1b[32mREADY\\x1b[0m] \\x1b[90m${time}\\x1b[0m App running on port \\x1b[33m${port}\\x1b[0m, server waiting on http://localhost:${port}`\n // );\n\n // if (!!process.env.NODE_ENV)\n // console.info(`${`Environment: ${process.env.NODE_ENV}`}`);\n }\n );\n\n return _app;\n}\n\nprocess.on(\"unhandledRejection\", (err: AppError) => {\n console.error(\"UNHANDLED REJECTION! SHUTTING DOWN...\");\n console.error(err.name, err.message);\n console.error(err);\n server?.close(() => {\n process.exit(1);\n });\n});\n\nexport function getArkosConfig() {\n return _arkosConfig;\n}\n\nexport function getExpressApp() {\n return _app;\n}\n\nexport { server, initApp };\n"]}
|
|
@@ -6,7 +6,7 @@ const BUILD_DIR = ".build";
|
|
|
6
6
|
const MODULE_TYPES = ["cjs", "esm"];
|
|
7
7
|
export function buildCommand(options = {}) {
|
|
8
8
|
try {
|
|
9
|
-
console.info(`🚀 Building project
|
|
9
|
+
console.info(`🚀 Building an optimized production ready project...\n`);
|
|
10
10
|
ensureBuildDir();
|
|
11
11
|
const fileExt = getUserFileExtension();
|
|
12
12
|
if (fileExt === "ts") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../../src/utils/cli/build.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAG7D,MAAM,SAAS,GAAG,QAAQ,CAAC;AAC3B,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU,CAAC;AAY7C,MAAM,UAAU,YAAY,CAAC,UAAwB,EAAE;IACrD,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAEvC,cAAc,EAAE,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CAAC;IACtE,CAAC;AACH,CAAC","sourcesContent":["// src/utils/cli/build.ts\nimport path from \"path\";\nimport fs from \"fs\";\nimport { execSync, spawn } from \"child_process\";\nimport { getUserFileExtension } from \"../helpers/fs.helpers\";\n\n// Constants\nconst BUILD_DIR = \".build\";\nconst MODULE_TYPES = [\"cjs\", \"esm\"] as const;\ntype ModuleType = (typeof MODULE_TYPES)[number];\n\ninterface BuildOptions {\n watch?: boolean;\n config?: string;\n module?: string;\n}\n\n/**\n * Main build function for the arkos CLI\n */\nexport function buildCommand(options: BuildOptions = {}) {\n try {\n console.info(`🚀 Building project...`);\n\n ensureBuildDir();\n\n // Detect project type\n const fileExt = getUserFileExtension();\n\n if (fileExt === \"ts\") {\n buildTypeScriptProject(options);\n } else {\n buildJavaScriptProject(options);\n }\n\n console.info(`✅ Build complete! \\n`);\n console.info(`Next step:\\n`);\n console.info(`Run the generated build with the start command.\\n`);\n } catch (error) {\n console.error(\"❌ Build failed:\", error);\n process.exit(1);\n }\n}\n\n/**\n * Validates and normalizes module type option\n */\nfunction validateModuleType(moduleType?: string): ModuleType {\n if (!moduleType) return \"cjs\";\n\n const normalizedType = moduleType.toLowerCase();\n\n // Map common terms to our module types\n if (normalizedType === \"cjs\" || normalizedType === \"commonjs\") {\n return \"cjs\";\n } else if (\n [\"esm\", \"es\", \"es2020\", \"esnext\", \"module\"].includes(normalizedType)\n ) {\n return \"esm\";\n }\n\n // Default to CJS if unrecognized\n console.warn(\n `⚠️ Unrecognized module type \"${moduleType}\", defaulting to \"cjs\"`\n );\n return \"cjs\";\n}\n\n/**\n * Ensure the build directory exists\n */\nfunction ensureBuildDir() {\n if (!fs.existsSync(BUILD_DIR)) {\n fs.mkdirSync(BUILD_DIR, { recursive: true });\n }\n\n // Create module-specific subdirectories\n for (const moduleType of MODULE_TYPES) {\n const moduleDir = path.join(BUILD_DIR, moduleType);\n if (!fs.existsSync(moduleDir)) {\n fs.mkdirSync(moduleDir, { recursive: true });\n }\n }\n}\n\n/**\n * Build a TypeScript project\n */\nfunction buildTypeScriptProject(options: BuildOptions) {\n // Read the user's tsconfig.json\n const tsconfigPath = path.join(\n process.cwd(),\n options.config || \"tsconfig.json\"\n );\n let tsconfig: any = {};\n\n try {\n if (fs.existsSync(tsconfigPath)) {\n const tsconfigContent = fs.readFileSync(tsconfigPath, \"utf8\");\n tsconfig = JSON.parse(tsconfigContent);\n }\n } catch (error) {\n console.error(\"❌ Error reading tsconfig.json:\", error);\n // Continue with default config\n }\n\n // Create a custom tsconfig that outputs to our .build directory\n const tempTsconfig = {\n ...tsconfig,\n compilerOptions: {\n ...(tsconfig.compilerOptions || {}),\n outDir: path.join(`./${BUILD_DIR}`),\n },\n };\n\n const tempTsconfigPath = path.join(\n process.cwd(),\n `tsconfig.arkos-build.json`\n );\n fs.writeFileSync(tempTsconfigPath, JSON.stringify(tempTsconfig, null, 2));\n\n try {\n // Run TypeScript compiler\n\n if (options.watch) {\n // For watch mode, spawn a process\n const tsc = spawn(\"npx\", [\"tsc\", \"-p\", tempTsconfigPath, \"--watch\"], {\n stdio: \"inherit\",\n shell: true,\n });\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n tsc.kill();\n cleanupTempConfig(tempTsconfigPath);\n process.exit(0);\n });\n } else {\n // For one-time build, use execSync\n execSync(`npx tsc -p ${tempTsconfigPath}`, {\n stdio: \"inherit\",\n cwd: process.cwd(),\n });\n\n // Copy non-TypeScript files\n // copyAssetFiles(moduleType);\n\n // Clean up temp config\n cleanupTempConfig(tempTsconfigPath);\n }\n } catch (error) {\n cleanupTempConfig(tempTsconfigPath);\n throw error;\n }\n}\n\n/**\n * Build a JavaScript project\n */\nfunction buildJavaScriptProject(options: BuildOptions) {\n // Target directory\n const targetDir = path.join(BUILD_DIR);\n\n try {\n // For JS projects, we need to handle module transformations if needed\n if (true) {\n // For ESM output, we might want to transform CJS to ESM if needed\n // This is a simplified approach - for production, consider using tools like Babel\n execSync(\n `npx copyfiles -u 0 \"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.mjs\" \"src/**/*.cjs\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n } else {\n // For CJS output, direct copy is usually fine\n execSync(\n `npx copyfiles -u 0 \"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.cjs\" \"src/**/*.mjs\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n }\n\n // Copy asset files\n copyAssetFiles();\n\n // Handle watch mode\n if (options.watch) {\n const patterns = `\"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.mjs\" \"src/**/*.cjs\"`;\n\n const watcher = spawn(\n \"npx\",\n [\"chokidar\", patterns, \"-c\", `npx copyfiles -u 0 {path} ${targetDir}`],\n {\n stdio: \"inherit\",\n shell: true,\n }\n );\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n watcher.kill();\n process.exit(0);\n });\n }\n } catch (error) {\n console.error(\"❌ Error building JavaScript project:\", error);\n throw error;\n }\n}\n\n/**\n * Copy asset files to the build directory\n */\nfunction copyAssetFiles() {\n const targetDir = path.join(BUILD_DIR);\n\n try {\n execSync(\n `npx copyfiles -u 0 \"src/**/*.json\" \"src/**/*.html\" \"src/**/*.css\" \"src/**/*.svg\" \"src/**/*.png\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n } catch (error) {\n console.warn(\"Warning: Error copying asset files:\", error);\n }\n}\n\n/**\n * Clean up temporary tsconfig\n */\nfunction cleanupTempConfig(configPath: string) {\n try {\n if (fs.existsSync(configPath)) {\n fs.unlinkSync(configPath);\n }\n } catch (error) {\n console.warn(\"Warning: Error cleaning up temporary config:\", error);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../../src/utils/cli/build.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAA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AqC,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAKD,SAAS,iBAAiB,CAAC,UAAkB;IAC3C,IAAI,CAAC;QACH,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;IACtE,CAAC;AACH,CAAC","sourcesContent":["// src/utils/cli/build.ts\nimport path from \"path\";\nimport fs from \"fs\";\nimport { execSync, spawn } from \"child_process\";\nimport { getUserFileExtension } from \"../helpers/fs.helpers\";\n\n// Constants\nconst BUILD_DIR = \".build\";\nconst MODULE_TYPES = [\"cjs\", \"esm\"] as const;\ntype ModuleType = (typeof MODULE_TYPES)[number];\n\ninterface BuildOptions {\n watch?: boolean;\n config?: string;\n module?: string;\n}\n\n/**\n * Main build function for the arkos CLI\n */\nexport function buildCommand(options: BuildOptions = {}) {\n try {\n console.info(`🚀 Building an optimized production ready project...\\n`);\n\n ensureBuildDir();\n\n // Detect project type\n const fileExt = getUserFileExtension();\n\n if (fileExt === \"ts\") {\n buildTypeScriptProject(options);\n } else {\n buildJavaScriptProject(options);\n }\n\n console.info(`✅ Build complete! \\n`);\n console.info(`Next step:\\n`);\n console.info(`Run the generated build with the start command.\\n`);\n } catch (error) {\n console.error(\"❌ Build failed:\", error);\n process.exit(1);\n }\n}\n\n/**\n * Validates and normalizes module type option\n */\nfunction validateModuleType(moduleType?: string): ModuleType {\n if (!moduleType) return \"cjs\";\n\n const normalizedType = moduleType.toLowerCase();\n\n // Map common terms to our module types\n if (normalizedType === \"cjs\" || normalizedType === \"commonjs\") {\n return \"cjs\";\n } else if (\n [\"esm\", \"es\", \"es2020\", \"esnext\", \"module\"].includes(normalizedType)\n ) {\n return \"esm\";\n }\n\n // Default to CJS if unrecognized\n console.warn(\n `⚠️ Unrecognized module type \"${moduleType}\", defaulting to \"cjs\"`\n );\n return \"cjs\";\n}\n\n/**\n * Ensure the build directory exists\n */\nfunction ensureBuildDir() {\n if (!fs.existsSync(BUILD_DIR)) {\n fs.mkdirSync(BUILD_DIR, { recursive: true });\n }\n\n // Create module-specific subdirectories\n for (const moduleType of MODULE_TYPES) {\n const moduleDir = path.join(BUILD_DIR, moduleType);\n if (!fs.existsSync(moduleDir)) {\n fs.mkdirSync(moduleDir, { recursive: true });\n }\n }\n}\n\n/**\n * Build a TypeScript project\n */\nfunction buildTypeScriptProject(options: BuildOptions) {\n // Read the user's tsconfig.json\n const tsconfigPath = path.join(\n process.cwd(),\n options.config || \"tsconfig.json\"\n );\n let tsconfig: any = {};\n\n try {\n if (fs.existsSync(tsconfigPath)) {\n const tsconfigContent = fs.readFileSync(tsconfigPath, \"utf8\");\n tsconfig = JSON.parse(tsconfigContent);\n }\n } catch (error) {\n console.error(\"❌ Error reading tsconfig.json:\", error);\n // Continue with default config\n }\n\n // Create a custom tsconfig that outputs to our .build directory\n const tempTsconfig = {\n ...tsconfig,\n compilerOptions: {\n ...(tsconfig.compilerOptions || {}),\n outDir: path.join(`./${BUILD_DIR}`),\n },\n };\n\n const tempTsconfigPath = path.join(\n process.cwd(),\n `tsconfig.arkos-build.json`\n );\n fs.writeFileSync(tempTsconfigPath, JSON.stringify(tempTsconfig, null, 2));\n\n try {\n // Run TypeScript compiler\n\n if (options.watch) {\n // For watch mode, spawn a process\n const tsc = spawn(\"npx\", [\"tsc\", \"-p\", tempTsconfigPath, \"--watch\"], {\n stdio: \"inherit\",\n shell: true,\n });\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n tsc.kill();\n cleanupTempConfig(tempTsconfigPath);\n process.exit(0);\n });\n } else {\n // For one-time build, use execSync\n execSync(`npx tsc -p ${tempTsconfigPath}`, {\n stdio: \"inherit\",\n cwd: process.cwd(),\n });\n\n // Copy non-TypeScript files\n // copyAssetFiles(moduleType);\n\n // Clean up temp config\n cleanupTempConfig(tempTsconfigPath);\n }\n } catch (error) {\n cleanupTempConfig(tempTsconfigPath);\n throw error;\n }\n}\n\n/**\n * Build a JavaScript project\n */\nfunction buildJavaScriptProject(options: BuildOptions) {\n // Target directory\n const targetDir = path.join(BUILD_DIR);\n\n try {\n // For JS projects, we need to handle module transformations if needed\n if (true) {\n // For ESM output, we might want to transform CJS to ESM if needed\n // This is a simplified approach - for production, consider using tools like Babel\n execSync(\n `npx copyfiles -u 0 \"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.mjs\" \"src/**/*.cjs\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n } else {\n // For CJS output, direct copy is usually fine\n execSync(\n `npx copyfiles -u 0 \"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.cjs\" \"src/**/*.mjs\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n }\n\n // Copy asset files\n copyAssetFiles();\n\n // Handle watch mode\n if (options.watch) {\n const patterns = `\"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.mjs\" \"src/**/*.cjs\"`;\n\n const watcher = spawn(\n \"npx\",\n [\"chokidar\", patterns, \"-c\", `npx copyfiles -u 0 {path} ${targetDir}`],\n {\n stdio: \"inherit\",\n shell: true,\n }\n );\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n watcher.kill();\n process.exit(0);\n });\n }\n } catch (error) {\n console.error(\"❌ Error building JavaScript project:\", error);\n throw error;\n }\n}\n\n/**\n * Copy asset files to the build directory\n */\nfunction copyAssetFiles() {\n const targetDir = path.join(BUILD_DIR);\n\n try {\n execSync(\n `npx copyfiles -u 0 \"src/**/*.json\" \"src/**/*.html\" \"src/**/*.css\" \"src/**/*.svg\" \"src/**/*.png\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n } catch (error) {\n console.warn(\"Warning: Error copying asset files:\", error);\n }\n}\n\n/**\n * Clean up temporary tsconfig\n */\nfunction cleanupTempConfig(configPath: string) {\n try {\n if (fs.existsSync(configPath)) {\n fs.unlinkSync(configPath);\n }\n } catch (error) {\n console.warn(\"Warning: Error cleaning up temporary config:\", error);\n }\n}\n"]}
|
|
@@ -1,44 +1,57 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { spawn } from "child_process";
|
|
2
11
|
import { getUserFileExtension } from "../helpers/fs.helpers";
|
|
3
12
|
import { getVersion } from ".";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
child
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
import { getArkosConfig } from "../../server";
|
|
14
|
+
export function devCommand() {
|
|
15
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
16
|
+
try {
|
|
17
|
+
const { port, host } = options;
|
|
18
|
+
const fileExt = getUserFileExtension();
|
|
19
|
+
const entryPoint = `src/app.${fileExt}`;
|
|
20
|
+
if (!entryPoint) {
|
|
21
|
+
console.error("❌ Could not find application entry point.");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
const env = Object.assign(Object.assign(Object.assign({ NODE_ENV: "development" }, process.env), (port && { PORT: port })), (host && { HOST: host }));
|
|
25
|
+
let child;
|
|
26
|
+
if (fileExt === "ts") {
|
|
27
|
+
child = spawn("npx", ["ts-node-dev", "--respawn", entryPoint], {
|
|
28
|
+
stdio: "inherit",
|
|
29
|
+
env,
|
|
30
|
+
shell: true,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
child = spawn("npx", ["nodemon", entryPoint], {
|
|
35
|
+
stdio: "inherit",
|
|
36
|
+
env,
|
|
37
|
+
shell: true,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
console.log(getArkosConfig());
|
|
41
|
+
console.info(` \x1b[1m\x1b[36m Arkos.js ${getVersion()}\x1b[0m`);
|
|
42
|
+
console.info(` - Local: http://${host}:${port}`);
|
|
43
|
+
console.info(` - Environments: development\n`);
|
|
44
|
+
process.on("SIGINT", () => {
|
|
45
|
+
if (child) {
|
|
46
|
+
child.kill();
|
|
47
|
+
}
|
|
48
|
+
process.exit(0);
|
|
20
49
|
});
|
|
21
50
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
env,
|
|
26
|
-
shell: true,
|
|
27
|
-
});
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error("❌ Development server failed to start:", error);
|
|
53
|
+
process.exit(1);
|
|
28
54
|
}
|
|
29
|
-
|
|
30
|
-
console.info(` - Local: http://${host}:${port}`);
|
|
31
|
-
console.info(` - Environments: development\n`);
|
|
32
|
-
process.on("SIGINT", () => {
|
|
33
|
-
if (child) {
|
|
34
|
-
child.kill();
|
|
35
|
-
}
|
|
36
|
-
process.exit(0);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
console.error("❌ Development server failed to start:", error);
|
|
41
|
-
process.exit(1);
|
|
42
|
-
}
|
|
55
|
+
});
|
|
43
56
|
}
|
|
44
57
|
//# sourceMappingURL=dev.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../src/utils/cli/dev.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../src/utils/cli/dev.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAU9C,MAAM,UAAgB,UAAU;yDAAC,UAAsB,EAAE;QACvD,IAAI,CAAC;YACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;YAG/B,MAAM,OAAO,GAAG,oBAAoB,EAAE,CAAC;YAGvC,MAAM,UAAU,GAAG,WAAW,OAAO,EAAE,CAAC;YAExC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;gBAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YAGD,MAAM,GAAG,+CACP,QAAQ,EAAE,aAAa,IACpB,OAAO,CAAC,GAAG,GACX,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,GACxB,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAC5B,CAAC;YAGF,IAAI,KAAK,CAAC;YAGV,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBACrB,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE;oBAC7D,KAAK,EAAE,SAAS;oBAChB,GAAG;oBACH,KAAK,EAAE,IAAI;iBACZ,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC,EAAE;oBAC5C,KAAK,EAAE,SAAS;oBAChB,GAAG;oBACH,KAAK,EAAE,IAAI;iBACZ,CAAC,CAAC;YACL,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC;YAE9B,OAAO,CAAC,IAAI,CAAC,+BAA+B,UAAU,EAAE,SAAS,CAAC,CAAC;YACnE,OAAO,CAAC,IAAI,CAAC,4BAA4B,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;YACzD,OAAO,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;YAGhD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;gBACxB,IAAI,KAAK,EAAE,CAAC;oBACV,KAAK,CAAC,IAAI,EAAE,CAAC;gBACf,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;YAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CAAA","sourcesContent":["// src/utils/cli/dev.ts\nimport { spawn } from \"child_process\";\nimport { getUserFileExtension } from \"../helpers/fs.helpers\";\nimport { getVersion } from \".\";\nimport { getArkosConfig } from \"../../server\";\n\ninterface DevOptions {\n port?: string;\n host?: string;\n}\n\n/**\n * Dev server command for the arkos CLI\n */\nexport async function devCommand(options: DevOptions = {}) {\n try {\n const { port, host } = options;\n\n // Detect if project uses TypeScript or JavaScript\n const fileExt = getUserFileExtension();\n\n // Find the application entry point\n const entryPoint = `src/app.${fileExt}`;\n\n if (!entryPoint) {\n console.error(\"❌ Could not find application entry point.\");\n process.exit(1);\n }\n\n // Set environment variables\n const env = {\n NODE_ENV: \"development\",\n ...process.env,\n ...(port && { PORT: port }),\n ...(host && { HOST: host }),\n };\n\n // Start the application with the appropriate runner\n let child;\n\n // Setup file watching if enabled\n if (fileExt === \"ts\") {\n child = spawn(\"npx\", [\"ts-node-dev\", \"--respawn\", entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n } else {\n child = spawn(\"npx\", [\"nodemon\", entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n }\n\n console.log(getArkosConfig());\n\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(` - Local: http://${host}:${port}`);\n console.info(` - Environments: development\\n`);\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n if (child) {\n child.kill();\n }\n process.exit(0);\n });\n } catch (error) {\n console.error(\"❌ Development server failed to start:\", error);\n process.exit(1);\n }\n}\n"]}
|
|
@@ -1,36 +1,45 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import path from "path";
|
|
2
11
|
import fs from "fs";
|
|
3
12
|
import { spawn } from "child_process";
|
|
4
|
-
import { getArkosConfig } from "../../server";
|
|
5
13
|
import { getVersion } from ".";
|
|
6
|
-
export function startCommand(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
export function startCommand() {
|
|
15
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
16
|
+
try {
|
|
17
|
+
const { port, host } = options;
|
|
18
|
+
const entryPoint = path.join(".build", "src", "app.js");
|
|
19
|
+
if (!fs.existsSync(path.join(process.cwd(), entryPoint))) {
|
|
20
|
+
console.error(`❌ Could not find built application entry point at ${entryPoint}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
const env = Object.assign(Object.assign(Object.assign(Object.assign({}, process.env), (port && { PORT: port })), (host && { HOST: host })), { NODE_ENV: "production", ARKOS_BUILD: "true" });
|
|
24
|
+
const child = spawn("node", [entryPoint], {
|
|
25
|
+
stdio: "inherit",
|
|
26
|
+
env,
|
|
27
|
+
shell: true,
|
|
28
|
+
});
|
|
29
|
+
process.on("SIGINT", () => {
|
|
30
|
+
if (child) {
|
|
31
|
+
child.kill();
|
|
32
|
+
}
|
|
33
|
+
process.exit(0);
|
|
34
|
+
});
|
|
35
|
+
console.info(` \x1b[1m\x1b[36m Arkos.js ${getVersion()}\x1b[0m`);
|
|
36
|
+
console.info(` - Local: http://${host}:${port}`);
|
|
37
|
+
console.info(` - Environments: production\n`);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error("❌ Production server failed to start:", error);
|
|
13
41
|
process.exit(1);
|
|
14
42
|
}
|
|
15
|
-
|
|
16
|
-
const child = spawn("node", [entryPoint], {
|
|
17
|
-
stdio: "inherit",
|
|
18
|
-
env,
|
|
19
|
-
shell: true,
|
|
20
|
-
});
|
|
21
|
-
process.on("SIGINT", () => {
|
|
22
|
-
if (child) {
|
|
23
|
-
child.kill();
|
|
24
|
-
}
|
|
25
|
-
process.exit(0);
|
|
26
|
-
});
|
|
27
|
-
console.info(` \x1b[1m\x1b[36m♖ Arkos.js ${getVersion()}\x1b[0m`);
|
|
28
|
-
console.info(` - Local: http://${host}:${port}`);
|
|
29
|
-
console.info(` - Environments: production\n`);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.error("❌ Production server failed to start:", error);
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
43
|
+
});
|
|
35
44
|
}
|
|
36
45
|
//# sourceMappingURL=start.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../src/utils/cli/start.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAU/B,MAAM,UAAgB,YAAY;yDAAC,UAAwB,EAAE;QAG3D,IAAI,CAAC;YACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;YAG/B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YAExD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC;gBACzD,OAAO,CAAC,KAAK,CACX,qDAAqD,UAAU,EAAE,CAClE,CAAC;gBACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YAGD,MAAM,GAAG,+DACJ,OAAO,CAAC,GAAG,GACX,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,GACxB,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,KAC3B,QAAQ,EAAE,YAAY,EACtB,WAAW,EAAE,MAAM,GACpB,CAAC;YAGF,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE;gBACxC,KAAK,EAAE,SAAS;gBAChB,GAAG;gBACH,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;YAGH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;gBACxB,IAAI,KAAK,EAAE,CAAC;oBACV,KAAK,CAAC,IAAI,EAAE,CAAC;gBACf,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;YAIH,OAAO,CAAC,IAAI,CAAC,+BAA+B,UAAU,EAAE,SAAS,CAAC,CAAC;YACnE,OAAO,CAAC,IAAI,CAAC,4BAA4B,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;YACzD,OAAO,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;YAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CAAA","sourcesContent":["// src/utils/cli/start.ts\nimport path from \"path\";\nimport fs from \"fs\";\nimport { spawn } from \"child_process\";\nimport { getArkosConfig } from \"../../server\";\nimport { getVersion } from \".\";\n\ninterface StartOptions {\n port?: string;\n host?: string;\n}\n\n/**\n * Production start command for the arkos CLI\n */\nexport async function startCommand(options: StartOptions = {}) {\n // const configs = getArkosConfig();\n // console.log(configs);\n try {\n const { port, host } = options;\n\n // Check for built app file\n const entryPoint = path.join(\".build\", \"src\", \"app.js\");\n\n if (!fs.existsSync(path.join(process.cwd(), entryPoint))) {\n console.error(\n `❌ Could not find built application entry point at ${entryPoint}`\n );\n process.exit(1);\n }\n\n // Set environment variables\n const env = {\n ...process.env,\n ...(port && { PORT: port }),\n ...(host && { HOST: host }),\n NODE_ENV: \"production\",\n ARKOS_BUILD: \"true\",\n };\n\n // Start the application\n const child = spawn(\"node\", [entryPoint], {\n stdio: \"inherit\",\n env,\n shell: true,\n });\n\n // Handle process exit\n process.on(\"SIGINT\", () => {\n if (child) {\n child.kill();\n }\n process.exit(0);\n });\n\n // console.log(getArkosConfig());\n\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(` - Local: http://${host}:${port}`);\n console.info(` - Environments: production\\n`);\n } catch (error) {\n console.error(\"❌ Production server failed to start:\", error);\n process.exit(1);\n }\n}\n"]}
|
|
@@ -13,7 +13,7 @@ import AppError from "../../modules/error-handler/utils/app-error";
|
|
|
13
13
|
import { crd, getUserFileExtension } from "./fs.helpers";
|
|
14
14
|
import { importModule } from "./global.helpers";
|
|
15
15
|
export let prismaInstance = null;
|
|
16
|
-
export function loadPrismaModule(
|
|
16
|
+
export function loadPrismaModule() {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
18
|
if (!prismaInstance) {
|
|
19
19
|
try {
|
|
@@ -24,12 +24,14 @@ export function loadPrismaModule(a) {
|
|
|
24
24
|
const prismaModule = yield importModule(prismaPath);
|
|
25
25
|
prismaInstance = prismaModule.default || prismaModule.prisma;
|
|
26
26
|
if (!prismaInstance)
|
|
27
|
-
throw new Error("not found");
|
|
27
|
+
throw new Error("Prisma not found");
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
if (error.message === "Prisma not found")
|
|
31
|
+
throw new AppError("Could not initialize Prisma module.", 500, {
|
|
32
|
+
tip: `Make sure your prisma instance is exported under src/utils/prisma.${getUserFileExtension()} or src/utils/prisma/index.${getUserFileExtension()}, read more about Arkos' Project Structure under https://www.arkosjs.com/docs/project-structure#root-structure`,
|
|
33
|
+
});
|
|
34
|
+
throw error;
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
return prismaInstance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,UAAU,MAAM,+CAA+C,CAAC;AACvE,OAAO,QAAQ,MAAM,6CAA6C,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,CAAC,IAAI,cAAc,GAAQ,IAAI,CAAC;AAEtC,MAAM,UAAgB,gBAAgB
|
|
1
|
+
{"version":3,"file":"prisma.helpers.js","sourceRoot":"","sources":["../../../../src/utils/helpers/prisma.helpers.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,UAAU,MAAM,+CAA+C,CAAC;AACvE,OAAO,QAAQ,MAAM,6CAA6C,CAAC;AACnE,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,CAAC,IAAI,cAAc,GAAQ,IAAI,CAAC;AAEtC,MAAM,UAAgB,gBAAgB;;QACpC,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,IAAI,CAAC;gBACH,IAAI,UAAU,GAAG,GAAG,GAAG,EAAE,qBAAqB,oBAAoB,EAAE,EAAE,CAAC;gBAEvE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC/B,UAAU,GAAG,GAAG,GAAG,EAAE,2BAA2B,oBAAoB,EAAE,EAAE,CAAC;gBAC3E,CAAC;gBAED,MAAM,YAAY,GAAG,MAAM,YAAY,CAAC,UAAU,CAAC,CAAC;gBACpD,cAAc,GAAG,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC;gBAE7D,IAAI,CAAC,cAAc;oBAAE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAC3D,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAI,KAAK,CAAC,OAAO,KAAK,kBAAkB;oBACtC,MAAM,IAAI,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;wBAC7D,GAAG,EAAE,qEAAqE,oBAAoB,EAAE,8BAA8B,oBAAoB,EAAE,gHAAgH;qBACrQ,CAAC,CAAC;gBACL,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;CAAA;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAC/C,CAAO,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,MAAM,MAAM,GAAG,MAAM,gBAAgB,EAAE,CAAC;IACxC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,IAAI,EAAE,CAAC;IACT,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;AACH,CAAC,CAAA,CACF,CAAC","sourcesContent":["import fs from \"fs\";\nimport { Request, Response, NextFunction } from \"express\";\nimport catchAsync from \"../../modules/error-handler/utils/catch-async\";\nimport AppError from \"../../modules/error-handler/utils/app-error\";\nimport { crd, getUserFileExtension } from \"./fs.helpers\";\nimport { importModule } from \"./global.helpers\";\n\nexport let prismaInstance: any = null;\n\nexport async function loadPrismaModule() {\n if (!prismaInstance) {\n try {\n let prismaPath = `${crd()}/src/utils/prisma.${getUserFileExtension()}`;\n\n if (!fs.existsSync(prismaPath)) {\n prismaPath = `${crd()}/src/utils/prisma/index.${getUserFileExtension()}`;\n }\n\n const prismaModule = await importModule(prismaPath);\n prismaInstance = prismaModule.default || prismaModule.prisma;\n\n if (!prismaInstance) throw new Error(\"Prisma not found\");\n } catch (error: any) {\n if (error.message === \"Prisma not found\")\n throw new AppError(\"Could not initialize Prisma module.\", 500, {\n tip: `Make sure your prisma instance is exported under src/utils/prisma.${getUserFileExtension()} or src/utils/prisma/index.${getUserFileExtension()}, read more about Arkos' Project Structure under https://www.arkosjs.com/docs/project-structure#root-structure`,\n });\n throw error;\n }\n }\n return prismaInstance;\n}\n\nexport function getPrismaInstance() {\n return prismaInstance;\n}\n\nexport const checkDatabaseConnection = catchAsync(\n async (req: Request, res: Response, next: NextFunction) => {\n const prisma = await loadPrismaModule();\n try {\n await prisma.$connect();\n next();\n } catch (error: any) {\n console.error(\"Database connection error\", error.message);\n next(new AppError(error.message, 503));\n }\n }\n);\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare let prismaInstance: any;
|
|
2
|
-
export declare function loadPrismaModule(
|
|
2
|
+
export declare function loadPrismaModule(): Promise<any>;
|
|
3
3
|
export declare function getPrismaInstance(): any;
|
|
4
4
|
export declare const checkDatabaseConnection: (req: import("../../types").ArkosRequest, res: import("../../types").ArkosResponse, next: import("../../types").ArkosNextFunction) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arkos",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7-beta",
|
|
4
4
|
"description": "The Express & Prisma Framework For RESTful API",
|
|
5
5
|
"main": "dist/cjs/exports/index.js",
|
|
6
6
|
"module": "dist/es2020/exports/index.js",
|
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"README.md"
|
|
131
131
|
],
|
|
132
132
|
"devDependencies": {
|
|
133
|
+
"@prisma/client": "^6.4.1",
|
|
133
134
|
"@types/bcrypt": "^5.0.2",
|
|
134
135
|
"@types/body-parser": "^1.19.5",
|
|
135
136
|
"@types/compression": "^1.7.5",
|
|
@@ -152,8 +153,7 @@
|
|
|
152
153
|
"prisma": "^6.4.1",
|
|
153
154
|
"ts-jest": "^29.3.1",
|
|
154
155
|
"ts-node": "^10.9.2",
|
|
155
|
-
"typescript": "^5.8.2"
|
|
156
|
-
"@prisma/client": "^6.4.1"
|
|
156
|
+
"typescript": "^5.8.2"
|
|
157
157
|
},
|
|
158
158
|
"dependencies": {
|
|
159
159
|
"commander": "^13.1.0",
|