fix _shared links for production

This commit is contained in:
SrGooglo 2023-05-31 20:36:54 +00:00
parent e3e7131304
commit 6b39be3a4a
8 changed files with 105 additions and 40 deletions

2
.gitignore vendored
View File

@ -4,6 +4,8 @@
/**/**/server.manifest
/**/**/server.registry
/**/**/_shared
# Trash
/**/**/*.log
/**/**/dumps.log

View File

@ -9,13 +9,17 @@ global.isProduction = process.env.NODE_ENV === "production"
import path from "path"
import { registerBaseAliases } from "linebridge/dist/server"
globalThis["__root"] = path.resolve(__dirname)
const customAliases = {
"@shared-classes": path.resolve(__dirname, "shared-classes"),
"root": globalThis["__root"],
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
"@services": path.resolve(__dirname, "services"),
}
if (!global.isProduction) {
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
}
registerBaseAliases(undefined, customAliases)

View File

@ -9,12 +9,13 @@ globalThis["__root"] = path.resolve(__dirname)
const customAliases = {
"root": globalThis["__root"],
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
"@services": path.resolve(__dirname, "services"),
"@shared-classes": path.resolve(__dirname, "shared-classes"),
}
if (!global.isProduction) {
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
}
registerBaseAliases(undefined, customAliases)

View File

@ -5,13 +5,17 @@ import { webcrypto as crypto } from "crypto"
import path from "path"
import { registerBaseAliases } from "linebridge/dist/server"
globalThis["__root"] = path.resolve(__dirname)
const customAliases = {
"root": globalThis["__root"],
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
"@services": path.resolve(__dirname, "services"),
"@shared-classes": path.resolve(__dirname, "shared-classes"),
}
if (!global.isProduction) {
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
}
registerBaseAliases(undefined, customAliases)

View File

@ -13,12 +13,13 @@ globalThis["__root"] = path.resolve(__dirname)
const customAliases = {
"root": globalThis["__root"],
"@shared-classes": path.resolve(__dirname, "_shared/classes"),
"@services": path.resolve(__dirname, "services"),
"@shared-classes": path.resolve(__dirname, "shared-classes"),
}
if (!global.isProduction) {
customAliases["comty.js"] = path.resolve(__dirname, "../../comty.js/src")
customAliases["@shared-classes"] = path.resolve(__dirname, "shared-classes")
}
registerBaseAliases(undefined, customAliases)

38
scripts/docker-build.js Normal file
View 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)

View File

@ -7,39 +7,7 @@ const sharedClassesPath = path.resolve(sharedRootPath, "classes")
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
}
const getPackages = require("./utils/getPackages")
async function linkSharedClasses(pkgJSON, packagePath) {
if (typeof pkgJSON !== "object") {
@ -77,9 +45,7 @@ async function main() {
console.time("Postinstall tooks:")
// read dir with absolute paths
let packages = await fs.promises.readdir(packagesPath)
packages = filterPackages(packages)
let packages = await getPackages()
for (const packageName of packages) {
const packagePath = path.resolve(packagesPath, packageName)

View 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