Skip to content

Commit b9706b9

Browse files
authored
Merge pull request #21 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 73209c1 + c62d3de commit b9706b9

25 files changed

+286
-49
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
dist/
2+
build/
3+
importsMap.jsx
4+
Generate-Import-Map.js

Generate-Import-Map.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Using ES Module syntax compatible with Node.js 18 and ensuring cross-platform compatibility
2+
import fs from 'fs/promises'
3+
import path from 'path'
4+
import { fileURLToPath } from 'url'
5+
6+
// Convert __dirname equivalent for ES Modules
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
9+
10+
// Adjust the relative path as necessary to point to your routes.json location
11+
const routesPath = path.join(__dirname, './src/routes.json') // Example path
12+
13+
// Load routes.json with an import assertion for JSON
14+
const routes = await import(`file://${routesPath}`, { assert: { type: 'json' } }).then(
15+
(module) => module.default,
16+
)
17+
18+
let importsMap = "import React from 'react'\n export const importsMap = {\n"
19+
20+
routes.forEach((route) => {
21+
if (route.component) {
22+
// Adjust the import path to be relative to the importsMap.js file location
23+
const importPath = route.component.replace('views', './views')
24+
// Ensure paths are Unix-like for the dynamic import to work cross-platform
25+
const unixImportPath = importPath.split(path.sep).join('/')
26+
importsMap += ` "${route.path}": React.lazy(() => import('${unixImportPath}')), \n`
27+
}
28+
})
29+
30+
importsMap += '}\nexport default importsMap'
31+
32+
// Specify the output file path for the generated imports map
33+
const outputPath = path.join(__dirname, './src/importsMap.jsx')
34+
await fs.writeFile(outputPath, importsMap)
35+
console.log('Import map generated.')

Importmap.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// generate-imports-map.js
2+
const fs = require('fs')
3+
const path = require('path')
4+
const routes = require('./path/to/routes.json')
5+
6+
let importsMap = 'export const importsMap = {\n'
7+
8+
routes.forEach(route => {
9+
if (route.component) {
10+
// Convert the path to a format that's relative to where you'll be importing from
11+
const importPath = route.component.replace('views', './views')
12+
const componentName = path.basename(importPath)
13+
14+
// Create an import statement for the component
15+
importsMap += "${route.path}": React.lazy(() = > import('${importPath}')), \n`;
16+
}
17+
})
18+
19+
importsMap += '};\n'
20+
21+
fs.writeFileSync(path.resolve(__dirname,'./src/importsMap.js'), importsMap)
22+
console.log('Import map generated.')

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cipp",
3-
"version": "5.4.0",
3+
"version": "5.4.1",
44
"description": "The CyberDrain Improved Partner Portal is a portal to help manage administration for Microsoft Partners.",
55
"homepage": "https://cipp.app/",
66
"bugs": {
@@ -14,6 +14,7 @@
1414
"license": "AGPL-3.0",
1515
"author": "CIPP Contributors",
1616
"scripts": {
17+
"prebuild": "node Generate-Import-Map.js",
1718
"build": "echo react-scripts build && vite build",
1819
"changelog": "auto-changelog --starting-version 3.0.0 --commit-limit false --hide-credit",
1920
"lint": "eslint \"src/**/*.js\"",

public/img/augmentt-dark.png

5.66 KB
Loading

public/img/augmentt-light.png

33.3 KB
Loading

public/img/netfriends.png

-3.69 KB
Binary file not shown.

public/img/netfriends_dark.png

-14 KB
Binary file not shown.

public/version_latest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.4.0
1+
5.4.1

0 commit comments

Comments
 (0)