@@ -9,20 +9,31 @@ const fs = require('hexo-fs'),
9
9
path = require ( 'path' ) ,
10
10
url = require ( 'url' ) ,
11
11
_ = require ( 'lodash' ) ,
12
- localJsPath = '/live2d/lib/' ,
12
+ localJsPath = '/live2dw/lib/' ,
13
+ localModelPath = '/live2dw/assets/'
13
14
coreJsList = require ( 'live2d-widget/lib/manifest' ) ,
15
+ coreJsDepPath = require ( 'live2d-widget/lib' ) ,
14
16
defaultConfig = require ( 'live2d-widget/src/config/defaultConfig' ) ;
15
17
16
18
let fileArr = new Array ( ) ,
17
19
modelPath ,
18
20
jsPath ,
21
+ coreJsNameLength ,
19
22
modelJsonPath ,
20
23
config = _ . defaultsDeep ( hexo . config . live2d , hexo . theme . config . live2d , defaultConfig ) ;
21
24
22
- function getModelJson ( pathName ) {
23
- var fileName = path . parse ( pathName ) . name . split ( '.' ) ;
25
+ function getCoreJs ( path ) {
26
+ let fileName = path . parse ( path ) . name ;
27
+ if ( ( fileName . length < coreJsNameLength ) || ( coreJsNameLength === undefined ) ) {
28
+ jsPath = fileName ;
29
+ coreJsNameLength = fileName . length ;
30
+ }
31
+ }
32
+
33
+ function getModelJson ( path ) {
34
+ let fileName = path . parse ( path ) . name . split ( '.' ) ;
24
35
if ( fileName [ 1 ] === 'model' ) {
25
- modelJsonPath = pathName ;
36
+ modelJsonPath = path ;
26
37
}
27
38
}
28
39
@@ -33,10 +44,11 @@ function addFile(destPath, sourceFile){
33
44
} ) ;
34
45
}
35
46
36
- function addDir ( destPath , sourceDir ) {
47
+ function addDir ( destPath , sourceDir , func ) {
37
48
let lsDir = fs . readdirSync ( sourceDir )
38
49
lsDir . forEach ( function ( file ) {
39
50
addFile ( destPath + file , path . resolve ( sourceDir , file ) ) ;
51
+ if ( func !== undefined ) func ( destPath ) ;
40
52
} , this ) ;
41
53
}
42
54
@@ -78,24 +90,24 @@ if(_.hasIn(config, 'model.jsonPath')){
78
90
// Set modelPath and config.model.use in some case
79
91
// Copy file and apply config.model.jsonPath only if !_.hasIn(config, 'model.jsonPath')
80
92
if ( _ . hasIn ( config , 'model.use' ) ) {
81
- // 2.a is a npm-module
82
93
try ( ) {
83
- modelPath = require . resolve ( config . model . use ) ;
94
+ // 2.a is a npm-module
95
+ modelPath = path . resolve ( path . dirname ( require . resolve ( config . model . use + '/package' ) ) , './assets/' ) ;
84
96
} catch ( e ) {
85
97
// 2.b is in live2d_models/ folder
86
98
let tryPath = path . resolve ( hexo . base_dir , path . join ( './live2d_models/' , config . model . use ) ) ;
87
99
fs . exists ( tryPath , function ( exists ) {
88
100
if ( exists ) {
89
- // 2.b continue
101
+ // 2.b founded in live2d_models/
102
+ // 3.b Apply config.model.jsonPath
103
+ modelPath = tryPath ;
90
104
} else {
91
- // 2.c maybe an url or something, just apply it.
105
+ // 2.c maybe an url or something, let it go~
92
106
// 3.c Apply config.model.jsonPath
93
107
config . model . jsonPath = config . model . use ;
94
108
}
95
109
} )
96
110
}
97
-
98
-
99
111
_ . unset ( config , 'model.use' ) ;
100
112
} else {
101
113
// 2.d doesn't have config.model.use use default
@@ -106,20 +118,22 @@ if(_.hasIn(config, 'model.use')){
106
118
// Process config.model.jsonPath
107
119
// and copy files
108
120
if ( ! _ . hasIn ( config , 'model.jsonPath' ) ) {
109
-
121
+ addDir ( localModelPath , modelPath , getModelJson ) ;
122
+ config . model . jsonPath = localModelPath + modelJsonPath ;
110
123
}
111
124
112
125
113
- // Process jsPath with real_jsPath(not a varible )
126
+ // Process jsPath with jsPath(processed )
114
127
// and copy files
115
128
if ( jsPath === jsOnLocalPath ) {
116
129
// a. is local
117
130
// copy coreJs
118
-
119
- // apply jsPath
120
-
131
+ for ( let f of Object . keys ( coreJsList ) ) {
132
+ addFile ( localJsPath + f , path . resolve ( coreJsDepPath , f ) ) ;
133
+ getCoreJs ( localJsPath + f ) ;
134
+ }
121
135
} else {
122
- // b. is a CDN or url , let it go ~
136
+ // b. is a url or something , let it go ~
123
137
}
124
138
125
139
0 commit comments