aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2024-03-14 00:24:19 +0000
committerLeonardo Bishop <me@leonardobishop.com>2024-03-14 00:24:19 +0000
commit6072e6c583dd9122ba670db555a075654a852e62 (patch)
treeead89df29d1efb2a9f60b4bed8dec41ce9b38050
parente1ff3b44a55349dad8c07de690ca86c984c91469 (diff)
Move git hash fetch to nuxt-prepare
-rw-r--r--Dockerfile4
-rw-r--r--nuxt.config.ts14
-rw-r--r--package-lock.json25
-rw-r--r--package.json1
-rw-r--r--server.prepare.ts22
5 files changed, 53 insertions, 13 deletions
diff --git a/Dockerfile b/Dockerfile
index bf50ea0..e4f6b1b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,9 @@
FROM node:20-slim as base
+RUN apt-get update && \
+ apt-get install -y git && \
+ apt-get clean
+
ENV NODE_ENV=production
WORKDIR /src
diff --git a/nuxt.config.ts b/nuxt.config.ts
index db228a9..f748dc2 100644
--- a/nuxt.config.ts
+++ b/nuxt.config.ts
@@ -1,5 +1,3 @@
-import { execSync } from "child_process";
-
export default defineNuxtConfig({
components: [
{ path: '~/components', pathPrefix: true },
@@ -11,6 +9,7 @@ export default defineNuxtConfig({
modules: [
// ...
'@pinia/nuxt',
+ 'nuxt-prepare'
],
css: [
'@fortawesome/fontawesome-svg-core/styles.css'
@@ -23,17 +22,6 @@ export default defineNuxtConfig({
"@fortawesome/free-regular-svg-icons",
],
},
- hooks: {
- "build:before": () => {
- const gitCommitHash = execSync('git rev-parse HEAD').toString().trim();
- const gitCommitHashShort = gitCommitHash.slice(0, 8);
- const gitBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
-
- process.env.GIT_COMMIT_HASH = gitCommitHash;
- process.env.GIT_COMMIT_HASH_SHORT = gitCommitHashShort;
- process.env.GIT_BRANCH = gitBranch;
- }
- },
runtimeConfig: {
public: {
gitCommitHash: process.env.GIT_COMMIT_HASH,
diff --git a/package-lock.json b/package-lock.json
index 278db43..fdbf84c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -19,6 +19,7 @@
"git-describe": "^4.1.1",
"jszip": "^3.10.1",
"nuxt": "^3.10.3",
+ "nuxt-prepare": "^1.1.0",
"pinia": "^2.1.7",
"vue": "^3.4.15",
"vue-multiselect": "^3.0.0-beta.3",
@@ -8541,6 +8542,30 @@
}
}
},
+ "node_modules/nuxt-prepare": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/nuxt-prepare/-/nuxt-prepare-1.1.0.tgz",
+ "integrity": "sha512-G0KJhxWoVtIJR6tqs92+Y6O8nugqNqQnz31RhcOVIVWamv8bwKOMS2xF4tetGg2dDj5X5lwpcdTHZdqSIWuiMg==",
+ "dependencies": {
+ "@nuxt/kit": "^3.9.3",
+ "defu": "^6.1.4",
+ "jiti": "^1.21.0",
+ "pathe": "^1.1.2",
+ "scule": "^1.2.0",
+ "type-fest": "^4.9.0"
+ }
+ },
+ "node_modules/nuxt-prepare/node_modules/type-fest": {
+ "version": "4.12.0",
+ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.12.0.tgz",
+ "integrity": "sha512-5Y2/pp2wtJk8o08G0CMkuFPCO354FGwk/vbidxrdhRGZfd0tFnb4Qb8anp9XxXriwBgVPjdWbKpGl4J9lJY2jQ==",
+ "engines": {
+ "node": ">=16"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
"node_modules/nuxt/node_modules/@esbuild/aix-ppc64": {
"version": "0.20.1",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.20.1.tgz",
diff --git a/package.json b/package.json
index 3c5fa4f..37c0f68 100644
--- a/package.json
+++ b/package.json
@@ -21,6 +21,7 @@
"git-describe": "^4.1.1",
"jszip": "^3.10.1",
"nuxt": "^3.10.3",
+ "nuxt-prepare": "^1.1.0",
"pinia": "^2.1.7",
"vue": "^3.4.15",
"vue-multiselect": "^3.0.0-beta.3",
diff --git a/server.prepare.ts b/server.prepare.ts
new file mode 100644
index 0000000..a858e69
--- /dev/null
+++ b/server.prepare.ts
@@ -0,0 +1,22 @@
+import { execSync } from 'child_process';
+import { defineNuxtPrepareHandler } from 'nuxt-prepare/config'
+
+export default defineNuxtPrepareHandler(async () => {
+ const gitCommitHash = execSync('git rev-parse HEAD').toString().trim();
+ const gitCommitHashShort = gitCommitHash.slice(0, 8);
+ const gitBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
+
+ return {
+ runtimeConfig: {
+ public: {
+ gitCommitHash: gitCommitHash,
+ gitCommitHashShort: gitCommitHashShort,
+ gitBranch: gitBranch
+ }
+ },
+
+ state: {
+ foo: 'bar',
+ },
+ }
+}) \ No newline at end of file