arkos 1.1.96-test → 1.1.98-test
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/auth/auth.controller.js +0 -5
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +82 -35
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +5 -5
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js +7 -14
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.service.js +21 -12
- package/dist/cjs/modules/base/base.service.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.middlewares.helpers.js +50 -0
- package/dist/cjs/modules/base/utils/helpers/base.middlewares.helpers.js.map +1 -0
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +93 -40
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
- package/dist/cjs/server.js +3 -2
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +176 -26
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/index.js +3 -2
- package/dist/cjs/utils/cli/index.js.map +1 -1
- package/dist/cjs/utils/cli/start.js +12 -8
- package/dist/cjs/utils/cli/start.js.map +1 -1
- package/dist/cjs/utils/cli/utils/cli.helpers.js +7 -0
- package/dist/cjs/utils/cli/utils/cli.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/fs.helpers.js +1 -1
- package/dist/cjs/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/cjs/utils/helpers/models.helpers.js +7 -0
- package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
- package/dist/es2020/modules/auth/auth.controller.js +0 -5
- package/dist/es2020/modules/auth/auth.controller.js.map +1 -1
- package/dist/es2020/modules/auth/auth.router.js +82 -35
- package/dist/es2020/modules/auth/auth.router.js.map +1 -1
- package/dist/es2020/modules/auth/auth.service.js +5 -5
- package/dist/es2020/modules/auth/auth.service.js.map +1 -1
- package/dist/es2020/modules/base/base.middlewares.js +7 -14
- package/dist/es2020/modules/base/base.middlewares.js.map +1 -1
- package/dist/es2020/modules/base/base.service.js +21 -12
- package/dist/es2020/modules/base/base.service.js.map +1 -1
- package/dist/es2020/modules/base/utils/helpers/base.middlewares.helpers.js +44 -0
- package/dist/es2020/modules/base/utils/helpers/base.middlewares.helpers.js.map +1 -0
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js +93 -40
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/es2020/modules/error-handler/utils/error-handler.helpers.js.map +1 -1
- package/dist/es2020/server.js +3 -2
- package/dist/es2020/server.js.map +1 -1
- package/dist/es2020/types/index.js.map +1 -1
- package/dist/es2020/utils/cli/dev.js +173 -27
- package/dist/es2020/utils/cli/dev.js.map +1 -1
- package/dist/es2020/utils/cli/index.js +3 -2
- package/dist/es2020/utils/cli/index.js.map +1 -1
- package/dist/es2020/utils/cli/start.js +11 -8
- package/dist/es2020/utils/cli/start.js.map +1 -1
- package/dist/es2020/utils/cli/utils/cli.helpers.js +6 -0
- package/dist/es2020/utils/cli/utils/cli.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/fs.helpers.js +1 -1
- package/dist/es2020/utils/helpers/fs.helpers.js.map +1 -1
- package/dist/es2020/utils/helpers/models.helpers.js +7 -0
- package/dist/es2020/utils/helpers/models.helpers.js.map +1 -1
- package/dist/types/modules/base/base.middlewares.d.ts +2 -2
- package/dist/types/modules/base/base.service.d.ts +2 -2
- package/dist/types/modules/base/utils/helpers/base.middlewares.helpers.d.ts +3 -0
- package/dist/types/server.d.ts +1 -0
- package/dist/types/types/index.d.ts +11 -3
- package/dist/types/utils/cli/dev.d.ts +1 -0
- package/dist/types/utils/cli/start.d.ts +1 -0
- package/dist/types/utils/cli/utils/cli.helpers.d.ts +1 -0
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.helpers.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/error-handler.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,aAAa,CAAC;AA2BnC,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,QAAQ,CAAC,qCAAqC,EAAE,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,QAAQ,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,GAAa;IAC7D,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9E,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,GAAa;IACrD,MAAM,OAAO,GACX,mFAAmF,CAAC;IACtF,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,GAAa;IACzD,MAAM,OAAO,GACX,qGAAqG,CAAC;IACxG,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,GAAa;IACxD,MAAM,OAAO,GACX,gGAAgG,CAAC;IACnG,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,GAAa;IACvD,M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AG,qGAAqG,CAAC;IACtH,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,GAAa;IACvD,MAAM,OAAO,GAAG,iGAAiG,CAAC;IAClH,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,GAAa;IAC/C,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,eAAe,CAAC;IAClD,MAAM,YAAY,GAAG,GAAG,EAAE,IAAI,EAAE,aAAa,IAAI,cAAc,CAAC;IAChE,MAAM,OAAO,GAAG,gCAAgC,KAAK,qBAAqB,YAAY,GAAG,CAAC;IAC1F,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAa;IAClD,MAAM,OAAO,GAAG,6FAA6F,CAAC;IAC9G,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import AppError from \"./app-error\";\n\nexport interface PrismaError {\n code?: string; // Prisma-specific error code\n message: string; // Error message\n meta?: Record<string, any>; // Metadata provided by Prisma\n name?: string; // Error name\n}\n\n// const handleCastErrorDB = (err: AppError) => {\n// const message = `Invalid ${err?.path}: ${err?.value}`\n// return new AppError(message, 400)\n// }\n\n// const handleDuplicateFieldDB = (err: AppError) => {\n// const value = err?.keyValue.name\n// const message = `Duplicate fiedl value: ${value}. Please use another value!`\n\n// return new AppError(message, 400)\n// }\n\n// const handleValidationErrorDB = (err: AppError) => {\n// const errors = Object.values(err?.errors).map((el) => el.message)\n// const message = `Ivalid input data. ${errors.join('. ')}`\n// return new AppError(message, 400)\n// }\n\nexport function handleJWTError() {\n return new AppError(\"Invalid token. Please log in again!\", 401);\n}\n\nexport function handleJWTExpired() {\n return new AppError(\"Your token has expired, Please log again!\", 401);\n}\n\nexport function handlePrismaClientValidationError(err: AppError) {\n const message = err?.message.split(\"\\n\")[err?.message.split(\"\\n\").length - 1];\n return new AppError(message, 400);\n}\n\nexport function handleAuthenticationError(err: AppError) {\n const message =\n \"Authentication failed against the database server. Please check your credentials.\";\n return new AppError(message, 401);\n}\n\nexport function handleServerNotReachableError(err: AppError) {\n const message =\n \"The database server is not reachable. Verify your connection string or ensure the server is online.\";\n return new AppError(message, 503);\n}\n\nexport function handleConnectionTimeoutError(err: AppError) {\n const message =\n \"Connection to the database timed out. Please check server performance or network connectivity.\";\n return new AppError(message, 504);\n}\n\nexport function handleDatabaseNotFoundError(err: AppError) {\n const message = \"The specified database does not exist on the server.\";\n return new AppError(message, 404);\n}\n\nexport function handleEnvironmentVariableError(err: AppError) {\n const missingVars = err?.missing || \"unknown environment variables\";\n const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;\n return new AppError(message, 500);\n}\n\nexport function handleFieldValueTooLargeError(err: AppError) {\n const message = `The value for the field \"${err?.meta?.field_name}\" is too large. Please provide a smaller value.`;\n return new AppError(message, 400);\n}\n\nexport function handleRecordNotFoundError(err: AppError) {\n const message =\n \"No record found for the given query. Ensure the query parameters are correct.\";\n return new AppError(message, 404);\n}\n\nexport function handleUniqueConstraintError(err: AppError) {\n const field = err?.meta?.target || \"unknown field\";\n const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;\n return new AppError(message, 409);\n}\n\nexport function handleForeignKeyConstraintError(err: AppError) {\n const message =\n \"Foreign key constraint violation. Ensure that the referenced record exists.\";\n return new AppError(message, 400);\n}\n\nexport function handleConstraintFailedError(err: AppError) {\n const constraint = err?.meta?.constraint || \"unknown constraint\";\n const message = `A database constraint \"${constraint}\" failed. Please review your input data.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldValueError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `Invalid value provided for the field \"${fieldName}\". Please provide a valid value.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldProvidedError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" has been provided with an invalid value. Check the data and try again.`;\n return new AppError(message, 400);\n}\n\nexport function handleDataValidationError(err: AppError) {\n const message =\n \"Data validation error occurred. Please ensure all fields meet the required criteria.\";\n return new AppError(message, 400);\n}\n\nexport function handleQueryParsingError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `Failed to parse the query: \"${query}\". Check the syntax and structure.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidQueryFormatError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `The query format is invalid: \"${query}\". Ensure the query adheres to the expected format.`;\n return new AppError(message, 400);\n}\n\nexport function handleRawQueryExecutionError(err: AppError) {\n const message =\n \"An error occurred during the execution of a raw query. Verify the query and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleNullConstraintViolationError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" cannot be null. Please provide a value.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaCreationFailedError(err: AppError) {\n const message =\n \"Failed to create the database schema. Verify the schema definition and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleMigrationAlreadyAppliedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration \"${migrationName}\" has already been applied to the database.`;\n return new AppError(message, 409);\n}\n\nexport function handleMigrationScriptFailedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration script \"${migrationName}\" failed. Review the script and resolve any issues.`;\n return new AppError(message, 500);\n}\n\nexport function handleVersionMismatchError(err: AppError) {\n const message = `Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.`;\n return new AppError(message, 400);\n}\n\nexport function handleMigrationFileReadError(err: AppError) {\n const migrationFile = err?.meta?.migration_file || \"unknown file\";\n const message = `Failed to read the migration file \"${migrationFile}\". Ensure the file exists and is accessible.`;\n return new AppError(message, 500);\n}\n\nexport function handleSchemaDriftError(err: AppError) {\n const message = `Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaSyntaxError(err: AppError) {\n const message = `Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.`;\n return new AppError(message, 500);\n}\n\nexport function handleClientTypeError(err: AppError) {\n const message = `Type error, Ensure proper usage of methods and correct data types.`;\n return new AppError(message, 400);\n}\n\nexport function handleDynamicQueryError(err: AppError) {\n const message = `Error constructing or executing a dynamic query. Verify query structure and parameters.`;\n return new AppError(message, 400);\n}\n\nexport function handleRelationLoadingError(err: AppError) {\n const relation = err?.meta?.relation || \"unknown relation\";\n const message = `Error loading relation \"${relation}\". Ensure it is correctly defined and included in the query.`;\n return new AppError(message, 400);\n}\n\nexport function handleBinaryError(err: AppError) {\n const binaryName = err?.meta?.binary || \"unknown binary\";\n const message = `Error with Prisma binary \"${binaryName}\". Ensure the binary is properly installed and compatible.`;\n return new AppError(message, 500);\n}\n\nexport function handleNetworkError(err: AppError) {\n const message = `Network error: Unable to connect to the database or internet. Please check your network connection.`;\n return new AppError(message, 500);\n}\n\nexport function handleUnhandledPromiseError(err: AppError) {\n const message = `Unhandled promise rejection detected. Please check asynchronous code for proper error handling.`;\n return new AppError(message, 500);\n}\n\nexport function handleDataTypeError(err: AppError) {\n const field = err?.meta?.field || \"unknown field\";\n const expectedType = err?.meta?.expected_type || \"unknown type\";\n const message = `Invalid data type for field \"${field}\". Expected type: ${expectedType}.`;\n return new AppError(message, 400);\n}\n\nexport function handleEmptyResultError(err: AppError) {\n const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;\n return new AppError(message, 404);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"error-handler.helpers.js","sourceRoot":"","sources":["../../../../../src/modules/error-handler/utils/error-handler.helpers.ts"],"names":[],"mappings":"AAAA,OA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AAC;AAED,MAAM,UAAU,mBAAmB,CAAC,GAAa;IAC/C,MAAM,KAAK,GAAG,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,eAAe,CAAC;IAClD,MAAM,YAAY,GAAG,GAAG,EAAE,IAAI,EAAE,aAAa,IAAI,cAAc,CAAC;IAChE,MAAM,OAAO,GAAG,gCAAgC,KAAK,qBAAqB,YAAY,GAAG,CAAC;IAC1F,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAa;IAClD,MAAM,OAAO,GAAG,6FAA6F,CAAC;IAC9G,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import AppError from \"./app-error\";\n\nexport interface PrismaError {\n code?: string; // Prisma-specific error code\n message: string; // Error message\n meta?: Record<string, any>; // Metadata provided by Prisma\n name?: string; // Error name\n}\n\nexport function handleJWTError() {\n return new AppError(\"Invalid token. Please log in again!\", 401);\n}\n\nexport function handleJWTExpired() {\n return new AppError(\"Your token has expired, Please log again!\", 401);\n}\n\nexport function handlePrismaClientValidationError(err: AppError) {\n const message = err?.message.split(\"\\n\")[err?.message.split(\"\\n\").length - 1];\n return new AppError(message, 400);\n}\n\nexport function handleAuthenticationError(err: AppError) {\n const message =\n \"Authentication failed against the database server. Please check your credentials.\";\n return new AppError(message, 401);\n}\n\nexport function handleServerNotReachableError(err: AppError) {\n const message =\n \"The database server is not reachable. Verify your connection string or ensure the server is online.\";\n return new AppError(message, 503);\n}\n\nexport function handleConnectionTimeoutError(err: AppError) {\n const message =\n \"Connection to the database timed out. Please check server performance or network connectivity.\";\n return new AppError(message, 504);\n}\n\nexport function handleDatabaseNotFoundError(err: AppError) {\n const message = \"The specified database does not exist on the server.\";\n return new AppError(message, 404);\n}\n\nexport function handleEnvironmentVariableError(err: AppError) {\n const missingVars = err?.missing || \"unknown environment variables\";\n const message = `Missing or invalid environment variables: ${missingVars}. Please check your configuration.`;\n return new AppError(message, 500);\n}\n\nexport function handleFieldValueTooLargeError(err: AppError) {\n const message = `The value for the field \"${err?.meta?.field_name}\" is too large. Please provide a smaller value.`;\n return new AppError(message, 400);\n}\n\nexport function handleRecordNotFoundError(err: AppError) {\n const message =\n \"No record found for the given query. Ensure the query parameters are correct.\";\n return new AppError(message, 404);\n}\n\nexport function handleUniqueConstraintError(err: AppError) {\n const field = err?.meta?.target || \"unknown field\";\n const message = `Duplicate value detected for the unique field(s): ${field}. Please use a different value.`;\n return new AppError(message, 409);\n}\n\nexport function handleForeignKeyConstraintError(err: AppError) {\n const message =\n \"Foreign key constraint violation. Ensure that the referenced record exists.\";\n return new AppError(message, 400);\n}\n\nexport function handleConstraintFailedError(err: AppError) {\n const constraint = err?.meta?.constraint || \"unknown constraint\";\n const message = `A database constraint \"${constraint}\" failed. Please review your input data.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldValueError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `Invalid value provided for the field \"${fieldName}\". Please provide a valid value.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidFieldProvidedError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" has been provided with an invalid value. Check the data and try again.`;\n return new AppError(message, 400);\n}\n\nexport function handleDataValidationError(err: AppError) {\n const message =\n \"Data validation error occurred. Please ensure all fields meet the required criteria.\";\n return new AppError(message, 400);\n}\n\nexport function handleQueryParsingError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `Failed to parse the query: \"${query}\". Check the syntax and structure.`;\n return new AppError(message, 400);\n}\n\nexport function handleInvalidQueryFormatError(err: AppError) {\n const query = err?.meta?.query || \"unknown query\";\n const message = `The query format is invalid: \"${query}\". Ensure the query adheres to the expected format.`;\n return new AppError(message, 400);\n}\n\nexport function handleRawQueryExecutionError(err: AppError) {\n const message =\n \"An error occurred during the execution of a raw query. Verify the query and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleNullConstraintViolationError(err: AppError) {\n const fieldName = err?.meta?.field_name || \"unknown field\";\n const message = `The field \"${fieldName}\" cannot be null. Please provide a value.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaCreationFailedError(err: AppError) {\n const message =\n \"Failed to create the database schema. Verify the schema definition and try again.\";\n return new AppError(message, 500);\n}\n\nexport function handleMigrationAlreadyAppliedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration \"${migrationName}\" has already been applied to the database.`;\n return new AppError(message, 409);\n}\n\nexport function handleMigrationScriptFailedError(err: AppError) {\n const migrationName = err?.meta?.migration || \"unknown migration\";\n const message = `The migration script \"${migrationName}\" failed. Review the script and resolve any issues.`;\n return new AppError(message, 500);\n}\n\nexport function handleVersionMismatchError(err: AppError) {\n const message = `Version mismatch: The database schema and migration versions are inconsistent. Please check and resolve this issue.`;\n return new AppError(message, 400);\n}\n\nexport function handleMigrationFileReadError(err: AppError) {\n const migrationFile = err?.meta?.migration_file || \"unknown file\";\n const message = `Failed to read the migration file \"${migrationFile}\". Ensure the file exists and is accessible.`;\n return new AppError(message, 500);\n}\n\nexport function handleSchemaDriftError(err: AppError) {\n const message = `Schema drift detected: The database schema differs from the expected state. Run migrations or sync schema to resolve.`;\n return new AppError(message, 400);\n}\n\nexport function handleSchemaSyntaxError(err: AppError) {\n const message = `Syntax error in the schema file. Please check for typos or invalid syntax in your schema definition.`;\n return new AppError(message, 500);\n}\n\nexport function handleClientTypeError(err: AppError) {\n const message = `Type error, Ensure proper usage of methods and correct data types.`;\n return new AppError(message, 400);\n}\n\nexport function handleDynamicQueryError(err: AppError) {\n const message = `Error constructing or executing a dynamic query. Verify query structure and parameters.`;\n return new AppError(message, 400);\n}\n\nexport function handleRelationLoadingError(err: AppError) {\n const relation = err?.meta?.relation || \"unknown relation\";\n const message = `Error loading relation \"${relation}\". Ensure it is correctly defined and included in the query.`;\n return new AppError(message, 400);\n}\n\nexport function handleBinaryError(err: AppError) {\n const binaryName = err?.meta?.binary || \"unknown binary\";\n const message = `Error with Prisma binary \"${binaryName}\". Ensure the binary is properly installed and compatible.`;\n return new AppError(message, 500);\n}\n\nexport function handleNetworkError(err: AppError) {\n const message = `Network error: Unable to connect to the database or internet. Please check your network connection.`;\n return new AppError(message, 500);\n}\n\nexport function handleUnhandledPromiseError(err: AppError) {\n const message = `Unhandled promise rejection detected. Please check asynchronous code for proper error handling.`;\n return new AppError(message, 500);\n}\n\nexport function handleDataTypeError(err: AppError) {\n const field = err?.meta?.field || \"unknown field\";\n const expectedType = err?.meta?.expected_type || \"unknown type\";\n const message = `Invalid data type for field \"${field}\". Expected type: ${expectedType}.`;\n return new AppError(message, 400);\n}\n\nexport function handleEmptyResultError(err: AppError) {\n const message = `Empty result: No data was found for the given query. Ensure the query criteria are correct.`;\n return new AppError(message, 404);\n}\n"]}
|
package/dist/es2020/server.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
"use strict";import{bootstrap as a}from"./app";import
|
|
1
|
+
"use strict";import{bootstrap as a}from"./app";import i from"./utils/helpers/deepmerge.helper";import p from"http";process.on("uncaughtException",o=>{console.error(`
|
|
2
2
|
UNCAUGHT EXCEPTION! SHUTTING DOWN...
|
|
3
|
-
`),console.error(
|
|
3
|
+
`),console.error(o.name,o.message),console.error(o),process.exit(1)});let r,t,e={welcomeMessage:"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com",port:Number(process.env.CLI_PORT)||Number(process.env.PORT)||8e3,host:process.env.CLI_HOST||process.env.HOST||"localhost",fileUpload:{baseUploadDir:"uploads",baseRoute:"/api/uploads"},available:!1};async function c(o={}){e.available=!0,e=i(e,o);const s=e.port;return t=await a(e),s&&(r=p.createServer(t),e?.configureServer&&await e.configureServer(r),r.listen(s,e.host,()=>{const n=new Date().toTimeString().split(" ")[0];console.info(`
|
|
4
|
+
[\x1B[32mREADY\x1B[0m] \x1B[90m${n}\x1B[0m server waiting on http://${e.host||"localhost"}:${s}`)})),t}process.on("unhandledRejection",o=>{console.error("UNHANDLED REJECTION! SHUTTING DOWN..."),console.error(o.name,o.message),console.error(o),r?.close(()=>{process.exit(1)})});export function terminateApplicationRunningProcessAndServer(){r?.close(()=>{process.exit(1)})}export function getArkosConfig(){return e}export function getExpressApp(){return t}export{r as server,c 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;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;IACtC,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC1D,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,GAA0C;IACxD,cAAc,EACZ,6FAA6F;IAC/F,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI;IACtE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,WAAW;IAC7D,UAAU,EAAE;QACV,aAAa,EAAE,SAAS;QACxB,SAAS,EAAE,cAAc;KAC1B;IACD,SAAS,EAAE,KAAK;CACjB,CAAC;AAeF,KAAK,UA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E;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,EAAE,KAAK,CAAC,GAAG,EAAE;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAOH,MAAM,UAAU,2CAA2C;IACzD,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;AAOD,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\";\nimport http from \"http\";\n\nprocess.on(\"uncaughtException\", (err) => {\n console.error(\"\\nUNCAUGHT EXCEPTION! SHUTTING DOWN...\\n\");\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 & { available?: boolean } = {\n welcomeMessage:\n \"Welcome to our RESTful API generated by Arkos, find out more about Arkos at www.arkosjs.com\",\n port: Number(process.env.CLI_PORT) || Number(process.env.PORT) || 8000,\n host: process.env.CLI_HOST || process.env.HOST || \"localhost\",\n fileUpload: {\n baseUploadDir: \"uploads\",\n baseRoute: \"/api/uploads\",\n },\n available: false,\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.available = true;\n _arkosConfig = deepmerge(_arkosConfig, arkosConfig);\n\n const port = _arkosConfig.port;\n _app = await bootstrap(_arkosConfig);\n\n if (port) {\n server = http.createServer(_app);\n\n if (_arkosConfig?.configureServer)\n await _arkosConfig.configureServer(server);\n\n server.listen(port, _arkosConfig.host!, () => {\n const time = new Date().toTimeString().split(\" \")[0];\n console.info(\n `\\n[\\x1b[32mREADY\\x1b[0m] \\x1b[90m${time}\\x1b[0m server waiting on http://${_arkosConfig.host || \"localhost\"}:${port}`\n );\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\n/**\n * Terminates the current running express application, server and process.\n *\n * @returns {void}\n */\nexport function terminateApplicationRunningProcessAndServer(): void {\n server?.close(() => {\n process.exit(1);\n });\n}\n\n/**\n * Gives access to the underlying current configurations being used by **Arkos** by default and also passed through `arkos.init()`\n *\n * @returns {ArkosConfig}\n */\nexport function getArkosConfig(): ArkosConfig {\n return _arkosConfig;\n}\n\nexport function getExpressApp() {\n return _app;\n}\n\nexport { server, initApp };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAwLA,MAAM,CAAN,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,yCAAiB,CAAA;IACjB,qCAAa,CAAA;IACb,yCAAiB,CAAA;IACjB,yCAAiB,CAAA;AACnB,CAAC,EALW,oBAAoB,KAApB,oBAAoB,QAK/B","sourcesContent":["import { NextFunction, Request, RequestHandler, Response } from \"express\";\n\nexport type PrismaOperations = \"findMany\";\n\n/**\n * Type definition for Prisma query operations with flexible options\n * @template T - The Prisma model delegate type\n */\nexport type PrismaQueryOptions<T extends Record<string, any>> = {\n /**\n * @deprecated Use `global` instead for general query options\n */\n queryOptions?: Partial<Parameters<T[\"findMany\"]>[0]>;\n\n /**\n * Global query options that can be used for all operations\n * Replaces the deprecated queryOptions\n */\n global?: Partial<Parameters<T[\"findMany\"]>[0]>;\n\n /**\n * General find options for findMany and findOne operations\n */\n find?: Partial<Parameters<T[\"findMany\"]>[0]>;\n\n /**\n * General create options for createOne and createMany operations\n */\n create?: Partial<Parameters<T[\"create\"]>[0]>;\n\n /**\n * General update options for updateOne and updateMany operations\n */\n update?: Partial<Parameters<T[\"update\"]>[0]>;\n\n /**\n * General delete options for deleteOne and deleteMany operations\n */\n delete?: Partial<Parameters<T[\"delete\"]>[0]>;\n\n /**\n * General save options for createOne, createMany, updateOne, updateMany operations\n */\n save?:\n | Partial<Parameters<T[\"create\"]>[0]>\n | Partial<Parameters<T[\"update\"]>[0]>;\n\n /**\n * Save options for single record operations (createOne, updateOne)\n */\n saveOne?:\n | Partial<Parameters<T[\"create\"]>[0]>\n | Partial<Parameters<T[\"update\"]>[0]>;\n\n /**\n * Save options for multiple record operations (createMany, updateMany)\n */\n saveMany?:\n | Partial<Parameters<T[\"createMany\"]>[0]>\n | Partial<Parameters<T[\"updateMany\"]>[0]>;\n\n /**\n * Options for finding a single record (first match)\n */\n findOne?: Partial<Parameters<T[\"findFirst\"]>[0]>;\n\n /**\n * Options for finding multiple records\n */\n findMany?: Partial<Parameters<T[\"findMany\"]>[0]>;\n\n /**\n * Options for creating a single record\n */\n createOne?: Partial<Parameters<T[\"create\"]>[0]>;\n\n /**\n * Options for creating multiple records\n */\n createMany?: Partial<Parameters<T[\"createMany\"]>[0]>;\n\n /**\n * Options for updating a single record\n */\n updateOne?: Partial<Parameters<T[\"update\"]>[0]>;\n\n /**\n * Options for updating multiple records\n */\n updateMany?: Partial<Parameters<T[\"updateMany\"]>[0]>;\n\n /**\n * Options for deleting a single record\n */\n deleteOne?: Partial<Parameters<T[\"delete\"]>[0]>;\n\n /**\n * Options for deleting multiple records\n */\n deleteMany?: Partial<Parameters<T[\"deleteMany\"]>[0]>;\n};\n\n/**\n * Type definition for authentication-related Prisma query operations\n * @template T - The Prisma model delegate type\n */\nexport type AuthPrismaQueryOptions<T extends Record<string, any>> = {\n // User profile endpoints\n /**\n * Options for retrieving the current authenticated user's profile\n */\n getMe?: Partial<Parameters<T[\"findUnique\"]>[0]>;\n\n /**\n * Options for updating the current authenticated user's profile\n */\n updateMe?: Partial<Parameters<T[\"update\"]>[0]>;\n\n /**\n * Options for soft deleting or deactivating the current authenticated user's account\n */\n deleteMe?: Partial<Parameters<T[\"update\"]>[0]>;\n\n // Authentication endpoints\n /**\n * Options for user login authentication queries\n */\n login?: Partial<Parameters<T[\"findFirst\"]>[0]>;\n\n /**\n * Options for user registration and account creation\n */\n signup?: Partial<Parameters<T[\"create\"]>[0]>;\n\n /**\n * Options for updating the current authenticated user's password\n */\n updatePassword?: Partial<Parameters<T[\"update\"]>[0]>;\n};\n\n/**\n * Interface defining the minimum structure required for Prisma model delegates\n * This allows us to constraint TModel without requiring Prisma imports\n */\nexport type PrismaModelDelegate = {\n create: (args: { data: never; [key: string]: never }) => Promise<any>;\n createMany: (args: { data: never; [key: string]: never }) => Promise<any>;\n findMany: (args: { [key: string]: never }) => Promise<any[]>;\n findFirst: (args: { where: never; [key: string]: never }) => Promise<any>;\n findUnique: (args: { where: never; [key: string]: never }) => Promise<any>;\n update: (args: {\n where: never;\n data: never;\n [key: string]: never;\n }) => Promise<any>;\n updateMany: (args: {\n where: never;\n data: never;\n [key: string]: never;\n }) => Promise<any>;\n delete: (args: { where: never; [key: string]: never }) => Promise<any>;\n deleteMany: (args: { where: never; [key: string]: never }) => Promise<any>;\n count: (args: { where: never; [key: string]: never }) => Promise<number>;\n};\n\nexport interface UserRole {\n id: string;\n createdAt: Date;\n deletedAt?: Date;\n roleId: string;\n role: AuthRole;\n user: User;\n userId: string;\n}\n\nexport interface AuthRole {\n id: string;\n createdAt: Date;\n deletedAt?: Date;\n name: string;\n permissions: AuthPermission[];\n userRoles: UserRole[];\n}\n\nexport enum AuthPermissionAction {\n Create = \"Create\",\n View = \"View\",\n Update = \"Update\",\n Delete = \"Delete\",\n}\n\nexport interface AuthPermission {\n id: string;\n createdAt: Date;\n deletedAt?: Date;\n resource: string;\n action: AuthPermissionAction;\n roleId: string;\n role: AuthRole;\n}\n\nexport interface User {\n id: string;\n isStaff: boolean;\n isSuperUser: boolean;\n password: string;\n passwordChangedAt?: Date;\n deletedSelfAccountAt: Date;\n isActive: boolean;\n roles?: UserRole[] | any[];\n role?: UserRole | any;\n}\n\nexport interface ArkosRequest<Body = any, Query = any> extends Request {\n user?: User & Record<string, any>;\n relationFields?: Record<string, boolean>;\n include?: Record<string, any>;\n responseData?: Record<string, any> | null | undefined;\n additionalData?: Record<string, any> | null | undefined;\n responseStatus?: number | string | null | undefined;\n body: Body;\n prismaQueryOptions?: Record<string, any>;\n // query: Query extends Request['ParsedQs'];\n}\n\nexport interface ArkosResponse extends Response {}\nexport interface ArkosNextFunction extends NextFunction {}\nexport interface ArkosRequestHandler extends RequestHandler {}\n"]}
|
|
@@ -1,51 +1,169 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
-
import {
|
|
2
|
+
import { watch } from "chokidar";
|
|
3
|
+
import { fullCleanCwd, getUserFileExtension } from "../helpers/fs.helpers";
|
|
3
4
|
import { getVersion } from ".";
|
|
4
5
|
import { loadEnvironmentVariables } from "../dotenv.helpers";
|
|
5
6
|
import { importModule } from "../helpers/global.helpers";
|
|
7
|
+
import fs from "fs";
|
|
8
|
+
let child = null;
|
|
9
|
+
let envFiles;
|
|
6
10
|
export async function devCommand(options = {}) {
|
|
7
11
|
process.env.NODE_ENV = "development";
|
|
8
|
-
|
|
12
|
+
envFiles = loadEnvironmentVariables();
|
|
13
|
+
child = null;
|
|
14
|
+
let restartTimeout = null;
|
|
9
15
|
try {
|
|
10
16
|
const { port, host } = options;
|
|
11
17
|
const fileExt = getUserFileExtension();
|
|
12
18
|
const entryPoint = `src/app.${fileExt}`;
|
|
13
|
-
if (!entryPoint) {
|
|
14
|
-
console.error("
|
|
19
|
+
if (!fs.existsSync(entryPoint)) {
|
|
20
|
+
console.error("Could not find application entry point.");
|
|
15
21
|
process.exit(1);
|
|
16
22
|
}
|
|
17
|
-
const
|
|
23
|
+
const getEnv = () => ({
|
|
18
24
|
NODE_ENV: "development",
|
|
19
25
|
...process.env,
|
|
20
26
|
...(port && { CLI_PORT: port }),
|
|
21
27
|
...(host && { CLI_HOST: host }),
|
|
28
|
+
});
|
|
29
|
+
const startServer = () => {
|
|
30
|
+
if (child) {
|
|
31
|
+
child.kill();
|
|
32
|
+
child = null;
|
|
33
|
+
}
|
|
34
|
+
const env = getEnv();
|
|
35
|
+
if (fileExt === "ts") {
|
|
36
|
+
child = spawn("npx", [
|
|
37
|
+
"ts-node-dev",
|
|
38
|
+
"--respawn",
|
|
39
|
+
"--notify=false",
|
|
40
|
+
"--ignore-watch",
|
|
41
|
+
"node_modules",
|
|
42
|
+
"--ignore-watch",
|
|
43
|
+
"dist",
|
|
44
|
+
"--ignore-watch",
|
|
45
|
+
"build",
|
|
46
|
+
"--ignore-watch",
|
|
47
|
+
".dist",
|
|
48
|
+
"--ignore-watch",
|
|
49
|
+
".build",
|
|
50
|
+
"--watch",
|
|
51
|
+
"src",
|
|
52
|
+
entryPoint,
|
|
53
|
+
], {
|
|
54
|
+
stdio: "inherit",
|
|
55
|
+
env,
|
|
56
|
+
shell: true,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
child = spawn("npx", [
|
|
61
|
+
"nodemon",
|
|
62
|
+
"--watch",
|
|
63
|
+
"src",
|
|
64
|
+
"--ext",
|
|
65
|
+
"js,json",
|
|
66
|
+
"--ignore",
|
|
67
|
+
"node_modules/",
|
|
68
|
+
"--ignore",
|
|
69
|
+
"dist/",
|
|
70
|
+
"--ignore",
|
|
71
|
+
"build/",
|
|
72
|
+
"--ignore",
|
|
73
|
+
".dist/",
|
|
74
|
+
"--ignore",
|
|
75
|
+
".build/",
|
|
76
|
+
"--delay",
|
|
77
|
+
"1000ms",
|
|
78
|
+
entryPoint,
|
|
79
|
+
], {
|
|
80
|
+
stdio: "inherit",
|
|
81
|
+
env,
|
|
82
|
+
shell: true,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (child) {
|
|
86
|
+
child.on("error", (error) => {
|
|
87
|
+
console.error("Failed to start server:", error);
|
|
88
|
+
});
|
|
89
|
+
child.on("exit", (code, signal) => {
|
|
90
|
+
if (signal !== "SIGTERM" && signal !== "SIGINT") {
|
|
91
|
+
console.info(`Server exited with code ${code}, restarting...`);
|
|
92
|
+
setTimeout(startServer, 1000);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const scheduleRestart = (reason) => {
|
|
98
|
+
if (restartTimeout)
|
|
99
|
+
clearTimeout(restartTimeout);
|
|
100
|
+
console.info(`\n${reason} `);
|
|
101
|
+
console.info("Restarting server...");
|
|
102
|
+
restartTimeout = setTimeout(() => {
|
|
103
|
+
startServer();
|
|
104
|
+
restartTimeout = null;
|
|
105
|
+
}, 1000);
|
|
22
106
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
107
|
+
const setupEnvWatcher = () => {
|
|
108
|
+
const envWatcher = watch(fullCleanCwd(envFiles?.join(",") || "")
|
|
109
|
+
.replaceAll("/", "")
|
|
110
|
+
.split(",") || [], {
|
|
111
|
+
ignoreInitial: true,
|
|
112
|
+
persistent: true,
|
|
29
113
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
114
|
+
envWatcher.on("all", (event, filePath) => {
|
|
115
|
+
try {
|
|
116
|
+
envFiles = loadEnvironmentVariables();
|
|
117
|
+
scheduleRestart("Environment file changed");
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.error(`Error reloading ${filePath}:`, error);
|
|
121
|
+
}
|
|
36
122
|
});
|
|
37
|
-
|
|
123
|
+
return envWatcher;
|
|
124
|
+
};
|
|
125
|
+
const setupAdditionalWatcher = () => {
|
|
126
|
+
const additionalWatcher = watch([
|
|
127
|
+
"src",
|
|
128
|
+
"package.json",
|
|
129
|
+
"tsconfig.json",
|
|
130
|
+
"arkos.config.ts",
|
|
131
|
+
"arkos.config.js",
|
|
132
|
+
], {
|
|
133
|
+
ignoreInitial: true,
|
|
134
|
+
ignored: [
|
|
135
|
+
/node_modules/,
|
|
136
|
+
/\.git/,
|
|
137
|
+
/\.dist/,
|
|
138
|
+
/\.build/,
|
|
139
|
+
/dist/,
|
|
140
|
+
/build/,
|
|
141
|
+
/\.env.*/,
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
additionalWatcher.on("add", (filePath) => {
|
|
145
|
+
scheduleRestart(`New file detected: ${fullCleanCwd(filePath)}`);
|
|
146
|
+
});
|
|
147
|
+
additionalWatcher.on("unlink", (filePath) => {
|
|
148
|
+
scheduleRestart(`File deleted: ${fullCleanCwd(filePath)}`);
|
|
149
|
+
});
|
|
150
|
+
return additionalWatcher;
|
|
151
|
+
};
|
|
152
|
+
startServer();
|
|
153
|
+
const envWatcher = setupEnvWatcher();
|
|
154
|
+
const additionalWatcher = setupAdditionalWatcher();
|
|
38
155
|
const checkConfig = async () => {
|
|
39
156
|
try {
|
|
40
157
|
const { getArkosConfig } = await importModule("../../server");
|
|
41
158
|
const config = getArkosConfig();
|
|
42
159
|
if (config && config.available) {
|
|
160
|
+
const env = getEnv();
|
|
43
161
|
console.info("\n");
|
|
44
162
|
console.info(` \x1b[1m\x1b[36m Arkos.js ${getVersion()}\x1b[0m`);
|
|
45
163
|
console.info(` - Local: http://${env.CLI_HOST || config.host || env.HOST || "localhost"}:${env.CLI_PORT || config.port || env.PORT || "8000"}`);
|
|
46
|
-
console.info(` - Environments: ${envFiles
|
|
47
|
-
|
|
48
|
-
.replaceAll(
|
|
164
|
+
console.info(` - Environments: ${fullCleanCwd(envFiles?.join(", ") || "")
|
|
165
|
+
.replaceAll(`${process.cwd()}/`, "")
|
|
166
|
+
.replaceAll("/", "")}`);
|
|
49
167
|
return true;
|
|
50
168
|
}
|
|
51
169
|
return false;
|
|
@@ -65,25 +183,53 @@ export async function devCommand(options = {}) {
|
|
|
65
183
|
attempts++;
|
|
66
184
|
}
|
|
67
185
|
if (attempts >= maxAttempts) {
|
|
186
|
+
const env = getEnv();
|
|
68
187
|
console.info("\n");
|
|
69
188
|
console.info(` \x1b[1m\x1b[36m Arkos.js ${getVersion()}\x1b[0m`);
|
|
70
189
|
console.info(` - Local: http://${env.CLI_HOST || env.HOST || "localhost"}:${env.CLI_PORT || env.PORT || "8000"}`);
|
|
71
|
-
console.info(` - Environments: ${envFiles
|
|
72
|
-
|
|
73
|
-
.replaceAll(
|
|
190
|
+
console.info(` - Environments: ${fullCleanCwd(envFiles?.join(", ") || "")
|
|
191
|
+
.replaceAll(`${process.cwd()}/`, "")
|
|
192
|
+
.replaceAll("/", "")}`);
|
|
74
193
|
}
|
|
75
194
|
};
|
|
76
195
|
waitForConfig();
|
|
77
|
-
|
|
196
|
+
const cleanup = () => {
|
|
197
|
+
console.info("\nShutting down development server...");
|
|
198
|
+
if (restartTimeout) {
|
|
199
|
+
clearTimeout(restartTimeout);
|
|
200
|
+
}
|
|
201
|
+
if (envWatcher)
|
|
202
|
+
envWatcher.close();
|
|
203
|
+
if (additionalWatcher)
|
|
204
|
+
additionalWatcher.close();
|
|
78
205
|
if (child) {
|
|
79
|
-
child.kill();
|
|
206
|
+
child.kill("SIGTERM");
|
|
207
|
+
setTimeout(() => {
|
|
208
|
+
if (child && !child.killed) {
|
|
209
|
+
child.kill("SIGKILL");
|
|
210
|
+
}
|
|
211
|
+
}, 5000);
|
|
80
212
|
}
|
|
81
213
|
process.exit(0);
|
|
214
|
+
};
|
|
215
|
+
process.on("SIGINT", cleanup);
|
|
216
|
+
process.on("SIGTERM", cleanup);
|
|
217
|
+
process.on("uncaughtException", (error) => {
|
|
218
|
+
console.error("Uncaught Exception:", error);
|
|
219
|
+
cleanup();
|
|
82
220
|
});
|
|
83
221
|
}
|
|
84
222
|
catch (error) {
|
|
85
|
-
console.error("
|
|
223
|
+
console.error("Development server failed to start:", error);
|
|
224
|
+
if (child) {
|
|
225
|
+
child?.kill?.();
|
|
226
|
+
child = null;
|
|
227
|
+
}
|
|
86
228
|
process.exit(1);
|
|
87
229
|
}
|
|
88
230
|
}
|
|
231
|
+
export function killDevelopmentServerChildProcess() {
|
|
232
|
+
child?.kill?.();
|
|
233
|
+
child = null;
|
|
234
|
+
}
|
|
89
235
|
//# 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;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAUzD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAAsB,EAAE;I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AC;gBACnB,OAAO,CAAC,IAAI,CAAC,+BAA+B,UAAU,EAAE,SAAS,CAAC,CAAC;gBACnE,OAAO,CAAC,IAAI,CACV,4BACE,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,WAC9B,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,MAAM,EAAE,CACzC,CAAC;gBACF,OAAO,CAAC,IAAI,CACV,qBAAqB,QAAQ;oBAC3B,EAAE,IAAI,CAAC,IAAI,CAAC;qBACX,UAAU,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAC3C,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QAEF,aAAa,EAAE,CAAC;QAahB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;YACxB,IAAI,KAAK,EAAE,CAAC;gBACV,KAAK,CAAC,IAAI,EAAE,CAAC;YACf,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC","sourcesContent":["// src/utils/cli/dev.ts\nimport { spawn } from \"child_process\";\nimport { getUserFileExtension } from \"../helpers/fs.helpers\";\nimport { getVersion } from \".\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { importModule } from \"../helpers/global.helpers\";\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 process.env.NODE_ENV = \"development\";\n\n const envFiles = loadEnvironmentVariables();\n\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: { [x: string]: string } = {\n NODE_ENV: \"development\",\n ...process.env,\n ...(port && { CLI_PORT: port }),\n ...(host && { CLI_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 const checkConfig = async () => {\n try {\n // Import the config getter\n\n const { getArkosConfig } = await importModule(\"../../server\");\n\n const config = getArkosConfig();\n\n if (config && config.available) {\n // Config is ready, display the info with actual values\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || config.host || env.HOST || \"localhost\"\n }:${env.CLI_PORT || config.port || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${envFiles\n ?.join(\", \")\n .replaceAll(`${process.cwd()}/`, \"\")}\\n`\n );\n return true;\n }\n return false;\n } catch (error) {\n return false;\n }\n };\n\n // Try to get config periodically\n const waitForConfig = async () => {\n let attempts = 0;\n const maxAttempts = 15;\n\n while (attempts < maxAttempts) {\n const ready = await checkConfig();\n if (ready) break;\n\n await new Promise((resolve) => setTimeout(resolve, 300));\n attempts++;\n }\n\n // Fall back to defaults if config never became available\n if (attempts >= maxAttempts) {\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || env.HOST || \"localhost\"\n }:${env.CLI_PORT || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${envFiles\n ?.join(\", \")\n .replaceAll(`${process.cwd()}/`, \"\")}\\n`\n );\n }\n };\n\n waitForConfig();\n\n // console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n // console.info(\n // ` - Local: http://${env.HOST || host}:${env.PORT || port}`\n // );\n // console.info(\n // ` - Environments: ${envFiles\n // ?.join(\", \")\n // .replaceAll(`${process.cwd()}/`, \"\")}\\n`\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
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../src/utils/cli/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgB,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,MAAM,IAAI,CAAC;AAOpB,IAAI,KAAK,GAAwB,IAAI,CAAC;AACtC,IAAI,QAA8B,CAAC;AAKnC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAAsB,EAAE;IACvD,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,aAAa,CAAC;IACrC,QAAQ,GAAG,wBAAwB,EAAE,CAAC;IACtC,KAAK,GAAG,IAAI,CAAC;IACb,IAAI,cAAc,GAA0B,IAAI,CAAC;IAEjD,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QAG/B,MAAM,OAAO,GAAG,oBAAoB,EAAE,CAAC;Q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AAC;YAEjD,IAAI,KAAK,EAAE,CAAC;gBACV,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAGtB,UAAU,CAAC,GAAG,EAAE;oBACd,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;wBAC3B,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;oBACxB,CAAC;gBACH,CAAC,EAAE,IAAI,CAAC,CAAC;YACX,CAAC;YAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QAGF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAG/B,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;YACxC,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;YAC5C,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAE5D,IAAI,KAAK,EAAE,CAAC;YACT,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;YAClC,KAAK,GAAG,IAAI,CAAC;QACf,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAKD,MAAM,UAAU,iCAAiC;IAC9C,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;IAClC,KAAK,GAAG,IAAI,CAAC;AACf,CAAC","sourcesContent":["import { spawn, ChildProcess } from \"child_process\";\nimport { watch } from \"chokidar\";\nimport { fullCleanCwd, getUserFileExtension } from \"../helpers/fs.helpers\";\nimport { getVersion } from \".\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { importModule } from \"../helpers/global.helpers\";\nimport fs from \"fs\";\n\ninterface DevOptions {\n port?: string;\n host?: string;\n}\n\nlet child: ChildProcess | null = null;\nlet envFiles: string[] | undefined;\n\n/**\n * Dev server command for the arkos CLI\n */\nexport async function devCommand(options: DevOptions = {}) {\n process.env.NODE_ENV = \"development\";\n envFiles = loadEnvironmentVariables();\n child = null;\n let restartTimeout: NodeJS.Timeout | null = null;\n\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 (!fs.existsSync(entryPoint)) {\n console.error(\"Could not find application entry point.\");\n process.exit(1);\n }\n\n // Set environment variables\n const getEnv = () =>\n ({\n NODE_ENV: \"development\",\n ...process.env,\n ...(port && { CLI_PORT: port }),\n ...(host && { CLI_HOST: host }),\n }) as { [x: string]: string };\n\n // Function to start the child process\n const startServer = () => {\n if (child) {\n child.kill();\n child = null;\n }\n\n const env = getEnv();\n\n if (fileExt === \"ts\") {\n // Enhanced ts-node-dev configuration\n child = spawn(\n \"npx\",\n [\n \"ts-node-dev\",\n \"--respawn\",\n \"--notify=false\", // Disable desktop notifications\n \"--ignore-watch\",\n \"node_modules\",\n \"--ignore-watch\",\n \"dist\",\n \"--ignore-watch\",\n \"build\",\n \"--ignore-watch\",\n \".dist\",\n \"--ignore-watch\",\n \".build\",\n \"--watch\",\n \"src\", // Explicitly watch src directory\n entryPoint,\n ],\n {\n stdio: \"inherit\",\n env,\n shell: true,\n }\n );\n } else {\n // Enhanced nodemon configuration\n child = spawn(\n \"npx\",\n [\n \"nodemon\",\n \"--watch\",\n \"src\",\n \"--ext\",\n \"js,json\",\n \"--ignore\",\n \"node_modules/\",\n \"--ignore\",\n \"dist/\",\n \"--ignore\",\n \"build/\",\n \"--ignore\",\n \".dist/\",\n \"--ignore\",\n \".build/\",\n \"--delay\",\n \"1000ms\",\n entryPoint,\n ],\n {\n stdio: \"inherit\",\n env,\n shell: true,\n }\n );\n }\n\n if (child) {\n child.on(\"error\", (error) => {\n console.error(\"Failed to start server:\", error);\n });\n\n child.on(\"exit\", (code, signal) => {\n if (signal !== \"SIGTERM\" && signal !== \"SIGINT\") {\n console.info(`Server exited with code ${code}, restarting...`);\n setTimeout(startServer, 1000);\n }\n });\n }\n };\n\n // Function to handle server restart with debouncing\n const scheduleRestart = (reason: string) => {\n if (restartTimeout) clearTimeout(restartTimeout);\n\n console.info(`\\n${reason} `);\n console.info(\"Restarting server...\");\n\n restartTimeout = setTimeout(() => {\n startServer();\n restartTimeout = null;\n }, 1000);\n };\n\n // Setup environment file watching\n const setupEnvWatcher = () => {\n const envWatcher = watch(\n fullCleanCwd(envFiles?.join(\",\") || \"\")\n .replaceAll(\"/\", \"\")\n .split(\",\") || [],\n {\n ignoreInitial: true,\n persistent: true,\n }\n );\n\n envWatcher.on(\"all\", (event, filePath) => {\n try {\n envFiles = loadEnvironmentVariables();\n\n // Restart server to pick up new env vars\n scheduleRestart(\"Environment file changed\");\n } catch (error) {\n console.error(`Error reloading ${filePath}:`, error);\n }\n });\n\n return envWatcher;\n };\n\n // Setup additional file watching for better new file detection\n const setupAdditionalWatcher = () => {\n const additionalWatcher = watch(\n [\n \"src\",\n \"package.json\",\n \"tsconfig.json\",\n \"arkos.config.ts\",\n \"arkos.config.js\",\n ],\n {\n ignoreInitial: true,\n ignored: [\n /node_modules/,\n /\\.git/,\n /\\.dist/,\n /\\.build/,\n /dist/,\n /build/,\n /\\.env.*/,\n ],\n }\n );\n\n additionalWatcher.on(\"add\", (filePath) => {\n scheduleRestart(`New file detected: ${fullCleanCwd(filePath)}`);\n });\n\n additionalWatcher.on(\"unlink\", (filePath) => {\n scheduleRestart(`File deleted: ${fullCleanCwd(filePath)}`);\n });\n\n return additionalWatcher;\n };\n\n // Start the server\n startServer();\n\n // Setup watchers if enabled\n const envWatcher = setupEnvWatcher();\n const additionalWatcher = setupAdditionalWatcher();\n\n const checkConfig = async () => {\n try {\n // Import the config getter\n const { getArkosConfig } = await importModule(\"../../server\");\n const config = getArkosConfig();\n if (config && config.available) {\n // Config is ready, display the info with actual values\n const env = getEnv();\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || config.host || env.HOST || \"localhost\"\n }:${env.CLI_PORT || config.port || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${fullCleanCwd(envFiles?.join(\", \") || \"\")\n .replaceAll(`${process.cwd()}/`, \"\")\n .replaceAll(\"/\", \"\")}`\n );\n return true;\n }\n return false;\n } catch (error) {\n return false;\n }\n };\n\n // Try to get config periodically\n const waitForConfig = async () => {\n let attempts = 0;\n const maxAttempts = 15;\n while (attempts < maxAttempts) {\n const ready = await checkConfig();\n if (ready) break;\n await new Promise((resolve) => setTimeout(resolve, 300));\n attempts++;\n }\n\n // Fall back to defaults if config never became available\n if (attempts >= maxAttempts) {\n const env = getEnv();\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || env.HOST || \"localhost\"\n }:${env.CLI_PORT || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${fullCleanCwd(envFiles?.join(\", \") || \"\")\n .replaceAll(`${process.cwd()}/`, \"\")\n .replaceAll(\"/\", \"\")}`\n );\n }\n };\n\n waitForConfig();\n\n // Enhanced cleanup function\n const cleanup = () => {\n console.info(\"\\nShutting down development server...\");\n\n if (restartTimeout) {\n clearTimeout(restartTimeout);\n }\n\n if (envWatcher) envWatcher.close();\n\n if (additionalWatcher) additionalWatcher.close();\n\n if (child) {\n child.kill(\"SIGTERM\");\n\n // Force kill after 5 seconds if still running\n setTimeout(() => {\n if (child && !child.killed) {\n child.kill(\"SIGKILL\");\n }\n }, 5000);\n }\n\n process.exit(0);\n };\n\n // Handle process exit\n process.on(\"SIGINT\", cleanup);\n process.on(\"SIGTERM\", cleanup);\n\n // Handle uncaught exceptions\n process.on(\"uncaughtException\", (error) => {\n console.error(\"Uncaught Exception:\", error);\n cleanup();\n });\n } catch (error) {\n console.error(\"Development server failed to start:\", error);\n\n if (child) {\n (child as ChildProcess)?.kill?.();\n child = null;\n }\n\n process.exit(1);\n }\n}\n\n/**\n * Help function to help other processes to terminate the development server child process\n */\nexport function killDevelopmentServerChildProcess() {\n (child as ChildProcess)?.kill?.();\n child = null;\n}\n"]}
|
|
@@ -6,8 +6,9 @@ import { devCommand } from "./dev";
|
|
|
6
6
|
import { startCommand } from "./start";
|
|
7
7
|
import { generateCommand } from "./generate";
|
|
8
8
|
export function getVersion() {
|
|
9
|
-
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../../../../package.json"), "utf8")
|
|
10
|
-
|
|
9
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "../../../../package.json"), "utf8") ||
|
|
10
|
+
"{}");
|
|
11
|
+
return packageJson?.version || "1.0.0";
|
|
11
12
|
}
|
|
12
13
|
const program = new Command();
|
|
13
14
|
program.name("arkos").description("Arkos.js CLI").version(getVersion());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/cli/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,UAAU,UAAU;IACxB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAC5B,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAA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e,EAAE,6BAA6B,EAAE,aAAa,CAAC;KACrE,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;AAEvC,QAAQ;KACL,OAAO,CAAC,eAAe,CAAC;KACxB,KAAK,CAAC,GAAG,CAAC;KACV,WAAW,CAAC,+BAA+B,CAAC;KAC5C,cAAc,CAAC,oBAAoB,EAAE,YAAY,CAAC;KAClD,MAAM,CAAC,mBAAmB,EAAE,+BAA+B,EAAE,aAAa,CAAC;KAC3E,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;AAExC,QAAQ;KACL,OAAO,CAAC,aAAa,CAAC;KACtB,KAAK,CAAC,GAAG,CAAC;KACV,WAAW,CAAC,gCAAgC,CAAC;KAC7C,cAAc,CAAC,oBAAoB,EAAE,iBAAiB,CAAC;KACvD,MAAM,CAAC,mBAAmB,EAAE,4BAA4B,EAAE,aAAa,CAAC;KACxE,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;AAEvC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC","sourcesContent":["// src/utils/cli/index.ts\nimport { Command } from \"commander\";\nimport { buildCommand } from \"./build\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { devCommand } from \"./dev\";\nimport { startCommand } from \"./start\";\nimport { generateCommand } from \"./generate\";\n\nexport function getVersion() {\n const packageJson = JSON.parse(\n fs.readFileSync(path.join(__dirname, \"../../../../package.json\"), \"utf8\") ||\n \"{}\"\n );\n\n return packageJson?.version || \"1.0.0\";\n}\n\nconst program = new Command();\n\nprogram.name(\"arkos\").description(\"Arkos.js CLI\").version(getVersion());\n\nprogram\n .command(\"build\")\n .description(\"Build your Arkos project\")\n .option(\"-m, --module <type>\", \"Module type (cjs or esm)\", \"cjs\")\n .action(buildCommand);\n\nprogram\n .command(\"dev\")\n .description(\"Run development server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(devCommand);\n\nprogram\n .command(\"start\")\n .description(\"Run production server\")\n .option(\"-p, --port <number>\", \"Port number\")\n .option(\"-h, --host <host>\", \"Host to bind to\")\n .action(startCommand);\n\n// Generate command with alias 'g'\nconst generate = program\n .command(\"generate\")\n .alias(\"g\")\n .description(\"Generate arkos components\");\n\ngenerate\n .command(\"controller\")\n .alias(\"c\")\n .description(\"Generate a new controller\")\n .requiredOption(\"-m, --model <name>\", \"Model name\")\n .option(\"-p, --path <path>\", \"Custom path for the controller\", \"src/modules\")\n .action(generateCommand.controller);\n\ngenerate\n .command(\"service\")\n .alias(\"s\")\n .description(\"Generate a new service\")\n .requiredOption(\"-m, --model <name>\", \"Model name\")\n .option(\"-p, --path <path>\", \"Custom path for the service\", \"src/modules\")\n .action(generateCommand.service);\n\ngenerate\n .command(\"router\")\n .alias(\"r\")\n .description(\"Generate a new router\")\n .requiredOption(\"-m, --model <name>\", \"Model name\")\n .option(\"-p, --path <path>\", \"Custom path for the router\", \"src/modules\")\n .action(generateCommand.router);\n\ngenerate\n .command(\"auth-configs\")\n .alias(\"a\")\n .description(\"Generate auth configuration\")\n .option(\"--path <path>\", \"Custom path for auth config\", \"src/modules\")\n .action(generateCommand.authConfigs);\n\ngenerate\n .command(\"query-options\")\n .alias(\"q\")\n .description(\"Generate prisma query options\")\n .requiredOption(\"-m, --model <name>\", \"Model name\")\n .option(\"-p, --path <path>\", \"Custom path for query options\", \"src/modules\")\n .action(generateCommand.queryOptions);\n\ngenerate\n .command(\"middlewares\")\n .alias(\"m\")\n .description(\"Generate a new middleware file\")\n .requiredOption(\"-m, --model <name>\", \"Middleware name\")\n .option(\"-p, --path <path>\", \"Custom path for middleware\", \"src/modules\")\n .action(generateCommand.middlewares);\n\nprogram.parse(process.argv);\n\nexport { program, buildCommand, devCommand, startCommand, generateCommand };\n"]}
|
|
@@ -4,9 +4,12 @@ import { spawn } from "child_process";
|
|
|
4
4
|
import { getVersion } from ".";
|
|
5
5
|
import { loadEnvironmentVariables } from "../dotenv.helpers";
|
|
6
6
|
import { importModule } from "../helpers/global.helpers";
|
|
7
|
+
import { fullCleanCwd } from "../helpers/fs.helpers";
|
|
8
|
+
let child = null;
|
|
9
|
+
let envFiles;
|
|
7
10
|
export async function startCommand(options = {}) {
|
|
8
11
|
process.env.NODE_ENV = "production";
|
|
9
|
-
|
|
12
|
+
envFiles = loadEnvironmentVariables();
|
|
10
13
|
try {
|
|
11
14
|
const { port, host } = options;
|
|
12
15
|
const entryPoint = path.join(".build", "src", "app.js");
|
|
@@ -21,7 +24,7 @@ export async function startCommand(options = {}) {
|
|
|
21
24
|
...(host && { CLI_HOST: host }),
|
|
22
25
|
ARKOS_BUILD: "true",
|
|
23
26
|
};
|
|
24
|
-
|
|
27
|
+
child = spawn("node", [entryPoint], {
|
|
25
28
|
stdio: "inherit",
|
|
26
29
|
env,
|
|
27
30
|
shell: true,
|
|
@@ -32,6 +35,7 @@ export async function startCommand(options = {}) {
|
|
|
32
35
|
}
|
|
33
36
|
process.exit(0);
|
|
34
37
|
});
|
|
38
|
+
console.log(envFiles);
|
|
35
39
|
const checkConfig = async () => {
|
|
36
40
|
try {
|
|
37
41
|
const { getArkosConfig } = await importModule("../../server");
|
|
@@ -40,12 +44,7 @@ export async function startCommand(options = {}) {
|
|
|
40
44
|
console.info("\n");
|
|
41
45
|
console.info(` \x1b[1m\x1b[36m Arkos.js ${getVersion()}\x1b[0m`);
|
|
42
46
|
console.info(` - Local: http://${env.CLI_HOST || config.host || env.HOST || "localhost"}:${env.CLI_PORT || config.port || env.PORT || "8000"}`);
|
|
43
|
-
console.info(` - Environments: ${envFiles
|
|
44
|
-
?.join(", ")
|
|
45
|
-
.replaceAll(`${process.cwd()}/`, "")
|
|
46
|
-
.replaceAll(`/${process.cwd()}`, "")
|
|
47
|
-
.replaceAll(`/${process.cwd()}/`, "")
|
|
48
|
-
.replaceAll(`${process.cwd()}`, "")}\n`);
|
|
47
|
+
console.info(` - Environments: ${fullCleanCwd(envFiles?.join(", ") || "").replaceAll("/", "")}\n`);
|
|
49
48
|
return true;
|
|
50
49
|
}
|
|
51
50
|
return false;
|
|
@@ -81,4 +80,8 @@ export async function startCommand(options = {}) {
|
|
|
81
80
|
process.exit(1);
|
|
82
81
|
}
|
|
83
82
|
}
|
|
83
|
+
export function killProductionServerChildProcess() {
|
|
84
|
+
child?.kill?.();
|
|
85
|
+
child = null;
|
|
86
|
+
}
|
|
84
87
|
//# 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,
|
|
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,EAAgB,KAAK,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAOrD,IAAI,KAAK,GAAwB,IAAI,CAAC;AACtC,IAAI,QAA8B,CAAC;AAKnC,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,UAAwB,EAAE;IAC3D,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,YAAY,CAAC;IACpC,QAAQ,GAAG,wBAAwB,EAAE,CAAC;IAEtC,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CA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AU,EAAE,SAAS,CAAC,CAAC;gBACnE,OAAO,CAAC,IAAI,CACV,4BACE,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,WAC9B,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,MAAM,EAAE,CACzC,CAAC;gBACF,OAAO,CAAC,IAAI,CACV,qBAAqB,QAAQ;oBAC3B,EAAE,IAAI,CAAC,IAAI,CAAC;qBACX,UAAU,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAC3C,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QAEF,aAAa,EAAE,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAKD,MAAM,UAAU,gCAAgC;IAC7C,KAAsB,EAAE,IAAI,EAAE,EAAE,CAAC;IAClC,KAAK,GAAG,IAAI,CAAC;AACf,CAAC","sourcesContent":["// src/utils/cli/start.ts\nimport path from \"path\";\nimport fs from \"fs\";\nimport { ChildProcess, spawn } from \"child_process\";\nimport { getVersion } from \".\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\nimport { importModule } from \"../helpers/global.helpers\";\nimport { fullCleanCwd } from \"../helpers/fs.helpers\";\n\ninterface StartOptions {\n port?: string;\n host?: string;\n}\n\nlet child: ChildProcess | null = null;\nlet envFiles: string[] | undefined;\n\n/**\n * Production start command for the arkos CLI\n */\nexport async function startCommand(options: StartOptions = {}) {\n process.env.NODE_ENV = \"production\";\n envFiles = loadEnvironmentVariables();\n\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: { [x: string]: string } = {\n ...process.env,\n NODE_ENV: \"production\",\n ...(port && { CLI_PORT: port }),\n ...(host && { CLI_HOST: host }),\n ARKOS_BUILD: \"true\",\n };\n\n // Start the application\n 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(envFiles);\n\n const checkConfig = async () => {\n try {\n const { getArkosConfig } = await importModule(\"../../server\");\n\n const config = getArkosConfig();\n\n if (config && config.available) {\n // Config is ready, display the info with actual values\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || config.host || env.HOST || \"localhost\"\n }:${env.CLI_PORT || config.port || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${fullCleanCwd(envFiles?.join(\", \") || \"\").replaceAll(\"/\", \"\")}\\n`\n );\n return true;\n }\n return false;\n } catch (error) {\n console.info(error);\n return false;\n }\n };\n\n // Try to get config periodically\n const waitForConfig = async () => {\n let attempts = 0;\n const maxAttempts = 15;\n\n while (attempts < maxAttempts) {\n const ready = await checkConfig();\n if (ready) break;\n\n await new Promise((resolve) => setTimeout(resolve, 300));\n attempts++;\n }\n\n // Fall back to defaults if config never became available\n if (attempts >= maxAttempts) {\n console.info(\"\\n\");\n console.info(` \\x1b[1m\\x1b[36m Arkos.js ${getVersion()}\\x1b[0m`);\n console.info(\n ` - Local: http://${\n env.CLI_HOST || env.HOST || \"localhost\"\n }:${env.CLI_PORT || env.PORT || \"8000\"}`\n );\n console.info(\n ` - Environments: ${envFiles\n ?.join(\", \")\n .replaceAll(`${process.cwd()}/`, \"\")}\\n`\n );\n }\n };\n\n waitForConfig();\n } catch (error) {\n console.error(\"❌ Production server failed to start:\", error);\n process.exit(1);\n }\n}\n\n/**\n * Help function to help other processes to terminate the production server child process\n */\nexport function killProductionServerChildProcess() {\n (child as ChildProcess)?.kill?.();\n child = null;\n}\n"]}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
+
import { killDevelopmentServerChildProcess } from "../dev";
|
|
3
|
+
import { killProductionServerChildProcess } from "../start";
|
|
2
4
|
export function ensureDirectoryExists(dirPath) {
|
|
3
5
|
if (!fs.existsSync(dirPath)) {
|
|
4
6
|
fs.mkdirSync(dirPath, { recursive: true });
|
|
5
7
|
}
|
|
6
8
|
}
|
|
9
|
+
export function killServerChildProcess() {
|
|
10
|
+
killDevelopmentServerChildProcess();
|
|
11
|
+
killProductionServerChildProcess();
|
|
12
|
+
}
|
|
7
13
|
//# sourceMappingURL=cli.helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.helpers.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/cli.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.helpers.js","sourceRoot":"","sources":["../../../../../src/utils/cli/utils/cli.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,iCAAiC,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAE5D,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,iCAAiC,EAAE,CAAC;IACpC,gCAAgC,EAAE,CAAC;AACrC,CAAC","sourcesContent":["import fs from \"fs\";\nimport { killDevelopmentServerChildProcess } from \"../dev\";\nimport { killProductionServerChildProcess } from \"../start\";\n\nexport function ensureDirectoryExists(dirPath: string): void {\n if (!fs.existsSync(dirPath)) {\n fs.mkdirSync(dirPath, { recursive: true });\n }\n}\n\nexport function killServerChildProcess() {\n killDevelopmentServerChildProcess();\n killProductionServerChildProcess();\n}\n"]}
|