Comparing version
@@ -10,6 +10,2 @@ #!/usr/bin/env node | ||
import { PrismaHighlighter } from "./highlighter.js"; | ||
export declare const loadPrismaSchema: (inputPath?: string) => Promise<{ | ||
schema: string; | ||
path: string; | ||
}>; | ||
declare const highlighterInstance: PrismaHighlighter; | ||
@@ -16,0 +12,0 @@ export default highlighterInstance; |
@@ -10,164 +10,6 @@ #!/usr/bin/env node | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PrismaHighlighter = exports.loadPrismaSchema = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const highlighter_js_1 = __importStar(require("./highlighter.js")); | ||
exports.PrismaHighlighter = void 0; | ||
const highlighter_js_1 = require("./highlighter.js"); | ||
Object.defineProperty(exports, "PrismaHighlighter", { enumerable: true, get: function () { return highlighter_js_1.PrismaHighlighter; } }); | ||
// Function to load Prisma Schema | ||
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_1.default.isAbsolute(inputPath) ? inputPath : path_1.default.resolve(cwd, inputPath); | ||
if (fs_1.default.existsSync(resolvedPath)) { | ||
const stat = fs_1.default.statSync(resolvedPath); | ||
if (stat.isDirectory()) { | ||
// If it's a directory, look for `schema.prisma` | ||
const possibleSchemaPaths = [ | ||
path_1.default.join(resolvedPath, "prisma", "schema.prisma"), | ||
path_1.default.join(resolvedPath, "schema.prisma") | ||
]; | ||
schemaPath = possibleSchemaPaths.find(fs_1.default.existsSync) || null; | ||
} | ||
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 | ||
const possibleSchemaPaths = [ | ||
path_1.default.join(cwd, "prisma", "schema.prisma"), | ||
path_1.default.join(cwd, "schema.prisma") | ||
]; | ||
schemaPath = possibleSchemaPaths.find(fs_1.default.existsSync) || null; | ||
} | ||
// If no file is found, throw an error | ||
if (!schemaPath) { | ||
throw new Error(`❌ Prisma schema file not found. Try: prismalux --path=[path_to_schema]`); | ||
} | ||
// Read the file | ||
const schemaContent = await fs_1.default.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.`); | ||
} | ||
return { schema: schemaContent, path: schemaPath }; | ||
}; | ||
exports.loadPrismaSchema = loadPrismaSchema; | ||
// 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 | ||
if (options.help || options.h) { | ||
console.log(` | ||
Usage: prismalux --path=[path_to_schema] [--filter=modelName] | ||
Options: | ||
--help, -h Show this help message | ||
--version, -v Show the installed version | ||
--path=[path] Specify a Prisma schema file (default: ./prisma/schema.prisma) | ||
--filter=[name], --f Highlight only the specified model or enum | ||
`); | ||
process.exit(0); | ||
} | ||
if (options.version || options.v) { | ||
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; | ||
} | ||
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; | ||
}; | ||
// Loading and rendering Prisma Schema | ||
(async () => { | ||
try { | ||
const filePath = typeof options.path === "string" ? options.path : undefined; | ||
const { schema, path } = await (0, exports.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_js_1.default.highlight(schemaToHighlight)); | ||
} | ||
catch (error) { | ||
console.error(error instanceof Error ? error.message : "❌ An unknown error occurred."); | ||
process.exit(1); | ||
} | ||
})(); | ||
// Exporting for ESM and CommonJS | ||
@@ -180,6 +22,4 @@ const highlighterInstance = new highlighter_js_1.PrismaHighlighter(); | ||
PrismaHighlighter: highlighter_js_1.PrismaHighlighter, | ||
highlight: highlighterInstance.highlight.bind(highlighterInstance), | ||
loadPrismaSchema: exports.loadPrismaSchema | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -10,6 +10,2 @@ #!/usr/bin/env node | ||
import { PrismaHighlighter } from "./highlighter.js"; | ||
export declare const loadPrismaSchema: (inputPath?: string) => Promise<{ | ||
schema: string; | ||
path: string; | ||
}>; | ||
declare const highlighterInstance: PrismaHighlighter; | ||
@@ -16,0 +12,0 @@ export default highlighterInstance; |
@@ -9,124 +9,3 @@ #!/usr/bin/env node | ||
*/ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import highlighter, { PrismaHighlighter } 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; | ||
} | ||
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 | ||
const possibleSchemaPaths = [ | ||
path.join(cwd, "prisma", "schema.prisma"), | ||
path.join(cwd, "schema.prisma") | ||
]; | ||
schemaPath = possibleSchemaPaths.find(fs.existsSync) || null; | ||
} | ||
// If no file is found, throw an error | ||
if (!schemaPath) { | ||
throw new Error(`❌ Prisma schema file not found. Try: prismalux --path=[path_to_schema]`); | ||
} | ||
// 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.`); | ||
} | ||
return { schema: schemaContent, path: schemaPath }; | ||
}; | ||
// 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 | ||
if (options.help || options.h) { | ||
console.log(` | ||
Usage: prismalux --path=[path_to_schema] [--filter=modelName] | ||
Options: | ||
--help, -h Show this help message | ||
--version, -v Show the installed version | ||
--path=[path] Specify a Prisma schema file (default: ./prisma/schema.prisma) | ||
--filter=[name], --f Highlight only the specified model or enum | ||
`); | ||
process.exit(0); | ||
} | ||
if (options.version || options.v) { | ||
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; | ||
} | ||
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; | ||
}; | ||
// 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."); | ||
process.exit(1); | ||
} | ||
})(); | ||
import { PrismaHighlighter } from "./highlighter.js"; | ||
// Exporting for ESM and CommonJS | ||
@@ -140,6 +19,4 @@ const highlighterInstance = new PrismaHighlighter(); | ||
PrismaHighlighter, | ||
highlight: highlighterInstance.highlight.bind(highlighterInstance), | ||
loadPrismaSchema | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -10,6 +10,2 @@ #!/usr/bin/env node | ||
import { PrismaHighlighter } from "./highlighter.js"; | ||
export declare const loadPrismaSchema: (inputPath?: string) => Promise<{ | ||
schema: string; | ||
path: string; | ||
}>; | ||
declare const highlighterInstance: PrismaHighlighter; | ||
@@ -16,0 +12,0 @@ export default highlighterInstance; |
@@ -9,124 +9,3 @@ #!/usr/bin/env node | ||
*/ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import highlighter, { PrismaHighlighter } 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; | ||
} | ||
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 | ||
const possibleSchemaPaths = [ | ||
path.join(cwd, "prisma", "schema.prisma"), | ||
path.join(cwd, "schema.prisma") | ||
]; | ||
schemaPath = possibleSchemaPaths.find(fs.existsSync) || null; | ||
} | ||
// If no file is found, throw an error | ||
if (!schemaPath) { | ||
throw new Error(`❌ Prisma schema file not found. Try: prismalux --path=[path_to_schema]`); | ||
} | ||
// 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.`); | ||
} | ||
return { schema: schemaContent, path: schemaPath }; | ||
}; | ||
// 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 | ||
if (options.help || options.h) { | ||
console.log(` | ||
Usage: prismalux --path=[path_to_schema] [--filter=modelName] | ||
Options: | ||
--help, -h Show this help message | ||
--version, -v Show the installed version | ||
--path=[path] Specify a Prisma schema file (default: ./prisma/schema.prisma) | ||
--filter=[name], --f Highlight only the specified model or enum | ||
`); | ||
process.exit(0); | ||
} | ||
if (options.version || options.v) { | ||
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; | ||
} | ||
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; | ||
}; | ||
// 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."); | ||
process.exit(1); | ||
} | ||
})(); | ||
import { PrismaHighlighter } from "./highlighter.js"; | ||
// Exporting for ESM and CommonJS | ||
@@ -140,6 +19,4 @@ const highlighterInstance = new PrismaHighlighter(); | ||
PrismaHighlighter, | ||
highlight: highlighterInstance.highlight.bind(highlighterInstance), | ||
loadPrismaSchema | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "prismalux", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "✨ A lightweight Prisma Schema Highlighter for CLI & Node.js. Works with CommonJS and ES Modules.", | ||
@@ -14,13 +14,14 @@ "type": "module", | ||
}, | ||
"main": "./output/cjs/index.js", | ||
"main": "./output/index.js", | ||
"module": "./output/esm/index.js", | ||
"types": "./output/index.d.ts", | ||
"bin": { | ||
"prismalux": "./output/index.js" | ||
"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", | ||
"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", | ||
@@ -45,2 +46,5 @@ "clean": "rm -rf output" | ||
"prisma", | ||
"prisma-highlight", | ||
"prisma-schema", | ||
"prisma-schema-highlighter", | ||
"prisma-highlighter", | ||
@@ -57,3 +61,4 @@ "syntax-highlighting", | ||
"devDependencies": { | ||
"typescript": "^5.7.2" | ||
"typescript": "^5.7.2", | ||
"@types/node": "^22.10.10" | ||
}, | ||
@@ -60,0 +65,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
72796
1.17%39
44.44%764
2%2
100%1
Infinity%