-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
63 lines (49 loc) · 1.89 KB
/
Copy pathdeploy.js
File metadata and controls
63 lines (49 loc) · 1.89 KB
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
// deploy.js
import { execSync } from "child_process";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const repoUrl = "https://github.com/stakco/stakco.github.io.git"; // GitHub Pages repo
const branch = "gh-pages";
const subDir = "kiwrious"; // where to copy inside gh-pages
const sourceDir = path.join(__dirname, "lib"); // your static folder
const tempDir = path.join(__dirname, "gh-pages");
try {
console.log("🚀 Starting deployment...");
// Clean up old clone if exists
if (fs.existsSync(tempDir)) {
fs.rmSync(tempDir, { recursive: true, force: true });
}
// Shallow + sparse clone only the gh-pages branch
execSync(
`git clone --depth 1 --filter=blob:none --sparse --branch ${branch} ${repoUrl} ${tempDir}`,
{ stdio: "inherit" }
);
// Move into repo
process.chdir(tempDir);
// Checkout only the target subDir
execSync(`git sparse-checkout set ${subDir}`, { stdio: "inherit" });
// Ensure target subdir exists (if first deploy)
const targetPath = path.join(tempDir, subDir);
fs.mkdirSync(targetPath, { recursive: true });
// Copy files from dist -> gh-pages/itiles-web-bluetooth
fs.cpSync(sourceDir, targetPath, { recursive: true });
// Commit + push
execSync("git add .", { stdio: "inherit" });
try {
execSync(`git commit -m "Deploy dist to ${subDir}"`, { stdio: "inherit" });
} catch (e) {
console.log("No changes to commit");
}
execSync(`git push origin ${branch}`, { stdio: "inherit" });
// Clean up temp clone
process.chdir(__dirname);
fs.rmSync(tempDir, { recursive: true, force: true });
console.log("✅ Deployment completed successfully!");
console.log(`📦 Files available at: https://stakco.github.io/${subDir}/`);
} catch (err) {
console.error("❌ Deployment failed:", err);
process.exit(1);
}