diff --git a/.dockerignore b/.dockerignore index 57d008bc..4c7d15c1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,3 +4,4 @@ /deploy/ /dist/ /node_modules/ +/src/frontend/hooks/api-hooks.tsx diff --git a/Dockerfile b/Dockerfile index 88d38c16..a491f87e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,6 +63,21 @@ RUN \ +# +# Stage: Frontend hooks build +# +FROM builder AS frontend-hooks + +COPY src/common/ src/common/ +COPY src/backend/ src/backend/ + +RUN \ + mkdir --parents dist src/frontend/hooks \ + && npm run build:hooks \ + && rm -rf .parcel-cache + + + # # Stage: Frontend build # @@ -71,6 +86,7 @@ FROM builder AS frontend COPY --from=scripts /app/dist/scripts/ dist/scripts/ COPY src/common/ src/common/ COPY src/frontend/ src/frontend/ +COPY --from=frontend-hooks /app/src/frontend/hooks/ src/frontend/hooks/ RUN \ npm run build:frontend \ diff --git a/package.json b/package.json index 3888b7fb..1bfadd3d 100644 --- a/package.json +++ b/package.json @@ -13,19 +13,19 @@ "lint": "eslint --ignore-path .gitignore ./src/backend", "test": "jest --coverage --forceExit --passWithNoTests", "doc": "jsdoc -d ./dist/doc/ -r ./src/backend ./src/frontend", - "build": "rimraf dist && npm run build:scripts && npm run build:backend && npm run build:frontend", - "build:dev": "rimraf dist && npm run build:scripts && npm run build:backend:dev && npm run build:frontend:dev", + "build": "rimraf dist && npm run build:scripts && npm run build:backend && npm run build:hooks && npm run build:frontend", + "build:dev": "rimraf dist && npm run build:scripts && npm run build:backend:dev && npm run build:hooks && npm run build:frontend:dev", "build:backend": "parcel build --target=backend --no-optimize src/backend/index.js && npm run build:templates", "build:backend:dev": "parcel build --target=backend --no-optimize src/backend/index.js && npm run build:templates", "watch:backend:dev": "npm-watch build:backend:dev", - "build:frontend": "npm run build:hooks && parcel build --no-scope-hoist --target=frontend src/frontend/index.html", - "build:frontend:dev": "npm run build:hooks && parcel build --target=frontend src/frontend/index.html", + "build:frontend": "parcel build --no-scope-hoist --target=frontend src/frontend/index.html", + "build:frontend:dev": "parcel build --target=frontend src/frontend/index.html", "build:scripts:migrations": "npm run scan:migrations && parcel build --target=migrations-script src/backend/scripts/dbMigrations.ts", "build:scripts:seeds": "parcel build --target=seeds-script src/backend/scripts/dbSeeds.ts", "build:scripts:init": "parcel build --target=init-script --no-optimize src/backend/scripts/dbInit.ts", "build:scripts:spec": "parcel build --target=spec-script src/backend/scripts/genSpec.js", "build:scripts": "rimraf dist/scripts && npm run build:scripts:migrations && npm run build:scripts:init && npm run build:scripts:spec", - "build:hooks:spec": "node dist/scripts/genSpec.js", + "build:hooks:spec": "ts-node --transpile-only src/backend/scripts/genSpec.js > ./dist/openapi.json", "build:hooks:import": "restful-react import --file ./dist/openapi.json --output ./src/frontend/hooks/api-hooks.tsx", "build:hooks": "npm run build:hooks:spec && npm run build:hooks:import && rimraf dist/openapi.json", "build:templates": "copyfiles -u 2 src/backend/templates/email/**/*.hbs dist/backend", @@ -38,7 +38,7 @@ "start:backend": "node dist/backend/index.js", "start:backend:dev": "nodemon -w dist/backend --enable-source-maps dist/backend/index.js -p 3001", "start": "npm run start:backend", - "start:frontend:dev": "parcel serve -p 3000 src/frontend/index.html", + "start:frontend:dev": "npm run build:hooks && parcel serve -p 3000 src/frontend/index.html", "start:dev": "concurrently -k -p \"[{name}]\" -n \"BACKEND,FRONTEND,WATCH\" -c \"bgBlue.bold,bgMagenta.bold,bgGreen.bold\" \"npm run start:backend:dev\" \"npm run start:frontend:dev\" \"npm run watch:backend:dev\"" }, "targets": { diff --git a/src/backend/scripts/genSpec.js b/src/backend/scripts/genSpec.js index b08f5fcc..300c2e37 100644 --- a/src/backend/scripts/genSpec.js +++ b/src/backend/scripts/genSpec.js @@ -1,5 +1,3 @@ -import fs from 'fs'; -import path from 'path'; import { SwaggerAPI } from 'koa-joi-router-docs'; import preprintRoutes from '../controllers/preprint.js'; import authWrapper from '../middleware/auth.js'; @@ -19,9 +17,6 @@ import tagRoutes from '../controllers/tag.js'; import templateRoutes from '../controllers/template.js'; import notificationRoutes from '../controllers/notification.js'; -const __dirname = path.resolve(); -const OUT_FILE = path.resolve(__dirname, 'dist', 'openapi.json'); - function docs() { const generator = new SwaggerAPI(); const authz = authWrapper({}); // authorization, not authentication @@ -65,7 +60,7 @@ function docs() { ); const specJson = JSON.stringify(spec, null, 2); - fs.writeFileSync(OUT_FILE, specJson); + process.stdout.write(specJson); } docs();