arkos 1.1.10-beta → 1.1.12-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/app.js +1 -1
- package/dist/cjs/app.js.map +1 -1
- package/dist/cjs/exports/auth/index.js +1 -1
- package/dist/cjs/exports/auth/index.js.map +1 -1
- package/dist/cjs/exports/utils/index.js.map +1 -1
- package/dist/cjs/modules/auth/auth.controller.js.map +1 -1
- package/dist/cjs/modules/auth/auth.router.js +20 -20
- package/dist/cjs/modules/auth/auth.router.js.map +1 -1
- package/dist/cjs/modules/auth/auth.service.js +22 -21
- package/dist/cjs/modules/auth/auth.service.js.map +1 -1
- package/dist/cjs/modules/base/base.middlewares.js +5 -12
- package/dist/cjs/modules/base/base.middlewares.js.map +1 -1
- package/dist/cjs/modules/base/base.router.js +1 -1
- package/dist/cjs/modules/base/base.router.js.map +1 -1
- package/dist/cjs/modules/base/base.service.js +9 -7
- package/dist/cjs/modules/base/base.service.js.map +1 -1
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js +64 -22
- package/dist/cjs/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/cjs/modules/file-uploader/file-uploader.router.js +3 -3
- package/dist/cjs/modules/file-uploader/file-uploader.router.js.map +1 -1
- package/dist/cjs/types/arkos-config.js.map +1 -1
- package/dist/cjs/types/auth.js.map +1 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/utils/cli/build.js +93 -47
- package/dist/cjs/utils/cli/build.js.map +1 -1
- package/dist/cjs/utils/cli/dev.js +5 -3
- package/dist/cjs/utils/cli/dev.js.map +1 -1
- package/dist/cjs/utils/cli/index.js +4 -6
- package/dist/cjs/utils/cli/index.js.map +1 -1
- package/dist/cjs/utils/cli/start.js +5 -3
- package/dist/cjs/utils/cli/start.js.map +1 -1
- package/dist/cjs/utils/dotenv.helpers.js +43 -0
- package/dist/cjs/utils/dotenv.helpers.js.map +1 -0
- 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 +4 -0
- package/dist/cjs/utils/helpers/models.helpers.js.map +1 -1
- package/dist/cjs/utils/validate-dto.js +1 -1
- package/dist/cjs/utils/validate-dto.js.map +1 -1
- package/dist/cjs/utils/validate-schema.js +1 -1
- package/dist/cjs/utils/validate-schema.js.map +1 -1
- package/dist/es2020/app.js +1 -1
- package/dist/es2020/app.js.map +1 -1
- package/dist/es2020/exports/auth/index.js +1 -2
- package/dist/es2020/exports/auth/index.js.map +1 -1
- package/dist/es2020/exports/utils/index.js.map +1 -1
- package/dist/es2020/modules/auth/auth.controller.js.map +1 -1
- package/dist/es2020/modules/auth/auth.router.js +20 -20
- package/dist/es2020/modules/auth/auth.router.js.map +1 -1
- package/dist/es2020/modules/auth/auth.service.js +22 -21
- package/dist/es2020/modules/auth/auth.service.js.map +1 -1
- package/dist/es2020/modules/base/base.middlewares.js +5 -12
- package/dist/es2020/modules/base/base.middlewares.js.map +1 -1
- package/dist/es2020/modules/base/base.router.js +1 -1
- package/dist/es2020/modules/base/base.router.js.map +1 -1
- package/dist/es2020/modules/base/base.service.js +9 -7
- package/dist/es2020/modules/base/base.service.js.map +1 -1
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js +31 -22
- package/dist/es2020/modules/base/utils/helpers/base.router.helpers.js.map +1 -1
- package/dist/es2020/modules/file-uploader/file-uploader.router.js +3 -3
- package/dist/es2020/modules/file-uploader/file-uploader.router.js.map +1 -1
- package/dist/es2020/types/arkos-config.js.map +1 -1
- package/dist/es2020/types/auth.js.map +1 -1
- package/dist/es2020/types/index.js.map +1 -1
- package/dist/es2020/utils/cli/build.js +94 -48
- package/dist/es2020/utils/cli/build.js.map +1 -1
- package/dist/es2020/utils/cli/dev.js +5 -3
- package/dist/es2020/utils/cli/dev.js.map +1 -1
- package/dist/es2020/utils/cli/index.js +4 -6
- package/dist/es2020/utils/cli/index.js.map +1 -1
- package/dist/es2020/utils/cli/start.js +5 -3
- package/dist/es2020/utils/cli/start.js.map +1 -1
- package/dist/es2020/utils/dotenv.helpers.js +37 -0
- package/dist/es2020/utils/dotenv.helpers.js.map +1 -0
- 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 +4 -0
- package/dist/es2020/utils/helpers/models.helpers.js.map +1 -1
- package/dist/es2020/utils/validate-dto.js +1 -1
- package/dist/es2020/utils/validate-dto.js.map +1 -1
- package/dist/es2020/utils/validate-schema.js +1 -1
- package/dist/es2020/utils/validate-schema.js.map +1 -1
- package/dist/types/exports/auth/index.d.ts +2 -3
- package/dist/types/modules/auth/auth.service.d.ts +3 -3
- package/dist/types/modules/base/base.middlewares.d.ts +5 -5
- package/dist/types/modules/base/base.router.d.ts +1 -1
- package/dist/types/modules/base/utils/helpers/base.router.helpers.d.ts +2 -1
- package/dist/types/types/auth.d.ts +10 -9
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/utils/cli/build.d.ts +0 -1
- package/dist/types/utils/dotenv.helpers.d.ts +1 -0
- package/dist/types/utils/helpers/models.helpers.d.ts +21 -2
- package/dist/types/utils/validate-dto.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arkos-config.js","sourceRoot":"","sources":["../../../src/types/arkos-config.ts"],"names":[],"mappings":"","sourcesContent":["import cors from \"cors\";\nimport express from \"express\";\nimport { Options as RateLimitOptions } from \"express-rate-limit\";\nimport cookieParser from \"cookie-parser\";\nimport compression from \"compression\";\nimport { Options as QueryParserOptions } from \"../utils/helpers/query-parser.helpers\";\nimport { ValidatorOptions } from \"class-validator\";\nimport { MsDuration } from \"../modules/auth/utils/helpers/auth.controller.helpers\";\n\n/**\n * Defines the initial configs of the api to be loaded at startup when arkos.init() is called.\n */\nexport type ArkosConfig = {\n /**\n * Allows to configure request configs\n */\n request?: {\n /**\n * Allows to configure request parameters\n */\n parameters?: {\n /**\n * Toggles allowing `VERY DANGEROUS` request paramateres under `req.query` for pass prisma query options.\n *\n * See more\n */\n allowDangerousPrismaQueryOptions?: boolean;\n };\n };\n /** Message you would like to send, as Json and 200 response when\n * ```\n * GET /api\n * ```\n * ```json\n * { \"message\": \"Welcome to YourAppName\" }\n * ```\n *\n * default message is: Welcome to our Rest API generated by Arkos, find more about Arkos at www.arkosjs.com,\n *\n *\n * */\n welcomeMessage?: string;\n /**\n * Port where the application will run, can be set in 3 ways:\n *\n * 1. default is 8000\n * 2. PORT under environment variables (Lower precedence)\n * 3. this config option (Higher precedence)\n */\n port?: number | undefined;\n /**\n * Allows to listen on a different host than localhost only\n */\n host?: string;\n /**\n * Defines authentication related configurations, by default is undefined.\n *\n * See [www.arkosjs.com/docs/core-concepts/built-in-authentication-system](https://www.arkosjs.com/docs/core-concepts/built-in-authentication-system) for details.\n */\n authentication?: {\n /**\n * Defines whether to use Static or Dynamic Role-Based Acess Control\n *\n * Visit [www.arkosjs.com/docs/core-concepts/built-in-authentication-system](https://www.arkosjs.com/docs/core-concepts/built-in-authentication-system) for more details.\n */\n mode: \"static\" | \"dynamic\";\n /**\n * Defines auth login related configurations to customize the api.\n */\n login?: {\n /**\n * Defines the field that will be used as username by the built-in auth system, by default arkos will look for the field \"username\" in your model User, hence when making login for example you must send:\n *\n * ```json\n * {\n * \"username\": \"johndoe\",\n * \"password\": \"somePassword123\"\n * }\n * ```\n *\n * **Note:** You can also modify the usernameField on the fly by passing it to the request query parameters. example:\n *\n * ```curl\n * POST /api/auth/login?usernameField=email\n * ```\n *\n * See more at [www.arkosjs.com/docs/authentication-system/sending-authentication-requests#example-changing-the-username-field](https://www.arkosjs.com/docs/authentication-system/sending-authentication-requests#example-changing-the-username-field)\n *\n * By specifing here another field for username, for example passing \"email\", \"companyCode\" or something else your json will be like:\n *\n * **Example with email**\n *\n * ```json\n * {\n * \"email\": \"john.doe@example.com\",\n * \"password\": \"somePassword123\"\n * }\n * ```\n */\n allowedUsernames?: string[];\n /** Defines wether to send the access token in response after login or only send as cookie, defeault is both.*/\n sendAccessTokenThrough?: \"cookie-only\" | \"response-only\" | \"both\";\n };\n /**\n * @deprecated\n *\n * **Use this instead**:\n *\n * ```ts\n * arkos.init({\n * authentication: {\n * login: {\n * allowedUsernames: [\"email\", \"profile.nickname\"]\n * }\n * }\n * })\n * ```\n *\n * * See more at [www.arkosjs.com/docs/authentication-system/sending-authentication-requests#example-changing-the-username-field](https://www.arkosjs.com/docs/authentication-system/sending-authentication-requests#example-changing-the-username-field)\n *\n */\n usernameField?: string;\n /**\n * Specifies the regex pattern used by the authentication system to enforce password strength requirements.\n *\n * **Important**: If using validation libraries like Zod or class-validator, this will be completely overwritten.\n *\n * **Default**: ```/^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).+$/``` - Ensures the password contains at least one uppercase letter, one lowercase letter, and one numeric digit.\n *\n * **message**: (Optional) A custom error message to display when the password does not meet the required strength criteria.\n */\n passwordValidation?: { regex: RegExp; message?: string };\n /**\n * Allows to specify the request rate limit for all authentication endpoints but `/api/users/me`.\n * \n * #### Default\n *{\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n }\n * \n * Passing an object not overriding all the default options will only\n * cause it to be deepmerged and not actually replace with empty fields\n * \n * This is are the options used on the `express-rate-limit` npm package used on epxress. read more about [https://www.npmjs.com/package/express-rate-limit](https://www.npmjs.com/package/express-rate-limit)\n */\n requestRateLimitOptions?: RateLimitOptions;\n /**\n * JWT (JSON Web Token) authentication configuration.\n *\n * You can override these values directly in code, or use environment variables:\n *\n * - `JWT_SECRET`: Secret used to sign and verify JWT tokens.\n * - `JWT_EXPIRES_IN`: Duration string or number indicating when the token should expire (e.g. \"30d\", 3600).\n * - `JWT_COOKIE_SECURE`: Whether the cookie is sent only over HTTPS. Default: `true` in production.\n * - `JWT_COOKIE_HTTP_ONLY`: Whether the cookie is HTTP-only. Default: `true`.\n * - `JWT_COOKIE_SAME_SITE`: Can be \"lax\", \"strict\", or \"none\". Defaults to \"lax\" in dev, \"none\" in prod.\n *\n * ⚠️ Values passed here take precedence over environment variables.\n */\n jwt?: {\n /** Secret key used for signing and verifying JWT tokens */\n secret?: string;\n /**\n * Duration after which the JWT token expires.\n * Accepts either a duration string (e.g. \"30d\", \"1h\") or a number in milliseconds.\n * Defaults to \"30d\" if not provided.\n */\n expiresIn?: MsDuration | number;\n\n /**\n * Configuration for the JWT cookie sent to the client\n */\n cookie?: {\n /**\n * Whether the cookie should be marked as secure (sent only over HTTPS).\n * Defaults to `true` in production and `false` in development.\n */\n secure?: boolean;\n\n /**\n * Whether the cookie should be marked as HTTP-only.\n * Default is `true` to prevent access via JavaScript.\n */\n httpOnly?: boolean;\n\n /**\n * Controls the SameSite attribute of the cookie.\n * Defaults to \"none\" in production and \"lax\" in development.\n * Options: \"lax\" | \"strict\" | \"none\"\n */\n sameSite?: \"lax\" | \"strict\" | \"none\";\n };\n };\n };\n /** Allows to customize and toggle the built-in validation, by default it is set to `false`. If true is passed it will use validation with the default resolver set to `class-validator` if you intend to change the resolver to `zod` do the following:\n *\n *```ts\n * // src/app.ts\n * import arkos from 'arkos'\n *\n * arkos.init({\n * validation: {\n * resolver: \"zod\"\n * }\n * })\n * ```\n *\n * See [www.arkosjs.com/docs/core-concepts/request-data-validation](https://www.arkosjs.com/docs/core-concepts/request-data-validation) for more details.\n */\n validation?:\n | {\n resolver?: \"class-validator\";\n /**\n * ValidatorOptions to used while validating request data.\n *\n * **Default**:\n * ```ts\n * {\n * whitelist: true\n * }\n * ```\n */\n validationOptions?: ValidatorOptions;\n }\n | {\n resolver?: \"zod\";\n validationOptions?: Record<string, any>;\n };\n /**\n * Defines file upload configurations\n *\n * See [www.arkosjs.com/docs/core-concepts/file-upload#costum-configurations](https://www.arkosjs.com/docs/core-concepts/file-upload#costum-configurations)\n */\n fileUpload?: {\n /**\n * Defiens the base file upload directory, default is set to /uploads (on root directory)\n *\n * When setting up a path dir always now that root directory will be the starting reference.\n *\n * #### Example\n * passing `../my-arkos-uploaded-files`\n *\n * Will save uploaded files one level outside the root dir inside `my-arkos-uploaded-files`\n *\n * NB: You must be aware of permissions on your server to acess files outside your project directory.\n *\n */\n baseUploadDir?: string;\n /**\n * Changes the default `/api/uploads` base route for accessing file upload route.\n *\n * #### IMPORTANT\n * Changing this will not affect the `baseUploadDir` folder. You can\n * pass here `/api/files/my-user-files` and `baseUploadDir` be `/uploaded-files`.\n *\n */\n baseRoute?: string;\n /**\n * Defines options for `express.static(somePath, someOptions)`\n *\n * #### Default:\n *\n * ```ts\n *{\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n }\n * ```\n * \n * By passing your custom options have in mind that it\n * will be deepmerged with the default.\n * \n * Visit [https://expressjs.com/en/4x/api.html#express.static](https://expressjs.com/en/4x/api.html#express.static) for more understanding.\n * \n */\n expressStaticOptions?: Parameters<typeof express.static>[1];\n /**\n * Defines upload restrictions for each file type: image, video, document or other.\n *\n * #### Important:\n * Passing an object without overriding everything will only cause it\n * to be deepmerged with the default options.\n *\n * See [www.arkosjs.com/docs/api-reference/default-supported-upload-files](https://www.arkosjs.com/docs/api-reference/default-supported-upload-files) for detailed explanation about default values.\n * ```\n */\n restrictions?: {\n images?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n videos?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n documents?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n files?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n };\n };\n /**\n * Allows to specify the request rate limit for all endpoints.\n * \n * #### Default\n *```ts\n *{\n windowMs: 60 * 1000,\n limit: 1000,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n }\n ```\n * \n * Passing an object not overriding all the default options will only\n * cause it to be deepmerged and not actually replace with empty fields\n * \n * This is are the options used on the `express-rate-limit` npm package used on epxress. read more about [https://www.npmjs.com/package/express-rate-limit](https://www.npmjs.com/package/express-rate-limit)\n */\n globalRequestRateLimitOptions?: Partial<RateLimitOptions>;\n /**\n * Defines options for the built-in express.json() middleware\n * Nothing is passed by default.\n */\n jsonBodyParserOptions?: Parameters<typeof express.json>[0];\n /**\n * Allows to pass paremeters to cookieParser from npm package cookie-parser\n * Nothing is passed by default.\n *\n * See [www.npmjs.com/package/cookie-parser](https://www.npmjs.com/package/cookie-parser) for further details.\n */\n cookieParserParameters?: Parameters<typeof cookieParser>;\n /**\n * Allows to define options for npm package compression\n * Nothing is passed by default.\n *\n * See [www.npmjs.com/package/compression](https://www.npmjs.com/package/compression) for further details.\n */\n compressionOptions?: compression.CompressionOptions;\n /**\n * Options to define how query must be parsed.\n *\n * #### for example:\n * ```\n * GET /api/product?saleId=null\n * ```\n *\n * Normally would parsed to { saleId: \"null\" } so query parser\n * trough setting option `parseNull` will transform { saleId: null }\n * \n * #### Default:\n * \n * {\n parseNull: true,\n parseUndefined: true,\n parseBoolean: true,\n }\n * \n * parseNumber may convert fields that are string but you only passed\n * numbers to query pay attention to this.\n * \n * Soon a feature to converted the query to the end prisma type will be added.\n */\n queryParserOptions?: QueryParserOptions;\n /**\n * Configuration for CORS (Cross-Origin Resource Sharing).\n *\n * @property {string | string[] | \"all\"} [allowedOrigins] - List of allowed origins. If set to `\"all\"`, all origins are accepted.\n * @property {import('cors').CorsOptions} [options] - Additional CORS options passed directly to the `cors` middleware.\n * @property {import('cors').CorsOptionsDelegate} [customMiddleware] - A custom middleware function that overrides the default behavior.\n *\n * @remarks\n * If `customMiddleware` is provided, both `allowedOrigins` and `options` will be ignored in favor of the custom logic.\n *\n * See https://www.npmjs.com/package/cors\n */\n cors?: {\n allowedOrigins?: string | string[] | \"*\";\n options?: cors.CorsOptions;\n /**\n * If you would like to override the entire middleware\n *\n * see\n */\n customHandler?: cors.CorsOptionsDelegate;\n };\n /**\n * Defines express/arkos middlewares configurations\n */\n middlewares?: {\n /**\n * Allows to add an array of custom express middlewares into the default middleware stack.\n *\n * **Tip**: If you would like to acess the express app before everthing use `configureApp` and pass a function.\n *\n * **Where will these be placed?**: see [www.arkosjs.com/docs/advanced-guide/replace-or-disable-built-in-middlewares#middleware-execution-order](https://www.arkosjs.com/docs/advanced-guide/replace-or-disable-built-in-middlewares#middleware-execution-order)\n *\n * **Note**: If you want to use custom global error handler middleware use `middlewares.replace.globalErrorHandler`.\n *\n * Read more about The Arkos Middleware Stack at [www.arkosjs.com/docs/the-middleware-stack](https://www.arkosjs.com/docs/the-middleware-stack) for in-depth details.\n */\n additional?: express.RequestHandler[];\n /**\n * An array containing a list of defaults middlewares to be disabled\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n disable?: (\n | \"compression\"\n | \"global-rate-limit\"\n | \"auth-rate-limit\"\n | \"cors\"\n | \"express-json\"\n | \"cookie-parser\"\n | \"query-parser\"\n | \"database-connection\"\n | \"request-logger\"\n | \"global-error-handler\"\n )[];\n /**\n * Allows you to replace each of the built-in middlewares with your own implementation\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n replace?: {\n /**\n * Replace the default compression middleware\n */\n compression?: express.RequestHandler;\n /**\n * Replace the default global rate limit middleware\n */\n globalRateLimit?: express.RequestHandler;\n /**\n * Replace the default authentication rate limit middleware\n */\n authRateLimit?: express.RequestHandler;\n /**\n * Replace the default CORS middleware\n */\n cors?: express.RequestHandler;\n /**\n * Replace the default JSON body parser middleware\n */\n expressJson?: express.RequestHandler;\n /**\n * Replace the default cookie parser middleware\n */\n cookieParser?: express.RequestHandler;\n /**\n * Replace the default query parser middleware\n */\n queryParser?: express.RequestHandler;\n /**\n * Replace the default database connection check middleware\n */\n databaseConnection?: express.RequestHandler;\n /**\n * Replace the default request logger middleware\n */\n requestLogger?: express.RequestHandler;\n /**\n * Replace the default global error handler middleware\n */\n globalErrorHandler?: express.ErrorRequestHandler;\n };\n };\n /**\n * Defines express/arkos routers configurations\n */\n routers?: {\n /**\n * Allows to add an array of custom express routers into the default middleware/router stack.\n *\n * **Where will these be placed?**: see [www.arkosjs.com/docs/advanced-guide/adding-custom-routers](https://www.arkosjs.com/docs/advanced-guide/adding-custom-routers)\n *\n *\n * Read more about The Arkos Middleware Stack at [www.arkosjs.com/docs/the-middleware-stack](https://www.arkosjs.com/docs/the-middleware-stack) for in-depth details.\n */\n additional?: express.Router[];\n disable?: (\n | \"auth-router\"\n | \"prisma-models-router\"\n | \"file-uploader\"\n | \"welcome-endpoint\"\n )[];\n /**\n * Allows you to replace each of the built-in routers with your own implementation.\n *\n * **Note**: Doing this you will lose all default middleware chaining, auth control, handlers from the specific router.\n *\n * **Tip**: I you want to disable some prisma models specific endpoint\n * see [www.arkosjs.com/docs/advanced-guide/customizing-prisma-models-routers#disabling-endpoints](https://www.arkosjs.com/docs/advanced-guide/customizing-prisma-models-routers#disabling-endpoints)\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n replace?: {\n /**\n * Replace the default authentication router\n * @param config The original Arkos configuration\n * @returns A router handling authentication endpoints\n */\n authRouter?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default Prisma models router\n * @param config The original Arkos configuration\n * @returns A router handling Prisma model endpoints\n */\n prismaModelsRouter?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default file uploader router\n * @param config The original Arkos configuration\n * @returns A router handling file upload endpoints\n */\n fileUploader?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default welcome endpoint handler\n * @param req Express request object\n * @param res Express response object\n * @param next Express next function\n */\n welcomeEndpoint?: express.RequestHandler;\n };\n };\n /**\n * Gives acess to the underlying express app so that you can add custom configurations beyong **Arkos** customization capabilities\n *\n * **Note**: In the end **Arkos** will call `app.listen` for you.\n *\n * If you want to call `app.listen` by yourself pass port as `undefined` and then use the return app from `arkos.init()`.\n *\n * See how to call `app.listen` correctly [www.arkosjs.com/docs/accessing-the-express-app#calling-applisten-by-yourself](https://www.arkosjs.com/docs/accessing-the-express-app#calling-applisten-by-yourself)\n *\n * See [www.arkosjs.com/docs/accessing-the-express-app](https://www.arkosjs.com/docs/accessing-the-express-app) for further details on the method configureApp.\n *\n * @param {express.Express} app\n * @returns {any}\n */\n configureApp?: (app: express.Express) => Promise<any> | any;\n /**\n * Allows to configure email configurations for sending emails through `emailService`\n *\n * See [www.arkosjs.com/docs/core-concepts/sending-emails](https://www.arkosjs.com/docs/core-concepts/sending-emails)\n */\n email?: {\n /**\n * Your email provider url\n */\n host: string;\n /**\n * Email provider SMTP port, Default is `465`\n */\n port?: number;\n /**\n * If smtp connection must be secure, Default is `true`\n */\n secure?: boolean;\n /**\n * Used to authenticate in your smtp server\n */\n auth: {\n /**\n * Email used for auth as well as sending emails\n */\n user: string;\n /**\n * Your SMTP password\n */\n pass: string;\n };\n /**\n * Email name to used like:\n *\n * John Doe\\<john.doe@gmail.com>\n */\n name?: string;\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"arkos-config.js","sourceRoot":"","sources":["../../../src/types/arkos-config.ts"],"names":[],"mappings":"","sourcesContent":["import cors from \"cors\";\nimport express from \"express\";\nimport { Options as RateLimitOptions } from \"express-rate-limit\";\nimport cookieParser from \"cookie-parser\";\nimport compression from \"compression\";\nimport { Options as QueryParserOptions } from \"../utils/helpers/query-parser.helpers\";\nimport { ValidatorOptions } from \"class-validator\";\nimport { MsDuration } from \"../modules/auth/utils/helpers/auth.controller.helpers\";\n\n/**\n * Defines the initial configs of the api to be loaded at startup when arkos.init() is called.\n */\nexport type ArkosConfig = {\n /**\n * Allows to configure request configs\n */\n request?: {\n /**\n * Allows to configure request parameters\n */\n parameters?: {\n /**\n * Toggles allowing `VERY DANGEROUS` request paramateres under `req.query` for pass prisma query options.\n *\n * See more\n */\n allowDangerousPrismaQueryOptions?: boolean;\n };\n };\n /** Message you would like to send, as Json and 200 response when\n * ```\n * GET /api\n * ```\n * ```json\n * { \"message\": \"Welcome to YourAppName\" }\n * ```\n *\n * default message is: Welcome to our Rest API generated by Arkos, find more about Arkos at www.arkosjs.com,\n *\n *\n * */\n welcomeMessage?: string;\n /**\n * Port where the application will run, can be set in 3 ways:\n *\n * 1. default is 8000\n * 2. PORT under environment variables (Lower precedence)\n * 3. this config option (Higher precedence)\n */\n port?: number | undefined;\n /**\n * Allows to listen on a different host than localhost only\n */\n host?: string;\n /**\n * Defines authentication related configurations, by default is undefined.\n *\n * See [www.arkosjs.com/docs/core-concepts/built-in-authentication-system](https://www.arkosjs.com/docs/core-concepts/built-in-authentication-system) for details.\n */\n authentication?: {\n /**\n * Defines whether to use Static or Dynamic Role-Based Acess Control\n *\n * Visit [www.arkosjs.com/docs/core-concepts/built-in-authentication-system](https://www.arkosjs.com/docs/core-concepts/built-in-authentication-system) for more details.\n */\n mode: \"static\" | \"dynamic\";\n /**\n * Defines auth login related configurations to customize the api.\n */\n login?: {\n /**\n * Defines the field that will be used as username by the built-in auth system, by default arkos will look for the field \"username\" in your model User, hence when making login for example you must send:\n *\n * ```json\n * {\n * \"username\": \"johndoe\",\n * \"password\": \"somePassword123\"\n * }\n * ```\n *\n * **Note:** You can also modify the usernameField on the fly by passing it to the request query parameters. example:\n *\n * ```curl\n * POST /api/auth/login?usernameField=email\n * ```\n *\n * See more at [www.arkosjs.com/docs/guide/authentication-system/sending-authentication-requests#example-changing-the-username-field](https://www.arkosjs.com/docs/guide/authentication-system/sending-authentication-requests#example-changing-the-username-field)\n *\n * By specifing here another field for username, for example passing \"email\", \"companyCode\" or something else your json will be like:\n *\n * **Example with email**\n *\n * ```json\n * {\n * \"email\": \"john.doe@example.com\",\n * \"password\": \"somePassword123\"\n * }\n * ```\n */\n allowedUsernames?: string[];\n /** Defines wether to send the access token in response after login or only send as cookie, defeault is both.*/\n sendAccessTokenThrough?: \"cookie-only\" | \"response-only\" | \"both\";\n };\n /**\n * @deprecated\n *\n * **Use this instead**:\n *\n * ```ts\n * arkos.init({\n * authentication: {\n * login: {\n * allowedUsernames: [\"email\", \"profile.nickname\"]\n * }\n * }\n * })\n * ```\n *\n * * See more at [www.arkosjs.com/docs/guide/authentication-system/sending-authentication-requests#example-changing-the-username-field](https://www.arkosjs.com/docs/guide/authentication-system/sending-authentication-requests#example-changing-the-username-field)\n *\n */\n usernameField?: string;\n /**\n * Specifies the regex pattern used by the authentication system to enforce password strength requirements.\n *\n * **Important**: If using validation libraries like Zod or class-validator, this will be completely overwritten.\n *\n * **Default**: ```/^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).+$/``` - Ensures the password contains at least one uppercase letter, one lowercase letter, and one numeric digit.\n *\n * **message**: (Optional) A custom error message to display when the password does not meet the required strength criteria.\n */\n passwordValidation?: { regex: RegExp; message?: string };\n /**\n * Allows to specify the request rate limit for all authentication endpoints but `/api/users/me`.\n * \n * #### Default\n *{\n windowMs: 5000,\n limit: 10,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n }\n * \n * Passing an object not overriding all the default options will only\n * cause it to be deepmerged and not actually replace with empty fields\n * \n * This is are the options used on the `express-rate-limit` npm package used on epxress. read more about [https://www.npmjs.com/package/express-rate-limit](https://www.npmjs.com/package/express-rate-limit)\n */\n requestRateLimitOptions?: RateLimitOptions;\n /**\n * JWT (JSON Web Token) authentication configuration.\n *\n * You can override these values directly in code, or use environment variables:\n *\n * - `JWT_SECRET`: Secret used to sign and verify JWT tokens.\n * - `JWT_EXPIRES_IN`: Duration string or number indicating when the token should expire (e.g. \"30d\", 3600).\n * - `JWT_COOKIE_SECURE`: Whether the cookie is sent only over HTTPS. Default: `true` in production.\n * - `JWT_COOKIE_HTTP_ONLY`: Whether the cookie is HTTP-only. Default: `true`.\n * - `JWT_COOKIE_SAME_SITE`: Can be \"lax\", \"strict\", or \"none\". Defaults to \"lax\" in dev, \"none\" in prod.\n *\n * ⚠️ Values passed here take precedence over environment variables.\n */\n jwt?: {\n /** Secret key used for signing and verifying JWT tokens */\n secret?: string;\n /**\n * Duration after which the JWT token expires.\n * Accepts either a duration string (e.g. \"30d\", \"1h\") or a number in milliseconds.\n * Defaults to \"30d\" if not provided.\n */\n expiresIn?: MsDuration | number;\n\n /**\n * Configuration for the JWT cookie sent to the client\n */\n cookie?: {\n /**\n * Whether the cookie should be marked as secure (sent only over HTTPS).\n * Defaults to `true` in production and `false` in development.\n */\n secure?: boolean;\n\n /**\n * Whether the cookie should be marked as HTTP-only.\n * Default is `true` to prevent access via JavaScript.\n */\n httpOnly?: boolean;\n\n /**\n * Controls the SameSite attribute of the cookie.\n * Defaults to \"none\" in production and \"lax\" in development.\n * Options: \"lax\" | \"strict\" | \"none\"\n */\n sameSite?: \"lax\" | \"strict\" | \"none\";\n };\n };\n };\n /** Allows to customize and toggle the built-in validation, by default it is set to `false`. If true is passed it will use validation with the default resolver set to `class-validator` if you intend to change the resolver to `zod` do the following:\n *\n *```ts\n * // src/app.ts\n * import arkos from 'arkos'\n *\n * arkos.init({\n * validation: {\n * resolver: \"zod\"\n * }\n * })\n * ```\n *\n * See [www.arkosjs.com/docs/core-concepts/request-data-validation](https://www.arkosjs.com/docs/core-concepts/request-data-validation) for more details.\n */\n validation?:\n | {\n resolver?: \"class-validator\";\n /**\n * ValidatorOptions to used while validating request data.\n *\n * **Default**:\n * ```ts\n * {\n * whitelist: true\n * }\n * ```\n */\n validationOptions?: ValidatorOptions;\n }\n | {\n resolver?: \"zod\";\n validationOptions?: Record<string, any>;\n };\n /**\n * Defines file upload configurations\n *\n * See [www.arkosjs.com/docs/core-concepts/file-upload#costum-configurations](https://www.arkosjs.com/docs/core-concepts/file-upload#costum-configurations)\n */\n fileUpload?: {\n /**\n * Defiens the base file upload directory, default is set to /uploads (on root directory)\n *\n * When setting up a path dir always now that root directory will be the starting reference.\n *\n * #### Example\n * passing `../my-arkos-uploaded-files`\n *\n * Will save uploaded files one level outside the root dir inside `my-arkos-uploaded-files`\n *\n * NB: You must be aware of permissions on your server to acess files outside your project directory.\n *\n */\n baseUploadDir?: string;\n /**\n * Changes the default `/api/uploads` base route for accessing file upload route.\n *\n * #### IMPORTANT\n * Changing this will not affect the `baseUploadDir` folder. You can\n * pass here `/api/files/my-user-files` and `baseUploadDir` be `/uploaded-files`.\n *\n */\n baseRoute?: string;\n /**\n * Defines options for `express.static(somePath, someOptions)`\n *\n * #### Default:\n *\n * ```ts\n *{\n maxAge: \"1y\",\n etag: true,\n lastModified: true,\n dotfiles: \"ignore\",\n fallthrough: true,\n index: false,\n cacheControl: true,\n }\n * ```\n * \n * By passing your custom options have in mind that it\n * will be deepmerged with the default.\n * \n * Visit [https://expressjs.com/en/4x/api.html#express.static](https://expressjs.com/en/4x/api.html#express.static) for more understanding.\n * \n */\n expressStaticOptions?: Parameters<typeof express.static>[1];\n /**\n * Defines upload restrictions for each file type: image, video, document or other.\n *\n * #### Important:\n * Passing an object without overriding everything will only cause it\n * to be deepmerged with the default options.\n *\n * See [www.arkosjs.com/docs/api-reference/default-supported-upload-files](https://www.arkosjs.com/docs/api-reference/default-supported-upload-files) for detailed explanation about default values.\n * ```\n */\n restrictions?: {\n images?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n videos?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n documents?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n files?: {\n maxCount?: number;\n maxSize?: number;\n supportedFilesRegex?: RegExp;\n };\n };\n };\n /**\n * Allows to specify the request rate limit for all endpoints.\n * \n * #### Default\n *```ts\n *{\n windowMs: 60 * 1000,\n limit: 1000,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n }\n ```\n * \n * Passing an object not overriding all the default options will only\n * cause it to be deepmerged and not actually replace with empty fields\n * \n * This is are the options used on the `express-rate-limit` npm package used on epxress. read more about [https://www.npmjs.com/package/express-rate-limit](https://www.npmjs.com/package/express-rate-limit)\n */\n globalRequestRateLimitOptions?: Partial<RateLimitOptions>;\n /**\n * Defines options for the built-in express.json() middleware\n * Nothing is passed by default.\n */\n jsonBodyParserOptions?: Parameters<typeof express.json>[0];\n /**\n * Allows to pass paremeters to cookieParser from npm package cookie-parser\n * Nothing is passed by default.\n *\n * See [www.npmjs.com/package/cookie-parser](https://www.npmjs.com/package/cookie-parser) for further details.\n */\n cookieParserParameters?: Parameters<typeof cookieParser>;\n /**\n * Allows to define options for npm package compression\n * Nothing is passed by default.\n *\n * See [www.npmjs.com/package/compression](https://www.npmjs.com/package/compression) for further details.\n */\n compressionOptions?: compression.CompressionOptions;\n /**\n * Options to define how query must be parsed.\n *\n * #### for example:\n * ```\n * GET /api/product?saleId=null\n * ```\n *\n * Normally would parsed to { saleId: \"null\" } so query parser\n * trough setting option `parseNull` will transform { saleId: null }\n * \n * #### Default:\n * \n * {\n parseNull: true,\n parseUndefined: true,\n parseBoolean: true,\n }\n * \n * parseNumber may convert fields that are string but you only passed\n * numbers to query pay attention to this.\n * \n * Soon a feature to converted the query to the end prisma type will be added.\n */\n queryParserOptions?: QueryParserOptions;\n /**\n * Configuration for CORS (Cross-Origin Resource Sharing).\n *\n * @property {string | string[] | \"all\"} [allowedOrigins] - List of allowed origins. If set to `\"all\"`, all origins are accepted.\n * @property {import('cors').CorsOptions} [options] - Additional CORS options passed directly to the `cors` middleware.\n * @property {import('cors').CorsOptionsDelegate} [customMiddleware] - A custom middleware function that overrides the default behavior.\n *\n * @remarks\n * If `customMiddleware` is provided, both `allowedOrigins` and `options` will be ignored in favor of the custom logic.\n *\n * See https://www.npmjs.com/package/cors\n */\n cors?: {\n allowedOrigins?: string | string[] | \"*\";\n options?: cors.CorsOptions;\n /**\n * If you would like to override the entire middleware\n *\n * see\n */\n customHandler?: cors.CorsOptionsDelegate;\n };\n /**\n * Defines express/arkos middlewares configurations\n */\n middlewares?: {\n /**\n * Allows to add an array of custom express middlewares into the default middleware stack.\n *\n * **Tip**: If you would like to acess the express app before everthing use `configureApp` and pass a function.\n *\n * **Where will these be placed?**: see [www.arkosjs.com/docs/advanced-guide/replace-or-disable-built-in-middlewares#middleware-execution-order](https://www.arkosjs.com/docs/advanced-guide/replace-or-disable-built-in-middlewares#middleware-execution-order)\n *\n * **Note**: If you want to use custom global error handler middleware use `middlewares.replace.globalErrorHandler`.\n *\n * Read more about The Arkos Middleware Stack at [www.arkosjs.com/docs/the-middleware-stack](https://www.arkosjs.com/docs/the-middleware-stack) for in-depth details.\n */\n additional?: express.RequestHandler[];\n /**\n * An array containing a list of defaults middlewares to be disabled\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n disable?: (\n | \"compression\"\n | \"global-rate-limit\"\n | \"auth-rate-limit\"\n | \"cors\"\n | \"express-json\"\n | \"cookie-parser\"\n | \"query-parser\"\n | \"database-connection\"\n | \"request-logger\"\n | \"global-error-handler\"\n )[];\n /**\n * Allows you to replace each of the built-in middlewares with your own implementation\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n replace?: {\n /**\n * Replace the default compression middleware\n */\n compression?: express.RequestHandler;\n /**\n * Replace the default global rate limit middleware\n */\n globalRateLimit?: express.RequestHandler;\n /**\n * Replace the default authentication rate limit middleware\n */\n authRateLimit?: express.RequestHandler;\n /**\n * Replace the default CORS middleware\n */\n cors?: express.RequestHandler;\n /**\n * Replace the default JSON body parser middleware\n */\n expressJson?: express.RequestHandler;\n /**\n * Replace the default cookie parser middleware\n */\n cookieParser?: express.RequestHandler;\n /**\n * Replace the default query parser middleware\n */\n queryParser?: express.RequestHandler;\n /**\n * Replace the default database connection check middleware\n */\n databaseConnection?: express.RequestHandler;\n /**\n * Replace the default request logger middleware\n */\n requestLogger?: express.RequestHandler;\n /**\n * Replace the default global error handler middleware\n */\n globalErrorHandler?: express.ErrorRequestHandler;\n };\n };\n /**\n * Defines express/arkos routers configurations\n */\n routers?: {\n /**\n * Allows to add an array of custom express routers into the default middleware/router stack.\n *\n * **Where will these be placed?**: see [www.arkosjs.com/docs/advanced-guide/adding-custom-routers](https://www.arkosjs.com/docs/advanced-guide/adding-custom-routers)\n *\n *\n * Read more about The Arkos Middleware Stack at [www.arkosjs.com/docs/the-middleware-stack](https://www.arkosjs.com/docs/the-middleware-stack) for in-depth details.\n */\n additional?: express.Router[];\n disable?: (\n | \"auth-router\"\n | \"prisma-models-router\"\n | \"file-uploader\"\n | \"welcome-endpoint\"\n )[];\n /**\n * Allows you to replace each of the built-in routers with your own implementation.\n *\n * **Note**: Doing this you will lose all default middleware chaining, auth control, handlers from the specific router.\n *\n * **Tip**: I you want to disable some prisma models specific endpoint\n * see [www.arkosjs.com/docs/advanced-guide/customizing-prisma-models-routers#disabling-endpoints](https://www.arkosjs.com/docs/advanced-guide/customizing-prisma-models-routers#disabling-endpoints)\n *\n * **Caution**: Be careful with this because you may endup breaking your entire application.\n */\n replace?: {\n /**\n * Replace the default authentication router\n * @param config The original Arkos configuration\n * @returns A router handling authentication endpoints\n */\n authRouter?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default Prisma models router\n * @param config The original Arkos configuration\n * @returns A router handling Prisma model endpoints\n */\n prismaModelsRouter?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default file uploader router\n * @param config The original Arkos configuration\n * @returns A router handling file upload endpoints\n */\n fileUploader?: (\n config: ArkosConfig\n ) => express.Router | Promise<express.Router>;\n /**\n * Replace the default welcome endpoint handler\n * @param req Express request object\n * @param res Express response object\n * @param next Express next function\n */\n welcomeEndpoint?: express.RequestHandler;\n };\n };\n /**\n * Gives acess to the underlying express app so that you can add custom configurations beyong **Arkos** customization capabilities\n *\n * **Note**: In the end **Arkos** will call `app.listen` for you.\n *\n * If you want to call `app.listen` by yourself pass port as `undefined` and then use the return app from `arkos.init()`.\n *\n * See how to call `app.listen` correctly [www.arkosjs.com/docs/guide/accessing-the-express-app#calling-applisten-by-yourself](https://www.arkosjs.com/docs/guide/accessing-the-express-app#calling-applisten-by-yourself)\n *\n * See [www.arkosjs.com/docs/guide/accessing-the-express-app](https://www.arkosjs.com/docs/guide/accessing-the-express-app) for further details on the method configureApp.\n *\n * @param {express.Express} app\n * @returns {any}\n */\n configureApp?: (app: express.Express) => Promise<any> | any;\n /**\n * Allows to configure email configurations for sending emails through `emailService`\n *\n * See [www.arkosjs.com/docs/core-concepts/sending-emails](https://www.arkosjs.com/docs/core-concepts/sending-emails)\n */\n email?: {\n /**\n * Your email provider url\n */\n host: string;\n /**\n * Email provider SMTP port, Default is `465`\n */\n port?: number;\n /**\n * If smtp connection must be secure, Default is `true`\n */\n secure?: boolean;\n /**\n * Used to authenticate in your smtp server\n */\n auth: {\n /**\n * Email used for auth as well as sending emails\n */\n user: string;\n /**\n * Your SMTP password\n */\n pass: string;\n };\n /**\n * Email name to used like:\n *\n * John Doe\\<john.doe@gmail.com>\n */\n name?: string;\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/types/auth.ts"],"names":[],"mappings":"","sourcesContent":["import { JwtPayload } from \"jsonwebtoken\";\n\n/**\n * Base set of controller actions available to all controllers.\n
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/types/auth.ts"],"names":[],"mappings":"","sourcesContent":["import { JwtPayload } from \"jsonwebtoken\";\n\n/**\n * Base set of controller actions available to all controllers.\n *\n * @example\n * const action: AccessAction = \"Create\";\n * const customAction: AccessAction = \"export\"; // Custom action\n */\nexport type AccessAction = \"Create\" | \"Update\" | \"Delete\" | \"View\" | string;\n\n/**\n * Rules defining access control for different controller actions.\n * The array contains role names that are allowed to perform the action.\n *\n * @see {@link https://www.arkosjs.com/docs/advanced-guide/static-rbac-authentication#using-auth-config-to-customize-endpoint-behavior}\n * @example\n * const rules: AccessControlRules = {\n * Create: [\"Admin\", \"Manager\"],\n * Update: [\"Admin\"],\n * Delete: [\"Admin\"],\n * View: [\"Admin\", \"User\", \"Guest\"]\n * };\n */\nexport type AccessControlRules = {\n [key in AccessAction]: string[];\n};\n\n/**\n * Rules defining authentication requirements for different controller actions.\n *\n * @see {@link https://www.arkosjs.com/docs/advanced-guide/static-rbac-authentication#using-auth-config-to-customize-endpoint-behavior}\n * @example\n * const authRules: AuthenticationControlRules = {\n * Create: true,\n * Update: true,\n * Delete: true,\n * View: false // Public access\n * };\n */\nexport type AuthenticationControlRules = {\n [key in AccessAction]: boolean;\n};\n\n/**\n * Configuration for authentication control.\n *\n * @example\n * // All actions require authentication\n * const config1: AuthenticationControlConfig = true;\n *\n * // Specific rules per action\n * const config2: AuthenticationControlConfig = {\n * Create: true,\n * View: false\n * };\n */\nexport type AuthenticationControlConfig =\n | boolean\n | Partial<AuthenticationControlRules>;\n\n/**\n * Configuration for access control.\n *\n * @see {@link https://www.arkosjs.com/docs/core-concepts/built-in-authentication-system#1-static-rbac-config-based}\n * @example\n * // All actions allowed for these roles\n * const config1: AccessControlConfig = [\"Admin\", \"Manager\"];\n *\n * // Specific rules per action\n * const config2: AccessControlConfig = {\n * Create: [\"Admin\"],\n * View: [\"User\", \"Admin\"]\n * };\n */\nexport type AccessControlConfig = string[] | Partial<AccessControlRules>;\n\n/**\n * Configuration for authentication and access control.\n *\n * @see {@link https://www.arkosjs.com/docs/advanced-guide/static-rbac-authentication#using-auth-config-to-customize-endpoint-behavior}\n * @example\n * export const authConfig: AuthConfigs = {\n * authenticationControl: {\n * Create: true,\n * View: false\n * },\n * accessControl: {\n * Create: [\"Admin\"],\n * View: [\"User\", \"Admin\"]\n * }\n * };\n */\nexport type AuthConfigs = {\n authenticationControl?: AuthenticationControlConfig;\n accessControl?: AccessControlConfig;\n};\n\n/**\n * Payload structure for JWT-based authentication, extending the standard `JwtPayload`.\n *\n * @example\n * const payload: AuthJwtPayload = {\n * id: 123,\n * roles: [\"Admin\"],\n * email: \"user@example.com\"\n * };\n */\nexport interface AuthJwtPayload extends JwtPayload {\n id?: number | string;\n [x: string]: any;\n}\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":";;;AAmCA,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,yCAAiB,CAAA;IACjB,qCAAa,CAAA;IACb,yCAAiB,CAAA;IACjB,yCAAiB,CAAA;AACnB,CAAC,EALW,oBAAoB,oCAApB,oBAAoB,QAK/B","sourcesContent":["import { NextFunction, Request, RequestHandler, Response } from \"express\";\n\nexport type PrismaOperations = \"findMany\";\n\nexport type PrismaQueryOptions<T extends Record<string, any>> = {\n queryOptions?: Partial<Parameters<T[\"findMany\"]>[0]>;\n findOne?: Partial<Parameters<T[\"findFirst\"]>[0]>;\n findMany?: Partial<Parameters<T[\"findMany\"]>[0]>;\n deleteMany?: Partial<Parameters<T[\"deleteMany\"]>[0]>;\n updateMany?: Partial<Parameters<T[\"updateMany\"]>[0]>;\n createMany?: Partial<Parameters<T[\"createMany\"]>[0]>;\n createOne?: Partial<Parameters<T[\"create\"]>[0]>;\n updateOne?: Partial<Parameters<T[\"update\"]>[0]>;\n deleteOne?: Partial<Parameters<T[\"delete\"]>[0]>;\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 // query: Query extends Request['ParsedQs'];\n}\n\nexport interface ArkosResponse extends Response {}\nexport interface ArkosNextFunction extends NextFunction {}\nexport interface ArkosRequestHandler extends RequestHandler {}\n"]}
|
|
@@ -8,18 +8,22 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const child_process_1 = require("child_process");
|
|
10
10
|
const fs_helpers_1 = require("../helpers/fs.helpers");
|
|
11
|
-
const
|
|
11
|
+
const dotenv_helpers_1 = require("../dotenv.helpers");
|
|
12
|
+
const BUILD_DIR = "build";
|
|
12
13
|
const MODULE_TYPES = ["cjs", "esm"];
|
|
13
14
|
function buildCommand(options = {}) {
|
|
15
|
+
const envFiles = (0, dotenv_helpers_1.loadEnvironmentVariables)();
|
|
16
|
+
const moduleType = validateModuleType(options.module);
|
|
14
17
|
try {
|
|
15
|
-
console.info(
|
|
18
|
+
console.info(`🛠️ Using env variables from ${envFiles === null || envFiles === void 0 ? void 0 : envFiles.join(", ")}...`);
|
|
19
|
+
console.info(`🚀 Building an optimized production ready project with ${moduleType} format...\n`);
|
|
16
20
|
ensureBuildDir();
|
|
17
21
|
const fileExt = (0, fs_helpers_1.getUserFileExtension)();
|
|
18
22
|
if (fileExt === "ts") {
|
|
19
|
-
buildTypeScriptProject(options);
|
|
23
|
+
buildTypeScriptProject(options, moduleType);
|
|
20
24
|
}
|
|
21
25
|
else {
|
|
22
|
-
buildJavaScriptProject(options);
|
|
26
|
+
buildJavaScriptProject(options, moduleType);
|
|
23
27
|
}
|
|
24
28
|
console.info(`✅ Build complete! \n`);
|
|
25
29
|
console.info(`Next step:\n`);
|
|
@@ -54,7 +58,7 @@ function ensureBuildDir() {
|
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
|
-
function buildTypeScriptProject(options) {
|
|
61
|
+
function buildTypeScriptProject(options, moduleType) {
|
|
58
62
|
const tsconfigPath = path_1.default.join(process.cwd(), options.config || "tsconfig.json");
|
|
59
63
|
let tsconfig = {};
|
|
60
64
|
try {
|
|
@@ -66,42 +70,31 @@ function buildTypeScriptProject(options) {
|
|
|
66
70
|
catch (error) {
|
|
67
71
|
console.error("❌ Error reading tsconfig.json:", error);
|
|
68
72
|
}
|
|
69
|
-
const tempTsconfig = Object.assign(Object.assign({}, tsconfig), { compilerOptions: Object.assign(Object.assign({}, (tsconfig.compilerOptions || {})), { outDir: path_1.default.join(`./${BUILD_DIR}`) }) });
|
|
73
|
+
const tempTsconfig = Object.assign(Object.assign({}, tsconfig), { compilerOptions: Object.assign(Object.assign({}, (tsconfig.compilerOptions || {})), { outDir: path_1.default.join(`./${BUILD_DIR}/${moduleType}`), module: moduleType === "esm" ? "ESNext" : "CommonJS" }) });
|
|
70
74
|
const tempTsconfigPath = path_1.default.join(process.cwd(), `tsconfig.arkos-build.json`);
|
|
71
75
|
fs_1.default.writeFileSync(tempTsconfigPath, JSON.stringify(tempTsconfig, null, 2));
|
|
72
76
|
try {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
tsc.kill();
|
|
80
|
-
cleanupTempConfig(tempTsconfigPath);
|
|
81
|
-
process.exit(0);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
(0, child_process_1.execSync)(`npx tsc -p ${tempTsconfigPath}`, {
|
|
86
|
-
stdio: "inherit",
|
|
87
|
-
cwd: process.cwd(),
|
|
88
|
-
});
|
|
89
|
-
cleanupTempConfig(tempTsconfigPath);
|
|
90
|
-
}
|
|
77
|
+
(0, child_process_1.execSync)(`npx tsc -p ${tempTsconfigPath}`, {
|
|
78
|
+
stdio: "inherit",
|
|
79
|
+
cwd: process.cwd(),
|
|
80
|
+
});
|
|
81
|
+
copyAllNonSourceFiles(moduleType, [".ts", ".tsx"]);
|
|
82
|
+
cleanupTempConfig(tempTsconfigPath);
|
|
91
83
|
}
|
|
92
84
|
catch (error) {
|
|
93
85
|
cleanupTempConfig(tempTsconfigPath);
|
|
94
86
|
throw error;
|
|
95
87
|
}
|
|
96
88
|
}
|
|
97
|
-
function buildJavaScriptProject(options) {
|
|
98
|
-
const targetDir = path_1.default.join(BUILD_DIR);
|
|
89
|
+
function buildJavaScriptProject(options, moduleType) {
|
|
90
|
+
const targetDir = path_1.default.join(BUILD_DIR, moduleType);
|
|
99
91
|
try {
|
|
100
|
-
if (
|
|
101
|
-
(0, child_process_1.execSync)(`npx copyfiles -u 0 "src/**/*.js" "src/**/*.jsx" "src/**/*.mjs"
|
|
92
|
+
if (moduleType === "esm") {
|
|
93
|
+
(0, child_process_1.execSync)(`npx copyfiles -u 0 "src/**/*.js" "src/**/*.jsx" "src/**/*.mjs" ${targetDir}`, {
|
|
102
94
|
stdio: "inherit",
|
|
103
95
|
cwd: process.cwd(),
|
|
104
96
|
});
|
|
97
|
+
console.info("Note: .cjs files are skipped in ESM build");
|
|
105
98
|
}
|
|
106
99
|
else {
|
|
107
100
|
(0, child_process_1.execSync)(`npx copyfiles -u 0 "src/**/*.js" "src/**/*.jsx" "src/**/*.cjs" "src/**/*.mjs" ${targetDir}`, {
|
|
@@ -109,34 +102,87 @@ function buildJavaScriptProject(options) {
|
|
|
109
102
|
cwd: process.cwd(),
|
|
110
103
|
});
|
|
111
104
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
process.exit(0);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
105
|
+
copyAllNonSourceFiles(moduleType, [
|
|
106
|
+
".js",
|
|
107
|
+
".jsx",
|
|
108
|
+
".mjs",
|
|
109
|
+
".cjs",
|
|
110
|
+
".ts",
|
|
111
|
+
".tsx",
|
|
112
|
+
]);
|
|
113
|
+
createModulePackageJson(moduleType);
|
|
124
114
|
}
|
|
125
115
|
catch (error) {
|
|
126
116
|
console.error("❌ Error building JavaScript project:", error);
|
|
127
117
|
throw error;
|
|
128
118
|
}
|
|
129
119
|
}
|
|
130
|
-
function
|
|
131
|
-
const targetDir = path_1.default.join(BUILD_DIR);
|
|
120
|
+
function copyAllNonSourceFiles(moduleType, skipExtensions) {
|
|
121
|
+
const targetDir = path_1.default.join(BUILD_DIR, moduleType);
|
|
122
|
+
const sourceDir = "src";
|
|
132
123
|
try {
|
|
133
|
-
(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
124
|
+
function copyDirRecursive(dir) {
|
|
125
|
+
if (!fs_1.default.existsSync(dir))
|
|
126
|
+
return;
|
|
127
|
+
const items = fs_1.default.readdirSync(dir);
|
|
128
|
+
for (const item of items) {
|
|
129
|
+
const sourcePath = path_1.default.join(dir, item);
|
|
130
|
+
const targetPath = path_1.default.join(targetDir, dir.replace(sourceDir, ""), item);
|
|
131
|
+
const stats = fs_1.default.statSync(sourcePath);
|
|
132
|
+
if (stats.isDirectory()) {
|
|
133
|
+
if (!fs_1.default.existsSync(targetPath)) {
|
|
134
|
+
fs_1.default.mkdirSync(targetPath, { recursive: true });
|
|
135
|
+
}
|
|
136
|
+
copyDirRecursive(sourcePath);
|
|
137
|
+
}
|
|
138
|
+
else if (stats.isFile()) {
|
|
139
|
+
const ext = path_1.default.extname(item).toLowerCase();
|
|
140
|
+
if (!skipExtensions.includes(ext)) {
|
|
141
|
+
const targetDir = path_1.default.dirname(targetPath);
|
|
142
|
+
if (!fs_1.default.existsSync(targetDir)) {
|
|
143
|
+
fs_1.default.mkdirSync(targetDir, { recursive: true });
|
|
144
|
+
}
|
|
145
|
+
fs_1.default.copyFileSync(sourcePath, targetPath);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
copyDirRecursive(sourceDir);
|
|
151
|
+
const rootFilesToCopy = ["README.md", "LICENSE"];
|
|
152
|
+
for (const file of rootFilesToCopy) {
|
|
153
|
+
if (fs_1.default.existsSync(path_1.default.join(process.cwd(), file))) {
|
|
154
|
+
fs_1.default.copyFileSync(path_1.default.join(process.cwd(), file), path_1.default.join(targetDir, file));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
console.info(`📦 Copied all non-source files to ${targetDir}`);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.warn("Warning: Error copying project files:", error);
|
|
161
|
+
console.error(error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function createModulePackageJson(moduleType) {
|
|
165
|
+
const packageJsonPath = path_1.default.join(process.cwd(), "package.json");
|
|
166
|
+
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, "utf8"));
|
|
171
|
+
const buildPackageJson = {
|
|
172
|
+
name: packageJson.name,
|
|
173
|
+
version: packageJson.version,
|
|
174
|
+
description: packageJson.description,
|
|
175
|
+
main: "index.js",
|
|
176
|
+
dependencies: packageJson.dependencies,
|
|
177
|
+
};
|
|
178
|
+
if (moduleType === "esm") {
|
|
179
|
+
buildPackageJson.type = "module";
|
|
180
|
+
}
|
|
181
|
+
const targetDir = path_1.default.join(BUILD_DIR, moduleType);
|
|
182
|
+
fs_1.default.writeFileSync(path_1.default.join(targetDir, "package.json"), JSON.stringify(buildPackageJson, null, 2));
|
|
137
183
|
}
|
|
138
184
|
catch (error) {
|
|
139
|
-
console.warn("Warning:
|
|
185
|
+
console.warn("Warning: Failed to create module-specific package.json", error);
|
|
140
186
|
}
|
|
141
187
|
}
|
|
142
188
|
function cleanupTempConfig(configPath) {
|
|
@@ -1 +1 @@
|
|
|
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,CAAC;IAE9B,MAAM,cAAc,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC;IAGhD,IAAI,cAAc,KAAK,KAAK,IAAI,cAAc,KAAK,UAAU,EAAE,CAAC;QAC9D,OAAO,KAAK,CAAC;IACf,CAAC;SAAM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AAS,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
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../../src/utils/cli/build.ts"],"names":[],"mappings":";;;;;AAoBA,oCA4BC;AA/CD,gDAAwB;AACxB,4CAAoB;AACpB,iDAAyC;AACzC,sDAA6D;AAC7D,sDAA6D;AAG7D,MAAM,SAAS,GAAG,OAAO,CAAC;AAC1B,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU,CAAC;AAW7C,SAAgB,YAAY,CAAC,UAAwB,EAAE;IACrD,MAAM,QAAQ,GAAG,IAAA,yCAAwB,GAAE,CAAC;IAC5C,MAAM,UAAU,GAAG,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEtD,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,gCAAgC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CACV,0DAA0D,UAAU,cAAc,CACnF,CAAC;QAEF,cAAc,EAAE,CAAC;QAGjB,MAAM,OAAO,GAAG,IAAA,iCAAoB,GAAE,CAAC;QAEvC,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,sBAAsB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,sBAAsB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC9C,CAAC;Q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AAgB,GAAQ;YAC5B,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,OAAO,EAAE,WAAW,CAAC,OAAO;YAC5B,WAAW,EAAE,WAAW,CAAC,WAAW;YACpC,IAAI,EAAE,UAAU;YAChB,YAAY,EAAE,WAAW,CAAC,YAAY;SACvC,CAAC;QAGF,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;YACzB,gBAAgB,CAAC,IAAI,GAAG,QAAQ,CAAC;QACnC,CAAC;QAED,MAAM,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACnD,YAAE,CAAC,aAAa,CACd,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,EACpC,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,EAAE,CAAC,CAAC,CAC1C,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CACV,wDAAwD,EACxD,KAAK,CACN,CAAC;IACJ,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 } from \"child_process\";\nimport { getUserFileExtension } from \"../helpers/fs.helpers\";\nimport { loadEnvironmentVariables } from \"../dotenv.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 config?: string;\n module?: string;\n}\n\n/**\n * Main build function for the arkos CLI\n */\nexport function buildCommand(options: BuildOptions = {}) {\n const envFiles = loadEnvironmentVariables();\n const moduleType = validateModuleType(options.module);\n\n try {\n console.info(`🛠️ Using env variables from ${envFiles?.join(\", \")}...`);\n console.info(\n `🚀 Building an optimized production ready project with ${moduleType} format...\\n`\n );\n\n ensureBuildDir();\n\n // Detect project type\n const fileExt = getUserFileExtension();\n\n if (fileExt === \"ts\") {\n buildTypeScriptProject(options, moduleType);\n } else {\n buildJavaScriptProject(options, moduleType);\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, moduleType: ModuleType) {\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 with the correct module type\n const tempTsconfig = {\n ...tsconfig,\n compilerOptions: {\n ...(tsconfig.compilerOptions || {}),\n outDir: path.join(`./${BUILD_DIR}/${moduleType}`),\n module: moduleType === \"esm\" ? \"ESNext\" : \"CommonJS\",\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 execSync(`npx tsc -p ${tempTsconfigPath}`, {\n stdio: \"inherit\",\n cwd: process.cwd(),\n });\n\n // Copy non-TypeScript files\n copyAllNonSourceFiles(moduleType, [\".ts\", \".tsx\"]);\n\n // Clean up temp config\n cleanupTempConfig(tempTsconfigPath);\n } catch (error) {\n cleanupTempConfig(tempTsconfigPath);\n throw error;\n }\n}\n\n/**\n * Build a JavaScript project\n */\nfunction buildJavaScriptProject(options: BuildOptions, moduleType: ModuleType) {\n // Target directory\n const targetDir = path.join(BUILD_DIR, moduleType);\n\n try {\n // Copy JavaScript files based on module type\n if (moduleType === \"esm\") {\n // Copy JS files for ESM (skip .cjs files as they are CommonJS)\n execSync(\n `npx copyfiles -u 0 \"src/**/*.js\" \"src/**/*.jsx\" \"src/**/*.mjs\" ${targetDir}`,\n {\n stdio: \"inherit\",\n cwd: process.cwd(),\n }\n );\n\n // Note about CommonJS files\n console.info(\"Note: .cjs files are skipped in ESM build\");\n } else {\n // Copy all JS files for CommonJS\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 all non-JS files\n copyAllNonSourceFiles(moduleType, [\n \".js\",\n \".jsx\",\n \".mjs\",\n \".cjs\",\n \".ts\",\n \".tsx\",\n ]);\n\n // Create appropriate package.json in the build directory\n createModulePackageJson(moduleType);\n } catch (error) {\n console.error(\"❌ Error building JavaScript project:\", error);\n throw error;\n }\n}\n\n/**\n * Copy all non-source code files to the build directory\n * This function will copy everything except the specified source file extensions\n */\nfunction copyAllNonSourceFiles(\n moduleType: ModuleType,\n skipExtensions: string[]\n) {\n const targetDir = path.join(BUILD_DIR, moduleType);\n const sourceDir = \"src\";\n\n try {\n // Recursive function to copy files\n function copyDirRecursive(dir: string) {\n if (!fs.existsSync(dir)) return;\n\n const items = fs.readdirSync(dir);\n\n for (const item of items) {\n const sourcePath = path.join(dir, item);\n const targetPath = path.join(\n targetDir,\n dir.replace(sourceDir, \"\"),\n item\n );\n\n // Get file stats\n const stats = fs.statSync(sourcePath);\n\n if (stats.isDirectory()) {\n // Ensure target directory exists\n if (!fs.existsSync(targetPath)) {\n fs.mkdirSync(targetPath, { recursive: true });\n }\n // Recurse into subdirectory\n copyDirRecursive(sourcePath);\n } else if (stats.isFile()) {\n // Check if this is a file we should skip\n const ext = path.extname(item).toLowerCase();\n if (!skipExtensions.includes(ext)) {\n // Ensure the target directory exists\n const targetDir = path.dirname(targetPath);\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n // Copy the file\n fs.copyFileSync(sourcePath, targetPath);\n }\n }\n }\n }\n\n // Start copying from src directory\n copyDirRecursive(sourceDir);\n\n // Copy project root files if needed\n const rootFilesToCopy = [\"README.md\", \"LICENSE\"];\n\n for (const file of rootFilesToCopy) {\n if (fs.existsSync(path.join(process.cwd(), file))) {\n fs.copyFileSync(\n path.join(process.cwd(), file),\n path.join(targetDir, file)\n );\n }\n }\n\n console.info(`📦 Copied all non-source files to ${targetDir}`);\n } catch (error) {\n console.warn(\"Warning: Error copying project files:\", error);\n console.error(error);\n }\n}\n\n/**\n * Create appropriate package.json in the build directory\n */\nfunction createModulePackageJson(moduleType: ModuleType) {\n const packageJsonPath = path.join(process.cwd(), \"package.json\");\n\n if (!fs.existsSync(packageJsonPath)) {\n return;\n }\n\n try {\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf8\"));\n const buildPackageJson: any = {\n name: packageJson.name,\n version: packageJson.version,\n description: packageJson.description,\n main: \"index.js\",\n dependencies: packageJson.dependencies,\n };\n\n // Set appropriate type field for ESM\n if (moduleType === \"esm\") {\n buildPackageJson.type = \"module\";\n }\n\n const targetDir = path.join(BUILD_DIR, moduleType);\n fs.writeFileSync(\n path.join(targetDir, \"package.json\"),\n JSON.stringify(buildPackageJson, null, 2)\n );\n } catch (error) {\n console.warn(\n \"Warning: Failed to create module-specific package.json\",\n error\n );\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"]}
|
|
@@ -13,8 +13,10 @@ exports.devCommand = devCommand;
|
|
|
13
13
|
const child_process_1 = require("child_process");
|
|
14
14
|
const fs_helpers_1 = require("../helpers/fs.helpers");
|
|
15
15
|
const _1 = require(".");
|
|
16
|
+
const dotenv_helpers_1 = require("../dotenv.helpers");
|
|
16
17
|
function devCommand() {
|
|
17
18
|
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
19
|
+
const envFiles = (0, dotenv_helpers_1.loadEnvironmentVariables)();
|
|
18
20
|
try {
|
|
19
21
|
const { port, host } = options;
|
|
20
22
|
const fileExt = (0, fs_helpers_1.getUserFileExtension)();
|
|
@@ -23,7 +25,7 @@ function devCommand() {
|
|
|
23
25
|
console.error("❌ Could not find application entry point.");
|
|
24
26
|
process.exit(1);
|
|
25
27
|
}
|
|
26
|
-
const env = Object.assign(Object.assign(Object.assign({
|
|
28
|
+
const env = Object.assign(Object.assign(Object.assign({}, process.env), (port && { PORT: port })), (host && { HOST: host }));
|
|
27
29
|
let child;
|
|
28
30
|
if (fileExt === "ts") {
|
|
29
31
|
child = (0, child_process_1.spawn)("npx", ["ts-node-dev", "--respawn", entryPoint], {
|
|
@@ -40,8 +42,8 @@ function devCommand() {
|
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
44
|
console.info(` \x1b[1m\x1b[36m Arkos.js ${(0, _1.getVersion)()}\x1b[0m`);
|
|
43
|
-
console.info(` - Local: http://${host}:${port}`);
|
|
44
|
-
console.info(` - Environments:
|
|
45
|
+
console.info(` - Local: http://${env.HOST || host}:${env.PORT || port}`);
|
|
46
|
+
console.info(` - Environments: ${envFiles === null || envFiles === void 0 ? void 0 : envFiles.join(", ")}\n`);
|
|
45
47
|
process.on("SIGINT", () => {
|
|
46
48
|
if (child) {
|
|
47
49
|
child.kill();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../src/utils/cli/dev.ts"],"names":[],"mappings":";;;;;;;;;;;AAcA,
|
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../../src/utils/cli/dev.ts"],"names":[],"mappings":";;;;;;;;;;;AAcA,gCA6DC;AA1ED,iDAAsC;AACtC,sDAA6D;AAC7D,wBAA+B;AAC/B,sDAA6D;AAU7D,SAAsB,UAAU;yDAAC,UAAsB,EAAE;QACvD,MAAM,QAAQ,GAAG,IAAA,yCAAwB,GAAE,CAAC;QAE5C,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,I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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 { loadEnvironmentVariables } from \"../dotenv.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 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 = {\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(\n ` - Local: http://${env.HOST || host}:${env.PORT || port}`\n );\n console.info(` - Environments: ${envFiles?.join(\", \")}\\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"]}
|
|
@@ -24,21 +24,19 @@ program.name("arkos").description("Arkos framework CLI").version(getVersion());
|
|
|
24
24
|
program
|
|
25
25
|
.command("build")
|
|
26
26
|
.description("Build your Arkos project")
|
|
27
|
-
.option("-w, --watch", "Watch for changes")
|
|
28
|
-
.option("-c, --config <path>", "Path to config file")
|
|
29
27
|
.option("-m, --module <type>", "Module type (cjs or esm)", "cjs")
|
|
30
28
|
.action(build_1.buildCommand);
|
|
31
29
|
program
|
|
32
30
|
.command("dev")
|
|
33
31
|
.description("Run development server")
|
|
34
|
-
.option("-p, --port <number>", "Port number")
|
|
35
|
-
.option("-h, --host <host>", "Host to bind to")
|
|
32
|
+
.option("-p, --port <number>", "Port number", "8000")
|
|
33
|
+
.option("-h, --host <host>", "Host to bind to", "localhost")
|
|
36
34
|
.action(dev_1.devCommand);
|
|
37
35
|
program
|
|
38
36
|
.command("start")
|
|
39
37
|
.description("Run production server")
|
|
40
|
-
.option("-p, --port <number>", "Port number")
|
|
41
|
-
.option("-h, --host <host>", "Host to bind to")
|
|
38
|
+
.option("-p, --port <number>", "Port number", "8000")
|
|
39
|
+
.option("-h, --host <host>", "Host to bind to", "localhost")
|
|
42
40
|
.action(start_1.startCommand);
|
|
43
41
|
program.parse(process.argv);
|
|
44
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/cli/index.ts"],"names":[],"mappings":";;;;;;AAQA,gCAMC;AAbD,yCAAoC;AACpC,mCAAuC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/cli/index.ts"],"names":[],"mappings":";;;;;;AAQA,gCAMC;AAbD,yCAAoC;AACpC,mCAAuC;AAwCrB,6FAxCT,oBAAY,OAwCS;AAvC9B,gDAAwB;AACxB,4CAAoB;AACpB,+BAAmC;AAqCH,2FArCvB,gBAAU,OAqCuB;AApC1C,mCAAuC;AAoCK,6FApCnC,oBAAY,OAoCmC;AAlCxD,SAAgB,UAAU;IACxB,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAC5B,YAAE,CAAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,0BAA0B,CAAC,EAAE,MAAM,CAAC,CAC1E,CAAC;IAEF,OAAO,WAAW,CAAC,OAAO,IAAI,OAAO,CAAC;AACxC,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AA0BrB,0BAAO;AAxBhB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AAE/E,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,0BAA0B,CAAC;KACvC,MAAM,CAAC,qBAAqB,EAAE,0BAA0B,EAAE,KAAK,CAAC;KAChE,MAAM,CAAC,oBAAY,CAAC,CAAC;AAExB,OAAO;KACJ,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,wBAAwB,CAAC;KACrC,MAAM,CAAC,qBAAqB,EAAE,aAAa,EAAE,MAAM,CAAC;KACpD,MAAM,CAAC,mBAAmB,EAAE,iBAAiB,EAAE,WAAW,CAAC;KAC3D,MAAM,CAAC,gBAAU,CAAC,CAAC;AAEtB,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,uBAAuB,CAAC;KACpC,MAAM,CAAC,qBAAqB,EAAE,aAAa,EAAE,MAAM,CAAC;KACpD,MAAM,CAAC,mBAAmB,EAAE,iBAAiB,EAAE,WAAW,CAAC;KAC3D,MAAM,CAAC,oBAAY,CAAC,CAAC;AAExB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,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\";\n\nexport function getVersion() {\n const packageJson = JSON.parse(\n fs.readFileSync(path.join(__dirname, \"../../../../package.json\"), \"utf8\")\n );\n\n return packageJson.version || \"1.0.0\";\n}\n\nconst program = new Command();\n\nprogram.name(\"arkos\").description(\"Arkos framework 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\", \"8000\")\n .option(\"-h, --host <host>\", \"Host to bind to\", \"localhost\")\n .action(devCommand);\n\nprogram\n .command(\"start\")\n .description(\"Run production server\")\n .option(\"-p, --port <number>\", \"Port number\", \"8000\")\n .option(\"-h, --host <host>\", \"Host to bind to\", \"localhost\")\n .action(startCommand);\n\nprogram.parse(process.argv);\n\nexport { program, buildCommand, devCommand, startCommand };\n"]}
|
|
@@ -17,11 +17,13 @@ const path_1 = __importDefault(require("path"));
|
|
|
17
17
|
const fs_1 = __importDefault(require("fs"));
|
|
18
18
|
const child_process_1 = require("child_process");
|
|
19
19
|
const _1 = require(".");
|
|
20
|
+
const dotenv_helpers_1 = require("../dotenv.helpers");
|
|
20
21
|
function startCommand() {
|
|
21
22
|
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
23
|
+
const envFiles = (0, dotenv_helpers_1.loadEnvironmentVariables)();
|
|
22
24
|
try {
|
|
23
25
|
const { port, host } = options;
|
|
24
|
-
const entryPoint = path_1.default.join("
|
|
26
|
+
const entryPoint = path_1.default.join("build", "src", "app.js");
|
|
25
27
|
if (!fs_1.default.existsSync(path_1.default.join(process.cwd(), entryPoint))) {
|
|
26
28
|
console.error(`❌ Could not find built application entry point at ${entryPoint}`);
|
|
27
29
|
process.exit(1);
|
|
@@ -39,8 +41,8 @@ function startCommand() {
|
|
|
39
41
|
process.exit(0);
|
|
40
42
|
});
|
|
41
43
|
console.info(` \x1b[1m\x1b[36m Arkos.js ${(0, _1.getVersion)()}\x1b[0m`);
|
|
42
|
-
console.info(` - Local: http://${host}:${port}`);
|
|
43
|
-
console.info(` - Environments:
|
|
44
|
+
console.info(` - Local: http://${env.HOST || host}:${env.PORT || port}`);
|
|
45
|
+
console.info(` - Environments: ${envFiles === null || envFiles === void 0 ? void 0 : envFiles.join(", ")}\n`);
|
|
44
46
|
}
|
|
45
47
|
catch (error) {
|
|
46
48
|
console.error("❌ Production server failed to start:", error);
|
|
@@ -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":";;;;;;;;;;;;;;AAgBA,oCAmDC;AAlED,gDAAwB;AACxB,4CAAoB;AACpB,iDAAsC;AAEtC,wBAA+B;AAC/B,sDAA6D;AAU7D,SAAsB,YAAY;yDAAC,UAAwB,EAAE;QAC3D,MAAM,QAAQ,GAAG,IAAA,yCAAwB,GAAE,CAAC;QAE5C,IAAI,CAAC;YACH,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;YAG/B,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YAEvD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,cAAI,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,IAAA,qBAAK,EAAC,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,IAAA,aAAU,GAAE,SAAS,CAAC,CAAC;YACnE,OAAO,CAAC,IAAI,CACV,4BAA4B,GAAG,CAAC,IAAI,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,CACnE,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,qBAAqB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9D,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 \".\";\nimport { loadEnvironmentVariables } from \"../dotenv.helpers\";\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 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 = {\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(\n ` - Local: http://${env.HOST || host}:${env.PORT || port}`\n );\n console.info(` - Environments: ${envFiles?.join(\", \")}\\n`);\n } catch (error) {\n console.error(\"❌ Production server failed to start:\", error);\n process.exit(1);\n }\n}\n"]}
|