diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8a0db89..a7503ed 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -22,7 +22,7 @@ "forwardPorts": [1234], // 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. // "customizations": {}, diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100755 index 0000000..616dfaa --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -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" diff --git a/.gitignore b/.gitignore index c8aab24..3d613c6 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,5 @@ yarn-error.log* tmp parcel-bundle-reports/ .verdaccio_storage/ -sourcemap-info.json \ No newline at end of file +sourcemap-info.json +.env diff --git a/deploy.js b/deploy.js new file mode 100644 index 0000000..723dbc9 --- /dev/null +++ b/deploy.js @@ -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)); +}); diff --git a/src/index.html b/src/index.html index 4d4230d..2189d77 100644 --- a/src/index.html +++ b/src/index.html @@ -1,3 +1,4 @@ +