diff --git a/.aegir.js b/.aegir.js
index 198e84d3..6c01bc48 100644
--- a/.aegir.js
+++ b/.aegir.js
@@ -20,12 +20,8 @@ export default {
'ipfs-css',
'tachyons',
- // required by webpack
- 'webpack-cli',
- 'webpack-dev-server',
- 'babel-loader',
- 'style-loader',
- 'css-loader'
+ // playwright dependencies
+ 'http-server'
],
productionIgnorePatterns: [
'webpack.config.js',
@@ -33,7 +29,8 @@ export default {
'test-e2e',
'.aegir.js',
'/test',
- 'dist'
+ 'dist',
+ 'build.js'
]
}
}
diff --git a/build.js b/build.js
new file mode 100644
index 00000000..72671d5c
--- /dev/null
+++ b/build.js
@@ -0,0 +1,215 @@
+/* eslint-disable no-console */
+import { execSync } from 'node:child_process'
+import fs from 'node:fs'
+import path from 'node:path'
+import esbuild from 'esbuild'
+
+const copyPublicFiles = () => {
+ const srcDir = path.resolve('public')
+ const destDir = path.resolve('dist')
+
+ // Ensure the destination directory exists
+ if (!fs.existsSync(destDir)) {
+ fs.mkdirSync(destDir, { recursive: true })
+ }
+
+ // Read all files in the source directory
+ const files = fs.readdirSync(srcDir)
+
+ // Copy each file to the destination directory
+ files.forEach(file => {
+ const srcFile = path.join(srcDir, file)
+ const destFile = path.join(destDir, file)
+ fs.copyFileSync(srcFile, destFile)
+ console.log(`${file} copied to dist folder.`)
+ })
+}
+
+function gitRevision () {
+ try {
+ const ref = execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
+ const sha = execSync('git rev-parse --short HEAD').toString().trim()
+
+ try {
+ // detect production build
+ execSync('git fetch --force --depth=1 --quiet origin production')
+ const latestProduction = execSync('git rev-parse remotes/origin/production').toString().trim()
+ if (latestProduction.startsWith(sha)) {
+ return `production@${sha}`
+ }
+
+ // detect staging build
+ execSync('git fetch --force --depth=1 --quiet origin staging')
+ const latestStaging = execSync('git rev-parse remotes/origin/staging').toString().trim()
+ if (latestStaging.startsWith(sha)) {
+ return `staging@${sha}`
+ }
+ } catch (_) { /* noop */ }
+
+ return `${ref}@${sha}`
+ } catch (_) {
+ return `no-git-dirty@${new Date().getTime().toString()}`
+ }
+}
+
+/**
+ * Inject the dist/index.js and dist/index.css into the dist/index.html file
+ *
+ * @param {esbuild.Metafile} metafile
+ */
+const injectAssets = (metafile) => {
+ const htmlFilePath = path.resolve('dist/index.html')
+
+ // Extract the output file names from the metafile
+ const outputs = metafile.outputs
+ const scriptFile = Object.keys(outputs).find(file => file.endsWith('.js') && file.includes('ipfs-sw-index'))
+ const cssFile = Object.keys(outputs).find(file => file.endsWith('.css') && file.includes('ipfs-sw-index'))
+
+ const scriptTag = ``
+ const linkTag = ``
+
+ // Read the index.html file
+ let htmlContent = fs.readFileSync(htmlFilePath, 'utf8')
+
+ // Inject the link tag for CSS before the closing tag
+ htmlContent = htmlContent.replace('', `${linkTag}`)
+
+ // Inject the script tag for JS before the closing