@@ -2,40 +2,43 @@ var requirejs = require('requirejs');
22var fs = require ( 'fs' ) ;
33var sanitizeFilename = require ( 'sanitize-filename' ) ;
44
5-
65const source = process . argv [ 2 ] ;
76const destination = process . argv [ 3 ] ;
87const extension = process . argv [ 4 ] || '' ;
98
109requirejs . config ( {
11- nodeRequire : require
10+ nodeRequire : require
1211} ) ;
1312require ( 'node-define' ) ;
1413
1514sourceData = require ( source ) ;
1615
17- if ( ! fs . existsSync ( destination ) ) {
18- fs . mkdirSync ( destination ) ;
16+ if ( ! fs . existsSync ( destination ) ) {
17+ fs . mkdirSync ( destination ) ;
1918}
2019
2120function createLevel ( path , data ) {
22- if ( ! data . name ) {
23- return
24- }
25- const newPath = `${ path } /${ sanitizeFilename ( data . name ) } ` ;
26-
27- if ( data . snippet ) {
28- fs . writeFile ( ` ${ newPath } ${ extension } ` , data . snippet . join ( '\n' ) , function ( err ) {
29- if ( err ) throw err ;
30- } ) ;
31- } else if ( data [ 'sub-menu' ] ) {
32- if ( ! fs . existsSync ( newPath ) ) {
33- fs . mkdirSync ( newPath ) ;
34- }
35- data [ 'sub-menu' ] . forEach ( submenu => {
36- createLevel ( newPath , submenu ) ;
37- } ) ;
21+ if ( ! data . name ) {
22+ return ;
23+ }
24+ const newPath = `${ path } /${ sanitizeFilename ( data . name ) } ` ;
25+
26+ if ( data . snippet ) {
27+ fs . writeFile (
28+ ` ${ newPath } ${ extension } ` ,
29+ data . snippet . join ( '\n' ) ,
30+ function ( err ) {
31+ if ( err ) throw err ;
32+ }
33+ ) ;
34+ } else if ( data [ 'sub-menu' ] ) {
35+ if ( ! fs . existsSync ( newPath ) ) {
36+ fs . mkdirSync ( newPath ) ;
3837 }
38+ data [ 'sub-menu' ] . forEach ( submenu => {
39+ createLevel ( newPath , submenu ) ;
40+ } ) ;
41+ }
3942}
4043
4144createLevel ( destination , sourceData ) ;
0 commit comments