Spaces:
Runtime error
Runtime error
Update ftp-upload.js
Browse files- ftp-upload.js +19 -49
ftp-upload.js
CHANGED
@@ -1,53 +1,23 @@
|
|
1 |
-
|
2 |
-
const fs = require("fs");
|
3 |
-
const ftp = require("basic-ftp");
|
4 |
const path = require("path");
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
if (!user || !password) {
|
12 |
-
console.error("環境変数 'FTPname' または 'FTPpsw' が設定されていません。");
|
13 |
-
return;
|
14 |
-
}
|
15 |
-
|
16 |
-
const client = new ftp.Client();
|
17 |
-
client.ftp.verbose = true;
|
18 |
-
client.ftp.timeout = 300000;
|
19 |
-
|
20 |
-
const localDist = path.join(__dirname, "dist");
|
21 |
-
if (!fs.existsSync(localDist)) {
|
22 |
-
console.error(`❌ 'dist' フォルダが存在しません: ${localDist}`);
|
23 |
-
return;
|
24 |
-
}
|
25 |
-
|
26 |
-
try {
|
27 |
-
console.log("FTPアップロードを開始します...");
|
28 |
-
console.log(`接続中: ${host}(ユーザー: ${user})`);
|
29 |
-
await client.access({
|
30 |
-
host,
|
31 |
-
user,
|
32 |
-
password,
|
33 |
-
secure: false,
|
34 |
-
});
|
35 |
-
console.log("接続に成功しました。");
|
36 |
-
|
37 |
-
const remoteDir = "s4s-editor.ct.ws/htdocs/";
|
38 |
-
await client.ensureDir(remoteDir);
|
39 |
-
await client.clearWorkingDir();
|
40 |
-
|
41 |
-
console.log(`ローカルの 'dist' ディレクトリをアップロード中: ${localDist}`);
|
42 |
-
await client.uploadFromDir(localDist);
|
43 |
-
console.log("✅ アップロードが完了しました!");
|
44 |
-
} catch (err) {
|
45 |
-
console.error("❌ アップロード中にエラーが発生しました:");
|
46 |
-
console.error(err);
|
47 |
-
} finally {
|
48 |
-
client.close();
|
49 |
-
console.log("FTP接続を閉じました。");
|
50 |
-
}
|
51 |
}
|
52 |
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { execSync } = require("child_process");
|
|
|
|
|
2 |
const path = require("path");
|
3 |
|
4 |
+
const token = process.env["sc4sc_token"];
|
5 |
+
if (!token) {
|
6 |
+
console.error("環境変数 'sc4sc_token' が設定されていません。");
|
7 |
+
process.exit(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
}
|
9 |
|
10 |
+
const repoPath = path.join(__dirname, "dist");
|
11 |
+
const remoteUrl = `https://user:${token}@huggingface.co/spaces/soiz1/simple-editor`;
|
12 |
+
console.log("接続完了!...");
|
13 |
+
try {
|
14 |
+
console.log("Git リポジトリを初期化...");
|
15 |
+
execSync("git init", { cwd: repoPath });
|
16 |
+
execSync(`git remote add origin ${remoteUrl}`, { cwd: repoPath });
|
17 |
+
execSync("git add .", { cwd: repoPath });
|
18 |
+
execSync('git commit -m "Automated deploy"', { cwd: repoPath });
|
19 |
+
execSync("git push -f origin master", { cwd: repoPath }); // -f で強制上書き
|
20 |
+
console.log("✅ アップロードが完了しました!");
|
21 |
+
} catch (err) {
|
22 |
+
console.error("❌ アップロードに失敗しました:", err.message);
|
23 |
+
}
|