From 919f21d8ef83934aa828be0f03fc51722992d493 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julian=20B=C3=A4ume?= <julian@svg4all.de>
Date: Thu, 2 Sep 2021 18:18:08 +0200
Subject: [PATCH] first implementation to parse vite-manifest files
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

… and transform them to something that can be consumed by App Suite.
---
 spec/manifest_parsing_test.js | 111 ++++++++++++++++++++++++++++++++++
 src/manifests.js              |  13 ++++
 2 files changed, 124 insertions(+)
 create mode 100644 spec/manifest_parsing_test.js
 create mode 100644 src/manifests.js

diff --git a/spec/manifest_parsing_test.js b/spec/manifest_parsing_test.js
new file mode 100644
index 0000000..596b5c4
--- /dev/null
+++ b/spec/manifest_parsing_test.js
@@ -0,0 +1,111 @@
+import { describe, it, expect } from '@jest/globals'
+
+import { viteToOxManifest } from '../src/manifests.js'
+
+describe('Vite manifest parsing', () => {
+  it('should', () => {
+    const manifests = viteToOxManifest({
+      '../io.ox/guidedtours/i18n.de_DE.js': {
+        file: 'io.ox/guidedtours/i18n.de_DE.js',
+        src: '../io.ox/guidedtours/i18n.de_DE.js',
+        isEntry: true,
+        meta: {}
+      },
+      '../io.ox/guidedtours/i18n': {
+        file: 'io.ox/guidedtours/i18n.3de05d46.js',
+        src: '../io.ox/guidedtours/i18n',
+        isEntry: true,
+        imports: [
+          '_preload-helper-a7bbbf37.js'
+        ],
+        meta: {
+          gettext: {
+            dictionary: true
+          },
+          manifests: [
+            {
+              namespace: 'i18n'
+            }
+          ]
+        }
+      },
+      'io.ox/guidedtours/intro.js': {
+        file: 'io.ox/guidedtours/intro.e84819a5.js',
+        src: 'io.ox/guidedtours/intro.js',
+        isEntry: true,
+        isDynamicEntry: true,
+        imports: [
+          '../io.ox/guidedtours/i18n',
+          '_preload-helper-a7bbbf37.js'
+        ],
+        meta: {}
+      },
+      'io.ox/guidedtours/main.js': {
+        file: 'io.ox/guidedtours/main.07676e21.js',
+        src: 'io.ox/guidedtours/main.js',
+        isEntry: true,
+        imports: [
+          '_preload-helper-a7bbbf37.js',
+          '../io.ox/guidedtours/i18n'
+        ],
+        dynamicImports: [
+          'io.ox/guidedtours/intro.js',
+          'io.ox/guidedtours/multifactor.js'
+        ],
+        meta: {
+          manifests: [
+            {
+              namespace: 'settings'
+            },
+            {
+              namespace: 'io.ox/core/main',
+              title: 'Guided tours',
+              company: 'Open-Xchange',
+              icon: '/images/icon.png',
+              category: 'Dev',
+              settings: false,
+              index: 100,
+              package: 'open-xchange-guidedtours'
+            }
+          ]
+        }
+      },
+      'io.ox/guidedtours/multifactor.js': {
+        file: 'io.ox/guidedtours/multifactor.22d3e17d.js',
+        src: 'io.ox/guidedtours/multifactor.js',
+        isEntry: true,
+        isDynamicEntry: true,
+        imports: [
+          '_preload-helper-a7bbbf37.js',
+          '../io.ox/guidedtours/i18n',
+          'io.ox/guidedtours/main.js'
+        ],
+        meta: {}
+      },
+      'io.ox/guidedtours/utils.js': {
+        file: 'io.ox/guidedtours/utils.91ad511f.js',
+        src: 'io.ox/guidedtours/utils.js',
+        isEntry: true,
+        imports: [
+          '_preload-helper-a7bbbf37.js'
+        ],
+        meta: {}
+      },
+      '_preload-helper-a7bbbf37.js': {
+        file: 'io.ox/guidedtours/preload-helper-a7bbbf37.js'
+      }
+    })
+    expect(Array.isArray(manifests)).toBe(true)
+    expect(manifests.length).toBe(3)
+    expect(manifests.map(manifest => manifest.path)).toEqual([
+      'io.ox/guidedtours/i18n.3de05d46.js',
+      'io.ox/guidedtours/main.07676e21.js',
+      'io.ox/guidedtours/main.07676e21.js'
+    ])
+    expect(manifests.map(manifest => manifest.namespace)).toEqual([
+      'i18n',
+      'settings',
+      'io.ox/core/main'
+    ])
+  })
+})
diff --git a/src/manifests.js b/src/manifests.js
new file mode 100644
index 0000000..d949959
--- /dev/null
+++ b/src/manifests.js
@@ -0,0 +1,13 @@
+export function viteToOxManifest (viteManifests) {
+  return Object.values(viteManifests)
+    .filter(manifest => Array.isArray(manifest?.meta?.manifests))
+    .map(manifest =>
+      manifest.meta.manifests.map(oxManifest => {
+        return {
+          ...oxManifest,
+          path: manifest.file
+        }
+      })
+    )
+    .flat()
+}
-- 
GitLab