🆙 Add cms i using 🆙

This commit is contained in:
Remco
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
@@ -0,0 +1,38 @@
import { parse } from "./parser";
import { print } from "./printer";
import { options, defaultOptions } from "./options";
import { Parser, Printer, SupportLanguage } from "prettier";
export const languages: SupportLanguage[] = [
{
name: "Blade",
parsers: ["blade"],
since: "1.0.0",
extensions: [".blade.php"],
tmScope: "source.blade.php",
aceMode: "text",
linguistLanguageId: 33,
vscodeLanguageIds: ["blade"],
},
];
export const parsers: { [k: string]: Parser } = {
blade: {
parse,
astFormat: "blade-format",
locStart(node: any) {
return node.start;
},
locEnd(node: any) {
return node.end;
},
},
};
export const printers: { [k: string]: Printer } = {
"blade-format": {
print,
},
};
export { options, defaultOptions };
@@ -0,0 +1,58 @@
export const defaultOptions = {
tabWidth: 4,
printWidth: 120,
};
export const options = {
wrapAttributes: {
type: "string",
category: "Blade",
default: "auto",
description:
"The way to wrap attributes. [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned]",
since: "1.0.0",
},
endWithNewLine: {
type: "boolean",
category: "Blade",
default: true,
description: "End output with newline.",
since: "1.0.0",
},
sortTailwindcssClasses: {
type: "boolean",
category: "Blade",
default: false,
description: "Sort Tailwindcss classes automatically. This option respects `tailwind.config.js`.",
since: "1.0.0",
},
tailwindcssConfigPath: {
type: "string",
category: "Blade",
default: '',
description: "Path to custom Tailwindcss config. This option is available only when `sortTailwindcssClasses` is present.",
since: "1.5.7",
},
sortHtmlAttributes: {
type: "string",
category: "Blade",
default: "none",
description: "Sort HTML Attributes. [none|alphabetical|code-guide|idiomatic|vuejs|custom]",
since: "1.5.0",
},
customHtmlAttributesOrder: {
type: "string",
category: "Blade",
default: "",
description: "Comma separated custom HTML attributes order. e.g. \"id, aria-.+, class, src\". To enable this you must specify sort html attributes option as `custom`. You can use regex for attribute names.",
since: "1.8.0",
},
noPhpSyntaxCheck: {
type: "boolean",
category: "Blade",
default: false,
description: "Disable PHP syntax checking",
since: "1.7.0",
},
};
@@ -0,0 +1,49 @@
import { Parser, ParserOptions, resolveConfigFile } from "prettier";
import { FormatterOption } from "blade-formatter";
import { createSyncFn } from "synckit";
import path from 'path';
export const parse = (
text: string,
parsers: { [parserName: string]: Parser },
opts: ParserOptions & FormatterOption
) => {
const formatterOptions: FormatterOption = {
indentSize: opts.tabWidth,
wrapLineLength: opts.printWidth,
wrapAttributes: opts.singleAttributePerLine ? 'force-expand-multiline' : opts.bracketSameLine ? 'force-aligned' : opts.wrapAttributes,
endWithNewline: opts.endWithNewline,
useTabs: opts.useTabs,
sortTailwindcssClasses: opts.sortTailwindcssClasses,
tailwindcssConfigPath: resolveTailwindConfigPath(opts.filepath, opts.tailwindcssConfigPath),
sortHtmlAttributes: opts.sortHtmlAttributes,
noMultipleEmptyLines: true,
noPhpSyntaxCheck: opts.noPhpSyntaxCheck,
customHtmlAttributesOrder: opts.customHtmlAttributesOrder,
};
const syncFn = createSyncFn(require.resolve("./worker"));
const result = syncFn(text, formatterOptions);
return {
type: "blade-formatter",
body: result,
end: text.length,
source: text,
start: 0,
};
};
function resolveTailwindConfigPath(filepath: string | undefined, optionPath: string | undefined): string | undefined {
if (!optionPath) {
return;
}
if (path.isAbsolute(optionPath ?? '')) {
return optionPath;
}
const prettierRcPath = resolveConfigFile.sync(filepath);
return path.resolve(path.dirname(prettierRcPath ?? ''), optionPath ?? '')
}
@@ -0,0 +1,13 @@
import { AstPath, Doc } from "prettier";
export const print = (path: AstPath): Doc => {
const node = path.getValue();
switch (node.type) {
case "blade-formatter": {
return node.body;
}
}
throw new Error(`Unknown node type: ${node.type}`);
};
@@ -0,0 +1,7 @@
const { runAsWorker } = require("synckit");
const { BladeFormatter } = require("blade-formatter");
runAsWorker(async (text, options) => {
const result = await new BladeFormatter(options).format(text);
return result;
});