mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
fix _shared
links for production
This commit is contained in:
parent
e3e7131304
commit
6b39be3a4a
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,6 +4,8 @@
|
|||||||
/**/**/server.manifest
|
/**/**/server.manifest
|
||||||
/**/**/server.registry
|
/**/**/server.registry
|
||||||
|
|
||||||
|
/**/**/_shared
|
||||||
|
|
||||||
# Trash
|
# Trash
|
||||||
/**/**/*.log
|
/**/**/*.log
|
||||||
/**/**/dumps.log
|
/**/**/dumps.log
|
||||||
|
@ -9,13 +9,17 @@ global.isProduction = process.env.NODE_ENV === "production"
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import { registerBaseAliases } from "linebridge/dist/server"
|
import { registerBaseAliases } from "linebridge/dist/server"
|
||||||
|
|
||||||
|
globalThis["__root"] = path.resolve(__dirname)
|
||||||
|
|
||||||
const customAliases = {
|
const customAliases = {
|
||||||
"@shared-classes": path.resolve(__dirname, "shared-classes"),
|
"root": globalThis["__root"],
|
||||||
|
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
||||||
"@services": path.resolve(__dirname, "services"),
|
"@services": path.resolve(__dirname, "services"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!global.isProduction) {
|
if (!global.isProduction) {
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
||||||
|
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
||||||
}
|
}
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
registerBaseAliases(undefined, customAliases)
|
||||||
|
@ -9,12 +9,13 @@ globalThis["__root"] = path.resolve(__dirname)
|
|||||||
|
|
||||||
const customAliases = {
|
const customAliases = {
|
||||||
"root": globalThis["__root"],
|
"root": globalThis["__root"],
|
||||||
|
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
||||||
"@services": path.resolve(__dirname, "services"),
|
"@services": path.resolve(__dirname, "services"),
|
||||||
"@shared-classes": path.resolve(__dirname, "shared-classes"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!global.isProduction) {
|
if (!global.isProduction) {
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
||||||
|
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
||||||
}
|
}
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
registerBaseAliases(undefined, customAliases)
|
||||||
|
@ -5,13 +5,17 @@ import { webcrypto as crypto } from "crypto"
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import { registerBaseAliases } from "linebridge/dist/server"
|
import { registerBaseAliases } from "linebridge/dist/server"
|
||||||
|
|
||||||
|
globalThis["__root"] = path.resolve(__dirname)
|
||||||
|
|
||||||
const customAliases = {
|
const customAliases = {
|
||||||
|
"root": globalThis["__root"],
|
||||||
|
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
||||||
"@services": path.resolve(__dirname, "services"),
|
"@services": path.resolve(__dirname, "services"),
|
||||||
"@shared-classes": path.resolve(__dirname, "shared-classes"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!global.isProduction) {
|
if (!global.isProduction) {
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
||||||
|
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
||||||
}
|
}
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
registerBaseAliases(undefined, customAliases)
|
||||||
|
@ -13,12 +13,13 @@ globalThis["__root"] = path.resolve(__dirname)
|
|||||||
|
|
||||||
const customAliases = {
|
const customAliases = {
|
||||||
"root": globalThis["__root"],
|
"root": globalThis["__root"],
|
||||||
|
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
|
||||||
"@services": path.resolve(__dirname, "services"),
|
"@services": path.resolve(__dirname, "services"),
|
||||||
"@shared-classes": path.resolve(__dirname, "shared-classes"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!global.isProduction) {
|
if (!global.isProduction) {
|
||||||
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
|
||||||
|
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
|
||||||
}
|
}
|
||||||
|
|
||||||
registerBaseAliases(undefined, customAliases)
|
registerBaseAliases(undefined, customAliases)
|
||||||
|
38
scripts/docker-build.js
Normal file
38
scripts/docker-build.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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)
|
@ -7,39 +7,7 @@ const sharedClassesPath = path.resolve(sharedRootPath, "classes")
|
|||||||
const rootPath = process.cwd()
|
const rootPath = process.cwd()
|
||||||
const packagesPath = path.resolve(rootPath, "packages")
|
const packagesPath = path.resolve(rootPath, "packages")
|
||||||
|
|
||||||
const excludedPackages = ["comty.js"]
|
const getPackages = require("./utils/getPackages")
|
||||||
|
|
||||||
function filterPackages(packages) {
|
|
||||||
const gitIgnore = fs.readFileSync(path.resolve(rootPath, ".gitignore"), "utf-8")
|
|
||||||
|
|
||||||
// create a regex to match all packages that are in the gitignore file
|
|
||||||
const gitIgnoreRegex = gitIgnore.split("\n").map((line) => {
|
|
||||||
// remove comments
|
|
||||||
if (line.startsWith("#")) return
|
|
||||||
|
|
||||||
return line.replace(/(\/)/g, "\\/").replace(/(\*)/g, "(.*)")
|
|
||||||
}).filter((line) => line)
|
|
||||||
|
|
||||||
// filter packages that are in the gitignore file
|
|
||||||
packages = packages.filter((packageName) => {
|
|
||||||
// filter excluded packages
|
|
||||||
if (excludedPackages.includes(packageName)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const resolvedPath = path.resolve(packagesPath, packageName)
|
|
||||||
|
|
||||||
return !gitIgnoreRegex.some((regex) => {
|
|
||||||
return resolvedPath.match(regex)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
packages = packages.filter((packageName) => {
|
|
||||||
return fs.statSync(path.resolve(packagesPath, packageName)).isDirectory()
|
|
||||||
})
|
|
||||||
|
|
||||||
return packages
|
|
||||||
}
|
|
||||||
|
|
||||||
async function linkSharedClasses(pkgJSON, packagePath) {
|
async function linkSharedClasses(pkgJSON, packagePath) {
|
||||||
if (typeof pkgJSON !== "object") {
|
if (typeof pkgJSON !== "object") {
|
||||||
@ -77,9 +45,7 @@ async function main() {
|
|||||||
console.time("Postinstall tooks:")
|
console.time("Postinstall tooks:")
|
||||||
|
|
||||||
// read dir with absolute paths
|
// read dir with absolute paths
|
||||||
let packages = await fs.promises.readdir(packagesPath)
|
let packages = await getPackages()
|
||||||
|
|
||||||
packages = filterPackages(packages)
|
|
||||||
|
|
||||||
for (const packageName of packages) {
|
for (const packageName of packages) {
|
||||||
const packagePath = path.resolve(packagesPath, packageName)
|
const packagePath = path.resolve(packagesPath, packageName)
|
||||||
|
49
scripts/utils/getPackages.js
Normal file
49
scripts/utils/getPackages.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
const fs = require("fs")
|
||||||
|
const path = require("path")
|
||||||
|
|
||||||
|
const rootPath = process.cwd()
|
||||||
|
const packagesPath = path.resolve(rootPath, "packages")
|
||||||
|
|
||||||
|
const excludedPackages = ["comty.js"]
|
||||||
|
|
||||||
|
function filterPackages(packages) {
|
||||||
|
const gitIgnore = fs.readFileSync(path.resolve(rootPath, ".gitignore"), "utf-8")
|
||||||
|
|
||||||
|
// create a regex to match all packages that are in the gitignore file
|
||||||
|
const gitIgnoreRegex = gitIgnore.split("\n").map((line) => {
|
||||||
|
// remove comments
|
||||||
|
if (line.startsWith("#")) return
|
||||||
|
|
||||||
|
return line.replace(/(\/)/g, "\\/").replace(/(\*)/g, "(.*)")
|
||||||
|
}).filter((line) => line)
|
||||||
|
|
||||||
|
// filter packages that are in the gitignore file
|
||||||
|
packages = packages.filter((packageName) => {
|
||||||
|
// filter excluded packages
|
||||||
|
if (excludedPackages.includes(packageName)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedPath = path.resolve(packagesPath, packageName)
|
||||||
|
|
||||||
|
return !gitIgnoreRegex.some((regex) => {
|
||||||
|
return resolvedPath.match(regex)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
packages = packages.filter((packageName) => {
|
||||||
|
return fs.statSync(path.resolve(packagesPath, packageName)).isDirectory()
|
||||||
|
})
|
||||||
|
|
||||||
|
return packages
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getPackages() {
|
||||||
|
let packages = await fs.promises.readdir(packagesPath)
|
||||||
|
|
||||||
|
packages = filterPackages(packages)
|
||||||
|
|
||||||
|
return packages
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getPackages
|
Loading…
x
Reference in New Issue
Block a user