feat(new tool): Gitattributes Generator

Fix #244
This commit is contained in:
ShareVB committed 2026-01-01 23:04:23 +01:00
1 parent 4351e57075
commit 1cafdfa9ad
2 files changed
+118

No files matched your search

@@ -0,0 +1,105 @@
<script setup lang="ts">
import { onMounted } from 'vue';
import { useLocalStorage } from '@vueuse/core';
const options = useLocalStorage<{ label: string; value: string }[]>('gitattr-gen:opts', []);
const selected = ref<string[]>([]);
const output = ref<string>('');
// Timestamp cache to allow refresh after X hours
const lastFetched = useLocalStorage<number>('gitattr-gen:ts', 0);
const CACHE_TTL = 1000 * 60 * 60 * 24; // 24h
async function loadOptions() {
const now = Date.now();
const isStale = !options.value.length || (now - lastFetched.value > CACHE_TTL);
if (!isStale) {
// Use cached options
return;
}
const res = await fetch('https://api.github.com/repos/alexkaratarakis/gitattributes/contents');
const files = await res.json();
options.value = files
.filter((f: any) => f.name.endsWith('.gitattributes'))
.map((f: any) => f.name.replace('.gitattributes', ''))
.filter(Boolean)
.map((name: string) => ({
label: name,
value: name,
}));
lastFetched.value = now;
}
async function generateOutput() {
let gitattributes = '';
for (const lang of selected.value) {
const url = `https://raw.githubusercontent.com/alexkaratarakis/gitattributes/master/${lang}.gitattributes`;
const res = await fetch(url);
const text = await res.text();
gitattributes += `${gitattributes ? '\n\n' : ''}# === .gitattributes for ${lang} (${url}) ===\n\n${text}`;
}
output.value = gitattributes;
}
// Multi-command generation
const commands = computed(() => {
if (!selected.value.length) {
return {};
}
const urls = selected.value
.map(lang => `https://raw.githubusercontent.com/alexkaratarakis/gitattributes/master/${lang}.gitattributes`)
.join(' ');
return {
curl: `curl ${urls} > .gitattributes`,
wget: `wget ${urls} -O .gitattributes`,
powershell: `Invoke-WebRequest ${urls} -OutFile .gitattributes`,
cmd: `powershell -Command "Invoke-WebRequest ${urls} -OutFile .gitattributes"`,
};
});
onMounted(loadOptions);
</script>
<template>
<div>
<n-form-item label="Gitattributes Templates:" label-placement="left">
<NSelect
v-model:value="selected"
multiple
filterable
placeholder="Select templates"
:options="options"
/>
</n-form-item>
<n-space justify="center" mb-2>
<NButton type="primary" :disabled="!selected.length" @click="generateOutput">
Fetch & Generate
</NButton>
</n-space>
<c-card v-if="output" title="Preview" mb-2>
<textarea-copyable
:value="output"
language="bash"
download-file-name=".gitattributes"
download-button-text="Download .gitattributes"
/>
</c-card>
<NTabs v-if="output" type="line" animated>
<NTabPane name="curl" tab="Curl">
<textarea-copyable :value="commands.curl" word-wrap />
</NTabPane>
<NTabPane name="wget" tab="Wget">
<textarea-copyable :value="commands.wget" word-wrap />
</NTabPane>
<NTabPane name="powershell" tab="PowerShell">
<textarea-copyable :value="commands.powershell" word-wrap />
</NTabPane>
<NTabPane name="cmd" tab="Windows CMD">
<textarea-copyable :value="commands.cmd" word-wrap />
</NTabPane>
</NTabs>
</div>
</template>
@@ -0,0 +1,13 @@
import { BrandGit } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Gitattributes Generator',
path: '/gitattributes-generator',
description: 'Generate .gitattributes from common configuration of https://github.com/alexkaratarakis/gitattributes',
keywords: ['gitattributes', 'generator'],
component: () => import('./gitattributes-generator.vue'),
icon: BrandGit,
createdAt: new Date('2026-01-01'),
category: 'Development',
});