FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
adminforth/adminforth/basePlugin.ts at fix-2fa · devforth/adminforth · GitHub
devforth
adminforth
Repository navigation
Code
Issues
16
(16)
Pull requests
4
(4)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
adminforth
/
adminforth
/
basePlugin.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (58 loc) · 2.7 KB
Breadcrumbs
adminforth
/
adminforth
/
basePlugin.ts
Copy path
File metadata and controls
73 lines (58 loc) · 2.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import
{
AdminForthResource
,
IAdminForthPlugin
,
IAdminForth
}
from
'./types/Back.js'
;
import
{
getComponentNameFromPath
,
md5hash
}
from
'./modules/utils.js'
;
import
{
currentFileDir
}
from
'./modules/utils.js'
;
import
path
from
'path'
;
import
fs
from
'fs'
;
import
crypto
from
'crypto'
;
export
default
class
AdminForthPlugin
implements
IAdminForthPlugin
{
adminforth
:
IAdminForth
;
pluginDir
:
string
;
customFolderName
:
string
=
'custom'
;
pluginInstanceId
:
string
;
customFolderPath
:
string
;
pluginOptions
:
any
;
resourceConfig
:
AdminForthResource
;
className
:
string
;
activationOrder
:
number
=
0
;
constructor
(
pluginOptions
:
any
,
metaUrl
:
string
)
{
// set up plugin here
this
.
pluginDir
=
currentFileDir
(
metaUrl
)
;
this
.
customFolderPath
=
path
.
join
(
this
.
pluginDir
,
this
.
customFolderName
)
;
this
.
pluginOptions
=
pluginOptions
;
process
.
env
.
HEAVY_DEBUG
&&
console
.
log
(
`🪲 🪲 AdminForthPlugin.constructor`
,
this
.
constructor
.
name
)
;
this
.
className
=
this
.
constructor
.
name
;
}
setupEndpoints
(
server
:
any
)
{
}
instanceUniqueRepresentation
(
pluginOptions
:
any
)
:
string
{
return
'non-uniquely-identified'
;
}
modifyResourceConfig
(
adminforth
:
IAdminForth
,
resourceConfig
:
AdminForthResource
)
{
this
.
resourceConfig
=
resourceConfig
;
const
uniqueness
=
this
.
instanceUniqueRepresentation
(
this
.
pluginOptions
)
;
const
seed
=
`af_pl_
${
this
.
constructor
.
name
}
_
${
resourceConfig
.
resourceId
}
_
${
uniqueness
}
`
;
this
.
pluginInstanceId
=
md5hash
(
seed
)
;
process
.
env
.
HEAVY_DEBUG
&&
console
.
log
(
`🪲 AdminForthPlugin.modifyResourceConfig`
,
seed
,
'id'
,
this
.
pluginInstanceId
)
;
this
.
adminforth
=
adminforth
;
}
/**
* This method des next:
* - fills this.adminforth.codeInjector.srcFoldersToSync with the custom folder path mapped to `./plugins/${this.constructor.name}/`
* - fills this.adminforth.codeInjector.allComponentNames with the component name mapped to the component path
*/
componentPath
(
componentFile
:
string
)
{
const
key
=
`@@/plugins/
${
this
.
constructor
.
name
}
/
${
componentFile
}
`
;
const
componentName
=
getComponentNameFromPath
(
key
)
;
if
(
!
this
.
adminforth
.
codeInjector
.
srcFoldersToSync
[
this
.
customFolderPath
]
)
{
this
.
adminforth
.
codeInjector
.
srcFoldersToSync
[
this
.
customFolderPath
]
=
`./plugins/
${
this
.
constructor
.
name
}
/`
;
}
if
(
!
this
.
adminforth
.
codeInjector
.
allComponentNames
[
key
]
)
{
const
absSrcPath
=
path
.
join
(
this
.
customFolderPath
,
componentFile
)
;
if
(
!
fs
.
existsSync
(
absSrcPath
)
)
{
throw
new
Error
(
`Plugin "
${
this
.
constructor
.
name
}
" tried to use file as component which does not exist at "
${
absSrcPath
}
"`
)
;
}
this
.
adminforth
.
codeInjector
.
allComponentNames
[
key
]
=
componentName
;
}
return
key
;
}
}
Back
|
FazBrowse Home
|
New Git URL