@xrystal/core 3.3.7 → 3.4.2
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/bin/main-cli.js +71 -152
- package/package.json +11 -56
- package/source/project/index.d.ts +5 -6
- package/source/project/index.js +46 -77
- package/source/utils/constants/index.js +1 -1
- package/source/utils/models/classes/class.tmp-file-loader.d.ts +3 -6
- package/source/utils/models/classes/class.tmp-file-loader.js +23 -23
- package/x/tmp.yml +0 -26
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 {
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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(!
|
|
42
|
-
|
|
43
|
+
if (!fs.existsSync(projectMainFolderPath)) {
|
|
44
|
+
fs.mkdirSync(projectMainFolderPath, { recursive: true })
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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 (
|
|
92
|
-
console.
|
|
93
|
-
|
|
53
|
+
if (fs.existsSync(targetPath)) {
|
|
54
|
+
console.log(chalk.red(`❌ Error: '${projectName}' folder already exists!`))
|
|
55
|
+
process.exit(1)
|
|
94
56
|
}
|
|
95
57
|
|
|
96
|
-
|
|
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
|
-
|
|
60
|
+
try {
|
|
61
|
+
execSync(`git clone --depth 1 ${templateRepoUri} "${targetPath}"`, { stdio: "ignore" })
|
|
132
62
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
139
|
-
|
|
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
|
-
|
|
71
|
+
const installCmd = isBun ? "bun install" : "npm install"
|
|
72
|
+
execSync(installCmd, { cwd: targetPath, stdio: "inherit" })
|
|
144
73
|
|
|
145
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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(
|
|
177
|
-
console.error(
|
|
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
|
+
"version": "3.4.2",
|
|
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
|
-
"
|
|
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": "
|
|
45
|
-
"
|
|
46
|
-
"build": "
|
|
47
|
-
"
|
|
48
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { webpack, webpackMerge, nodeExternals, MiniCssExtractPlugin };
|
|
1
|
+
declare const coreLoader: () => Promise<{
|
|
2
|
+
_?: undefined;
|
|
3
|
+
} | {
|
|
4
|
+
_: any;
|
|
5
|
+
}>;
|
|
7
6
|
export default coreLoader;
|
package/source/project/index.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
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(
|
|
11
|
+
const ownerTmpFilePath = findFileRecursively(".", tmpFileDefaultName, tmpFileDefaultExt);
|
|
22
12
|
if (!ownerTmpFilePath) {
|
|
23
|
-
|
|
13
|
+
throw new Error(`${tmpFileDefaultName} file not found`);
|
|
24
14
|
}
|
|
25
|
-
const tmpFileObject = new TmpFileLoader({
|
|
26
|
-
|
|
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
|
|
56
|
+
return { _: r };
|
|
88
57
|
}
|
|
89
58
|
catch (error) {
|
|
90
|
-
|
|
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 = '
|
|
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
|
-
|
|
4
|
-
private filePath;
|
|
3
|
+
#private;
|
|
5
4
|
constructor({ filePath }: {
|
|
6
5
|
filePath: string;
|
|
7
6
|
});
|
|
8
|
-
|
|
9
|
-
private watch;
|
|
10
|
-
getResolvedTmpFile(): Record<string, any>;
|
|
7
|
+
getResolvedTmpFile(): any;
|
|
11
8
|
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import EventEmitter from "events";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
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
|
|
12
|
-
this
|
|
13
|
-
this
|
|
11
|
+
this.#filePath = resolve(filePath);
|
|
12
|
+
this.#loadSync();
|
|
13
|
+
this.#initWatcher();
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
#loadSync() {
|
|
16
16
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
this.tmpFileJson
|
|
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(
|
|
22
|
+
console.error(`[TmpFileLoader] Error: ${err}`);
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
resolveObjWithHandlebars(
|
|
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
|
}
|
package/x/tmp.yml
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
project:
|
|
2
|
-
name: x
|
|
3
|
-
|
|
4
|
-
configs:
|
|
5
|
-
rootFolderPath: x
|
|
6
|
-
service: service-name
|
|
7
|
-
|
|
8
|
-
loaders:
|
|
9
|
-
configs:
|
|
10
|
-
envLoadPath: environments
|
|
11
|
-
#globalEnvFileName: glabalExample # Default: global
|
|
12
|
-
|
|
13
|
-
loggers:
|
|
14
|
-
loadPath: logs
|
|
15
|
-
logLevel: debug
|
|
16
|
-
topic: logs
|
|
17
|
-
|
|
18
|
-
localization:
|
|
19
|
-
loadPath: assets/langs
|
|
20
|
-
fallbackLang: en
|
|
21
|
-
preloadLangs:
|
|
22
|
-
- en
|
|
23
|
-
- tr
|
|
24
|
-
|
|
25
|
-
end:
|
|
26
|
-
version: 1
|