diff --git a/packages/app/package.json b/packages/app/package.json index 7af04388..f13a2435 100755 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -7,9 +7,8 @@ "author": "RageStudio", "description": "A prototype of a social network.", "scripts": { - "build": "vite build", "dev": "vite", - "docker-compose:update_run": "docker-compose down && git pull && yarn build && docker-compose up -d --build", + "build": "vite build", "preview": "vite preview", "release": "node ./scripts/release.js" }, diff --git a/scripts/docker-build.js b/scripts/docker-build.js deleted file mode 100755 index 3d36114f..00000000 --- a/scripts/docker-build.js +++ /dev/null @@ -1,38 +0,0 @@ -const path = require("path") -const fs = require("fs") -const exec = require("child_process").execSync - -const sharedRootPath = path.resolve(process.cwd(), "shared") - -const rootPath = process.cwd() -const packagesPath = path.resolve(rootPath, "packages") - -const getPackages = require("./utils/getPackages") - -async function main() { - const packages = await getPackages() - - // copy shared dir to each root package path - for await (const packageName of packages) { - const packagePath = path.resolve(packagesPath, packageName) - const sharedPath = path.resolve(packagePath, "src", "_shared") - - if (fs.existsSync(sharedPath)) { - // remove old shared folder - fs.rmdirSync(sharedPath, { recursive: true }) - } - - // copy entire shared folder - // shared/* => /_shared/* - fs.mkdirSync(sharedPath, { recursive: true }) - - await exec(`cp -r ${sharedRootPath}/* ${sharedPath}`) - } - - console.log("📦 Shared classes copied to each package.") - - // run docker build - await exec("sudo docker compose build --no-cache") -} - -main().catch(console.error) \ No newline at end of file diff --git a/scripts/post-deploy.js b/scripts/post-deploy.js deleted file mode 100755 index 4bad8c6e..00000000 --- a/scripts/post-deploy.js +++ /dev/null @@ -1,61 +0,0 @@ -require("dotenv").config() - -const path = require("path") -const fs = require("fs") -const child_process = require("child_process") - -const sharedRootPath = path.resolve(process.cwd(), "shared") - -const rootPath = process.cwd() -const packagesPath = path.resolve(rootPath, "packages") - -const getPackages = require("./utils/getPackages") - -async function main() { - const packages = await getPackages({ - ignore: ["shared", "app", "wrapper", "comty.js"] - }) - - for await (const packageName of packages) { - const packagePath = path.resolve(packagesPath, packageName) - - // copy shared - const sharedPath = path.resolve(packagePath, "src", "_shared") - - if (fs.existsSync(sharedPath)) { - // remove old shared folder - fs.rmdirSync(sharedPath, { recursive: true }) - } - - // copy entire shared folder - fs.mkdirSync(sharedPath, { recursive: true }) - - await child_process.execSync(`cp -r ${sharedRootPath}/* ${sharedPath} && echo Shared lib copied`, { - cwd: packagePath, - stdio: "inherit" - }) - - console.log(`Building [${packagePath}]`) - - // run yarn build - await child_process.execSync("yarn build", { - cwd: packagePath, - stdio: "inherit" - }) - - if (process.env.INFISICAL_TOKEN) { - // write env - const envPath = path.resolve(packagePath, ".env") - - if (fs.existsSync(envPath)) { - fs.unlinkSync(envPath) - } - - const envData = `INFISICAL_TOKEN="${process.env.INFISICAL_TOKEN}"` - - await fs.writeFileSync(envPath, envData) - } - } -} - -main().catch(console.error) \ No newline at end of file diff --git a/scripts/post-install.js b/scripts/post-install.js deleted file mode 100755 index 97a2e561..00000000 --- a/scripts/post-install.js +++ /dev/null @@ -1,196 +0,0 @@ -const fs = require("node:fs") -const path = require("node:path") -const child_process = require("node:child_process") - -const rootPath = process.cwd() - -const sharedRootPath = path.resolve(rootPath, "shared") -const packagesPath = path.resolve(rootPath, "packages") - -const getPackages = require("./utils/getPackages") - -const pkgjson = require("../package.json") - -// vars -const appPath = path.resolve(rootPath, pkgjson._web_app_path) -const comtyjsPath = path.resolve(rootPath, "comty.js") -const vesselPath = path.resolve(rootPath, "vessel") -const linebridePath = path.resolve(rootPath, "linebridge") - -async function linkSharedResources(pkgJSON, packagePath) { - if (typeof pkgJSON !== "object") { - throw new Error("Package must be an object") - } - - const { shared } = pkgJSON - - if (!shared) { - return - } - - if (typeof shared === "string") { - const finalLinkPath = path.resolve(packagePath, shared) - if (fs.existsSync(finalLinkPath)) { - console.warn(`⚠️ Resource [${shared}] link already exists in [${finalLinkPath}]`) - return - } - - // link entire folder - fs.symlinkSync(sharedRootPath, finalLinkPath, "dir") - } else { - for (const [resource, linkPath] of Object.entries(shared)) { - const originClassPath = path.resolve(sharedRootPath, resource) - const finalLinkPath = path.resolve(packagePath, linkPath) - - if (!fs.existsSync(originClassPath)) { - throw new Error(`Resource [${resource}] does not exist`) - } - - if (fs.existsSync(finalLinkPath)) { - console.warn(`⚠️ Resource [${resource}] link already exists in [${finalLinkPath}]`) - continue - } else { - fs.mkdirSync(path.resolve(finalLinkPath, ".."), { recursive: true }) - } - - try { - fs.symlinkSync(originClassPath, finalLinkPath, "dir") - console.log(`🔗 Linked resouce [${resource}] to [${finalLinkPath}]`) - } catch (error) { - if (error.code && error.code == 'EEXIST') { - fs.unlinkSync(finalLinkPath) - fs.symlinkSync(originClassPath, finalLinkPath, "dir") - console.log(`🔗 Linked resouce [${resource}] to [${finalLinkPath}]`) - } - } - - continue - } - } -} - -async function linkInternalSubmodules(packages) { - //* APP RUNTIME LINKING - console.log(`Linking Vessel to app...`) - - await child_process.execSync("yarn link", { - cwd: vesselPath, - stdio: "inherit", - }) - - await child_process.execSync(`yarn link "vessel"`, { - cwd: appPath, - stdio: "inherit", - }) - - //* COMTY.JS LINKING - console.log(`Linking comty.js to app...`) - - await child_process.execSync(`yarn link`, { - cwd: comtyjsPath, - stdio: "inherit", - }) - - await child_process.execSync(`yarn link "comty.js"`, { - cwd: appPath, - stdio: "inherit", - }) - - //* LINEBRIDE LINKING - console.log(`Linking Linebride to servers...`) - - await child_process.execSync(`yarn link`, { - cwd: linebridePath, - stdio: "inherit", - }) - - for await (const packageName of packages) { - const packagePath = path.resolve(packagesPath, packageName) - - const packageJsonPath = path.resolve(packagePath, "package.json") - - if (!fs.existsSync(packageJsonPath)) { - continue - } - - await child_process.execSync(`yarn link "linebridge"`, { - cwd: packagePath, - stdio: "inherit", - }) - - console.log(`Linking Linebride to package [${packageName}]...`) - } - - console.log(`✅ All submodules linked!`) - - return true -} - -async function main() { - console.time("✅ post-install tooks:") - - // read dir with absolute paths - let packages = await getPackages() - - // link shared resources - for (const packageName of packages) { - const packagePath = path.resolve(packagesPath, packageName) - - const packageJsonPath = path.resolve(packagePath, "package.json") - - if (!fs.existsSync(packageJsonPath)) { - continue - } - - const packageJson = require(packageJsonPath) - - if (packageJson.shared) { - console.log(`📦 Package [${packageName}] has declared shared resources.`) - - await linkSharedResources(packageJson, packagePath) - } - } - - // install dependencies for modules - console.log("Installing app dependencies...") - await child_process.execSync("npm install --force", { - cwd: appPath, - stdio: "inherit", - }) - - console.log("Installing vessel dependencies...") - await child_process.execSync("npm install --force", { - cwd: vesselPath, - stdio: "inherit", - }) - - console.log("Installing comty.js dependencies...") - await child_process.execSync("npm install --force", { - cwd: comtyjsPath, - stdio: "inherit", - }) - - console.log("Installing linebridge dependencies...") - await child_process.execSync("npm install --force", { - cwd: linebridePath, - stdio: "inherit", - }) - - // link internal submodules - await linkInternalSubmodules(packages) - - // fixes for arm architecture - if (process.arch == "arm64") { - // rebuild tfjs - console.log("Rebuilding TFJS...") - - await child_process.execSync("npm rebuild @tensorflow/tfjs-node --build-from-source", { - cwd: rootPath, - stdio: "inherit", - }) - } - - console.timeEnd("✅ post-install tooks:") -} - -main().catch(console.error) diff --git a/scripts/publishWidget.js b/scripts/publishWidget.js deleted file mode 100755 index 2ba8af6f..00000000 --- a/scripts/publishWidget.js +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env node -import path from "path" -import fs from "fs" -import axios from "axios" -import sevenzip from "7zip-min" -import formdata from "form-data" - -const marketplaceAPIOrigin = "https://indev.comty.app/api/extensions" -const token = process.argv[2] - -const excludedFiles = [ - "/.git", - "/.tmp", - "/bundle.7z", - "/node_modules", - "/package-lock.json", -] - -const rootPath = process.cwd() -const tmpPath = path.join(rootPath, ".tmp") -const buildPath = path.join(tmpPath, "build") -const bundlePath = path.join(tmpPath, "bundle.7z") - -async function copySources(origin, to) { - const files = fs.readdirSync(origin) - - if (!fs.existsSync(to)) { - await fs.promises.mkdir(to, { recursive: true }) - } - - for (const file of files) { - const filePath = path.join(origin, file) - - // run a rexeg to check if the filePath is excluded - const isExcluded = excludedFiles.some((excludedPath) => { - return filePath.match(excludedPath) - }) - - if (isExcluded) { - continue - } - - if (fs.lstatSync(filePath).isDirectory()) { - await copySources(filePath, path.join(to, file)) - } else { - await fs.promises.copyFile(filePath, path.join(to, file)) - } - } -} - -async function createBundle(origin, desitinationFile) { - return new Promise((resolve, reject) => { - sevenzip.pack(origin, desitinationFile, (err) => { - if (err) { - reject(err) - } else { - resolve() - } - }) - }) -} - -async function main() { - if (!token) { - console.error("🛑 You need to pass a token as argument") - return - } - - // create a .tmp folder - if (fs.existsSync(tmpPath)) { - await fs.promises.rm(tmpPath, { recursive: true, force: true }) - } - - try { - // try to read package.json - if (!fs.existsSync(path.resolve(rootPath, "package.json"))) { - console.error("🛑 package.json not found") - return - } - - const packageJSON = require(path.resolve(rootPath, "package.json")) - - // check if package.json has a main file - if (!packageJSON.main) { - console.error("🛑 package.json does not have a main file") - return - } - - if (!fs.existsSync(path.resolve(rootPath, packageJSON.main))) { - console.error("🛑 main file not found") - return - } - - console.log(packageJSON) - - console.log("📦 Creating bundle...") - - await copySources(rootPath, buildPath) - await createBundle(`${buildPath}/*`, bundlePath) - - console.log("📦✅ Bundle created successfully") - - console.log("🚚 Publishing bundle...") - - const formData = new formdata() - - formData.append("file", fs.createReadStream(bundlePath)) - - const response = await axios({ - method: "PUT", - url: `${marketplaceAPIOrigin}/publish`, - headers: { - ...formData.getHeaders(), - pkg: JSON.stringify(packageJSON), - Authorization: `Bearer ${token}`, - }, - data: formData, - }).catch((error) => { - console.error("🛑 Error while publishing bundle \n\t", error.response?.data ?? error) - - return false - }) - - if (response) { - console.log("🚚✅ Bundle published successfully! \n", response.data) - } - - await fs.promises.rm(tmpPath, { recursive: true, force: true }) - } catch (error) { - console.error("🛑 Error while publishing bundle \n\t", error) - await fs.promises.rm(tmpPath, { recursive: true, force: true }) - } -} - -main().catch(console.error) \ No newline at end of file