@@ -21,6 +21,7 @@ var template = require('jsdoc/template'),
2121 language ,
2222 outdir = env . opts . destination ;
2323var util = require ( 'util' ) ;
24+
2425function find ( spec ) {
2526 return helper . find ( data , spec ) ;
2627}
@@ -252,24 +253,33 @@ function sortNav(members) {
252253
253254function buildCategories ( members , templatePath ) {
254255 var categories = { } ;
255- _ . each ( members , function ( v ) {
256-
257- var category = getCustomTagValue ( v , 'category' ) ;
258- if ( ! category ) {
259- category = "BaseTypes" ;
256+ if ( language === 'en' ) {
257+ var exists = fs . existsSync ( path . resolve ( templatePath , "categories.json" ) ) ;
258+ if ( exists ) {
259+ categories = JSON . parse ( fs . readFileSync ( path . resolve ( templatePath , "categories.json" ) ) ) ;
260+ } else {
261+ logger . error ( 'Please generate a Chinese JSdoc first' )
260262 }
261- var arr = category . split ( " " ) ;
262- var aa = categories ;
263- for ( let index = 0 ; index < arr . length ; index ++ ) {
264- const element = arr [ index ] ;
265- if ( ! aa [ element ] ) {
266- aa [ element ] = { } ;
267- aa [ element ] . default = [ ] ;
263+ } else {
264+ _ . each ( members , function ( v ) {
265+
266+ var category = getCustomTagValue ( v , 'category' ) ;
267+ if ( ! category ) {
268+ category = "BaseTypes" ;
268269 }
269- aa = aa [ element ] ;
270- }
271- aa . default . push ( v . longname ) ;
272- } ) ;
270+ var arr = category . split ( " " ) ;
271+ var aa = categories ;
272+ for ( let index = 0 ; index < arr . length ; index ++ ) {
273+ const element = arr [ index ] ;
274+ if ( ! aa [ element ] ) {
275+ aa [ element ] = { } ;
276+ aa [ element ] . default = [ ] ;
277+ }
278+ aa = aa [ element ] ;
279+ }
280+ aa . default . push ( v . longname ) ;
281+ } ) ;
282+ }
273283 var outpath = path . resolve ( templatePath , "categories.json" ) ;
274284 fs . writeFileSync ( outpath , JSON . stringify ( categories ) , 'utf8' ) ;
275285 return categories ;
0 commit comments