mirror of
https://github.com/storytold/spark.git
synced 2026-10-22 08:16:06 +00:00
Add deploy site script
This commit is contained in:
@@ -4,5 +4,6 @@ examples/js/vendor
|
|||||||
examples/showcase/assets
|
examples/showcase/assets
|
||||||
node_modules/
|
node_modules/
|
||||||
site/
|
site/
|
||||||
|
site-repo/
|
||||||
*.zip
|
*.zip
|
||||||
*.gltf
|
*.gltf
|
||||||
|
|||||||
+2
-1
@@ -13,7 +13,8 @@
|
|||||||
"rust/target",
|
"rust/target",
|
||||||
"rust/forge-internal-rs/pkg",
|
"rust/forge-internal-rs/pkg",
|
||||||
"src/vrButton.ts",
|
"src/vrButton.ts",
|
||||||
"site"
|
"site",
|
||||||
|
"site-repo"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"formatter": {
|
"formatter": {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
"build:watch": "onchange 'src/**/*.{ts,glsl}' -- npm run build",
|
"build:watch": "onchange 'src/**/*.{ts,glsl}' -- npm run build",
|
||||||
"clean": "rm -rf dist/ && rm -rf node_modules/ && rm -rf rust/target/ && rm -rf rust/forge-internal-rs/pkg/ && npm run assets:clean",
|
"clean": "rm -rf dist/ && rm -rf node_modules/ && rm -rf rust/target/ && rm -rf rust/forge-internal-rs/pkg/ && npm run assets:clean",
|
||||||
"dev": "npm run build && (vite --host & npm run build:watch)",
|
"dev": "npm run build && (vite --host & npm run build:watch)",
|
||||||
"deploy": "node scripts/deploy.js",
|
|
||||||
"docs": "mkdocs serve",
|
"docs": "mkdocs serve",
|
||||||
"format": "biome format .",
|
"format": "biome format .",
|
||||||
"format:fix": "biome format . --fix",
|
"format:fix": "biome format . --fix",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { copyFile, mkdir, rename } from "node:fs/promises";
|
import { copyFile, mkdir, rename, rmSync } from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
|
||||||
function copyDir(src, dest) {
|
function copyDir(src, dest) {
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { execSync } from "node:child_process";
|
||||||
|
import fs from "node:fs/promises";
|
||||||
|
import { rm } from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
|
const siteRemoteURL = "git@github.com:forge-gfx/forge-gfx.github.io.git";
|
||||||
|
const siteRepoDir = "site-repo";
|
||||||
|
const siteBuild = "site";
|
||||||
|
|
||||||
|
function run(cmd, options = {}) {
|
||||||
|
console.log(`> ${cmd}`);
|
||||||
|
execSync(cmd, { stdio: "inherit", ...options });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyDir(src, dest) {
|
||||||
|
await fs.mkdir(dest, { recursive: true });
|
||||||
|
|
||||||
|
const entries = await fs.readdir(src, { withFileTypes: true });
|
||||||
|
|
||||||
|
for (const entry of entries) {
|
||||||
|
const srcPath = path.join(src, entry.name);
|
||||||
|
const destPath = path.join(dest, entry.name);
|
||||||
|
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
await copyDir(srcPath, destPath);
|
||||||
|
} else {
|
||||||
|
await fs.copyFile(srcPath, destPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function emptyDirectory(directoryPath) {
|
||||||
|
try {
|
||||||
|
const files = await fs.readdir(directoryPath);
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
if (file === ".git" || file === "CNAME") continue;
|
||||||
|
|
||||||
|
const filePath = path.join(directoryPath, file);
|
||||||
|
const stat = await fs.lstat(filePath);
|
||||||
|
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
await fs.rm(filePath, { recursive: true, force: true });
|
||||||
|
} else {
|
||||||
|
await fs.unlink(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Deleted:", filePath);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error processing directory:", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.access(siteRepoDir);
|
||||||
|
} catch {
|
||||||
|
run(`git clone ${siteRemoteURL} ${siteRepoDir}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
run("git reset --hard", { cwd: siteRepoDir });
|
||||||
|
run("git fetch origin", { cwd: siteRepoDir });
|
||||||
|
run("git merge --ff-only origin/main", { cwd: siteRepoDir });
|
||||||
|
await emptyDirectory(siteRepoDir);
|
||||||
|
await copyDir(siteBuild, siteRepoDir);
|
||||||
|
run("git add .", { cwd: siteRepoDir });
|
||||||
|
run('git commit -m "Update Forge site"', { cwd: siteRepoDir });
|
||||||
|
run("git push origin main", { cwd: siteRepoDir });
|
||||||
Reference in New Issue
Block a user