Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nocobase
Commits
11c0acb2
Commit
11c0acb2
authored
2 years ago
by
chenos
Browse files
Options
Download
Email Patches
Plain Diff
feat: improve code
parent
2c690a39
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
packages/core/server/src/application.ts
+14
-9
packages/core/server/src/application.ts
packages/core/server/src/plugin-manager.ts
+22
-21
packages/core/server/src/plugin-manager.ts
packages/presets/nocobase/src/index.ts
+3
-2
packages/presets/nocobase/src/index.ts
with
39 additions
and
32 deletions
+39
-32
packages/core/server/src/application.ts
+
14
-
9
View file @
11c0acb2
...
...
@@ -319,13 +319,18 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
return
(
<
any
>
this
.
cli
).
_findCommand
(
name
);
}
async
load
()
{
await
this
.
pm
.
load
();
async
load
(
options
?:
any
)
{
if
(
options
?.
reload
)
{
this
.
init
();
}
await
this
.
pm
.
load
(
options
);
}
async
reload
()
{
this
.
init
();
await
this
.
pm
.
load
();
async
reload
(
options
?:
any
)
{
await
this
.
load
({
...
options
,
reload
:
true
,
});
}
getPlugin
<
P
extends
Plugin
>
(
name
:
string
)
{
...
...
@@ -337,9 +342,9 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
}
async
runAsCLI
(
argv
=
process
.
argv
,
options
?:
ParseOptions
)
{
if
(
argv
?.[
2
]
!==
'
install
'
)
{
await
this
.
load
();
}
await
this
.
load
(
{
method
:
argv
?.[
2
],
}
);
return
this
.
cli
.
parseAsync
(
argv
,
options
);
}
...
...
@@ -419,11 +424,11 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
if
(
options
?.
clean
)
{
await
this
.
db
.
clean
(
isBoolean
(
options
.
clean
)
?
{
drop
:
options
.
clean
}
:
options
.
clean
);
await
this
.
reload
({
method
:
'
install
'
});
}
await
this
.
emitAsync
(
'
beforeInstall
'
,
this
,
options
);
await
this
.
load
();
await
this
.
db
.
sync
(
options
?.
sync
);
await
this
.
pm
.
install
(
options
);
await
this
.
version
.
update
();
...
...
This diff is collapsed.
Click to expand it.
packages/core/server/src/plugin-manager.ts
+
22
-
21
View file @
11c0acb2
...
...
@@ -23,6 +23,18 @@ class PluginManagerRepository extends Repository {
async
upgrade
(
name
:
string
|
string
[],
options
)
{}
}
const
collectionOptions
=
{
name
:
'
applicationPlugins
'
,
fields
:
[
{
type
:
'
string
'
,
name
:
'
name
'
,
unique
:
true
},
{
type
:
'
string
'
,
name
:
'
version
'
},
{
type
:
'
boolean
'
,
name
:
'
enabled
'
},
{
type
:
'
boolean
'
,
name
:
'
installed
'
},
{
type
:
'
boolean
'
,
name
:
'
builtIn
'
},
{
type
:
'
json
'
,
name
:
'
options
'
},
],
};
export
class
PluginManager
{
app
:
Application
;
collection
:
Collection
;
...
...
@@ -31,17 +43,7 @@ export class PluginManager {
constructor
(
options
:
PluginManagerOptions
)
{
this
.
app
=
options
.
app
;
this
.
collection
=
this
.
app
.
db
.
collection
({
name
:
'
applicationPlugins
'
,
fields
:
[
{
type
:
'
string
'
,
name
:
'
name
'
,
unique
:
true
},
{
type
:
'
string
'
,
name
:
'
version
'
},
{
type
:
'
boolean
'
,
name
:
'
enabled
'
},
{
type
:
'
boolean
'
,
name
:
'
installed
'
},
{
type
:
'
boolean
'
,
name
:
'
builtIn
'
},
{
type
:
'
json
'
,
name
:
'
options
'
},
],
});
this
.
collection
=
this
.
app
.
db
.
collection
(
collectionOptions
);
const
app
=
this
.
app
;
const
pm
=
this
;
this
.
repository
=
this
.
collection
.
repository
as
PluginManagerRepository
;
...
...
@@ -138,11 +140,10 @@ export class PluginManager {
}
await
next
();
});
this
.
app
.
on
(
'
beforeInstall
'
,
async
()
=>
{
await
this
.
collection
.
sync
();
});
this
.
app
.
on
(
'
beforeLoadAll
'
,
async
(
options
)
=>
{
await
this
.
collection
.
sync
();
this
.
app
.
on
(
'
beforeLoadAll
'
,
async
(
app
,
options
)
=>
{
if
(
options
.
method
&&
[
'
install
'
,
'
upgrade
'
].
includes
(
options
.
method
))
{
await
this
.
collection
.
sync
();
}
const
exists
=
await
this
.
app
.
db
.
collectionExistsInDb
(
'
applicationPlugins
'
);
if
(
!
exists
)
{
return
;
...
...
@@ -250,8 +251,8 @@ export class PluginManager {
return
instance
;
}
async
load
()
{
await
this
.
app
.
emitAsync
(
'
beforeLoadAll
'
);
async
load
(
options
:
any
=
{}
)
{
await
this
.
app
.
emitAsync
(
'
beforeLoadAll
'
,
this
.
app
,
options
);
for
(
const
[
name
,
plugin
]
of
this
.
plugins
)
{
if
(
!
plugin
.
enabled
)
{
...
...
@@ -264,12 +265,12 @@ export class PluginManager {
if
(
!
plugin
.
enabled
)
{
continue
;
}
await
this
.
app
.
emitAsync
(
'
beforeLoadPlugin
'
,
plugin
);
await
this
.
app
.
emitAsync
(
'
beforeLoadPlugin
'
,
plugin
,
options
);
await
plugin
.
load
();
await
this
.
app
.
emitAsync
(
'
afterLoadPlugin
'
,
plugin
);
await
this
.
app
.
emitAsync
(
'
afterLoadPlugin
'
,
plugin
,
options
);
}
await
this
.
app
.
emitAsync
(
'
afterLoadAll
'
);
await
this
.
app
.
emitAsync
(
'
afterLoadAll
'
,
this
.
app
,
options
);
}
async
install
(
options
:
InstallOptions
=
{})
{
...
...
This diff is collapsed.
Click to expand it.
packages/presets/nocobase/src/index.ts
+
3
-
2
View file @
11c0acb2
...
...
@@ -6,7 +6,7 @@ export class PresetNocoBase<O = any> extends Plugin {
}
initialize
()
{
this
.
app
.
on
(
'
beforeInstall
'
,
async
()
=>
{
this
.
app
.
on
(
'
beforeInstall
'
,
async
(
app
,
options
)
=>
{
const
plugins
=
[
'
error-handler
'
,
'
collection-manager
'
,
...
...
@@ -25,13 +25,14 @@ export class PresetNocoBase<O = any> extends Plugin {
];
for
(
const
plugin
of
plugins
)
{
const
instance
=
await
this
.
app
.
pm
.
add
(
plugin
);
if
(
instance
.
model
&&
plugin
!==
'
hello
'
)
{
if
(
instance
.
model
)
{
instance
.
model
.
enabled
=
true
;
instance
.
model
.
builtIn
=
true
;
instance
.
model
.
installed
=
true
;
await
instance
.
model
.
save
();
}
}
await
this
.
app
.
reload
();
});
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment