File size: 1,330 Bytes
302ab7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
'use strict';

const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

const ROOT = path.join(__dirname, '..');
const SPACE_YML = path.join(ROOT, '.huggingface', 'space.yml');
const README = path.join(ROOT, 'README.md');

function run(cmd) {
  console.log(`> ${cmd}`);
  return execSync(cmd, { stdio: 'inherit', cwd: ROOT });
}

async function main() {
  console.log('Syncing to Hugging Face Space...');

  if (!fs.existsSync(SPACE_YML)) {
    console.error('Error: .huggingface/space.yml not found');
    process.exit(1);
  }

  // 1. Create the HF version of README
  const metadata = fs.readFileSync(SPACE_YML, 'utf8');
  const content = fs.readFileSync(README, 'utf8');
  fs.writeFileSync(README, metadata + '\n' + content);

  try {
    // 2. Commit and Push
    run('git add README.md');
    run('git commit -m "chore: sync to Hugging Face with metadata [skip ci]"');
    run('git push hf main --force');
    console.log('\n✓ Successfully pushed to Hugging Face Space.');
  } catch (err) {
    console.error('\n✗ Failed to push to Hugging Face.');
  } finally {
    // 3. Revert the local commit and README change
    console.log('\nRestoring local README...');
    run('git reset --hard HEAD~1');
  }
}

main().catch(err => {
  console.error(err);
  process.exit(1);
});