Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Bootstrap
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
Koishi Bootstrap
Commits
897a95df
Commit
897a95df
authored
Mar 05, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use execFile and support org plugin
parent
e81bad5b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
60 deletions
+21
-60
src/install-plugin.ts
src/install-plugin.ts
+18
-10
src/prod.ts
src/prod.ts
+3
-2
src/utils/load-config.ts
src/utils/load-config.ts
+0
-48
No files found.
src/install-plugin.ts
View file @
897a95df
import
fs
from
'
fs
'
;
import
{
Logger
}
from
'
koishi
'
;
import
{
exec
}
from
'
child_process
'
;
import
{
exec
File
}
from
'
child_process
'
;
import
{
promisify
}
from
'
util
'
;
import
path
from
'
path
'
;
import
{
getPackageJsonPackages
}
from
'
./utils/read-package-json
'
;
import
{
loadConfig
}
from
'
./utils/load-config
'
;
import
{
Loader
}
from
"
@koishijs/cli
"
;
import
ConfigLoader
from
"
@koishijs/loader
"
;
import
{
KoishiConfig
,
PluginInstallConfig
}
from
"
./def/interfaces
"
;
const
execAsync
=
promisify
(
exec
);
import
ConfigLoader
from
'
@koishijs/loader
'
;
import
{
KoishiConfig
}
from
'
./def/interfaces
'
;
const
execFileAsync
=
promisify
(
execFile
);
const
logger
=
new
Logger
(
'
bootstrap-install-plugin
'
);
...
...
@@ -41,7 +39,13 @@ async function checkPluginExists(
async
function
npmInstall
(
name
:
string
)
{
logger
.
info
(
`Installing package
${
name
}
.`
);
try
{
await
execAsync
(
`npm install --save-exact --loglevel error
${
name
}
`
);
await
execFileAsync
(
'
npm
'
,
[
'
install
'
,
'
--save-exact
'
,
'
--loglevel
'
,
'
error
'
,
name
,
]);
logger
.
info
(
`Package
${
name
}
installed.`
);
return
true
;
}
catch
(
e
)
{
...
...
@@ -95,8 +99,11 @@ async function installPlugin(name: string, info: any) {
installList
.
push
(
`
${
name
}
@
${
installVersion
}
`
);
}
else
if
(
name
.
startsWith
(
'
@
'
)
&&
name
.
includes
(
'
/
'
))
{
const
[
author
,
pluginName
]
=
name
.
split
(
'
/
'
);
const
installName
=
pluginName
.
startsWith
(
communityPrefix
)
?
pluginName
:
`
${
communityPrefix
}${
pluginName
}
`
;
installList
.
push
(
`
${
author
}
/
${
communityPrefix
}${
plugin
Name
}
@
${
installVersion
}
`
,
`
${
author
}
/
${
communityPrefix
}${
install
Name
}
@
${
installVersion
}
`
,
);
}
else
{
if
(
allowOfficial
)
{
...
...
@@ -124,10 +131,11 @@ export async function installPluginEntry() {
logger
.
warn
(
`No plugins found, exiting.`
);
return
;
}
console
.
log
(
config
.
plugins
);
logger
.
info
(
`Cleaning NPM cache.`
);
await
exec
Async
(
`npm cache clean --force`
);
await
exec
FileAsync
(
'
npm
'
,
[
'
cache
'
,
'
clean
'
,
'
--force
'
]
);
for
(
const
[
name
,
info
]
of
Object
.
entries
(
plugins
))
{
if
(
!
info
.
$install
||
!
info
.
$version
)
{
if
(
!
info
.
$install
&&
!
info
.
$version
)
{
continue
;
}
await
installPlugin
(
name
,
info
);
...
...
src/prod.ts
View file @
897a95df
import
path
from
'
path
'
;
import
fs
from
'
fs
'
;
import
{
loadConfig
}
from
'
./utils/load-config
'
;
import
{
Logger
}
from
'
koishi
'
;
import
ConfigLoader
from
'
@koishijs/loader
'
;
import
{
KoishiConfig
}
from
'
./def/interfaces
'
;
const
logger
=
new
Logger
(
'
bootstrap-prod
'
);
...
...
@@ -22,7 +23,7 @@ async function handlePackageEntry(packagePath: string) {
export
async
function
prodEntry
()
{
logger
.
info
(
`Running production preparations...`
);
const
config
=
await
lo
adConfig
();
const
config
=
new
ConfigLoader
<
KoishiConfig
>
().
re
adConfig
();
const
plugins
=
config
?.
plugins
;
if
(
!
plugins
)
{
logger
.
warn
(
`No plugins found, exiting.`
);
...
...
src/utils/load-config.ts
deleted
100644 → 0
View file @
e81bad5b
import
{
KoishiConfig
}
from
'
../def/interfaces
'
;
import
yaml
from
'
yaml
'
;
import
fs
from
'
fs
'
;
import
path
from
'
path
'
;
import
loadJsonFile
from
'
load-json-file
'
;
import
{
Logger
}
from
'
koishi
'
;
const
logger
=
new
Logger
(
'
bootstrap-config-loader
'
);
async
function
loadFromYaml
():
Promise
<
KoishiConfig
>
{
return
yaml
.
parse
(
await
fs
.
promises
.
readFile
(
'
./koishi.config.yml
'
,
'
utf-8
'
));
}
function
loadFromJs
():
KoishiConfig
{
return
require
(
path
.
join
(
process
.
cwd
(),
'
koishi.config.js
'
));
}
async
function
loadFromJson
():
Promise
<
KoishiConfig
>
{
return
await
loadJsonFile
(
'
./koishi.config.json
'
);
}
export
async
function
loadConfig
():
Promise
<
KoishiConfig
|
undefined
>
{
try
{
logger
.
info
(
`Reading config from ./koishi.config.yml.`
);
return
await
loadFromYaml
();
}
catch
(
e
)
{
logger
.
warn
(
`Failed reading from YAML:
${(
e
as
any
).
toString
()}
, trying JS.`
,
);
logger
.
info
(
`Reading config from ./koishi.config.js.`
);
try
{
return
loadFromJs
();
}
catch
(
e
)
{
logger
.
warn
(
`Failed reading from JS:
${(
e
as
any
).
toString
()}
, trying JSON.`
,
);
logger
.
info
(
`Reading config from ./koishi.config.json.`
);
try
{
return
await
loadFromJson
();
}
catch
(
e
)
{
logger
.
warn
(
`Failed reading from JSON:
${(
e
as
any
).
toString
()}
, exiting.`
,
);
return
;
}
}
}
}
Write
Preview
Markdown
is supported
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