@xrystal/core 3.3.7 → 3.4.3

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.
Files changed (81) hide show
  1. package/bin/main-cli.js +71 -152
  2. package/package.json +11 -56
  3. package/source/project/index.d.ts +5 -6
  4. package/source/project/index.js +46 -77
  5. package/source/utils/constants/index.js +1 -1
  6. package/source/utils/models/classes/class.tmp-file-loader.d.ts +3 -6
  7. package/source/utils/models/classes/class.tmp-file-loader.js +23 -23
  8. package/x/dist/index.d.ts +2 -0
  9. package/x/dist/index.js +8 -0
  10. package/x/dist/loader/configs/index.d.ts +13 -0
  11. package/x/dist/loader/configs/index.js +17 -0
  12. package/x/dist/loader/events/index.d.ts +6 -0
  13. package/x/dist/loader/events/index.js +25 -0
  14. package/x/dist/loader/index.d.ts +6 -0
  15. package/x/dist/loader/index.js +6 -0
  16. package/x/dist/loader/localizations/index.d.ts +14 -0
  17. package/x/dist/loader/localizations/index.js +32 -0
  18. package/x/dist/loader/logger/index.d.ts +23 -0
  19. package/x/dist/loader/logger/index.js +126 -0
  20. package/x/dist/loader/system/index.d.ts +8 -0
  21. package/x/dist/loader/system/index.js +14 -0
  22. package/x/dist/project/index.d.ts +6 -0
  23. package/x/dist/project/index.js +63 -0
  24. package/x/dist/utils/constants/index.d.ts +8 -0
  25. package/x/dist/utils/constants/index.js +10 -0
  26. package/x/dist/utils/helpers/date/index.d.ts +16 -0
  27. package/x/dist/utils/helpers/date/index.js +48 -0
  28. package/x/dist/utils/helpers/filters/index.d.ts +17 -0
  29. package/x/dist/utils/helpers/filters/index.js +44 -0
  30. package/x/dist/utils/helpers/hash/crypto.d.ts +3 -0
  31. package/x/dist/utils/helpers/hash/crypto.js +22 -0
  32. package/x/dist/utils/helpers/id/index.d.ts +13 -0
  33. package/x/dist/utils/helpers/id/index.js +24 -0
  34. package/x/dist/utils/helpers/index.d.ts +16 -0
  35. package/x/dist/utils/helpers/index.js +16 -0
  36. package/x/dist/utils/helpers/ip/index.d.ts +1 -0
  37. package/x/dist/utils/helpers/ip/index.js +3 -0
  38. package/x/dist/utils/helpers/is/index.d.ts +11 -0
  39. package/x/dist/utils/helpers/is/index.js +35 -0
  40. package/x/dist/utils/helpers/locales/index.d.ts +52 -0
  41. package/x/dist/utils/helpers/locales/index.js +161 -0
  42. package/x/dist/utils/helpers/locales copy/index.d.ts +52 -0
  43. package/x/dist/utils/helpers/locales copy/index.js +161 -0
  44. package/x/dist/utils/helpers/math/index.d.ts +2 -0
  45. package/x/dist/utils/helpers/math/index.js +14 -0
  46. package/x/dist/utils/helpers/objects/index.d.ts +1 -0
  47. package/x/dist/utils/helpers/objects/index.js +55 -0
  48. package/x/dist/utils/helpers/path/index.d.ts +2 -0
  49. package/x/dist/utils/helpers/path/index.js +4 -0
  50. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.d.ts +1 -0
  51. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +3 -0
  52. package/x/dist/utils/helpers/string/index.d.ts +1 -0
  53. package/x/dist/utils/helpers/string/index.js +9 -0
  54. package/x/dist/utils/helpers/timer/index.d.ts +3 -0
  55. package/x/dist/utils/helpers/timer/index.js +5 -0
  56. package/x/dist/utils/helpers/tmp/index.d.ts +8 -0
  57. package/x/dist/utils/helpers/tmp/index.js +109 -0
  58. package/x/dist/utils/helpers/validates/index.d.ts +5 -0
  59. package/x/dist/utils/helpers/validates/index.js +20 -0
  60. package/x/dist/utils/index.d.ts +3 -0
  61. package/x/dist/utils/index.js +3 -0
  62. package/x/dist/utils/models/classes/class.controller.d.ts +121 -0
  63. package/x/dist/utils/models/classes/class.controller.js +421 -0
  64. package/x/dist/utils/models/classes/class.response.d.ts +17 -0
  65. package/x/dist/utils/models/classes/class.response.js +37 -0
  66. package/x/dist/utils/models/classes/class.services.d.ts +129 -0
  67. package/x/dist/utils/models/classes/class.services.js +344 -0
  68. package/x/dist/utils/models/classes/class.tmp-file-loader.d.ts +8 -0
  69. package/x/dist/utils/models/classes/class.tmp-file-loader.js +38 -0
  70. package/x/dist/utils/models/classes/class.x.d.ts +12 -0
  71. package/x/dist/utils/models/classes/class.x.js +16 -0
  72. package/x/dist/utils/models/enums/index.d.ts +117 -0
  73. package/x/dist/utils/models/enums/index.js +133 -0
  74. package/x/dist/utils/models/index.d.ts +8 -0
  75. package/x/dist/utils/models/index.js +8 -0
  76. package/x/dist/utils/models/types/index.d.ts +3 -0
  77. package/x/dist/utils/models/types/index.js +2 -0
  78. package/x/docker/Dockerfile +24 -0
  79. package/x/logs/critical/2025-11-30_critical.log +0 -0
  80. package/x/logs/error/2025-11-30_error.log +0 -0
  81. package/x/tmp.yml +0 -1
package/bin/main-cli.js CHANGED
@@ -1,179 +1,98 @@
1
1
  #!/usr/bin/env node
2
- import { execSync } from 'child_process'
3
- import fs from 'fs'
4
- import path from 'path'
5
- import yaml from 'yaml'
6
- import { Command } from 'commander'
7
- import chalk from 'chalk'
8
- import ora from 'ora'
9
2
 
10
- import { defaultOwnerTmpFilePath, defaultTmpFilePath, packageName, templateRepoUri, tmpFileDefaultExt, tmpFileDefaultMainFolderName, tmpFileDefaultName } from './constants/index.mjs'
11
- import { findFileRecursively, resolveObjWithHandlebars } from './helpers/index.mjs'
12
-
13
- let cli = null
14
-
15
- let ownerTmpFilePath = null
16
- let ownerTmpFile = null
17
-
18
- let parsedTmpObject = null
19
- let resolvedTmpObject = null
20
-
21
- let projectMainFolderPath = null
22
-
23
- try {
24
- cli = new Command()
3
+ import { execSync } from "node:child_process"
4
+ import fs from "node:fs"
5
+ import path from "node:path"
6
+ import { Command } from "commander"
7
+ import chalk from "chalk"
8
+ import ora from "ora"
9
+ import yaml from "yaml"
10
+
11
+ import {
12
+ defaultOwnerTmpFilePath,
13
+ defaultTmpFilePath,
14
+ packageName,
15
+ templateRepoUri,
16
+ tmpFileDefaultExt,
17
+ tmpFileDefaultMainFolderName,
18
+ tmpFileDefaultName
19
+ } from "./constants/index.mjs"
20
+ import { findFileRecursively, resolveObjWithHandlebars } from "./helpers/index.mjs"
21
+
22
+ const isBun = typeof Bun !== "undefined"
23
+ const packageManager = isBun ? "bun" : "npm"
24
+
25
+ const setupCLI = async () => {
26
+ const cli = new Command()
27
+
28
+ let ownerTmpFilePath = findFileRecursively(".", tmpFileDefaultName, tmpFileDefaultExt)
25
29
 
26
30
  try {
27
- ownerTmpFilePath = findFileRecursively('.', tmpFileDefaultName, tmpFileDefaultExt)
28
-
29
- if(!ownerTmpFilePath){
31
+ if (!ownerTmpFilePath) {
30
32
  const tmpFilePathBuffer = fs.readFileSync(defaultTmpFilePath)
31
-
32
- fs.mkdirSync(path.resolve(tmpFileDefaultMainFolderName), {recursive:true})
33
-
33
+ fs.mkdirSync(path.resolve(tmpFileDefaultMainFolderName), { recursive: true })
34
34
  fs.writeFileSync(defaultOwnerTmpFilePath, tmpFilePathBuffer)
35
-
36
35
  ownerTmpFilePath = defaultOwnerTmpFilePath
37
36
  }
38
37
 
39
- ownerTmpFile = fs.readFileSync(ownerTmpFilePath)
38
+ const ownerTmpFile = fs.readFileSync(ownerTmpFilePath, "utf8")
39
+ const parsedTmpObject = yaml.parse(ownerTmpFile)
40
+ const resolvedTmpObject = resolveObjWithHandlebars(parsedTmpObject, parsedTmpObject)
41
+ const projectMainFolderPath = path.resolve(resolvedTmpObject.configs.mainFolderPath)
40
42
 
41
- if(!ownerTmpFile){
42
- throw new Error(`${tmpFileDefaultName} File not read.`)
43
+ if (!fs.existsSync(projectMainFolderPath)) {
44
+ fs.mkdirSync(projectMainFolderPath, { recursive: true })
43
45
  }
44
46
 
45
- parsedTmpObject = yaml.parse(ownerTmpFile.toString())
46
-
47
- resolvedTmpObject = resolveObjWithHandlebars(parsedTmpObject, parsedTmpObject)
48
-
49
- projectMainFolderPath = path.resolve(resolvedTmpObject.configs.mainFolderPath)
50
-
51
- if(!fs.existsSync(path.resolve(projectMainFolderPath))){
52
- fs.mkdirSync(path.resolve(projectMainFolderPath))
53
- }
54
-
55
- } catch (error) {
56
- console.error(`${packageName} Error:`, error?.message)
57
- }
58
-
59
- cli
60
- .command('webpack')
61
- .action(function (pathOption, options) {
62
- if(resolvedTmpFile.configs.worker === 'development'){
63
- exec(
64
- `node --loader ts-node/esm node_modules/tmp-project-tool/node_modules/webpack-dev-server/bin/webpack-dev-server --config ${
65
- path.resolve(resolvedTmpFile.configs.webpack.location.worker[resolvedTmpFile.configs.worker])
66
- }`, {cwd: path.resolve()}, (error, stdout, stderr) => {
67
-
68
- if (error) {
69
- console.error(`error: ${error.message}`)
70
- return
71
- }
72
-
73
- if (stderr) {
74
- console.error(`stderr: ${stderr}`)
75
- return
76
- }
77
-
78
- console.log(`stdout: ${stdout}`)
79
- })
80
- }else{
81
- exec(
82
- `node --loader ts-node/esm node_modules/tmp-project-tool/node_modules/webpack-cli/bin/cli.js --config ${
83
- path.resolve(resolvedTmpFile.configs.webpack.location.worker[resolvedTmpFile.configs.worker])
84
- }`, {cwd: path.resolve()}, (error, stdout, stderr) => {
85
-
86
- if (error) {
87
- console.error(error, stderr)
88
- return
89
- }
47
+ cli
48
+ .command("create <project-name>")
49
+ .description("Clone template from GitHub (Private/Public)")
50
+ .action(async (projectName) => {
51
+ const targetPath = path.join(process.cwd(), projectName)
90
52
 
91
- if (stderr) {
92
- console.error(`stderr: ${stderr}`)
93
- return
53
+ if (fs.existsSync(targetPath)) {
54
+ console.log(chalk.red(`❌ Error: '${projectName}' folder already exists!`))
55
+ process.exit(1)
94
56
  }
95
57
 
96
- console.log(`stdout: ${stdout}`)
97
- })
98
- }
99
- })
100
-
101
- /*
102
- exec(`node --loader ts-node/esm ./${packagePathname}/src/index.ts ${options.config ? `--config ${options.config}` : ''}` , (error, stdout, stderr) => {
103
- if (error) {
104
- console.error(`error: ${error.message}`)
105
- return
106
- }
107
-
108
- if (stderr) {
109
- console.error(`stderr: ${stderr}`)
110
- return
111
- }
112
-
113
- console.log(`stdout: ${stdout}`)
114
- })
115
- */
116
-
117
- cli
118
- .command('create <project-name>')
119
- .description('Clone template from GitHub (Private/Public)')
120
- .action(async (projectName) => {
121
- const targetPath = path.join(process.cwd(), projectName)
122
-
123
- // 1. Klasör Kontrolü
124
- if (fs.existsSync(targetPath)) {
125
- console.log(chalk.red(`❌ Error: '${projectName}' folder already exists!`))
126
- process.exit(1)
127
- }
128
-
129
- const repoURL = templateRepoUri
58
+ const spinner = ora("Cloning template from GitHub...").start()
130
59
 
131
- const spinner = ora('Cloning template from GitHub...').start()
60
+ try {
61
+ execSync(`git clone --depth 1 ${templateRepoUri} "${targetPath}"`, { stdio: "ignore" })
132
62
 
133
- try {
134
- execSync(`git clone --depth 1 ${repoURL} "${targetPath}"`, {
135
- stdio: 'ignore'
136
- })
63
+ const gitFolder = path.join(targetPath, ".git")
64
+ if (fs.existsSync(gitFolder)) {
65
+ fs.rmSync(gitFolder, { recursive: true, force: true })
66
+ }
137
67
 
138
- const gitFolder = path.join(targetPath, '.git')
139
- if (fs.existsSync(gitFolder)) {
140
- fs.rmSync(gitFolder, { recursive: true, force: true })
141
- }
68
+ spinner.succeed(chalk.green("Template cloned successfully!"))
69
+ console.log(chalk.blue(`\n📦 Dependencies loading with ${packageManager}... (${projectName})`))
142
70
 
143
- spinner.succeed(chalk.green('Template cloned successfully!'))
71
+ const installCmd = isBun ? "bun install" : "npm install"
72
+ execSync(installCmd, { cwd: targetPath, stdio: "inherit" })
144
73
 
145
- console.log(chalk.blue(`\n📦 Dependencies loading... (${projectName})`))
74
+ console.log(chalk.green("\n Project Ready!"))
75
+ console.log(chalk.white(`\nStart Project:\n`))
76
+ console.log(chalk.cyan(` cd ${projectName}`))
77
+ console.log(chalk.cyan(` ${packageManager} run dev`))
146
78
 
147
- execSync('npm install', {
148
- cwd: targetPath,
149
- stdio: 'inherit'
79
+ } catch (err) {
80
+ spinner.fail(chalk.red("Failed to clone or install!"))
81
+ console.error(chalk.red(`\nError details: ${err.message}`))
82
+ if (fs.existsSync(targetPath)) fs.rmSync(targetPath, { recursive: true, force: true })
83
+ }
150
84
  })
151
85
 
152
- console.log(chalk.green('\n✅ Project Ready!'))
153
- console.log(chalk.white(`\nStart Project:\n`))
154
- console.log(chalk.cyan(` cd ${projectName}`))
155
- console.log(chalk.cyan(` npm run dev`))
156
-
157
- } catch (err) {
158
- spinner.fail(chalk.red('Failed to clone or install!'))
86
+ cli.parse(process.argv)
159
87
 
160
- console.error(chalk.red('\nPossible reasons:'))
161
- console.error(chalk.yellow('1. You might not have access to this private repo.'))
162
- console.error(chalk.yellow('2. Git is not installed or configured on this machine.'))
163
- console.error(chalk.red(`\nError details: ${err.message}`))
164
-
165
- if (fs.existsSync(targetPath)) {
166
- fs.rmSync(targetPath, { recursive: true, force: true })
167
- }
168
- }
169
- })
170
-
171
- cli.parse(process.argv)
172
- } catch (error) {
173
- console.error(`x cli:${error?.message}`)
88
+ } catch (error) {
89
+ console.error(`${packageName} Initialization Error:`, error?.message)
90
+ }
174
91
  }
175
92
 
176
- process.on('uncaughtException', (error) => {
177
- console.error('Uncaught Exception:', error.message)
93
+ process.on("uncaughtException", (error) => {
94
+ console.error("Critical Error:", error.message)
178
95
  process.exit(1)
179
- })
96
+ })
97
+
98
+ setupCLI()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xrystal/core",
3
- "version": "3.3.7",
3
+ "version": "3.4.3",
4
4
  "description": "Project core for xrystal",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -21,19 +21,7 @@
21
21
  "exports": {
22
22
  ".": {
23
23
  "types": "./source/index.d.ts",
24
- "import": "./source/index.js"
25
- },
26
- "./source/*/index": {
27
- "types": "./source/*/index.d.ts",
28
- "import": "./source/*/index.js"
29
- },
30
- "./source/*": {
31
- "types": "./source/*/index.d.ts",
32
- "import": "./source/*/index.js"
33
- },
34
- "./source/*.js": {
35
- "types": "./source/*.d.ts",
36
- "import": "./source/*.js"
24
+ "default": "./source/index.js"
37
25
  }
38
26
  },
39
27
  "type": "module",
@@ -41,80 +29,47 @@
41
29
  "tmp": "./bin/main-cli.js"
42
30
  },
43
31
  "scripts": {
44
- "dev": "tsx watch --env-file=../infrastructer/x/environments/.global.env --env-file=../infrastructer/x/environments/.dev.env --include \"./source/**/*.ts\" --include \"./x\" --exclude node_modules --exclude x/ts-build source/index.ts",
45
- "lint": "eslint .",
46
- "build": "./node_modules/.bin/tsc",
47
- "start": "tsx --env-file=../infrastructer/x/environments/.global.env --env-file=../infrastructer/x/environments/.dev.env --include \"./source/**/*.ts\" --include \"./x\" --exclude node_modules --exclude x/ts-build source/index.ts",
48
- "webpack-dev": "node --loader ts-node/esm node_modules/webpack-dev-server/bin/webpack-dev-server --config ./x/webpack/webpack.config.dev.ts",
49
- "webpack-prod": "node --loader ts-node/esm node_modules/webpack-cli/bin/cli.js --config ./x/webpack/webpack.config.prod.ts"
32
+ "dev": "bun --watch --env-file=../infrastructer/x/environments/.global.env --env-file=../infrastructer/x/environments/.dev.env source/index.ts",
33
+ "build": "rm -rf x/dist && bun build ./source/*.ts ./source/**/*.ts --outdir ./x/dist --target node --external '*' && bunx tsc --project tsconfig.json",
34
+ "build:dev": "bun --watch --env-file=../infrastructer/x/environments/.global.env --env-file=../infrastructer/x/environments/.dev.env ./x/dist/index.js",
35
+ "build:prod": "bun run build && find source -name '*.ts' -delete && cp -r x/dist/* source/ && rm -rf x/dist",
36
+ "start": "bun --env-file=../infrastructer/x/environments/.global.env --env-file=../infrastructer/x/environments/.dev.env source/index.js"
50
37
  },
51
38
  "dependencies": {
52
- "@babel/cli": "^7.21.0",
53
- "@babel/core": "^7.21.4",
54
- "@babel/preset-env": "^7.21.4",
55
- "@babel/preset-react": "^7.18.6",
56
39
  "@types/bcrypt": "^5.0.2",
57
- "@types/webpack": "^5.28.3",
58
- "@types/webpack-dev-server": "^4.7.2",
59
- "@types/webpack-merge": "^5.0.0",
60
- "@types/webpack-node-externals": "^3.0.4",
61
40
  "@types/yaml": "^1.9.7",
62
41
  "axios": "^1.13.2",
63
- "babel-loader": "^9.1.2",
64
42
  "chalk": "^5.6.2",
65
- "clean-webpack-plugin": "^4.0.0",
66
43
  "commander": "^13.0.0",
67
- "copy-webpack-plugin": "^11.0.0",
68
- "css-loader": "^6.7.3",
69
- "dotenv": "^16.3.1",
70
44
  "ejs": "^3.1.9",
71
- "ejs-compiled-loader": "^3.1.0",
72
- "ejs-loader": "^0.5.0",
73
- "ejs-webpack-loader": "^2.2.2",
74
- "file-loader": "^6.2.0",
75
45
  "handlebars": "^4.7.8",
76
- "handlebars-loader": "^1.7.3",
77
- "html-loader": "^4.2.0",
78
- "html-webpack-plugin": "^5.6.0",
79
46
  "i18next": "^25.6.3",
80
47
  "i18next-fs-backend": "^2.6.1",
81
48
  "i18next-http-middleware": "^3.8.2",
82
49
  "jquery": "^3.7.1",
83
50
  "kafkajs": "^2.2.4",
84
51
  "logform": "^2.7.0",
85
- "mini-css-extract-plugin": "^2.9.0",
86
52
  "minimist": "^1.2.8",
87
53
  "moment-timezone": "^0.6.0",
88
54
  "nodemailer": "^7.0.11",
89
55
  "nodemailer-express-handlebars": "^7.0.0",
90
56
  "ora": "^9.0.0",
91
- "postcss-loader": "^7.2.4",
57
+ "qs": "^6.14.1",
92
58
  "react": "^18.2.0",
93
59
  "react-dom": "^18.2.0",
94
60
  "sass": "^1.62.0",
95
- "sass-loader": "^13.2.2",
96
61
  "soap": "^1.6.0",
97
- "ts-loader": "^8.0.0",
98
- "url-loader": "^4.1.1",
99
- "webpack-dev-server": "^4.13.3",
100
- "webpack-merge": "^6.0.1",
101
- "webpack-node-externals": "^3.0.0",
102
62
  "winston": "^3.19.0",
103
63
  "winston-daily-rotate-file": "^5.0.0",
104
64
  "winston-mongodb": "^7.0.1",
105
65
  "yaml": "^2.5.0"
106
66
  },
107
- "author": "y.yasir.k",
108
- "license": "ISC",
109
67
  "devDependencies": {
68
+ "@types/express": "^5.0.6",
110
69
  "@types/minimist": "^1.2.5",
70
+ "@types/node": "^25.0.6",
111
71
  "@types/nodemailer": "^7.0.4",
112
72
  "@types/nodemailer-express-handlebars": "^4.0.6",
113
- "ts-node": "^10.9.2",
114
- "tsconfig-paths": "^4.2.0",
115
- "tsx": "^4.21.0",
116
- "typescript": "^5.5.3",
117
- "webpack": "^5.104.1",
118
- "webpack-cli": "^6.0.1"
73
+ "typescript": "^5.5.3"
119
74
  }
120
75
  }
@@ -1,7 +1,6 @@
1
- import webpack from 'webpack';
2
- import * as webpackMerge from 'webpack-merge';
3
- import nodeExternals from 'webpack-node-externals';
4
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
5
- declare const coreLoader: any;
6
- export { webpack, webpackMerge, nodeExternals, MiniCssExtractPlugin };
1
+ declare const coreLoader: () => Promise<{
2
+ _?: undefined;
3
+ } | {
4
+ _: any;
5
+ }>;
7
6
  export default coreLoader;
@@ -1,94 +1,63 @@
1
1
  // => import dependencies
2
2
  import path from 'path';
3
- import webpack from 'webpack';
4
- import * as webpackMerge from 'webpack-merge';
5
- import nodeExternals from 'webpack-node-externals';
6
- import MiniCssExtractPlugin from 'mini-css-extract-plugin';
7
3
  import { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService } from '../loader/index';
8
4
  import { packageName, tmpFileDefaultName, tmpFileDefaultExt, findFileRecursively, TmpFileLoader, x, kafkaBrokers, systemLoggerLayer, } from '../utils/index';
9
5
  //
10
6
  let coreHasRun = false;
11
7
  const coreLoader = async () => {
12
- let response = {};
13
- let r = {};
14
- let rootFolderPath = '';
15
- let ownerTmpFilePath = null;
16
- let resolvedTmpFileJson = null;
17
- if (coreHasRun) {
18
- return response;
19
- }
8
+ if (coreHasRun)
9
+ return {};
20
10
  try {
21
- ownerTmpFilePath = findFileRecursively('.', tmpFileDefaultName, tmpFileDefaultExt);
11
+ const ownerTmpFilePath = findFileRecursively(".", tmpFileDefaultName, tmpFileDefaultExt);
22
12
  if (!ownerTmpFilePath) {
23
- console.error(`${tmpFileDefaultName} file not found.`);
13
+ throw new Error(`${tmpFileDefaultName} file not found`);
24
14
  }
25
- const tmpFileObject = new TmpFileLoader({
26
- filePath: ownerTmpFilePath
15
+ const tmpFileObject = new TmpFileLoader({ filePath: ownerTmpFilePath });
16
+ const r = tmpFileObject.getResolvedTmpFile();
17
+ const { configs } = r;
18
+ const rootFolderPath = configs.rootFolderPath;
19
+ const services = [
20
+ SystemService,
21
+ ConfigsService,
22
+ LoggerService,
23
+ EventsService,
24
+ LocalizationsService
25
+ ];
26
+ services.forEach(service => x.set({ service, reference: service }));
27
+ const system = x.get(SystemService);
28
+ const configService = x.get(ConfigsService);
29
+ const logger = x.get(LoggerService);
30
+ const events = x.get(EventsService);
31
+ const i18n = x.get(LocalizationsService);
32
+ await system.load({
33
+ tmp: { _: r }
34
+ });
35
+ await configService.load({
36
+ tmpFolderPath: rootFolderPath,
37
+ systemService: system,
38
+ envLoadPath: path.join(rootFolderPath, configs.loaders.configs.envLoadPath),
39
+ ...(configs.loaders.configs.globalEnvFileName && { globalEnvFileName: configs.loaders.configs.globalEnvFileName })
40
+ });
41
+ await logger.load({
42
+ loadPath: path.join(rootFolderPath, configs.loaders.loggers.loadPath),
43
+ loggerLevel: systemLoggerLayer ?? configs.loaders.loggers.logLevel,
44
+ serviceName: configs.service,
45
+ env: process.env.NODE_ENV,
46
+ kafkaBrokers: kafkaBrokers ?? "",
47
+ kafkaTopic: configs.loaders.loggers.topic
48
+ });
49
+ await events.load({});
50
+ await i18n.load({
51
+ loadPath: path.resolve(rootFolderPath, configs.loaders.localization.loadPath),
52
+ fallbackLang: configs.loaders.localization.fallbackLang,
53
+ preloadLang: configs.loaders.localization.preloadLangs
27
54
  });
28
- resolvedTmpFileJson = tmpFileObject.getResolvedTmpFile();
29
- r = resolvedTmpFileJson;
30
- response = {
31
- _: r
32
- };
33
- rootFolderPath = resolvedTmpFileJson.configs.rootFolderPath;
34
- // => LOADER
35
- const serviceName = r.configs.service;
36
- const nodeEnv = process.env.NODE_ENV;
37
- try {
38
- x.set({
39
- service: SystemService,
40
- reference: SystemService
41
- });
42
- x.set({
43
- service: ConfigsService,
44
- reference: ConfigsService
45
- });
46
- x.set({
47
- service: LoggerService,
48
- reference: LoggerService
49
- });
50
- x.set({
51
- service: EventsService,
52
- reference: EventsService
53
- });
54
- x.set({
55
- service: LocalizationsService,
56
- reference: LocalizationsService
57
- });
58
- await x.get(SystemService).load({
59
- tmp: response
60
- });
61
- await x.get(ConfigsService).load({
62
- tmpFolderPath: rootFolderPath,
63
- systemService: x.get(SystemService),
64
- envLoadPath: `${rootFolderPath}/${r.configs.loaders.configs.envLoadPath}`,
65
- ...(r.configs.loaders.configs.globalEnvFileName ? { globalEnvFileName: r.configs.loaders.configs.globalEnvFileName } : null)
66
- });
67
- await x.get(LoggerService).load({
68
- loadPath: `${rootFolderPath}/${r.configs.loaders.loggers.loadPath}`,
69
- loggerLevel: systemLoggerLayer || r.configs.loaders.loggers.logLevel,
70
- serviceName,
71
- env: nodeEnv,
72
- kafkaBrokers: kafkaBrokers || '',
73
- kafkaTopic: r.configs.loaders.loggers.topic
74
- });
75
- await x.get(EventsService).load({});
76
- await x.get(LocalizationsService).load({
77
- loadPath: path.resolve(`${rootFolderPath}/${r.configs.loaders.localization.loadPath}`),
78
- fallbackLang: r.configs.loaders.localization.fallbackLang,
79
- preloadLang: r.configs.loaders.localization.preloadLangs,
80
- });
81
- }
82
- catch (error) {
83
- console.log(`x:${error}`);
84
- }
85
- //
86
55
  coreHasRun = true;
87
- return response;
56
+ return { _: r };
88
57
  }
89
58
  catch (error) {
90
- console.error(`${packageName} x:`, error?.message);
59
+ const errorMessage = error instanceof Error ? error.message : String(error);
60
+ console.error(`[${packageName} core failure]: ${errorMessage}`);
91
61
  }
92
62
  };
93
- export { webpack, webpackMerge, nodeExternals, MiniCssExtractPlugin };
94
63
  export default coreLoader;
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
2
  import { __dirname } from '../helpers/path';
3
- export const packageName = 'tmp-project-tool';
3
+ export const packageName = 'x';
4
4
  export const tmpFileDefaultMainFolderName = 'x';
5
5
  export const tmpFileDefaultName = 'tmp';
6
6
  export const tmpFileDefaultExt = '.yml';
@@ -1,11 +1,8 @@
1
- import EventEmitter from "events";
1
+ import { EventEmitter } from "node:events";
2
2
  export declare class TmpFileLoader extends EventEmitter {
3
- protected tmpFileJson: Record<string, any>;
4
- private filePath;
3
+ #private;
5
4
  constructor({ filePath }: {
6
5
  filePath: string;
7
6
  });
8
- private load;
9
- private watch;
10
- getResolvedTmpFile(): Record<string, any>;
7
+ getResolvedTmpFile(): any;
11
8
  }
@@ -1,38 +1,38 @@
1
- import EventEmitter from "events";
2
- import path from "path";
3
- import fs from "fs";
4
- import yaml from 'yaml';
1
+ import { EventEmitter } from "node:events";
2
+ import { resolve } from "node:path";
3
+ import { readFileSync, watchFile } from "node:fs";
4
+ import { parse } from "yaml";
5
5
  import { resolveObjWithHandlebars } from "../../helpers";
6
6
  export class TmpFileLoader extends EventEmitter {
7
- tmpFileJson = {};
8
- filePath;
7
+ #tmpFileJson = {};
8
+ #filePath;
9
9
  constructor({ filePath }) {
10
10
  super();
11
- this.filePath = path.resolve(filePath);
12
- this.load();
13
- this.watch();
11
+ this.#filePath = resolve(filePath);
12
+ this.#loadSync();
13
+ this.#initWatcher();
14
14
  }
15
- load() {
15
+ #loadSync() {
16
16
  try {
17
- const bufferFile = fs.readFileSync(this.filePath);
18
- const parsedYaml = yaml.parse(bufferFile.toString());
19
- this.tmpFileJson = parsedYaml;
20
- this.emit("reload", parsedYaml);
17
+ const content = readFileSync(this.#filePath, "utf8");
18
+ this.#tmpFileJson = parse(content);
19
+ this.emit("reload", this.#tmpFileJson);
21
20
  }
22
21
  catch (err) {
23
- console.error("Error:", err);
22
+ console.error(`[TmpFileLoader] Error: ${err}`);
24
23
  }
25
24
  }
26
- watch() {
27
- fs.watchFile(this.filePath, () => {
28
- this.load();
25
+ #initWatcher() {
26
+ watchFile(this.#filePath, { interval: 500 }, (curr, prev) => {
27
+ if (curr.mtimeMs !== prev.mtimeMs) {
28
+ this.#loadSync();
29
+ }
29
30
  });
30
31
  }
31
32
  getResolvedTmpFile() {
32
- if (this.tmpFileJson)
33
- return resolveObjWithHandlebars(this.tmpFileJson, this.tmpFileJson);
34
- this.load();
35
- resolveObjWithHandlebars(this.tmpFileJson, this.tmpFileJson);
36
- return this.tmpFileJson;
33
+ const data = Object.keys(this.#tmpFileJson).length > 0
34
+ ? this.#tmpFileJson
35
+ : (this.#loadSync(), this.#tmpFileJson);
36
+ return resolveObjWithHandlebars(data, data);
37
37
  }
38
38
  }
@@ -0,0 +1,2 @@
1
+ declare let tmp: any;
2
+ export default tmp;
@@ -0,0 +1,8 @@
1
+ import coreLoader from "./project/index.js";
2
+ let tmp;
3
+ // => tmp project tool => xrystal
4
+ await (async () => {
5
+ tmp = await coreLoader();
6
+ })();
7
+ //
8
+ export default tmp;
@@ -0,0 +1,13 @@
1
+ import SystemService from '../system/index';
2
+ export default class ConfigsService {
3
+ protected _globalEnvFileName: string;
4
+ protected _systemService: SystemService;
5
+ static tmpFolderPath: string;
6
+ private _envLoadPath;
7
+ load: ({ tmpFolderPath, systemService, envLoadPath, globalEnvFileName }: {
8
+ tmpFolderPath: string;
9
+ systemService: SystemService;
10
+ envLoadPath: string;
11
+ globalEnvFileName?: string | null;
12
+ }) => any;
13
+ }
@@ -0,0 +1,17 @@
1
+ export default class ConfigsService {
2
+ _globalEnvFileName = 'global';
3
+ _systemService;
4
+ static tmpFolderPath;
5
+ _envLoadPath = '';
6
+ load = ({ tmpFolderPath, systemService, envLoadPath, globalEnvFileName }) => {
7
+ ConfigsService.tmpFolderPath = tmpFolderPath;
8
+ this._systemService = systemService;
9
+ this._envLoadPath = `${envLoadPath}`;
10
+ /*
11
+ this._dynamicEnvLoader({
12
+ nodeEnv
13
+ globalEnvFileName
14
+ })
15
+ */
16
+ };
17
+ }