Spaces:
Running
Running
Rifza111
commited on
Commit
·
c5bf270
1
Parent(s):
7d4d1bf
up
Browse files
up.js
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
require('dotenv/config')
|
2 |
+
const { exec } = require('child_process');
|
3 |
+
|
4 |
+
const readline = require("readline")
|
5 |
+
const { promisify } = require('util')
|
6 |
+
|
7 |
+
const rl = readline.createInterface({
|
8 |
+
input: process.stdin,
|
9 |
+
output: process.stdout
|
10 |
+
});
|
11 |
+
const execPromise = promisify(exec);
|
12 |
+
|
13 |
+
|
14 |
+
const execute = (command) => {
|
15 |
+
return execPromise(command).then(({ stdout, stderr }) => {
|
16 |
+
if (stderr) {
|
17 |
+
console.warn(`Stderr: ${stderr}`);
|
18 |
+
}
|
19 |
+
return stdout;
|
20 |
+
}).catch((error) => {
|
21 |
+
throw new Error(`Error: ${error.message}`);
|
22 |
+
});
|
23 |
+
};
|
24 |
+
|
25 |
+
const push = async (username) => {
|
26 |
+
try {
|
27 |
+
const token = process.env.TOKEN;
|
28 |
+
const repoUrl = "huggingface.co/spaces/"+username+"/"+process.env.REPO_NAME
|
29 |
+
|
30 |
+
await execute('git add .');
|
31 |
+
console.log(await execute('git status'));
|
32 |
+
|
33 |
+
const question = (text) => new Promise((resolve) => rl.question(text, resolve));
|
34 |
+
const info = await question("Commit Info: ");
|
35 |
+
console.log(await execute(`git commit -m "${info}"`));
|
36 |
+
console.log(await execute('git branch -M main'));
|
37 |
+
console.log(await execute(`git push https://${username}:${token}@${repoUrl} main --force`));
|
38 |
+
console.log('Commands executed successfully');
|
39 |
+
return
|
40 |
+
} catch (error) {
|
41 |
+
console.error(`Failed to execute commands: ${error}`);
|
42 |
+
}
|
43 |
+
};
|
44 |
+
|
45 |
+
push("termai")
|
46 |
+
.then(()=> process.exit())
|