deploy update and canonical
parent
7a9f8e9561
commit
f0ee2a7f52
88
deploy.js
88
deploy.js
|
@ -1,88 +0,0 @@
|
|||
require("dotenv").config();
|
||||
const fs = require("fs-extra");
|
||||
const { exec } = require("child_process");
|
||||
import("webdav").then(({ createClient }) => {
|
||||
// Step 1: Clean the dist/ folder
|
||||
function cleanDist() {
|
||||
console.log("Cleaning dist/ folder...");
|
||||
return fs
|
||||
.emptyDir("./dist")
|
||||
.then(() => console.log("dist/ folder cleaned"))
|
||||
.catch((err) => console.error("Error cleaning dist/ folder:", err));
|
||||
}
|
||||
|
||||
// Step 2: Build with Parcel
|
||||
function buildWithParcel() {
|
||||
console.log("Building with Parcel...");
|
||||
const baseCommand = "npx parcel build src/index.html";
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(baseCommand, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`Error: ${error.message}`);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(`Stderr: ${stderr}`);
|
||||
reject(stderr);
|
||||
return;
|
||||
}
|
||||
console.log(stdout);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Step 3: Log into WebDAV
|
||||
function loginToWebDAV() {
|
||||
console.log("Logging into WebDAV server...");
|
||||
const client = createClient(process.env.WEBDAV_SERVER_URL, {
|
||||
username: process.env.WEBDAV_USERNAME,
|
||||
password: process.env.WEBDAV_PASSWORD,
|
||||
});
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
// Step 4: Clean main folder on server
|
||||
async function cleanMainFolder(client) {
|
||||
console.log("Cleaning main folder on server...");
|
||||
try {
|
||||
await client.deleteFile(process.env.WEBDAV_PATH).catch(() => {}); // Ignore error if folder doesn't exist
|
||||
await client.createDirectory(process.env.WEBDAV_PATH);
|
||||
console.log("main folder on server cleaned");
|
||||
} catch (err) {
|
||||
console.error("Error cleaning main folder on server:", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 5: Transfer content
|
||||
async function transferContent(client) {
|
||||
console.log("Transferring content to server...");
|
||||
try {
|
||||
const files = await fs.readdir("./dist");
|
||||
for (const file of files) {
|
||||
await client.putFileContents(
|
||||
process.env.WEBDAV_PATH.concat(file),
|
||||
await fs.readFile(`./dist/${file}`)
|
||||
);
|
||||
console.log(`Transferred ${file}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Error transferring content:", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// Start the process
|
||||
cleanDist()
|
||||
.then(buildWithParcel)
|
||||
.then(loginToWebDAV)
|
||||
// .then((client) => cleanMainFolder(client).then(() => client)) WILL DELETE OTHER SUBFOLDERS
|
||||
.then((client) => transferContent(client))
|
||||
.then(cleanDist)
|
||||
.then(() => console.log("Process completed successfully"))
|
||||
.catch((err) => console.error("Process failed:", err));
|
||||
});
|
|
@ -0,0 +1,100 @@
|
|||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
import dotenv from "dotenv";
|
||||
import fs from "fs-extra";
|
||||
import { exec } from "child_process";
|
||||
import path from "path";
|
||||
|
||||
// Initialize environment variables
|
||||
dotenv.config();
|
||||
|
||||
// Dynamically import the webdav module
|
||||
import("webdav").then(({ createClient }) => {
|
||||
function buildWithParcel() {
|
||||
console.log("Building with Parcel...");
|
||||
const baseCommand = "npx parcel build src/index.html";
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(baseCommand, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(`Error: ${error.message}`);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(`Stderr: ${stderr}`);
|
||||
reject(stderr);
|
||||
return;
|
||||
}
|
||||
console.log(stdout);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Step 2: Clean local folders
|
||||
function cleanDist() {
|
||||
console.log("Cleaning local folders...");
|
||||
return Promise.all([fs.emptyDir("./dist")])
|
||||
.then(() => console.log(".next/, and out/ folders cleaned"))
|
||||
.catch((err) => console.error("Error cleaning folders:", err));
|
||||
}
|
||||
|
||||
// Step 4: Log into WebDAV
|
||||
function loginToWebDAV() {
|
||||
console.log("Logging into WebDAV server...");
|
||||
const client = createClient(process.env.WEBDAV_SERVER_URL, {
|
||||
username: process.env.WEBDAV_USERNAME,
|
||||
password: process.env.WEBDAV_PASSWORD,
|
||||
});
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
// Step 7: Upload directory to WebDAV server
|
||||
async function uploadDirectory(client, localDir, remoteDir) {
|
||||
try {
|
||||
// Read the contents of the local directory
|
||||
const files = fs.readdirSync(localDir);
|
||||
|
||||
for (const file of files) {
|
||||
const localFilePath = path.join(localDir, file);
|
||||
const remoteFilePath = path.join(remoteDir, file);
|
||||
|
||||
// Check if the file is a directory
|
||||
if (fs.statSync(localFilePath).isDirectory()) {
|
||||
// Create directory on WebDAV server
|
||||
await client.createDirectory(remoteFilePath);
|
||||
|
||||
// Recursive call to upload the directory content
|
||||
await uploadDirectory(client, localFilePath, remoteFilePath);
|
||||
} else {
|
||||
// Read file content
|
||||
const fileContent = fs.readFileSync(localFilePath);
|
||||
|
||||
// Upload file to WebDAV server
|
||||
await client.putFileContents(remoteFilePath, fileContent);
|
||||
console.log(`Uploaded ${remoteFilePath}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error uploading directory:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// empty async function to use await
|
||||
async function empty() {}
|
||||
|
||||
// Start the process
|
||||
// empty()
|
||||
// .then(...
|
||||
|
||||
cleanDist()
|
||||
.then(buildWithParcel)
|
||||
.then(loginToWebDAV)
|
||||
//manual clean up
|
||||
.then((client) => uploadDirectory(client, "./dist", process.env.WEBDAV_PATH))
|
||||
.then(cleanDist)
|
||||
.then(() => console.log("Process completed successfully"))
|
||||
.catch((err) => console.error("Process failed:", err));
|
||||
});
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"devDependencies": {
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"parcel": "^2.10.2",
|
||||
"postcss": "^8.4.31",
|
||||
"prettier": "^3.1.0",
|
||||
|
@ -7,6 +8,8 @@
|
|||
"tailwindcss": "^3.3.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"flowbite": "^2.2.1"
|
||||
"flowbite": "^2.2.1",
|
||||
"fs-extra": "^11.2.0",
|
||||
"webdav": "^5.3.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
rel="stylesheet" />
|
||||
<link href="./index.css" rel="stylesheet" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="canonical" href="https://flupke.dev/" />
|
||||
</head>
|
||||
|
||||
<body class="flex min-h-screen justify-center items-center flex-col tex sm:text-xl w-screen overflow-x-hidden">
|
||||
|
|
Loading…
Reference in New Issue