@langpkg/mcs_gen 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Maysara Elshewehy (https://github.com/maysara-elshewehy)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ <!-- ╔═══════════════════════════ BEG ════════════════════════════╗ -->
2
+
3
+ <br>
4
+ <div align="center">
5
+ <p>
6
+ <img src="./assets/img/logo.png" alt="logo" style="" height="60" />
7
+ </p>
8
+ </div>
9
+
10
+ <div align="center">
11
+ <p align="center" style="font-style:italic; color:gray;">
12
+ ----------------<br>
13
+ </p>
14
+ <img data="version" src="https://img.shields.io/badge/v-0.0.1-black"/>
15
+ <a href="https://github.com/langpkg/pkg"><img src="https://img.shields.io/badge/part of-langpkg/pkg-black"/></a>
16
+ <br>
17
+ <img src="https://img.shields.io/badge/coverage-~%25-brightgreen" alt="Test Coverage" />
18
+ <img src="https://img.shields.io/github/issues/langpkg/mcs_gen?style=flat" alt="Github Repo Issues" />
19
+ <img src="https://img.shields.io/github/stars/langpkg/mcs_gen?style=social" alt="GitHub Repo stars" />
20
+ </div>
21
+
22
+ <br>
23
+
24
+ <!-- ╚════════════════════════════════════════════════════════════╝ -->
25
+
26
+
27
+
28
+ <!-- ╔═══════════════════════════ DOC ════════════════════════════╗ -->
29
+
30
+ - ## Quick Start 🔥
31
+
32
+ ```bash
33
+ # install via bun
34
+ bun i @langpkg/mcs_gen
35
+ ```
36
+
37
+ > **This is not the final version (I’m not providing any guarantees here).**
38
+
39
+ <!-- ╚════════════════════════════════════════════════════════════╝ -->
40
+
41
+
42
+
43
+ <!-- ╔═══════════════════════════ END ════════════════════════════╗ -->
44
+
45
+ <br>
46
+ <br>
47
+
48
+ ---
49
+
50
+ <div align="center">
51
+ <a href="https://github.com/maysara-elshewehy"><img src="https://img.shields.io/badge/by-Maysara-black"/></a>
52
+ </div>
53
+
54
+ <!-- ╚════════════════════════════════════════════════════════════╝ -->
Binary file
Binary file
package/docs/.gitkeep ADDED
File without changes
@@ -0,0 +1,89 @@
1
+ // eslint.config.mjs
2
+ //
3
+ // Made with ❤️ by Maysara.
4
+
5
+
6
+
7
+ // ╔════════════════════════════════════════ PACK ════════════════════════════════════════╗
8
+
9
+ import { defineConfig } from 'eslint/config';
10
+ import stylistic from '@stylistic/eslint-plugin';
11
+ import tseslint from 'typescript-eslint';
12
+ import js from '@eslint/js';
13
+
14
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
15
+
16
+
17
+
18
+ // ╔═══════════════════════════════════════ CONST ════════════════════════════════════════╗
19
+
20
+ const rules = {
21
+ "curly" : "off",
22
+ "@stylistic/semi" : ["warn", "always"],
23
+ "@typescript-eslint/no-empty-function" : "off",
24
+ "@typescript-eslint/naming-convention" : [
25
+ "warn",
26
+ {
27
+ "selector" : "variable",
28
+ "format" : ["snake_case", "camelCase"],
29
+ "filter" : {
30
+ "match" : false,
31
+ "regex" : "^_"
32
+ }
33
+ },
34
+ {
35
+ "selector" : "function",
36
+ "format" : ["camelCase"]
37
+ },
38
+ {
39
+ "selector" : "method",
40
+ "format" : ["camelCase"]
41
+ },
42
+ {
43
+ "selector" : "typeLike",
44
+ "format" : ["PascalCase"]
45
+ },
46
+ {
47
+ "selector" : "import",
48
+ "format" : ["camelCase", "PascalCase"]
49
+ },
50
+ {
51
+ "selector" : "variable",
52
+ "modifiers" : ["const"],
53
+ "format" : ["UPPER_CASE", "snake_case", "camelCase"],
54
+ "filter" : {
55
+ "match" : false,
56
+ "regex" : "^_"
57
+ }
58
+ },
59
+ {
60
+ "selector" : "enumMember",
61
+ "format" : ["PascalCase"]
62
+ }
63
+ ],
64
+ "@typescript-eslint/no-unused-vars" : [
65
+ "error",
66
+ {
67
+ "argsIgnorePattern" : "^_"
68
+ }
69
+ ]
70
+ };
71
+
72
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
73
+
74
+
75
+
76
+ // ╔════════════════════════════════════════ CONF ════════════════════════════════════════╗
77
+
78
+ export default defineConfig(
79
+
80
+ js.configs.recommended, ...tseslint.configs.recommended, ...tseslint.configs.stylistic,
81
+
82
+ {
83
+ ignores : ['**/.vscode-test', '**/out', 'dist/', 'node_modules/', '.git/'],
84
+ plugins : { '@stylistic': stylistic },
85
+ rules : rules,
86
+ }
87
+ );
88
+
89
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@langpkg/mcs_gen",
3
+ "version": "0.0.1",
4
+ "description": "maysara code style generator",
5
+ "keywords": [],
6
+ "license": "MIT",
7
+ "author": "Maysara Elshewehy <maysara.elshewehy@gmail.com>",
8
+ "type": "module",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/langpkg/mcs_gen.git"
12
+ },
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.js",
18
+ "types": "./dist/index.d.ts"
19
+ }
20
+ },
21
+ "module": "./dist/index.js",
22
+ "pkg": {
23
+ "type": "lib"
24
+ },
25
+ "scripts": {},
26
+ "dependencies": {
27
+ "@langpkg/mcs_fmt": "^0.0.1",
28
+ "glob": "^13.0.6"
29
+ },
30
+ "devDependencies": {
31
+ "@eslint/js": "^10.0.1",
32
+ "@stylistic/eslint-plugin": "^5.10.0",
33
+ "@types/bun": "^1.3.14",
34
+ "@types/node": "^25.8.0",
35
+ "bun-plugin-dts": "^0.4.0",
36
+ "bun-types": "^1.3.14",
37
+ "ts-node": "^10.9.2",
38
+ "tsup": "^8.5.1",
39
+ "typescript": "^6.0.3",
40
+ "typescript-eslint": "^8.59.3"
41
+ }
42
+ }
@@ -0,0 +1,112 @@
1
+ // src/common/index.ts
2
+ //
3
+ // Made with ❤️ by Maysara.
4
+
5
+
6
+
7
+ // ╔════════════════════════════════════════ PACK ════════════════════════════════════════╗
8
+
9
+ import { PkgError } from './types';
10
+ import * as path from 'path';
11
+ import * as fs from 'fs';
12
+ import process from 'process';
13
+ export * from './types';
14
+
15
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
16
+
17
+
18
+
19
+ // ╔════════════════════════════════════════ FILE ════════════════════════════════════════╗
20
+
21
+ export function resolvePath(filePath: string): string {
22
+ return path.isAbsolute(filePath) ? filePath : path.join(process.cwd(), filePath);
23
+ }
24
+
25
+ export function isFileExists(filePath: string): boolean {
26
+ try {
27
+ return fs.existsSync(resolvePath(filePath));
28
+ } catch {
29
+ return false;
30
+ }
31
+ }
32
+
33
+ export function isDirExists(dirPath: string): boolean {
34
+ try {
35
+ const resolved = resolvePath(dirPath);
36
+ return fs.existsSync(resolved) && fs.statSync(resolved).isDirectory();
37
+ } catch {
38
+ return false;
39
+ }
40
+ }
41
+
42
+ export function readFile(filePath: string): string {
43
+ const targetPath = resolvePath(filePath);
44
+
45
+ if (!fs.existsSync(targetPath)) {
46
+ throw new PkgError(`File not found: ${targetPath}`, 'FILE_NOT_FOUND', {
47
+ path : targetPath,
48
+ });
49
+ }
50
+
51
+ try {
52
+ return fs.readFileSync(targetPath, 'utf-8');
53
+ } catch (error) {
54
+ throw new PkgError(`Failed to read file: ${targetPath}`, 'FILE_READ_ERROR', {
55
+ path : targetPath,
56
+ cause : String(error),
57
+ });
58
+ }
59
+ }
60
+
61
+ export function writeFile(filePath: string, content: string): void {
62
+ const targetPath = resolvePath(filePath);
63
+ const dir = path.dirname(targetPath);
64
+
65
+ try {
66
+ if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); }
67
+ fs.writeFileSync(targetPath, content, 'utf-8');
68
+ } catch (error) {
69
+ throw new PkgError(`Failed to write file: ${targetPath}`, 'FILE_WRITE_ERROR', {
70
+ path : targetPath,
71
+ cause : String(error),
72
+ });
73
+ }
74
+ }
75
+
76
+ export function readJsonFile<T = unknown>(filePath: string): T {
77
+ const content = readFile(filePath);
78
+ try {
79
+ return JSON.parse(content) as T;
80
+ } catch (error) {
81
+ throw new PkgError(`Invalid JSON in file: ${filePath}`, 'JSON_PARSE_ERROR', {
82
+ path : filePath,
83
+ cause : String(error),
84
+ });
85
+ }
86
+ }
87
+
88
+ export function writeJsonFile(filePath: string, data: unknown, pretty = true): void {
89
+ const content = pretty ? JSON.stringify(data, null, 4) : JSON.stringify(data);
90
+ writeFile(filePath, content);
91
+ }
92
+
93
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
94
+
95
+
96
+
97
+ // ╔════════════════════════════════════════ PROC ════════════════════════════════════════╗
98
+
99
+ export function getCwd(): string {
100
+ return process.cwd();
101
+ }
102
+
103
+ export function sleep(ms: number): Promise<void> {
104
+ return new Promise((resolve) => setTimeout(resolve, ms));
105
+ }
106
+
107
+ export function createDir(dirPath: string): void {
108
+ const fullPath = path.resolve(getCwd(), dirPath);
109
+ fs.mkdirSync(fullPath, { recursive: true });
110
+ }
111
+
112
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
@@ -0,0 +1,69 @@
1
+ // src/common/types.ts
2
+ //
3
+ // Made with ❤️ by Maysara.
4
+
5
+
6
+
7
+ // ╔════════════════════════════════════════ TYPE ════════════════════════════════════════╗
8
+
9
+ export type ProjectType = 'pkg' | 'cli';
10
+
11
+ export interface ProjectMeta {
12
+ name : string;
13
+ version : string;
14
+ description : string;
15
+ license : string;
16
+ author : {
17
+ name : string;
18
+ email : string;
19
+ github : string;
20
+ };
21
+ org : string; // GitHub org or username
22
+ repoName : string; // GitHub repo name
23
+ }
24
+
25
+ export interface FormatResult {
26
+ formatted : string;
27
+ count : number;
28
+ errors? : FormatError[];
29
+ }
30
+
31
+ export interface FormatError {
32
+ message : string;
33
+ line? : number;
34
+ column? : number;
35
+ [key: string] : unknown;
36
+ }
37
+
38
+ export type IssueSeverity = 'error' | 'warning';
39
+
40
+ export type FormatFix =
41
+ | { type: 'reformat'; content: string }
42
+ | { type: 'replace_line'; line: number; content: string }
43
+ | { type: 'insert_after_line'; line: number; content: string }
44
+ | { type: 'insert_before_line'; line: number; content: string }
45
+ | { type: 'remove_blank_lines'; line: number; count: number }
46
+ | { type: 'append_lines'; content: string };
47
+
48
+ export interface FormatIssue {
49
+ file : string;
50
+ line : number;
51
+ code : string;
52
+ message : string;
53
+ severity : IssueSeverity;
54
+ fixable : boolean;
55
+ fix? : FormatFix;
56
+ }
57
+
58
+ export class PkgError extends Error {
59
+ constructor(
60
+ msg : string,
61
+ public code : string,
62
+ public ctx? : Record<string, unknown>
63
+ ) {
64
+ super(msg);
65
+ this.name = 'PkgError';
66
+ }
67
+ }
68
+
69
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
@@ -0,0 +1,13 @@
1
+ // src/gen/json/index.ts
2
+ //
3
+ // Made with ❤️ by Maysara.
4
+
5
+
6
+
7
+ // ╔════════════════════════════════════════ PACK ════════════════════════════════════════╗
8
+
9
+ export { generateVscodeSettings } from './vscode_settings';
10
+ export { generatePackageJson } from './package_json';
11
+ export { generateTsconfig } from './tsconfig';
12
+
13
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
@@ -0,0 +1,97 @@
1
+ // src/gen/json/package_json.ts
2
+ //
3
+ // Made with ❤️ by Maysara.
4
+
5
+
6
+
7
+ // ╔════════════════════════════════════════ PACK ════════════════════════════════════════╗
8
+
9
+ import type { ProjectType, ProjectMeta } from '../../common';
10
+
11
+ import { formatJSON } from '@langpkg/mcs_fmt';
12
+
13
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
14
+
15
+
16
+
17
+ // ╔════════════════════════════════════════ MAIN ════════════════════════════════════════╗
18
+
19
+ export function generatePackageJson(projectType: ProjectType, meta: ProjectMeta): string {
20
+ const repoUrl =
21
+ meta.org && meta.repoName ? `https://github.com/${meta.org}/${meta.repoName}` : '';
22
+
23
+ const authorStr = [meta.author.name, meta.author.email ? `<${meta.author.email}>` : '']
24
+ .filter(Boolean)
25
+ .join(' ');
26
+
27
+ // Keys ordered to match PACKAGE_JSON_ORDER in jsonFormat.ts so the
28
+ // generator output is identical to what the validator would produce -
29
+ // no false-positive JSON_FORMAT warning on a freshly initialised project.
30
+ // Order: name, version, description, keywords, license, author,
31
+ // repository, type, [bin (cli only)], main, module, types,
32
+ // exports, scripts, dependencies, devDependencies, [pkg (cli only)]
33
+ const pkgObj: Record<string, unknown> = {
34
+ name : meta.name,
35
+ version : meta.version,
36
+ description : meta.description,
37
+ keywords : [] as string[],
38
+ license : meta.license,
39
+ author : authorStr || '',
40
+ repository : repoUrl ? { type: 'git', url: `git+${repoUrl}.git` } : '',
41
+ type : 'module',
42
+ main : './dist/index.js',
43
+ module : './dist/index.js',
44
+ types : './dist/index.d.ts',
45
+ exports : {
46
+ '.': {
47
+ import : './dist/index.js',
48
+ types : './dist/index.d.ts',
49
+ },
50
+ },
51
+ scripts : {}, // use `pkg` cli instead.
52
+ dependencies : {},
53
+ devDependencies : {
54
+ // default devDependencies
55
+ '@eslint/js' : '^9.39.4',
56
+ '@stylistic/eslint-plugin' : '^5.10.0',
57
+ '@types/bun' : '^1.3.13',
58
+ '@types/node' : '^25.7.0',
59
+ 'bun-plugin-dts' : '^0.3.0',
60
+ 'bun-types' : '^1.3.13',
61
+ 'ts-node' : '^10.9.2',
62
+ 'tsup' : '^8.5.1',
63
+ 'typescript' : '^5.9.3',
64
+ 'typescript-eslint' : '^8.59.3',
65
+ },
66
+ };
67
+
68
+ // For CLI mode, add bin field (inserted after 'type', before 'scripts')
69
+ if (projectType === 'cli') {
70
+ const binName = meta.name.replace(/^@[^/]+\//, '');
71
+ const ordered: Record<string, unknown> = {};
72
+ for (const [k, v] of Object.entries(pkgObj)) {
73
+ ordered[k] = v;
74
+ if (k === 'type') {
75
+ ordered['bin'] = { [binName]: './dist/index.js' };
76
+ // Add pkg field for CLI projects
77
+ ordered['pkg'] = { type: 'cli', };
78
+ }
79
+ }
80
+ Object.keys(pkgObj).forEach((k) => delete pkgObj[k]);
81
+ Object.assign(pkgObj, ordered);
82
+ } else {
83
+ // For normal (library) projects, add pkg field at the end
84
+ pkgObj['pkg'] = { type: 'lib', };
85
+ }
86
+
87
+ const result = formatJSON(JSON.stringify(pkgObj), 'package.json');
88
+
89
+ if(result.errors?.length) {
90
+ console.error('Error formatting package.json:', JSON.stringify(result.errors, null, 2));
91
+ throw new Error('Failed to generate package.json due to formatting errors.');
92
+ }
93
+
94
+ return result.formatted + '\n';
95
+ }
96
+
97
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
@@ -0,0 +1,59 @@
1
+ // src/gen/json/tsconfig.ts
2
+ //
3
+ // Made with ❤️ by Maysara.
4
+
5
+
6
+
7
+ // ╔════════════════════════════════════════ PACK ════════════════════════════════════════╗
8
+
9
+ import type { ProjectType } from '../../common';
10
+
11
+ import { formatJSON } from '@langpkg/mcs_fmt';
12
+
13
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
14
+
15
+
16
+
17
+ // ╔════════════════════════════════════════ MAIN ════════════════════════════════════════╗
18
+
19
+ export function generateTsconfig(projectType: ProjectType): string {
20
+
21
+ const tsConfig = {
22
+
23
+ compilerOptions : {
24
+ target : 'ES2020',
25
+ module : 'ESNext',
26
+ moduleResolution : 'bundler',
27
+ lib : ['DOM', 'ES2020', 'ESNext'],
28
+ types : ['node'],
29
+ declaration : projectType === 'pkg',
30
+ outDir : './dist',
31
+ // rootDir : './src',
32
+ strict : true,
33
+ esModuleInterop : true,
34
+ skipLibCheck : true,
35
+ forceConsistentCasingInFileNames : true,
36
+ resolveJsonModule : true,
37
+ isolatedModules : true,
38
+ allowImportingTsExtensions : true,
39
+ noEmit : true,
40
+ ignoreDeprecations : "6.0"
41
+ },
42
+
43
+ include : ['src', 'test'],
44
+ exclude : ['node_modules', 'dist']
45
+
46
+ };
47
+
48
+ const result = formatJSON(JSON.stringify(tsConfig), 'tsconfig.json');
49
+
50
+ if(result.errors?.length) {
51
+ console.error('Error formatting tsconfig.json:', JSON.stringify(result.errors, null, 2));
52
+ throw new Error('Failed to generate tsconfig.json due to formatting errors.');
53
+ }
54
+
55
+ return result.formatted + '\n';
56
+
57
+ }
58
+
59
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
@@ -0,0 +1,67 @@
1
+ // src/gen/json/vscode_settings.ts
2
+ //
3
+ // Made with ❤️ by Maysara.
4
+
5
+
6
+
7
+ // ╔════════════════════════════════════════ PACK ════════════════════════════════════════╗
8
+
9
+ import { formatJSON } from '@langpkg/mcs_fmt';
10
+
11
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
12
+
13
+
14
+
15
+ // ╔════════════════════════════════════════ MAIN ════════════════════════════════════════╗
16
+
17
+ export function generateVscodeSettings(): string {
18
+
19
+ const settings = {
20
+
21
+ 'files.exclude' : {
22
+ '**/.git' : true,
23
+ '**/.svn' : true,
24
+ '**/.hg' : true,
25
+ '**/.DS_Store' : true,
26
+ '**/Thumbs.db' : true,
27
+ 'eslint.config.mjs' : true,
28
+ 'bun.lock' : true,
29
+ 'package-lock.json' : true,
30
+ 'LICENSE' : true,
31
+ '.gitignore' : true,
32
+ '.gitattributes' : true,
33
+ '.npmignore' : true,
34
+ 'node_modules' : true,
35
+ 'tsup.config.ts' : true,
36
+ 'tsconfig.json' : true,
37
+ },
38
+
39
+ 'hide-files.files': [
40
+ 'eslint.config.mjs',
41
+ '.pkg',
42
+ '.vscode',
43
+ 'bun.lock',
44
+ 'package-lock.json',
45
+ 'LICENSE',
46
+ '.gitignore',
47
+ '.gitattributes',
48
+ '.npmignore',
49
+ 'node_modules',
50
+ 'tsup.config.ts',
51
+ 'tsconfig.json',
52
+ ],
53
+
54
+ };
55
+
56
+ const result = formatJSON(JSON.stringify(settings), '.vscode/settings.json');
57
+
58
+ if(result.errors?.length) {
59
+ console.error('Error formatting vscode settings:', JSON.stringify(result.errors, null, 2));
60
+ throw new Error('Failed to generate vscode settings due to formatting errors.');
61
+ }
62
+
63
+ return result.formatted + '\n';
64
+
65
+ }
66
+
67
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝
@@ -0,0 +1,11 @@
1
+ // src/gen/md/index.ts
2
+ //
3
+ // Made with ❤️ by Maysara.
4
+
5
+
6
+
7
+ // ╔════════════════════════════════════════ PACK ════════════════════════════════════════╗
8
+
9
+ export { generateReadme } from './readme';
10
+
11
+ // ╚══════════════════════════════════════════════════════════════════════════════════════╝