@@ -12,18 +12,18 @@ var isDirectory = false;
1212
1313function display_help ( ) {
1414 console . log ( '' ) ;
15- console . log ( 'without arguments = creates empty-project' ) ;
16- console . log ( '-translate = creates a resource file with the localized text from views' ) ;
17- console . log ( '-translate "TEXT" = creates an identificator for the resource' ) ;
18- console . log ( '-translate filename = parses and creates a resource file from the text file' ) ;
19- console . log ( '-translatecsv = parses and creates CSV with localization in the current directory' ) ;
20- console . log ( '-diff source target = creates differences between two resources "-diff filename_source filename_target" ' ) ;
21- console . log ( '-merge source target = merges first resource into the second "-merge filename_source filename_target "' ) ;
22- console . log ( '-clean source = cleans a resource file "-clean filename_source "' ) ;
23- console . log ( '-minify filename = minifies .js, .css or .html file into filename.min.[extension] ' ) ;
24- console . log ( '-v or -version = Total.js version ' ) ;
25- console . log ( '/path/ = target (default current directory) ' ) ;
26- console . log ( '8000 = starts a server' ) ;
15+ console . log ( 'without arguments : creates empty-project' ) ;
16+ console . log ( '-translate : creates a resource file with the localized text from views' ) ;
17+ console . log ( '-translate "TEXT" : creates an identificator for the resource' ) ;
18+ console . log ( '-translate filename : parses and creates a resource file from the text file' ) ;
19+ console . log ( '-translatecsv : parses and creates CSV with localization in the current directory' ) ;
20+ console . log ( '-csv filename : parses CSV and creates resources from CSV file ' ) ;
21+ console . log ( '-diff source target : creates differences between two resources "-diff source target "' ) ;
22+ console . log ( '-merge source target : merges first resource into the second "-merge source target "' ) ;
23+ console . log ( '-clean source : cleans a resource file "-clean source" ' ) ;
24+ console . log ( '-minify filename : minifies .js, .css or .html file into filename.min.[extension] ' ) ;
25+ console . log ( '-v or -version : Total.js version ' ) ;
26+ console . log ( '8000 : starts a server' ) ;
2727 console . log ( '' ) ;
2828}
2929
@@ -285,13 +285,44 @@ function clean_resource(content) {
285285 return output . join ( '\n' ) ;
286286}
287287
288+ function parse_csv ( content ) {
289+ var output = { } ;
290+ var max = 0 ;
291+
292+ content . split ( '\n' ) . forEach ( function ( line ) {
293+ line = line . trim ( ) ;
294+ if ( ! line )
295+ return ;
296+ var arr = line . split ( ';' ) ;
297+ if ( arr . length <= 1 )
298+ return ;
299+
300+ var key = arr [ 0 ] . trim ( ) . replace ( / ( ^ \" ) | ( \" $ ) / g, '' ) ;
301+ var value = arr [ 1 ] . trim ( ) . replace ( / ( ^ \" ) | ( \" $ ) / g, '' ) ;
302+ if ( ! key || ! value )
303+ return ;
304+
305+ max = Math . max ( key . length , max ) ;
306+ output [ key ] = value ;
307+ } ) ;
308+
309+ var builder = [ ] ;
310+ max += 10 ;
311+
312+ Object . keys ( output ) . forEach ( function ( key ) {
313+ builder . push ( '{0}: {1}' . format ( key . padRight ( max , ' ' ) , output [ key ] ) ) ;
314+ } ) ;
315+
316+ return '\n' + builder . join ( '\n' ) ;
317+ }
318+
288319function main ( ) {
289320
290321 console . log ( '' ) ;
291- console . log ( '#################################################### ' ) ;
292- console . log ( '# Total.js - Web framework for Node.js # ' ) ;
293- console . log ( '# Version: v' + require ( 'total.js' ) . version_header . padRight ( 39 ) + '# ' ) ;
294- console . log ( '#################################################### ' ) ;
322+ console . log ( '|==================================================| ' ) ;
323+ console . log ( '| Total.js - Web framework for Node.js | ' ) ;
324+ console . log ( '| Version: v' + require ( 'total.js' ) . version_header . padRight ( 39 ) + '| ' ) ;
325+ console . log ( '|==================================================| ' ) ;
295326 console . log ( '' ) ;
296327
297328 var dir = process . cwd ( ) ;
@@ -387,6 +418,19 @@ function main() {
387418 continue ;
388419 }
389420
421+ if ( cmd === '-csv' ) {
422+ var tmp = process . argv [ i + 1 ] || '' ;
423+ var tt = path . join ( path . dirname ( tmp ) , path . basename ( tmp , '.csv' ) + '.resource' ) ;
424+ fs . writeFileSync ( tt , '// Total.js resource file\n// Created: ' + new Date ( ) . format ( 'yyyy-MM-dd HH:mm' ) + '\n' + parse_csv ( fs . readFileSync ( tmp ) . toString ( 'utf8' ) ) ) ;
425+ console . log ( '========================================' ) ;
426+ console . log ( 'Parsed CSV:' ) ;
427+ console . log ( '========================================' ) ;
428+ console . log ( '' ) ;
429+ console . log ( 'output : ' + tt ) ;
430+ console . log ( '' ) ;
431+ return ;
432+ }
433+
390434 if ( cmd === '-minify' || cmd === '-compress' || cmd === '-compile' ) {
391435 $type = 5 ;
392436 continue ;
0 commit comments