Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
fix: build
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Mar 11, 2022
1 parent c2351da commit 8fc3628
Show file tree
Hide file tree
Showing 14 changed files with 17,434 additions and 12,753 deletions.
2 changes: 2 additions & 0 deletions .socialgouv/chart/values.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app:
replicas: 1
5 changes: 5 additions & 0 deletions .socialgouv/chart/values.project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
components:
app: true
app:
imagePackage: template
probesPath: /healthz
7 changes: 0 additions & 7 deletions .socialgouv/config.json

This file was deleted.

9 changes: 0 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ ENV GITHUB_SHA $GITHUB_SHA
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN if [ -z "$PRODUCTION" ]; then \
echo "Overriding .env for staging"; \
cp .env.staging .env.production; \
fi && \
yarn build:export \
&& if [ -z "$PRODUCTION" ]; then \
echo "Overriding robots.txt for staging"; \
mv ./out/robots.staging.txt ./out/robots.txt; \
fi

# Production image, copy all the files and run next
FROM ghcr.io/socialgouv/docker/nginx:6.70.1 AS runner
Expand Down
5 changes: 0 additions & 5 deletions next-sitemap.js

This file was deleted.

1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const moduleExports = {
env: {
NEXT_PUBLIC_APP_VERSION: version,
NEXT_PUBLIC_APP_VERSION_COMMIT: process.env.GITHUB_SHA,
NEXT_PUBLIC_IS_PRODUCTION_DEPLOYMENT: process.env.PRODUCTION,
},
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"private": true,
"scripts": {
"dev": "next dev",
"prebuild": "node -r @swc-node/register scripts/prebuild.ts",
"build": "next build",
"postbuild": "next-sitemap",
"start": "next start",
"lint": "next lint",
"export": "next export",
Expand Down Expand Up @@ -41,6 +41,7 @@
"@storybook/addon-links": "^6.4.19",
"@storybook/react": "^6.4.19",
"@storybook/testing-library": "^0.0.9",
"@swc-node/register": "^1.4.2",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.2",
"@types/node": "17.0.13",
Expand All @@ -51,7 +52,6 @@
"eslint-plugin-storybook": "^0.5.7",
"gh-pages": "^3.2.3",
"jest": "^27.5.1",
"next-sitemap": "^2.1.14",
"start-server-and-test": "^1.14.0",
"typescript": "4.6.2"
}
Expand Down
2 changes: 0 additions & 2 deletions public/robots.staging.txt

This file was deleted.

10 changes: 0 additions & 10 deletions public/robots.txt

This file was deleted.

5 changes: 0 additions & 5 deletions public/sitemap-0.xml

This file was deleted.

11 changes: 8 additions & 3 deletions public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap><loc>https://template.fabrique.social.gouv.fr/sitemap-0.xml</loc></sitemap>
</sitemapindex>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>https://template.fabrique.social.gouv.fr</loc>
<changefreq>daily</changefreq>
<priority>1</priority>
<lastmod>2021-12-25T10:22:17.507Z</lastmod>
</url>
</urlset>
28 changes: 28 additions & 0 deletions scripts/__tests__/prebuild.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { filePath, generateRobotsTxt } from "../prebuild";
import fs from "fs";

jest.mock("fs");

describe("robots.txt", () => {
beforeEach(() => {
jest.clearAllMocks();
});
it("should generate production robots.txt", () => {
const host = "localhost";
const robotsProd = [
"User-agent: *",
"Disallow: /assets/",
"Disallow: /images/",
"",
`Sitemap: https://${host}/sitemap.xml`,
].join("\n");
generateRobotsTxt(true, host);
expect(fs.writeFileSync).toHaveBeenCalledWith(filePath, robotsProd);
});
it("should generate development robots.txt", () => {
const host = "localhost";
const robotsDev = ["User-agent: *", "Disallow: /"].join("\n");
generateRobotsTxt(false, host);
expect(fs.writeFileSync).toHaveBeenCalledWith(filePath, robotsDev);
});
});
28 changes: 28 additions & 0 deletions scripts/prebuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import path from "path";
import fs from "fs";

export const filePath = path.join(__dirname, "../public/robots.txt");

export const generateRobotsTxt = (isOnProduction: boolean, host: string) => {
const robotsDev = ["User-agent: *", "Disallow: /"].join("\n");
const robotsProd = [
"User-agent: *",
"Allow: /",
"",
`Sitemap: https://${host}/sitemap.xml`,
].join("\n");

const robot = isOnProduction ? robotsProd : robotsDev;

fs.writeFileSync(filePath, robot);
};

const run = () => {
generateRobotsTxt(
process.env.NEXT_PUBLIC_IS_PRODUCTION_DEPLOYMENT ? true : false,
process.env.NEXT_PUBLIC_SITE_URL ?? "localhost"
);
console.log("Robots.txt generated.");
};

run();
Loading

0 comments on commit 8fc3628

Please sign in to comment.