Skip to content

Commit caa928f

Browse files
committed
Merge branch 'main' of github.com:devforth/adminforth
2 parents 612d66b + 7c7d895 commit caa928f

3 files changed

Lines changed: 61 additions & 7 deletions

File tree

adminforth/commands/createApp/utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,11 @@ async function writeTemplateFiles(dirname, cwd, useNpm, options) {
354354
dest: '.agents/skills/adminforth-hooks/SKILL.md',
355355
data: {},
356356
},
357-
{
358-
src: '.agents/skills/adminforth-custom-vue/SKILL.md.hbs',
359-
dest: '.agents/skills/adminforth-custom-vue/SKILL.md',
360-
data: {},
361-
},
357+
// {
358+
// src: '.agents/skills/adminforth-custom-vue/SKILL.md.hbs',
359+
// dest: '.agents/skills/adminforth-custom-vue/SKILL.md',
360+
// data: {},
361+
// },
362362
{
363363
// We'll write .env using the same content as .env.sample
364364
src: '.env.local.hbs',

adminforth/documentation/docs/tutorial/09-Advanced/01-plugin-development.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,3 +763,22 @@ and:
763763
`ChatGptPlugin` is the class name that is defined inside `index.ts`.
764764
So if we want to access plugin files from a custom component, we should use the path:
765765
>`@/custom/plugins/*Plugin class name*/*File name*`
766+
767+
768+
## How to add files to the public folder of spa
769+
770+
There might be cases, when you'll need to add some files, like icons or audio files to the public folder of spa.
771+
772+
To do so, you need in custom folder create `public` folder like:
773+
`plugins/custom/public/...`
774+
775+
```text
776+
plugin/
777+
├── custom
778+
│ ├── public/
779+
780+
```
781+
782+
And then, in bundled spa folder, files will be stored in path:
783+
784+
`spa/public/plugins/**your plugin class name**/`

adminforth/modules/codeInjector.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class CodeInjector implements ICodeInjector {
8282
adminforth: AdminForth;
8383
allComponentNames: { [key: string]: string } = {};
8484
srcFoldersToSync: { [key: string]: string } = {};
85+
publicFoldersToSync: { [key: string]: string } = {};
8586
devServerPort: number = null;
8687

8788
spaTmpPath(): string {
@@ -327,6 +328,17 @@ class CodeInjector implements ICodeInjector {
327328
return spaDir;
328329
}
329330

331+
registerPluginPublicFoldersToSync() {
332+
this.publicFoldersToSync = {};
333+
334+
for (const plugin of this.adminforth.activatedPlugins) {
335+
const pluginPublicFolderPath = path.join(plugin.customFolderPath, 'public');
336+
if (fs.existsSync(pluginPublicFolderPath)) {
337+
this.publicFoldersToSync[pluginPublicFolderPath] = `./plugins/${plugin.className}/`;
338+
}
339+
}
340+
}
341+
330342
async updatePartials({ filesUpdated }: { filesUpdated: string[] }) {
331343
const spaDir = this.getSpaDir();
332344

@@ -477,6 +489,8 @@ class CodeInjector implements ICodeInjector {
477489
this.srcFoldersToSync[customCompAbsPath] = './'
478490
}
479491

492+
this.registerPluginPublicFoldersToSync();
493+
480494
// if this.adminforth.config.customization.favicon is set, copy it to assets
481495
const customFav = this.adminforth.config.customization?.favicon;
482496
if (customFav) {
@@ -501,6 +515,16 @@ class CodeInjector implements ICodeInjector {
501515
});
502516
}
503517

518+
for (const [src, dest] of Object.entries(this.publicFoldersToSync)) {
519+
const to = path.join(this.spaTmpPath(), 'public', dest);
520+
process.env.HEAVY_DEBUG && console.log(`🪲⚙️ publicFoldersToSync: fsExtra.copy from ${src}, ${to}`);
521+
522+
await fsExtra.copy(src, to, {
523+
recursive: true,
524+
dereference: true,
525+
});
526+
}
527+
504528
//collect all 'icon' fields from resources bulkActions
505529
this.adminforth.config.resources.forEach((resource) => {
506530
if (resource.options?.bulkActions) {
@@ -860,7 +884,11 @@ class CodeInjector implements ICodeInjector {
860884
this.allWatchers.push(watcher);
861885
}
862886

863-
async watchCustomComponentsForCopy({ customComponentsDir, destination }) {
887+
async watchCustomComponentsForCopy({ customComponentsDir, destination, targetRoot = path.join('src', 'custom') }: {
888+
customComponentsDir: string,
889+
destination: string,
890+
targetRoot?: string,
891+
}) {
864892
if (!customComponentsDir) {
865893
return;
866894
}
@@ -917,7 +945,7 @@ class CodeInjector implements ICodeInjector {
917945
process.env.HEAVY_DEBUG && console.log(`🔎 destination ${destination}`);
918946
const isFile = fs.lstatSync(fileOrDir).isFile();
919947
if (isFile) {
920-
const destPath = path.join(this.spaTmpPath(), 'src', 'custom', destination, relativeFilename);
948+
const destPath = path.join(this.spaTmpPath(), targetRoot, destination, relativeFilename);
921949
process.env.HEAVY_DEBUG && console.log(`🔎 Copying file ${fileOrDir} to ${destPath}`);
922950
await fsExtra.copy(fileOrDir, destPath);
923951
return;
@@ -1033,6 +1061,13 @@ class CodeInjector implements ICodeInjector {
10331061
destination: dest,
10341062
});
10351063
}),
1064+
...Object.entries(this.publicFoldersToSync).map(async ([src, dest]) => {
1065+
await this.watchCustomComponentsForCopy({
1066+
customComponentsDir: src,
1067+
destination: dest,
1068+
targetRoot: 'public',
1069+
});
1070+
}),
10361071
]);
10371072
}
10381073

0 commit comments

Comments
 (0)