@xrystal/core 3.18.0 → 3.18.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.
@@ -1,14 +1,17 @@
1
- import path from 'path'
1
+ import path from "node:path"
2
2
 
3
- import { __filename, __dirname } from '../helpers/index.mjs'
3
+ export class Constants {
4
+ static packageName = '@xrystal/core'
4
5
 
5
- export const packageName = '@xrystal/core'
6
+ static defaultRootFolderName = 'x'
7
+ static defaultTmpFileName = 'tmp'
8
+ static defaultTmpFileExt = '.yml'
6
9
 
7
- export const tmpFileDefaultMainFolderName = 'x'
8
- export const tmpFileDefaultName = 'tmp'
9
- export const tmpFileDefaultExt = '.yml'
10
+ static defaultTmpFilePath = path.join(__dirname, `../../${Constants.defaultRootFolderName}/${Constants.defaultTmpFileName}.${Constants.defaultTmpFileExt}`)
11
+ static defaultOwnerTmpFilePath = path.join(process.cwd(),`./${Constants.defaultRootFolderName}/${Constants.defaultTmpFileName}.${Constants.defaultTmpFileExt}`)
10
12
 
11
- export const defaultTmpFilePath = path.resolve(__dirname(__filename(import.meta.url)), `../../${tmpFileDefaultMainFolderName}/${tmpFileDefaultName}.yml`)
12
- export const defaultOwnerTmpFilePath = path.resolve(`./${tmpFileDefaultMainFolderName}/${tmpFileDefaultName}.yml`)
13
+ static publicFolderName = 'public'
14
+ static kafkaLogsTopic = 'logs'
13
15
 
14
- export const templateRepoUri = 'https://github.com/xdloper/xastral-general-project-tmp.git'
16
+ static templateRepoUri = 'https://github.com/xdloper/xastral-general-project-tmp.git'
17
+ }
package/bin/main-cli.js CHANGED
@@ -8,128 +8,124 @@ import chalk from "chalk"
8
8
  import ora from "ora"
9
9
  import yaml from "yaml"
10
10
 
11
- import {
12
- defaultOwnerTmpFilePath,
13
- defaultTmpFilePath,
14
- packageName,
15
- templateRepoUri,
16
- tmpFileDefaultExt,
17
- tmpFileDefaultMainFolderName,
18
- tmpFileDefaultName
19
- } from "./constants/index.mjs"
11
+ import { Constants } from "./constants/index.mjs"
20
12
  import { findFileRecursively, resolveObjWithHandlebars } from "./helpers/index.mjs"
21
13
 
22
14
  const setupCLI = async () => {
23
- const cli = new Command()
15
+ const cli = new Command()
16
+
17
+ const isBun = !!process.versions.bun
18
+ const runtimeName = isBun ? "Bun" : "Node.js"
19
+ const packageManager = isBun ? "bun" : "npm"
20
+ const installCommand = isBun ? "bun install" : "npm install"
21
+ const devCommand = isBun ? "bun run dev:local" : "npm run dev:local"
22
+
23
+ try {
24
+ let ownerTmpFilePath = findFileRecursively(".", Constants.defaultTmpFileName, Constants.defaultTmpFileExt)
25
+
26
+ if (!ownerTmpFilePath) {
27
+ if (!Constants.defaultTmpFilePath || !fs.existsSync(Constants.defaultTmpFilePath)) {
28
+ throw new Error("Default template configuration file not found in package")
29
+ }
30
+
31
+ const folderPath = path.resolve(Constants.defaultRootFolderName)
32
+ if (!fs.existsSync(folderPath)) {
33
+ fs.mkdirSync(folderPath, { recursive: true })
34
+ }
35
+
36
+ const tmpFilePathBuffer = fs.readFileSync(Constants.defaultTmpFilePath)
37
+ fs.writeFileSync(Constants.defaultOwnerTmpFilePath, tmpFilePathBuffer)
38
+ ownerTmpFilePath = Constants.defaultOwnerTmpFilePath
39
+ }
24
40
 
25
- const isBun = !!process.versions.bun
26
- const runtimeName = isBun ? "Bun" : "Node.js"
27
- const packageManager = isBun ? "bun" : "npm"
28
- const installCommand = isBun ? "bun install" : "npm install"
29
- const devCommand = isBun ? "bun run dev:local" : "npm run dev:local"
41
+ const ownerTmpFile = fs.readFileSync(ownerTmpFilePath, "utf8")
42
+ const parsedTmpObject = yaml.parse(ownerTmpFile)
43
+ const resolvedTmpObject = resolveObjWithHandlebars(parsedTmpObject, parsedTmpObject)
30
44
 
31
- try {
32
- let ownerTmpFilePath = findFileRecursively(".", tmpFileDefaultName, tmpFileDefaultExt)
45
+ cli
46
+ .command("create <project-name> [target-path]")
47
+ .description(`Project initializer using ${runtimeName}`)
48
+ .action(async (projectName, targetDir) => {
49
+ let targetPath = ""
50
+ const isCurrentDir = projectName === "."
33
51
 
34
- if (!ownerTmpFilePath) {
35
- if (!defaultTmpFilePath || !fs.existsSync(defaultTmpFilePath)) {
36
- throw new Error("Default template configuration file not found in package")
37
- }
52
+ if (targetDir) {
53
+ const baseDir = path.resolve(process.cwd(), targetDir)
54
+ targetPath = isCurrentDir ? baseDir : path.join(baseDir, projectName)
55
+ } else {
56
+ targetPath = isCurrentDir ? process.cwd() : path.resolve(process.cwd(), projectName)
57
+ }
38
58
 
39
- const tmpFilePathBuffer = fs.readFileSync(defaultTmpFilePath)
40
- const folderPath = path.resolve(tmpFileDefaultMainFolderName || ".xrystal")
59
+ if (fs.existsSync(targetPath) && fs.readdirSync(targetPath).length > 0) {
60
+ console.log(chalk.red(`❌ Error: Target directory '${targetPath}' is not empty!`))
61
+ process.exit(1)
62
+ }
41
63
 
42
- if (!fs.existsSync(folderPath)) {
43
- fs.mkdirSync(folderPath, { recursive: true })
44
- }
64
+ const mainPath = resolvedTmpObject?.configs?.mainFolderPath || "./source"
45
65
 
46
- fs.writeFileSync(defaultOwnerTmpFilePath, tmpFilePathBuffer)
47
- ownerTmpFilePath = defaultOwnerTmpFilePath
48
- }
66
+ if (!fs.existsSync(targetPath)) {
67
+ fs.mkdirSync(targetPath, { recursive: true })
68
+ }
49
69
 
50
- const ownerTmpFile = fs.readFileSync(ownerTmpFilePath, "utf8")
51
- const parsedTmpObject = yaml.parse(ownerTmpFile)
52
- const resolvedTmpObject = resolveObjWithHandlebars(parsedTmpObject, parsedTmpObject)
70
+ const spinner = ora(`${runtimeName} environment detected. Cloning template...`).start()
53
71
 
54
- const mainPath = resolvedTmpObject?.configs?.mainFolderPath || "./source"
55
- const projectMainFolderPath = path.resolve(mainPath)
72
+ try {
73
+ execSync(`git clone --depth 1 ${Constants.templateRepoUri} "${targetPath}"`, { stdio: "ignore" })
56
74
 
57
- if (!fs.existsSync(projectMainFolderPath)) {
58
- fs.mkdirSync(projectMainFolderPath, { recursive: true })
59
- }
75
+ const gitFolder = path.join(targetPath, ".git")
76
+ if (fs.existsSync(gitFolder)) {
77
+ fs.rmSync(gitFolder, { recursive: true, force: true })
78
+ }
60
79
 
61
- cli
62
- .command("create <project-name> [target-path]")
63
- .description(`Project initializer using ${runtimeName}`)
64
- .action(async (projectName, targetDir) => {
65
- let targetPath = ""
66
- const isCurrentDir = projectName === "."
67
-
68
- if (targetDir) {
69
- const baseDir = path.resolve(process.cwd(), targetDir)
70
- targetPath = isCurrentDir ? baseDir : path.join(baseDir, projectName)
71
- } else {
72
- targetPath = isCurrentDir ? process.cwd() : path.resolve(process.cwd(), projectName)
73
- }
80
+ try {
81
+ execSync(`git init`, { cwd: targetPath, stdio: "ignore" })
82
+ } catch (e) {
83
+ // Git init fail
84
+ }
74
85
 
75
- if (fs.existsSync(targetPath) && fs.readdirSync(targetPath).length > 0) {
76
- console.log(chalk.red(`❌ Error: Target directory '${targetPath}' is not empty!`))
77
- process.exit(1)
78
- }
79
-
80
- if (!fs.existsSync(targetPath)) {
81
- fs.mkdirSync(targetPath, { recursive: true })
82
- }
86
+ const projectMainFolderPath = path.resolve(targetPath, mainPath)
87
+ if (!fs.existsSync(projectMainFolderPath)) {
88
+ fs.mkdirSync(projectMainFolderPath, { recursive: true })
89
+ }
83
90
 
84
- const spinner = ora(`${runtimeName} environment detected. Cloning template...`).start()
91
+ spinner.succeed(chalk.green("Template cloned and git initialized!"))
92
+ console.log(chalk.blue(`\n📦 Installing dependencies with ${packageManager}...`))
85
93
 
86
- try {
87
- execSync(`git clone --depth 1 ${templateRepoUri} "${targetPath}"`, { stdio: "ignore" })
94
+ execSync(installCommand, { cwd: targetPath, stdio: "inherit" })
88
95
 
89
- const gitFolder = path.join(targetPath, ".git")
90
- if (fs.existsSync(gitFolder)) {
91
- fs.rmSync(gitFolder, { recursive: true, force: true })
92
- }
96
+ console.log(chalk.green("\n✅ Done!"))
93
97
 
94
- try {
95
- execSync(`git init`, { cwd: targetPath, stdio: "ignore" })
96
- } catch (e) {
97
- }
98
+ const relativePath = path.relative(process.cwd(), targetPath)
99
+ if (relativePath && relativePath !== ".") {
100
+ console.log(chalk.cyan(`\n cd ${relativePath}`))
101
+ }
102
+ console.log(chalk.cyan(` ${devCommand}`))
98
103
 
99
- spinner.succeed(chalk.green("Template cloned and git initialized!"))
100
- console.log(chalk.blue(`\n📦 Installing dependencies with ${packageManager}...`))
104
+ } catch (err) {
105
+ spinner.fail(chalk.red("Failed!"))
106
+ console.error(chalk.red(`\nDetails: ${err.message}`))
101
107
 
102
- execSync(installCommand, { cwd: targetPath, stdio: "inherit" })
108
+ if (fs.existsSync(targetPath) && !isCurrentDir) {
109
+ const files = fs.readdirSync(targetPath)
103
110
 
104
- console.log(chalk.green("\n✅ Done!"))
111
+ if (files.length < 5) {
112
+ fs.rmSync(targetPath, { recursive: true, force: true })
113
+ console.log(chalk.yellow(`🧹 Cleaned up failed installation at ${targetPath}`))
114
+ }
115
+ }
116
+ }
117
+ })
105
118
 
106
- const relativePath = path.relative(process.cwd(), targetPath)
107
- if (relativePath && relativePath !== ".") {
108
- console.log(chalk.cyan(`\n cd ${relativePath}`))
109
- }
119
+ cli.parse(process.argv)
110
120
 
111
- console.log(chalk.cyan(` ${devCommand}`))
112
-
113
- } catch (err) {
114
- spinner.fail(chalk.red("Failed!"))
115
- console.error(chalk.red(`\nDetails: ${err.message}`))
116
-
117
- if (fs.existsSync(targetPath) && targetPath !== process.cwd() && fs.readdirSync(targetPath).length === 0) {
118
- fs.rmSync(targetPath, { recursive: true, force: true })
119
- }
120
- }
121
- })
122
-
123
- cli.parse(process.argv)
124
-
125
- } catch (error) {
126
- console.error(`${packageName || "CLI"} Initialization Error:`, error?.message)
127
- }
121
+ } catch (error) {
122
+ console.error(`${Constants.packageName || "CLI"} Initialization Error:`, error?.message)
123
+ }
128
124
  }
129
125
 
130
126
  process.on("uncaughtException", (error) => {
131
- console.error("Critical Error:", error.message)
132
- process.exit(1)
127
+ console.error("Critical Error:", error.message)
128
+ process.exit(1)
133
129
  })
134
130
 
135
131
  setupCLI()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.18.0",
4
+ "version": "3.18.2",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -3,8 +3,8 @@ import { IService } from '../../utils';
3
3
  export default class ConfigsService implements IService {
4
4
  #private;
5
5
  private config;
6
- publicFolderName: string;
7
- kafkaLogsTopic: string;
6
+ readonly publicFolderName: string;
7
+ readonly kafkaLogsTopic: string;
8
8
  constructor({ systemService }: {
9
9
  systemService: SystemService;
10
10
  });
@@ -1,9 +1,9 @@
1
1
  import path from 'node:path';
2
- import { kafkaLogsTopic, publicFolderName } from '../../utils';
2
+ import { Constants } from '../../utils';
3
3
  export default class ConfigsService {
4
4
  config = {};
5
- publicFolderName = publicFolderName;
6
- kafkaLogsTopic = kafkaLogsTopic;
5
+ publicFolderName = Constants.publicFolderName;
6
+ kafkaLogsTopic = Constants.kafkaLogsTopic;
7
7
  #systemService;
8
8
  constructor({ systemService }) {
9
9
  this.#systemService = systemService;
@@ -151,7 +151,6 @@ export default class LoggerService {
151
151
  return;
152
152
  try {
153
153
  const { id, level, message, payload, code } = info;
154
- console.log('geldii', this.kafkaTopic);
155
154
  await this.kafkaProducer.send({
156
155
  topic: this.kafkaTopic,
157
156
  messages: [{
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
- import { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService, ClientsService, ControllerService } from '../loader/index';
3
- import { packageName, x, getTmp, } from '../utils/index';
2
+ import { SystemService, ConfigsService, LoggerService, EventsService, LocalizationsService, ClientsService, ControllerService } from '../loader';
3
+ import { Constants, x, getTmp, } from '../utils';
4
4
  //
5
5
  let coreHasRun = false;
6
6
  export const core = getTmp();
@@ -68,7 +68,7 @@ const coreLoader = async ({}) => {
68
68
  }
69
69
  catch (error) {
70
70
  const errorMessage = error instanceof Error ? error.message : String(error);
71
- console.error(`[${packageName} core failure]: ${errorMessage}`);
71
+ console.error(`[${Constants.packageName} core failure]: ${errorMessage}`);
72
72
  }
73
73
  };
74
74
  export default coreLoader;
@@ -1,9 +1,10 @@
1
- export declare const packageName: string;
2
- export declare const tmpFileDefaultMainFolderName: string;
3
- export declare const tmpFileDefaultName: string;
4
- export declare const tmpFileDefaultExt = ".yml";
5
- export declare const defaultTmpFilePath: string;
6
- export declare const defaultOwnerTmpFilePath: string;
7
- export declare const systemLoggerLayer: string;
8
- export declare const publicFolderName = "public";
9
- export declare const kafkaLogsTopic = "logs";
1
+ export declare class Constants {
2
+ static readonly packageName: string;
3
+ static readonly defaultRootFolderName: string;
4
+ static readonly defaultTmpFileName: string;
5
+ static readonly defaultTmpFileExt = ".yml";
6
+ static readonly defaultTmpFilePath: string;
7
+ static readonly defaultOwnerTmpFilePath: string;
8
+ static readonly publicFolderName = "public";
9
+ static readonly kafkaLogsTopic = "logs";
10
+ }
@@ -1,11 +1,11 @@
1
- import path from 'path';
2
- import { __dirname } from '../helpers/path';
3
- export const packageName = 'x';
4
- export const tmpFileDefaultMainFolderName = 'x';
5
- export const tmpFileDefaultName = 'tmp';
6
- export const tmpFileDefaultExt = '.yml';
7
- export const defaultTmpFilePath = path.resolve(__dirname(import.meta.url), `../../${tmpFileDefaultMainFolderName}/${tmpFileDefaultName}.yml`);
8
- export const defaultOwnerTmpFilePath = path.resolve(`./${tmpFileDefaultMainFolderName}/${tmpFileDefaultName}.yml`);
9
- export const systemLoggerLayer = process.env.SYSTEM_LOGGER_LAYER;
10
- export const publicFolderName = 'public';
11
- export const kafkaLogsTopic = 'logs';
1
+ import path from "node:path";
2
+ export class Constants {
3
+ static packageName = '@xrystal/core';
4
+ static defaultRootFolderName = 'x';
5
+ static defaultTmpFileName = 'tmp';
6
+ static defaultTmpFileExt = '.yml';
7
+ static defaultTmpFilePath = path.join(__dirname, `../../${Constants.defaultRootFolderName}/${Constants.defaultTmpFileName}.${Constants.defaultTmpFileExt}`);
8
+ static defaultOwnerTmpFilePath = path.join(process.cwd(), `./${Constants.defaultRootFolderName}/${Constants.defaultTmpFileName}.${Constants.defaultTmpFileExt}`);
9
+ static publicFolderName = 'public';
10
+ static kafkaLogsTopic = 'logs';
11
+ }
@@ -13,4 +13,3 @@ export declare const argvsConverter: (argvs: string) => {
13
13
  };
14
14
  export declare const findExt: (filename: string) => string;
15
15
  export declare const changeExtensions: (filename: string, repalceExt: string) => string;
16
- export declare const webFileFindEngine: (folderPath: string) => string[];
@@ -1,18 +1,18 @@
1
1
  import path from "path";
2
2
  import fs from 'fs';
3
3
  import Handlebars from 'handlebars';
4
- import { SupportFileExtensionsEnum, tmpFileDefaultExt, tmpFileDefaultName, TmpFileLoader } from "../../index.js";
4
+ import { Constants, TmpFileLoader } from "../../index.js";
5
5
  export const getTmp = () => {
6
- const ownerTmpFilePath = findFileRecursively(".", tmpFileDefaultName, tmpFileDefaultExt);
6
+ const ownerTmpFilePath = findFileRecursively(".", Constants.defaultTmpFileName, Constants.defaultTmpFileExt);
7
7
  if (!ownerTmpFilePath) {
8
- throw new Error(`${tmpFileDefaultName} file not found`);
8
+ throw new Error(`${Constants.defaultTmpFileName} file not found`);
9
9
  }
10
10
  const tmpFileObject = getTmpConfig({});
11
11
  return {
12
12
  _: tmpFileObject
13
13
  };
14
14
  };
15
- export const getTmpConfig = ({ root = '.', tmpFileName = tmpFileDefaultName, ext = '.yml' }) => {
15
+ export const getTmpConfig = ({ root = process.cwd(), tmpFileName = Constants.defaultTmpFileName, ext = Constants.defaultTmpFileExt }) => {
16
16
  const path = findFileRecursively(root, tmpFileName, ext);
17
17
  if (!path) {
18
18
  throw new Error(`${name}.${ext} file not found`);
@@ -95,33 +95,3 @@ export const findExt = (filename) => {
95
95
  export const changeExtensions = (filename, repalceExt) => {
96
96
  return filename.replace(findExt(filename), repalceExt);
97
97
  };
98
- export const webFileFindEngine = (folderPath) => {
99
- try {
100
- const files = fs.readdirSync(folderPath);
101
- const fullFileExtension = Object.values(SupportFileExtensionsEnum).map(ext => '.' + ext);
102
- const filteredFiles = [];
103
- files.forEach(file => {
104
- const filePath = path.join(folderPath, file);
105
- const isDirectory = fs.statSync(filePath).isDirectory();
106
- if (isDirectory) {
107
- const subFolderFiles = webFileFindEngine(filePath);
108
- subFolderFiles.forEach(subFile => {
109
- filteredFiles.push(path.join(file, subFile).split('\\').join('/')); // Alt klasördeki dosya yolunu, ana klasör yoluna ekleyerek dosyları benzersiz yapıyoruz sonda ise diğer işletim sistemlerien uygun hale getiriyoruz
110
- });
111
- }
112
- else {
113
- for (const ffn of fullFileExtension) {
114
- if (file.endsWith(ffn)) {
115
- filteredFiles.push(file);
116
- break;
117
- }
118
- }
119
- }
120
- });
121
- return filteredFiles;
122
- }
123
- catch (error /* unknow */) {
124
- console.error('Error: ', error.message);
125
- return [];
126
- }
127
- };
@@ -118,22 +118,3 @@ export declare enum EndpointResourceEnum {
118
118
  WEBHOOKS = "webhooks",
119
119
  OTHERS = "others"
120
120
  }
121
- export declare enum SupportFileExtensionsEnum {
122
- 'HTML' = "html",
123
- 'EJS' = "ejs",
124
- 'HBS' = "hbs",
125
- "TS" = "",
126
- "JS" = ".js",
127
- "TSX" = "x",
128
- "JSX" = ".jsx",
129
- "TTF" = ".ttf",
130
- "EOT" = ".eot",
131
- "OTF" = ".otf",
132
- "SVG" = ".svg",
133
- "PNG" = ".png",
134
- "WOFF" = ".woff",
135
- "WOFF2" = ".woff2",
136
- "CSS" = ".css",
137
- "SCSS" = ".scss",
138
- "SASS" = ".sass"
139
- }
@@ -137,23 +137,3 @@ export var EndpointResourceEnum;
137
137
  EndpointResourceEnum["WEBHOOKS"] = "webhooks";
138
138
  EndpointResourceEnum["OTHERS"] = "others";
139
139
  })(EndpointResourceEnum || (EndpointResourceEnum = {}));
140
- export var SupportFileExtensionsEnum;
141
- (function (SupportFileExtensionsEnum) {
142
- SupportFileExtensionsEnum["HTML"] = "html";
143
- SupportFileExtensionsEnum["EJS"] = "ejs";
144
- SupportFileExtensionsEnum["HBS"] = "hbs";
145
- SupportFileExtensionsEnum["TS"] = "";
146
- SupportFileExtensionsEnum["JS"] = ".js";
147
- SupportFileExtensionsEnum["TSX"] = "x";
148
- SupportFileExtensionsEnum["JSX"] = ".jsx";
149
- SupportFileExtensionsEnum["TTF"] = ".ttf";
150
- SupportFileExtensionsEnum["EOT"] = ".eot";
151
- SupportFileExtensionsEnum["OTF"] = ".otf";
152
- SupportFileExtensionsEnum["SVG"] = ".svg";
153
- SupportFileExtensionsEnum["PNG"] = ".png";
154
- SupportFileExtensionsEnum["WOFF"] = ".woff";
155
- SupportFileExtensionsEnum["WOFF2"] = ".woff2";
156
- SupportFileExtensionsEnum["CSS"] = ".css";
157
- SupportFileExtensionsEnum["SCSS"] = ".scss";
158
- SupportFileExtensionsEnum["SASS"] = ".sass";
159
- })(SupportFileExtensionsEnum || (SupportFileExtensionsEnum = {}));