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

Commit 8fc3628

Browse files
committed
fix: build
1 parent c2351da commit 8fc3628

14 files changed

+17434
-12753
lines changed

.socialgouv/chart/values.dev.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
app:
2+
replicas: 1

.socialgouv/chart/values.project.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
components:
2+
app: true
3+
app:
4+
imagePackage: template
5+
probesPath: /healthz

.socialgouv/config.json

-7
This file was deleted.

Dockerfile

-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ ENV GITHUB_SHA $GITHUB_SHA
2626
WORKDIR /app
2727
COPY --from=deps /app/node_modules ./node_modules
2828
COPY . .
29-
RUN if [ -z "$PRODUCTION" ]; then \
30-
echo "Overriding .env for staging"; \
31-
cp .env.staging .env.production; \
32-
fi && \
33-
yarn build:export \
34-
&& if [ -z "$PRODUCTION" ]; then \
35-
echo "Overriding robots.txt for staging"; \
36-
mv ./out/robots.staging.txt ./out/robots.txt; \
37-
fi
3829

3930
# Production image, copy all the files and run next
4031
FROM ghcr.io/socialgouv/docker/nginx:6.70.1 AS runner

next-sitemap.js

-5
This file was deleted.

next.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const moduleExports = {
1212
env: {
1313
NEXT_PUBLIC_APP_VERSION: version,
1414
NEXT_PUBLIC_APP_VERSION_COMMIT: process.env.GITHUB_SHA,
15+
NEXT_PUBLIC_IS_PRODUCTION_DEPLOYMENT: process.env.PRODUCTION,
1516
},
1617
};
1718

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"private": true,
55
"scripts": {
66
"dev": "next dev",
7+
"prebuild": "node -r @swc-node/register scripts/prebuild.ts",
78
"build": "next build",
8-
"postbuild": "next-sitemap",
99
"start": "next start",
1010
"lint": "next lint",
1111
"export": "next export",
@@ -41,6 +41,7 @@
4141
"@storybook/addon-links": "^6.4.19",
4242
"@storybook/react": "^6.4.19",
4343
"@storybook/testing-library": "^0.0.9",
44+
"@swc-node/register": "^1.4.2",
4445
"@testing-library/jest-dom": "^5.16.2",
4546
"@testing-library/react": "^12.1.2",
4647
"@types/node": "17.0.13",
@@ -51,7 +52,6 @@
5152
"eslint-plugin-storybook": "^0.5.7",
5253
"gh-pages": "^3.2.3",
5354
"jest": "^27.5.1",
54-
"next-sitemap": "^2.1.14",
5555
"start-server-and-test": "^1.14.0",
5656
"typescript": "4.6.2"
5757
}

public/robots.staging.txt

-2
This file was deleted.

public/robots.txt

-10
This file was deleted.

public/sitemap-0.xml

-5
This file was deleted.

public/sitemap.xml

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3-
<sitemap><loc>https://template.fabrique.social.gouv.fr/sitemap-0.xml</loc></sitemap>
4-
</sitemapindex>
2+
<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">
3+
<url>
4+
<loc>https://template.fabrique.social.gouv.fr</loc>
5+
<changefreq>daily</changefreq>
6+
<priority>1</priority>
7+
<lastmod>2021-12-25T10:22:17.507Z</lastmod>
8+
</url>
9+
</urlset>

scripts/__tests__/prebuild.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { filePath, generateRobotsTxt } from "../prebuild";
2+
import fs from "fs";
3+
4+
jest.mock("fs");
5+
6+
describe("robots.txt", () => {
7+
beforeEach(() => {
8+
jest.clearAllMocks();
9+
});
10+
it("should generate production robots.txt", () => {
11+
const host = "localhost";
12+
const robotsProd = [
13+
"User-agent: *",
14+
"Disallow: /assets/",
15+
"Disallow: /images/",
16+
"",
17+
`Sitemap: https://${host}/sitemap.xml`,
18+
].join("\n");
19+
generateRobotsTxt(true, host);
20+
expect(fs.writeFileSync).toHaveBeenCalledWith(filePath, robotsProd);
21+
});
22+
it("should generate development robots.txt", () => {
23+
const host = "localhost";
24+
const robotsDev = ["User-agent: *", "Disallow: /"].join("\n");
25+
generateRobotsTxt(false, host);
26+
expect(fs.writeFileSync).toHaveBeenCalledWith(filePath, robotsDev);
27+
});
28+
});

scripts/prebuild.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import path from "path";
2+
import fs from "fs";
3+
4+
export const filePath = path.join(__dirname, "../public/robots.txt");
5+
6+
export const generateRobotsTxt = (isOnProduction: boolean, host: string) => {
7+
const robotsDev = ["User-agent: *", "Disallow: /"].join("\n");
8+
const robotsProd = [
9+
"User-agent: *",
10+
"Allow: /",
11+
"",
12+
`Sitemap: https://${host}/sitemap.xml`,
13+
].join("\n");
14+
15+
const robot = isOnProduction ? robotsProd : robotsDev;
16+
17+
fs.writeFileSync(filePath, robot);
18+
};
19+
20+
const run = () => {
21+
generateRobotsTxt(
22+
process.env.NEXT_PUBLIC_IS_PRODUCTION_DEPLOYMENT ? true : false,
23+
process.env.NEXT_PUBLIC_SITE_URL ?? "localhost"
24+
);
25+
console.log("Robots.txt generated.");
26+
};
27+
28+
run();

0 commit comments

Comments
 (0)