Spaces:
Paused
Paused
File size: 1,901 Bytes
c62de68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | import fs from 'fs';
import path from 'path';
const TOKEN = process.env.HF_TOKEN || "hf_TOKEN_PLACEHOLDER";
const REPO = "dimensionalpulsar/caja";
const IGNORE_FILES = ['.git', 'node_modules', 'dist', '.env'];
function getFiles(dir, baseDir = dir) {
let results = [];
const list = fs.readdirSync(dir);
list.forEach(file => {
if (IGNORE_FILES.includes(file)) return;
const fullPath = path.join(dir, file);
const stat = fs.statSync(fullPath);
if (stat && stat.isDirectory()) {
results = results.concat(getFiles(fullPath, baseDir));
} else {
const relativePath = path.relative(baseDir, fullPath).replace(/\\/g, '/');
results.push({ fullPath, relativePath });
}
});
return results;
}
async function doPush() {
console.log(`Starting push to Hugging Face Space: ${REPO}...`);
const projectDir = process.cwd();
const files = getFiles(projectDir);
const operations = [];
for (const file of files) {
const buffer = fs.readFileSync(file.fullPath);
operations.push({
action: "addOrUpdate",
path: file.relativePath,
content: buffer.toString('base64'),
encoding: "base64"
});
}
const commitUrl = `https://huggingface.co/api/spaces/${REPO}/commit/main`;
try {
const response = await fetch(commitUrl, {
method: "POST",
headers: {
"Authorization": `Bearer ${TOKEN}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
summary: "Push PrestaCaja React System to Hugging Face Space",
operations: operations
})
});
const text = await response.text();
if (response.ok) {
console.log("✅ SUCCESS! Project successfully pushed to Hugging Face.");
} else {
console.error("❌ Push failed:", response.status, text);
}
} catch (err) {
console.error("❌ Network or API error:", err);
}
}
doPush();
|