main
psoubrie 2024-01-16 12:58:32 +00:00
parent 8f2b962cb5
commit 4fc0cfef34
5 changed files with 108 additions and 2 deletions

View File

@ -22,7 +22,7 @@
"forwardPorts": [1234], "forwardPorts": [1234],
// Use 'postCreateCommand' to run commands after the container is creahowted. // Use 'postCreateCommand' to run commands after the container is creahowted.
"postCreateCommand": "npm i" "postCreateCommand": "npm i && chmod +x ./.devcontainer/postCreateCommand.sh && ./.devcontainer/postCreateCommand.sh"
// Configure tool-specific properties. // Configure tool-specific properties.
// "customizations": {}, // "customizations": {},

View File

@ -0,0 +1,16 @@
#!/bin/bash
# Install starship
curl -sS https://starship.rs/install.sh | sh -s -- -y
# Set starship theme
starship preset gruvbox-rainbow -o ~/.config/starship.toml
# Install libegl1-mesa
sudo apt update && sudo apt-get install -y libegl1-mesa
# Set utc_time_offset in starship.toml
sed -i '/\[time\]/a utc_time_offset = \"+1\"' ~/.config/starship.toml
# Add starship to bashrc
echo 'eval "$(starship init bash)"' >> "/home/$USER/.bashrc"

1
.gitignore vendored
View File

@ -21,3 +21,4 @@ tmp
parcel-bundle-reports/ parcel-bundle-reports/
.verdaccio_storage/ .verdaccio_storage/
sourcemap-info.json sourcemap-info.json
.env

88
deploy.js Normal file
View File

@ -0,0 +1,88 @@
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))
.then((client) => transferContent(client))
.then(cleanDist)
.then(() => console.log("Process completed successfully"))
.catch((err) => console.error("Process failed:", err));
});

View File

@ -1,3 +1,4 @@
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>