repomix
Version:
A tool to pack repository contents to single file for AI consumption
162 lines (161 loc) • 3.27 kB
JavaScript
import Handlebars from 'handlebars';
const extensionToLanguageMap = {
js: 'javascript',
mjs: 'javascript',
cjs: 'javascript',
jsx: 'javascript',
ts: 'typescript',
mts: 'typescript',
cts: 'typescript',
tsx: 'typescript',
vue: 'vue',
svelte: 'svelte',
astro: 'astro',
py: 'python',
pyw: 'python',
pyi: 'python',
rb: 'ruby',
erb: 'erb',
java: 'java',
kt: 'kotlin',
kts: 'kotlin',
scala: 'scala',
groovy: 'groovy',
clj: 'clojure',
cljs: 'clojure',
cljc: 'clojure',
c: 'c',
h: 'c',
cpp: 'cpp',
cc: 'cpp',
cxx: 'cpp',
hpp: 'cpp',
hxx: 'cpp',
m: 'objectivec',
mm: 'objectivec',
cs: 'csharp',
fs: 'fsharp',
fsx: 'fsharp',
fsi: 'fsharp',
vb: 'vb',
cshtml: 'razor',
razor: 'razor',
go: 'go',
rs: 'rust',
swift: 'swift',
php: 'php',
dart: 'dart',
haml: 'haml',
slim: 'slim',
hs: 'haskell',
lhs: 'haskell',
ex: 'elixir',
exs: 'elixir',
erl: 'erlang',
hrl: 'erlang',
ml: 'ocaml',
mli: 'ocaml',
elm: 'elm',
r: 'r',
R: 'r',
jl: 'julia',
nim: 'nim',
zig: 'zig',
v: 'v',
lua: 'lua',
pl: 'perl',
pm: 'perl',
raku: 'raku',
sh: 'bash',
bash: 'bash',
zsh: 'zsh',
fish: 'fish',
ps1: 'powershell',
psm1: 'powershell',
bat: 'batch',
cmd: 'batch',
awk: 'awk',
html: 'html',
htm: 'html',
xhtml: 'html',
css: 'css',
scss: 'scss',
sass: 'sass',
less: 'less',
styl: 'stylus',
json: 'json',
json5: 'json5',
jsonc: 'json',
xml: 'xml',
xsl: 'xml',
xslt: 'xml',
svg: 'xml',
yaml: 'yaml',
yml: 'yaml',
toml: 'toml',
ini: 'ini',
cfg: 'ini',
conf: 'ini',
md: 'markdown',
mdx: 'markdown',
rst: 'rst',
tex: 'latex',
latex: 'latex',
sql: 'sql',
prisma: 'prisma',
dockerfile: 'dockerfile',
tf: 'hcl',
tfvars: 'hcl',
hcl: 'hcl',
nix: 'nix',
nginx: 'nginx',
apacheconf: 'apacheconf',
cmake: 'cmake',
makefile: 'makefile',
mk: 'makefile',
glsl: 'glsl',
vert: 'glsl',
frag: 'glsl',
wgsl: 'wgsl',
hlsl: 'hlsl',
vhdl: 'vhdl',
vhd: 'vhdl',
sol: 'solidity',
asm: 'asm',
s: 'asm',
hbs: 'handlebars',
handlebars: 'handlebars',
mustache: 'handlebars',
ejs: 'ejs',
jinja: 'jinja',
jinja2: 'jinja',
j2: 'jinja',
liquid: 'liquid',
njk: 'nunjucks',
pug: 'pug',
jade: 'pug',
twig: 'twig',
graphql: 'graphql',
gql: 'graphql',
proto: 'protobuf',
coffee: 'coffeescript',
vim: 'vim',
diff: 'diff',
patch: 'diff',
wasm: 'wasm',
wat: 'wasm',
};
export const getLanguageFromFilePath = (filePath) => {
const extension = filePath.split('.').pop()?.toLowerCase();
return extension ? extensionToLanguageMap[extension] || '' : '';
};
let handlebarsHelpersRegistered = false;
export const registerHandlebarsHelpers = () => {
if (handlebarsHelpersRegistered) {
return;
}
Handlebars.registerHelper('getFileExtension', (filePath) => {
return getLanguageFromFilePath(filePath);
});
handlebarsHelpersRegistered = true;
};