New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

prismalux

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prismalux - npm Package Compare versions

Comparing version

to
0.1.3

output/cjs/index.cjs

282

output/bin.js
#!/usr/bin/env node
/**
* Prismalux - Prisma Schema Highlighter
* Developed by Artyom Gorlovetskiy (unbywyd)
* Website: https://unbywyd.com
*
* This tool helps you to highlight and filter Prisma schema files directly from the command line.
*/
// src/bin.ts
import fs from "fs";
import path from "path";
import highlighter from "./highlighter.js";
// Function to load Prisma Schema
export const loadPrismaSchema = async (inputPath) => {
const cwd = process.cwd();
let schemaPath = null;
// Check if a path is provided
if (inputPath) {
// Determine if the path is absolute or relative
const resolvedPath = path.isAbsolute(inputPath) ? inputPath : path.resolve(cwd, inputPath);
if (fs.existsSync(resolvedPath)) {
const stat = fs.statSync(resolvedPath);
if (stat.isDirectory()) {
// If it's a directory, look for `schema.prisma`
const possibleSchemaPaths = [
path.join(resolvedPath, "prisma", "schema.prisma"),
path.join(resolvedPath, "schema.prisma")
];
schemaPath = possibleSchemaPaths.find(fs.existsSync) || null;
// src/highlighter.ts
var PrismaHighlighter = class _PrismaHighlighter {
config;
static DEFAULT_COLORS = {
reset: "\x1B[0m",
gray: "\x1B[90m",
whiteBold: "\x1B[1;37m",
cyanBold: "\x1B[1;36m",
purple: "\x1B[38;5;201m",
lightPurple: "\x1B[38;5;177m",
purpleDark: "\x1B[38;5;93m",
darkBlue: "\x1B[38;5;63m",
lightBlue: "\x1B[38;5;111m",
yellow: "\x1B[33m",
yellowBold: "\x1B[1;33m",
yellowBright: "\x1B[93m",
orange: "\x1B[38;5;208m",
green: "\x1B[32m",
greenBright: "\x1B[92m",
cyan: "\x1B[36m",
cyanLight: "\x1B[96m",
greenDark: "\x1B[38;5;22m"
};
static PRISMA_TYPES = /* @__PURE__ */ new Set([
"String",
"Int",
"Boolean",
"DateTime",
"Json",
"Float",
"Decimal",
"BigInt",
"Bytes"
]);
constructor(config = {}) {
this.config = {
enableColors: config.enableColors ?? true,
colors: { ..._PrismaHighlighter.DEFAULT_COLORS, ...config.colors }
};
}
colorize(text, color) {
if (!this.config.enableColors) return text;
return `${this.config.colors[color] || ""}${text}${this.config.colors.reset}`;
}
highlight(schema) {
return schema.replace(/\r\n/g, "\n").split("\n").map((_line) => {
const line = _line.replace(
/@\w+(?=\s|$)/g,
(match) => this.colorize(match, "greenBright")
).replace(/(@\w+)(\()([^()]*)(\))/g, (_, annotation, openBracket, args2, closeBracket) => {
const content = args2.split(",").map((arg) => {
if (/^\s*"([^"]+)"\s*$/.test(arg)) return this.colorize(arg, "purpleDark");
if (arg.includes(":")) {
const [key, value] = arg.split(":").map((part) => part.trim());
const coloredValue = value.replace(
/\[(.*?)\]/g,
(_2, inner) => `${this.colorize("[", "yellowBright")}${this.colorize(inner, "orange")}${this.colorize("]", "yellowBright")}`
);
return `${this.colorize(key, "yellowBright")}: ${coloredValue}`;
}
return this.colorize(arg, "cyan");
}).join(", ");
return this.colorize(annotation, "yellow") + this.colorize(openBracket, "yellowBold") + content + this.colorize(closeBracket, "yellowBold");
}).replace(/(@\w+)(\s*\(\s*)(.+)(\s*\))/g, (_, annotation, openBracket, value, closeBracket) => {
return this.colorize(annotation, "yellow") + this.colorize(openBracket, "yellowBright") + this.colorize(value, "cyan") + this.colorize(closeBracket, "yellowBright");
}).replace(
/\b(model|enum)\s+([A-Z][a-zA-Z0-9_]*)/g,
(_, keyword, modelName) => `${this.colorize(keyword, "cyanBold")} ${this.colorize(modelName, "purple")}`
).replace(
/\/\/(.*)$/gm,
(_, comment) => this.colorize("// " + comment, "green")
).replace(
/\/\*([\s\S]*?)\*\//g,
(_, content) => this.colorize(`/*${content}*/`, "greenDark")
).replace(/^(\s*\S+)(.*)$/, (match, firstPart, secondPart) => {
if (!secondPart.trim() && !["{", "}"].includes(firstPart.trim())) return this.colorize(match, "cyan");
return firstPart + (secondPart || "").replace(
/(?<!["'])(?<=\s|^)([A-Z][a-zA-Z0-9_]*)(\?)?(\[\])?(?![^()]*\))/g,
(match2, type, optional) => {
const isOptional = optional !== void 0;
if (_PrismaHighlighter.PRISMA_TYPES.has(type)) {
return isOptional ? this.colorize(match2, "gray") : this.colorize(match2, "lightBlue");
} else {
return isOptional ? this.colorize(match2, "lightPurple") : this.colorize(match2, "purple");
}
else if (stat.isFile()) {
// If it's a file, use it directly
schemaPath = resolvedPath;
}
}
if (!schemaPath) {
throw new Error(`❌ Path "${inputPath}" does not point to a valid Prisma schema file or directory.`);
}
}
else {
// If no path is provided, look in standard locations
}
);
});
return line;
}).join("\n").replace(/\b(generator|datasource)\s+(\w+)\s*({)([\s\S]*?)(})/g, (match, blockType, name, openBrace, content, closeBrace) => {
const highlightedContent = content.replace(/\b(provider|output|url)\b/g, (key) => this.colorize(key, "yellowBright")).replace(/"([^"]+)"/g, (_, value) => `"${this.colorize(value, "gray")}"`);
return `${this.colorize(blockType, "greenBright")} ${this.colorize(name, "purple")} ${this.colorize(openBrace, "gray")}${highlightedContent}${this.colorize(closeBrace, "gray")}`;
});
}
};
var highlighter = new PrismaHighlighter();
var highlighter_default = highlighter;
// src/bin.ts
var loadPrismaSchema = async (inputPath) => {
const cwd = process.cwd();
let schemaPath = null;
if (inputPath) {
const resolvedPath = path.isAbsolute(inputPath) ? inputPath : path.resolve(cwd, inputPath);
if (fs.existsSync(resolvedPath)) {
const stat = fs.statSync(resolvedPath);
if (stat.isDirectory()) {
const possibleSchemaPaths = [
path.join(cwd, "prisma", "schema.prisma"),
path.join(cwd, "schema.prisma")
path.join(resolvedPath, "prisma", "schema.prisma"),
path.join(resolvedPath, "schema.prisma")
];
schemaPath = possibleSchemaPaths.find(fs.existsSync) || null;
} else if (stat.isFile()) {
schemaPath = resolvedPath;
}
}
// If no file is found, throw an error
if (!schemaPath) {
throw new Error(`❌ Prisma schema file not found. Try: prismalux --path=[path_to_schema]`);
throw new Error(`\u274C Path "${inputPath}" does not point to a valid Prisma schema file or directory.`);
}
// Read the file
const schemaContent = await fs.promises.readFile(schemaPath, "utf-8");
// Check if it's really a Prisma schema (look for keywords)
if (!/^\s*(generator|datasource|client)\b/m.test(schemaContent)) {
throw new Error(`❌ The file at "${schemaPath}" does not appear to be a valid Prisma schema.`);
} else {
const possibleSchemaPaths = [
path.join(cwd, "prisma", "schema.prisma"),
path.join(cwd, "schema.prisma")
];
schemaPath = possibleSchemaPaths.find(fs.existsSync) || null;
}
if (!schemaPath) {
throw new Error(`\u274C Prisma schema file not found. Try: prismalux --path=[path_to_schema]`);
}
const schemaContent = await fs.promises.readFile(schemaPath, "utf-8");
if (!/^\s*(generator|datasource|client)\b/m.test(schemaContent)) {
throw new Error(`\u274C The file at "${schemaPath}" does not appear to be a valid Prisma schema.`);
}
return { schema: schemaContent, path: schemaPath };
};
var parseArgs = (args2) => {
const options2 = {};
args2.forEach((arg) => {
const match = arg.match(/^--(\w+)(?:=(.+))?$/);
if (match) {
const [, key, value] = match;
options2[key] = value !== void 0 ? value : true;
}
return { schema: schemaContent, path: schemaPath };
});
return options2;
};
// Function to parse CLI arguments
const parseArgs = (args) => {
const options = {};
args.forEach(arg => {
const match = arg.match(/^--(\w+)(?:=(.+))?$/);
if (match) {
const [, key, value] = match;
options[key] = value !== undefined ? value : true;
}
});
return options;
};
// CLI: process.argv
const args = process.argv.slice(2);
const options = parseArgs(args);
// Handling --help and --version flags
var args = process.argv.slice(2);
var options = parseArgs(args);
if (options.help || options.h) {
console.log(`
console.log(`
Usage: prismalux --path=[path_to_schema] [--filter=modelName]

@@ -85,48 +165,50 @@

`);
process.exit(0);
process.exit(0);
}
if (options.version || options.v) {
console.log("Prismalux v0.1.0");
process.exit(0);
console.log("Prismalux v0.1.0");
process.exit(0);
}
// Filtering model/enum
const filterSchemaPart = (schema, filterInput) => {
const filterNames = filterInput.split(/[,| ]+/).map(name => name.trim()).filter(name => name.length > 0);
if (filterNames.length === 0) {
console.error("❌ No valid model or enum names provided.");
return null;
var filterSchemaPart = (schema, filterInput) => {
const filterNames = filterInput.split(/[,| ]+/).map((name) => name.trim()).filter((name) => name.length > 0);
if (filterNames.length === 0) {
console.error("\u274C No valid model or enum names provided.");
return null;
}
let results = [];
for (const filterName of filterNames) {
const regex = new RegExp(`\\b(model|enum)\\s+${filterName}\\s*{[\\s\\S]*?}`, "g");
const match = schema.match(regex);
if (match) {
results.push(...match);
}
let results = [];
for (const filterName of filterNames) {
const regex = new RegExp(`\\b(model|enum)\\s+${filterName}\\s*{[\\s\\S]*?}`, "g");
const match = schema.match(regex);
if (match) {
results.push(...match);
}
}
return results.length > 0 ? results.join("\n\n") : null;
}
return results.length > 0 ? results.join("\n\n") : null;
};
// Loading and rendering Prisma Schema
(async () => {
try {
const filePath = typeof options.path === "string" ? options.path : undefined;
const { schema, path } = await loadPrismaSchema(filePath);
console.log(`\n✨ Highlighting Prisma schema: ${path}\n`);
let schemaToHighlight = schema;
const filter = options?.filter || options?.f;
if (typeof filter === "string") {
const filteredSchema = filterSchemaPart(schema, filter);
if (!filteredSchema) {
console.error(`❌ No model or enum found for "${filter}".`);
process.exit(1);
}
schemaToHighlight = filteredSchema;
}
console.log(highlighter.highlight(schemaToHighlight));
}
catch (error) {
console.error(error instanceof Error ? error.message : "❌ An unknown error occurred.");
try {
const filePath = typeof options.path === "string" ? options.path : void 0;
const { schema, path: path2 } = await loadPrismaSchema(filePath);
console.log(`
\u2728 Highlighting Prisma schema: ${path2}
`);
let schemaToHighlight = schema;
const filter = options?.filter || options?.f;
if (typeof filter === "string") {
const filteredSchema = filterSchemaPart(schema, filter);
if (!filteredSchema) {
console.error(`\u274C No model or enum found for "${filter}".`);
process.exit(1);
}
schemaToHighlight = filteredSchema;
}
console.log(highlighter_default.highlight(schemaToHighlight));
} catch (error) {
console.error(error instanceof Error ? error.message : "\u274C An unknown error occurred.");
process.exit(1);
}
})();
export {
loadPrismaSchema
};
//# sourceMappingURL=bin.js.map
#!/usr/bin/env node
/**
* Prismalux - Prisma Schema Highlighter
* Developed by Artyom Gorlovetskiy (unbywyd)
* Website: https://unbywyd.com
*
* This tool helps you to highlight and filter Prisma schema files directly from the command line.
*/
import { PrismaHighlighter } from "./highlighter.js";
declare const highlighterInstance: PrismaHighlighter;
export default highlighterInstance;
export { PrismaHighlighter };
//# sourceMappingURL=index.d.ts.map
interface HighlightConfig {
enableColors?: boolean;
colors?: Record<string, string>;
}
declare class PrismaHighlighter {
private config;
private static DEFAULT_COLORS;
private static PRISMA_TYPES;
constructor(config?: HighlightConfig);
private colorize;
highlight(schema: string): string;
}
export { type HighlightConfig, PrismaHighlighter };
#!/usr/bin/env node
/**
* Prismalux - Prisma Schema Highlighter
* Developed by Artyom Gorlovetskiy (unbywyd)
* Website: https://unbywyd.com
*
* This tool helps you to highlight and filter Prisma schema files directly from the command line.
*/
import { PrismaHighlighter } from "./highlighter.js";
// Exporting for ESM and CommonJS
const highlighterInstance = new PrismaHighlighter();
export default highlighterInstance;
export { PrismaHighlighter };
// CommonJS export
if (typeof module !== "undefined") {
module.exports = {
PrismaHighlighter,
// src/highlighter.ts
var PrismaHighlighter = class _PrismaHighlighter {
config;
static DEFAULT_COLORS = {
reset: "\x1B[0m",
gray: "\x1B[90m",
whiteBold: "\x1B[1;37m",
cyanBold: "\x1B[1;36m",
purple: "\x1B[38;5;201m",
lightPurple: "\x1B[38;5;177m",
purpleDark: "\x1B[38;5;93m",
darkBlue: "\x1B[38;5;63m",
lightBlue: "\x1B[38;5;111m",
yellow: "\x1B[33m",
yellowBold: "\x1B[1;33m",
yellowBright: "\x1B[93m",
orange: "\x1B[38;5;208m",
green: "\x1B[32m",
greenBright: "\x1B[92m",
cyan: "\x1B[36m",
cyanLight: "\x1B[96m",
greenDark: "\x1B[38;5;22m"
};
static PRISMA_TYPES = /* @__PURE__ */ new Set([
"String",
"Int",
"Boolean",
"DateTime",
"Json",
"Float",
"Decimal",
"BigInt",
"Bytes"
]);
constructor(config = {}) {
this.config = {
enableColors: config.enableColors ?? true,
colors: { ..._PrismaHighlighter.DEFAULT_COLORS, ...config.colors }
};
}
}
colorize(text, color) {
if (!this.config.enableColors) return text;
return `${this.config.colors[color] || ""}${text}${this.config.colors.reset}`;
}
highlight(schema) {
return schema.replace(/\r\n/g, "\n").split("\n").map((_line) => {
const line = _line.replace(
/@\w+(?=\s|$)/g,
(match) => this.colorize(match, "greenBright")
).replace(/(@\w+)(\()([^()]*)(\))/g, (_, annotation, openBracket, args, closeBracket) => {
const content = args.split(",").map((arg) => {
if (/^\s*"([^"]+)"\s*$/.test(arg)) return this.colorize(arg, "purpleDark");
if (arg.includes(":")) {
const [key, value] = arg.split(":").map((part) => part.trim());
const coloredValue = value.replace(
/\[(.*?)\]/g,
(_2, inner) => `${this.colorize("[", "yellowBright")}${this.colorize(inner, "orange")}${this.colorize("]", "yellowBright")}`
);
return `${this.colorize(key, "yellowBright")}: ${coloredValue}`;
}
return this.colorize(arg, "cyan");
}).join(", ");
return this.colorize(annotation, "yellow") + this.colorize(openBracket, "yellowBold") + content + this.colorize(closeBracket, "yellowBold");
}).replace(/(@\w+)(\s*\(\s*)(.+)(\s*\))/g, (_, annotation, openBracket, value, closeBracket) => {
return this.colorize(annotation, "yellow") + this.colorize(openBracket, "yellowBright") + this.colorize(value, "cyan") + this.colorize(closeBracket, "yellowBright");
}).replace(
/\b(model|enum)\s+([A-Z][a-zA-Z0-9_]*)/g,
(_, keyword, modelName) => `${this.colorize(keyword, "cyanBold")} ${this.colorize(modelName, "purple")}`
).replace(
/\/\/(.*)$/gm,
(_, comment) => this.colorize("// " + comment, "green")
).replace(
/\/\*([\s\S]*?)\*\//g,
(_, content) => this.colorize(`/*${content}*/`, "greenDark")
).replace(/^(\s*\S+)(.*)$/, (match, firstPart, secondPart) => {
if (!secondPart.trim() && !["{", "}"].includes(firstPart.trim())) return this.colorize(match, "cyan");
return firstPart + (secondPart || "").replace(
/(?<!["'])(?<=\s|^)([A-Z][a-zA-Z0-9_]*)(\?)?(\[\])?(?![^()]*\))/g,
(match2, type, optional) => {
const isOptional = optional !== void 0;
if (_PrismaHighlighter.PRISMA_TYPES.has(type)) {
return isOptional ? this.colorize(match2, "gray") : this.colorize(match2, "lightBlue");
} else {
return isOptional ? this.colorize(match2, "lightPurple") : this.colorize(match2, "purple");
}
}
);
});
return line;
}).join("\n").replace(/\b(generator|datasource)\s+(\w+)\s*({)([\s\S]*?)(})/g, (match, blockType, name, openBrace, content, closeBrace) => {
const highlightedContent = content.replace(/\b(provider|output|url)\b/g, (key) => this.colorize(key, "yellowBright")).replace(/"([^"]+)"/g, (_, value) => `"${this.colorize(value, "gray")}"`);
return `${this.colorize(blockType, "greenBright")} ${this.colorize(name, "purple")} ${this.colorize(openBrace, "gray")}${highlightedContent}${this.colorize(closeBrace, "gray")}`;
});
}
};
var highlighter = new PrismaHighlighter();
export {
PrismaHighlighter
};
//# sourceMappingURL=index.js.map
{
"name": "prismalux",
"version": "0.1.2",
"version": "0.1.3",
"description": "✨ A lightweight Prisma Schema Highlighter for CLI & Node.js. Works with CommonJS and ES Modules.",

@@ -10,21 +10,17 @@ "type": "module",

},
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"clean": "rm -rf output"
},
"exports": {
"import": "./output/esm/index.js",
"require": "./output/cjs/index.js"
"require": "./output/cjs/index.cjs"
},
"main": "./output/index.js",
"main": "./output/cjs/index.cjs",
"module": "./output/esm/index.js",
"types": "./output/index.d.ts",
"types": "./output/esm/index.d.ts",
"bin": {
"prismalux": "./output/bin.js"
},
"scripts": {
"prepare:dirs": "node -e \"require('fs').mkdirSync('output/cjs', { recursive: true }); require('fs').mkdirSync('output/esm', { recursive: true });\"",
"build": "npm run prepare:dirs && npm run build:cjs && npm run build:esm && npm run build:bin",
"build:cjs": "tsc --project tsconfig.cjs.json",
"build:esm": "tsc --project tsconfig.esm.json",
"build:bin": "tsc",
"dev": "tsc -w",
"clean": "rm -rf output"
},
"author": {

@@ -60,4 +56,5 @@ "name": "Artyom Gorlovetskiy",

"devDependencies": {
"typescript": "^5.7.2",
"@types/node": "^22.10.10"
"@types/node": "^22.10.10",
"tsup": "^8.4.0",
"typescript": "^5.7.2"
},

@@ -64,0 +61,0 @@ "files": [

@@ -8,5 +8,9 @@ # Prismalux 🌓 - A **Zero-Dependency** Prisma Schema Highlighter

💡 **Prismalux is minimalistic, fast, and does not require any dependencies**—pure **TypeScript + Node.js**.
🔍 You can also highlight a specific **model** or **enum** using the `--filter=` option.
## Just run it with npx:
```sh
npx prismalux
```
---

@@ -20,2 +24,3 @@

✔ **Filter a specific model or enum** using `--filter=User`
✔ **ESM & CommonJS** support

@@ -62,2 +67,3 @@ ---

```
```sh

@@ -136,3 +142,4 @@ prismalux --filter=User,Role

```typescript
import PrismaHighlighter from "prismalux";
import { PrismaHighlighter } from "prismalux";
const highlighter = new PrismaHighlighter();

@@ -148,3 +155,3 @@ const schema = `

console.log(PrismaHighlighter.highlight(schema));
console.log(highlighter.highlight(schema));
```

@@ -154,6 +161,7 @@

Similar to ESM
```javascript
const { PrismaHighlighter, highlight } = require("prismalux");
console.log(highlight(schema));
import { PrismaHighlighter } from "prismalux"; // or require("prismalux")
const highlighter = new PrismaHighlighter();
```

@@ -160,0 +168,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet