Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/catalyst.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ process.on("unhandledRejection", (err) => {
const { spawnSync } = require("node:child_process")
const args = process.argv.slice(2)
const scriptIndex = args.findIndex(
(x) => x === "build" || x === "start" || x === "serve" || x === "devBuild" || x === "devServe"
(x) => x === "build" || x === "start" || x === "serve" || x === "devBuild" || x === "devServe" || x === "cleanCache"
)
const script = scriptIndex === -1 ? args[0] : args[scriptIndex]
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []
if (["build", "start", "serve", "devBuild", "devServe"].includes(script)) {
if (["build", "start", "serve", "devBuild", "devServe", "cleanCache"].includes(script)) {
const result = spawnSync(
process.execPath,
nodeArgs.concat(require.resolve("../dist/scripts/" + script)).concat(args.slice(scriptIndex + 1)),
Expand All @@ -34,5 +34,5 @@ if (["build", "start", "serve", "devBuild", "devServe"].includes(script)) {
}
process.exit(result.status)
} else {
console.log('Unknown script "' + script + '".')
console.log('Unknown script "' + script + '". Available: build, start, serve, devBuild, devServe, cleanCache')
}
30 changes: 30 additions & 0 deletions src/scripts/cleanCache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require("fs")
const path = require("path")

function cleanCache() {
const catalystCacheDir = path.join(process.cwd(), "node_modules/catalyst-core")
const webpackCacheDir = path.join(catalystCacheDir, ".cache/webpack")
const loadableStats = path.join(catalystCacheDir, "loadable-stats.json")

let cleaned = false

if (fs.existsSync(webpackCacheDir)) {
fs.rmSync(webpackCacheDir, { recursive: true, force: true })
console.log("[Catalyst] Removed webpack filesystem cache.")
cleaned = true
}

if (fs.existsSync(loadableStats)) {
fs.rmSync(loadableStats)
console.log("[Catalyst] Removed loadable-stats.json.")
cleaned = true
}

if (!cleaned) {
console.log("[Catalyst] Nothing to clean — cache is already empty.")
} else {
console.log("[Catalyst] Clean complete. Next dev start will be a full rebuild.")
}
}

cleanCache()
6 changes: 4 additions & 2 deletions src/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ function start() {

const command = `
node ./dist/scripts/checkVersion
npx babel-node -r ./dist/scripts/loadScriptsBeforeServerStarts.js ./dist/webpack/development.client.babel --no-warnings=ExperimentalWarning --no-warnings=BABEL & npx babel-node -r ./dist/scripts/loadScriptsBeforeServerStarts.js ./dist/server/startServer.js --extensions .js,.ts,.jsx,.tsx --watch-path=${process.env.PWD}/server --watch-path=${process.env.PWD}/src --ignore='__IGNORE__' --no-warnings=ExperimentalWarning --no-warnings=BABEL
npx babel-node -r ./dist/scripts/loadScriptsBeforeServerStarts.js ./dist/webpack/development.client.babel --no-warnings=ExperimentalWarning --no-warnings=BABEL & npx babel-node -r ./dist/scripts/loadScriptsBeforeServerStarts.js ./dist/server/startServer.js --extensions .js,.ts,.jsx,.tsx --ignore='__IGNORE__' --no-warnings=ExperimentalWarning --no-warnings=BABEL
`

if (isWindows) {
// Windows doesn't support `&` for parallel processes in a single shell command,
// so we use two non-blocking spawn() calls instead of a single spawnSync().
spawn(
`node ./dist/scripts/checkVersion && start /b npx babel-node -r ./dist/scripts/loadScriptsBeforeServerStarts.js ./dist/webpack/development.client.babel --no-warnings=ExperimentalWarning --no-warnings=BABEL`,
[],
Expand All @@ -39,7 +41,7 @@ function start() {
)

spawn(
`node ./dist/scripts/checkVersion && npx babel-node -r ./dist/scripts/loadScriptsBeforeServerStarts.js ./dist/server/startServer.js --watch-path=${process.cwd()}/server --watch-path=${process.cwd()}/src --ignore='__IGNORE__' --no-warnings=ExperimentalWarning --no-warnings=BABEL`,
`node ./dist/scripts/checkVersion && npx babel-node -r ./dist/scripts/loadScriptsBeforeServerStarts.js ./dist/server/startServer.js --extensions .js,.ts,.jsx,.tsx --ignore='__IGNORE__' --no-warnings=ExperimentalWarning --no-warnings=BABEL`,
[],
{
cwd: dirname,
Expand Down
15 changes: 5 additions & 10 deletions src/server/expressServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@ const env = process.env.NODE_ENV || "development"

const app = express()

// This middleware is being used to extract the body of the request
app.use(bodyParser.json())
app.use(bodyParser.json({ limit: "100kb" }))

// This middleware has been added to accommodate “byetstream array”
app.use(bodyParser.raw({ type: "application/*" }))
// Handles "bytestream array" content types sent as raw application/* bodies
app.use(bodyParser.raw({ type: "application/*", limit: "100kb" }))

// This middleware is being used to parse cookies!
app.use(cookieParser())

// All the middlewares defined by the user will run here.
if (validateMiddleware(addMiddlewares)) addMiddlewares(app)

// The middleware will attempt to compress response bodies for all request that traverse through the middleware
app.use(compression())

// This endpoint will serve the built assets from the node server. The requests will be made to PUBLIC_STATIC_ASSET_PATH which has been defined in the application config.
// expressStaticGzip will compress the assets.
// Serve pre-compressed static assets (brotli preferred) from the build output directory
if (env === "production") {
app.use(
process.env.PUBLIC_STATIC_ASSET_PATH,
Expand All @@ -45,7 +40,7 @@ if (env === "production") {
)
}

// This middleware handles document requests.
// Catch-all: every non-asset request is handled by the SSR renderer
app.use("*", ReactRenderer)

export default app
Loading