/
totaljs
executable file
·835 lines (671 loc) · 22.4 KB
/
totaljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
#! /usr/bin/env node
var exec = require('child_process').exec;
var fs = require('fs');
var path = require('path');
var os = require('os');
var Utils = require('total.js/utils');
var Internal = require('total.js/internal');
var $type = 1;
var isDirectory = false;
function display_help() {
console.log('--------------------------------------------------------');
console.log('TEMPLATES');
console.log('--------------------------------------------------------');
console.log('');
console.log('without arguments : creates emptyproject');
console.log('flow : creates emptyproject-flow');
console.log('dashboard : creates emptyproject-dashboard');
console.log('flowboard : creates emptyproject-flowboard');
console.log('spa : creates emptyproject-jcomponent');
console.log('pwa : creates emptyproject-pwa');
console.log('rest : creates emptyproject-restservice');
console.log('cms : downloads Total.js CMS');
console.log('eshop : downloads Total.js Eshop');
console.log('superadmin : downloads Total.js SuperAdmin');
console.log('openplatform : downloads Total.js OpenPlatform');
console.log('helpdesk : downloads Total.js HelpDesk');
console.log('');
console.log('--------------------------------------------------------');
console.log('TOOLS');
console.log('--------------------------------------------------------');
console.log('');
console.log('-translate : creates a resource file with the localized text from views');
console.log('-translate "TEXT" : creates an identificator for the resource');
console.log('-translate filename : parses and creates a resource file from the text file');
console.log('-translatecsv : parses and creates CSV with localization in the current directory');
console.log('-csv filename : parses CSV and creates resources from CSV file');
console.log('-diff source target : creates differences between two resources "-diff source target"');
console.log('-merge source target : merges first resource into the second "-merge source target"');
console.log('-clean source : cleans a resource file "-clean source"');
console.log('-minify filename : minifies .js, .css or .html file into filename.min.[extension]');
console.log('-install : run "totaljs -install help" to see what can be installed');
console.log('8000 : starts a server');
console.log('');
}
function translateFile(a) {
if (!fs.existsSync(a))
return false;
var arr = fs.readFileSync(a).toString('utf8').split('\n');
var builder = [];
var count = 0;
for (var i = 0, length = arr.length; i < length; i++) {
var line = arr[i].trim();
if (line.length === 0)
continue;
builder.push('T' + line.hash().padRight(17, ' ') + ': ' + line);
count++;
}
fs.writeFileSync('translate.resource', '// Total.js translation file\n// Created: ' + new Date().format('yyyy-MM-dd HH:mm') + '\n' + builder.join('\n'));
console.log('Total.js: the translation was created (' + count + ' texts)');
return true;
}
function diff(a, b) {
if (!fs.existsSync(a)) {
console.log('The translation file does not exist: ' + a);
return;
}
if (!fs.existsSync(b)) {
console.log('The translation file does not exist: ' + b);
return;
}
var ba = fs.readFileSync(a).toString('utf8');
var bb = fs.readFileSync(b).toString('utf8');
var ca = ba.parseConfig();
var cb = bb.parseConfig();
var ka = Object.keys(ca);
var kb = Object.keys(cb);
ba = ba.split('\n');
bb = bb.split('\n');
var output = '';
var items = [];
var add = 0;
var rem = 0;
var padding = 0;
for (var i = 0, length = ba.length; i < length; i++) {
if (ba[i].indexOf(ka[0]) !== -1) {
padding = ba[i].indexOf(':');
break;
}
}
if (padding <= 0)
padding = 17;
function find_comment(arr, id) {
var comment = '';
for (var i = 0, length = arr.length; i < length; i++) {
if (arr[i].indexOf(id) !== -1)
return comment;
var line = arr[i];
if (line[0] !== '/' && line[1] !== '/')
continue;
comment = line;
}
return '';
}
var comment = '';
var prev = '';
for (var i = 0, length = ka.length; i < length; i++) {
var key = ka[i];
if (cb[key] !== undefined)
continue;
comment = find_comment(ba, key);
if (comment) {
if (items[items.length - 1] !== '')
items.push('');
items.push(comment);
}
var empty = comment === prev;
prev = comment;
items.push(key.padRight(padding) + ': ' + ca[key]);
if (!empty)
items.push('');
add++;
}
if (items.length > 0) {
output += '\n';
output += 'Add to "' + b + '" these:\n';
output += '\n';
output += items.join('\n');
output += '\n';
}
items = [];
for (var i = 0, length = kb.length; i < length; i++) {
var key = kb[i];
if (ca[key] !== undefined)
continue;
comment = find_comment(bb, key);
if (comment) {
if (items[items.length - 1] !== '')
items.push('');
items.push(comment);
}
else if (prev !== '')
items.push('');
var empty = comment === prev;
prev = comment;
items.push(key.padRight(padding) + ': ' + cb[key]);
if (!empty)
items.push('');
rem++;
}
if (items.length) {
output += '\n';
output += 'Remove from "' + b + '" these:\n';
output += '\n';
output += items.join('\n');
output += '\n';
}
var filename = path.join(path.dirname(b), path.basename(b, '.resource') + '-diff.txt');
fs.writeFileSync(filename, '// Total.js diff file\n// Created: ' + new Date().format('yyyy-MM-dd HH:mm') + '\n' + clean_resource(output));
console.log('========================================');
console.log('Translation files differences:');
console.log('========================================');
console.log('');
console.log('added : ' + add);
console.log('removed : ' + rem);
console.log('output : ' + filename);
console.log('');
}
function merge(a, b) {
if (!fs.existsSync(a)) {
console.log('The translation file does not exist: ' + a);
return;
}
if (!fs.existsSync(b)) {
console.log('The translation file does not exist: ' + b);
return;
}
var ba = fs.readFileSync(b).toString('utf8');
var bb = fs.readFileSync(a).toString('utf8');
var arr = ba.split('\n');
var output = [];
var cb = bb.parseConfig();
var upd = 0;
for (var i = 0, length = arr.length; i < length; i++) {
var line = arr[i];
if (!line || line[0] === '#' || line.startsWith('//')) {
output.push(line);
continue;
}
var index = line.indexOf(' :');
if (index === -1) {
index = line.indexOf('\t:');
if (index === -1) {
output.push(line);
continue;
}
}
var key = line.substring(0, index).trim();
var val = cb[key];
if (!val) {
output.push(line);
continue;
}
upd++;
output.push(key.padRight(index) + ' : ' + val);
}
var filename = path.join(path.dirname(b), path.basename(b, '.resource') + '-merged.txt');
fs.writeFileSync(filename, '// Total.js merged file\n// Created: ' + new Date().format('yyyy-MM-dd HH:mm') + '\n' + clean_resource(output.join('\n')));
console.log('========================================');
console.log('Merged result:');
console.log('========================================');
console.log('');
console.log('merged : ' + upd);
console.log('output : ' + filename);
console.log('');
}
function clean_resource(content) {
var lines = content.split('\n');
var output = [];
var max = 0;
for (var i = 0, length = lines.length; i < length; i++) {
var line = lines[i];
if (!line || line[0] === '#' || line.startsWith('//'))
continue;
var index = line.indexOf(' :');
if (index === -1) {
index = line.indexOf('\t:');
if (index === -1)
continue;
}
max = Math.max(max, index);
}
for (var i = 0, length = lines.length; i < length; i++) {
var line = lines[i];
if (!line || line[0] === '#' || line.startsWith('//')) {
output.push(line);
continue;
}
var index = line.indexOf(' :');
if (index === -1) {
index = line.indexOf('\t:');
if (index === -1) {
output.push(line);
continue;
}
}
var key = line.substring(0, index).trim();
output.push(key.padRight(max, ' ') + ' : ' + line.substring(index + 2).trim());
}
return output.join('\n');
}
function parse_csv(content) {
var output = {};
var max = 0;
content.split('\n').forEach(function(line, index) {
if (!index)
return;
line = line.trim();
if (!line)
return;
var arr = line.split(';');
if (arr.length <= 1)
return;
var key = arr[0].trim().replace(/(^")|("$)/g, '');
var value = arr[2].trim().replace(/(^")|("$)/g, '');
if (!key || !value)
return;
max = Math.max(key.length, max);
output[key] = value;
});
var builder = [];
max += 10;
Object.keys(output).forEach(function(key) {
builder.push('{0}: {1}'.format(key.padRight(max, ' '), output[key]));
});
return '\n' + builder.join('\n');
}
function main() {
console.log('');
console.log('|==================================================|');
console.log('| Total.js - Web framework for Node.js |');
console.log('| Version: v' + require('total.js').version_header.padRight(39) + '|');
console.log('|==================================================|');
console.log('');
var dir = process.cwd();
for (var i = 2; i < process.argv.length; i++) {
var arg = process.argv[i];
var cmd = arg.toLowerCase();
if (cmd.substring(0, 2) === '--')
cmd = cmd.substring(1);
if (i === 2) {
var port = cmd.parseInt();
if (port) {
CONF.directory_temp = '~' + path.join(os.tmpdir(), 'totaljs' + dir.hash());
CONF.directory_public = '~' + dir;
CONF.allow_compile_html = false;
CONF.allow_compile_script = false;
CONF.allow_compile_style = false;
F.accept('.less', 'text/less');
F.http('debug', { port: port, directory: dir });
F.route('/*', function() {
var self = this;
var dir = F.path.public(self.url.substring(1));
var filename = path.join(self.url, 'index.html').substring(1);
F.path.exists(filename, function(e) {
if (e)
return self.file(filename, '');
fs.readdir(dir, function(err, items) {
var render = function(controller, directories, files) {
controller.content('<!DOCTYPE html><html><head><title>Directory listing: {0}</title><meta charset="utf-8" /><style>body{font-family:Arial;font-size:16px;padding:10px 30px 30px}a{display:block}.directory:last-child{margin-bottom:10px}.directory{padding:2px 10px;background-color:#F8F8F8;margin-bottom:2px;text-decoration:none;color:black;font-weight:bold;font-size:18px}.directory-back{text-decoration:none;font-size:50px;margin:0 0 10px 5px;color:gray}.file{color:gray;text-decoration:none;font-size:14px;padding:3px 10px;border-bottom:1px solid #F0F0F0;}.file span{float:right;font-size:12px;margin:2px 0 0 0;color:#A0A0A0}.file:hover{background-color:#F8F8F8}</style></head><body><div class="directories">{1}</div><div class="files">{2}</div></body></html>'.format(controller.url, directories.join(''), files.join('')), 'text/html');
};
var directories = [];
var files = [];
if (self.url !== '/')
directories.push('<a href=".." class="directory-back">..</a>');
if (err)
return render(self, directories, files);
items.wait(function(item, next) {
var filename = path.join(dir, item);
fs.stat(filename, function(err, info) {
if (info.isFile())
files.push('<a href="{1}" class="file">{0}<span>{2}</span></a>'.format(item, self.url + item, info.size.filesize()));
else
directories.push('<a href="{1}/" class="directory">{0}</a>'.format(item, self.url + item));
next();
});
}, () => render(self, directories, files));
});
});
});
F.route('/proxy/', function() {
var self = this;
var method = self.req.method;
U.request(self.query.url, [self.req.method], method === 'POST' || method === 'PUT' || method === 'DELETE' ? self.body : null, (err, response, status, headers) => self.content(response, headers['content-type']));
}, ['get', 'post', 'put', 'delete'], 5120);
return;
}
}
if (cmd === '-v' || cmd === '-version')
return;
if (cmd === '-t' || cmd === '-translate') {
$type = 4;
continue;
}
if (cmd === '-merge') {
merge(process.argv[i + 1] || '', process.argv[i + 2] || '');
return;
}
if (cmd === '-translate-csv' || cmd === '-translatecsv' || cmd === '-c') {
$type = 6;
continue;
}
if (cmd === '-csv') {
var tmp = process.argv[i + 1] || '';
var tt = path.join(path.dirname(tmp), path.basename(tmp, '.csv') + '.resource');
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')));
console.log('========================================');
console.log('Parsed CSV:');
console.log('========================================');
console.log('');
console.log('output : ' + tt);
console.log('');
return;
}
if (cmd === '-i' || cmd === '-install') {
var libs = ['jc', 'jc.min', 'jcta', 'jcta.min', 'jctajr', 'jctajr.min', 'ta', 'jr', 'jr.jc', 'spa', 'spa.min'];
var tmp = process.argv[i + 1] || '';
if (tmp === 'help') {
return console.log('Following libs can be installed: jc, jc.min, jcta.min, jctajr.min, ta, jr, jr.jc, spa');
}
if (!tmp || libs.indexOf(tmp) < 0)
return console.log('Unknown library: "' + tmp + '"');
console.log('');
console.log('Installing: ' + tmp);
var url = '';
switch(tmp) {
case 'jc':
url = 'https://rawgit.com/totaljs/components/master/0dependencies/jc.js';
break;
case 'jc.min':
url = 'https://rawgit.com/totaljs/components/master/0dependencies/jc.min.js';
break;
case 'jcta.min':
url = 'https://rawgit.com/totaljs/components/master/0dependencies/jcta.min.js';
break;
case 'jctajr.min':
url = 'https://rawgit.com/totaljs/components/master/0dependencies/jctajr.min.js';
break;
case 'spa':
case 'spa.min':
url = 'https://rawgit.com/totaljs/components/master/0dependencies/spa.min.js';
break;
case 'spa@14':
case 'spa.min@14':
url = 'https://rawgit.com/totaljs/components/master/0dependencies/spa.min@14.js';
break;
case 'spa@15':
case 'spa.min@15':
url = 'https://rawgit.com/totaljs/components/master/0dependencies/spa.min@15.js';
break;
case 'ta':
url = 'https://rawgit.com/totaljs/Tangular/master/Tangular.js';
break;
case 'jr':
url = 'https://rawgit.com/totaljs/jRouting/master/jrouting.js';
break;
case 'jr.jc':
url = 'https://rawgit.com/totaljs/jRouting/master/jrouting.jcomponent.js';
break;
}
U.download(url, [], function callback(err,response) {
var target = fs.createWriteStream(path.join(dir, './' + tmp + '.js'));
response.pipe(target);
console.log('Done!');
});
return;
}
if (cmd === '-minify' || cmd === '-compress' || cmd === '-compile') {
$type = 5;
continue;
}
if (cmd === '-clean') {
var tmp = process.argv[i + 1] || '';
var tt = path.join(path.dirname(tmp), path.basename(tmp, '.resource') + '-cleaned.txt');
fs.writeFileSync(tt, '// Total.js cleaned file\n// Created: ' + new Date().format('yyyy-MM-dd HH:mm') + '\n' + clean_resource(fs.readFileSync(tmp).toString('utf8')));
console.log('========================================');
console.log('Cleaned result:');
console.log('========================================');
console.log('');
console.log('output : ' + tt);
console.log('');
return;
}
if (cmd === '-cms' || cmd === 'cms') {
git(dir, 'cms');
return;
}
if (cmd === '-eshop' || cmd === 'eshop') {
git(dir, 'eshop');
return;
}
if (cmd === '-superadmin' || cmd === 'superadmin') {
git(dir, 'superadmin');
return;
}
if (cmd === '-messenger' || cmd === 'messenger') {
git(dir, 'messenger');
return;
}
if (cmd === '-helpdesk' || cmd === 'helpdesk') {
git(dir, 'helpdesk');
return;
}
if (cmd === '-openplatform' || cmd === 'openplatform') {
git(dir, 'openplatform');
return;
}
if (cmd === '-flow' || cmd === 'flow') {
git(dir, 'emptyproject-flow');
return;
}
if (cmd === '-dashboard' || cmd === 'dashboard') {
git(dir, 'emptyproject-dashboard');
return;
}
if (cmd === '-flowboard' || cmd === 'flowboard') {
git(dir, 'emptyproject-flowboard');
return;
}
if (cmd === '-pwa' || cmd === 'pwa') {
git(dir, 'emptyproject-pwa');
return;
}
if (cmd === '-spa' || cmd === 'spa') {
git(dir, 'emptyproject-jcomponent');
return;
}
if (cmd === '-rest' || cmd === 'rest') {
git(dir, 'emptyproject-restservice');
return;
}
if (cmd === '-diff') {
diff(process.argv[i + 1] || '', process.argv[i + 2] || '');
return;
}
if (cmd === '-a' || cmd === '-angular' || cmd === 'angular') {
$type = 3;
continue;
}
if (cmd === '-m' || cmd === '-minimal' || cmd === '-minimum' || cmd === 'minimum') {
$type = 2;
continue;
}
if (cmd === '-n' || cmd === '-normal' || cmd === 'normal') {
$type = 1;
continue;
}
if (cmd === '-h' || cmd === '-help' || cmd === '--help' || cmd === 'help') {
display_help();
return;
}
dir = arg;
isDirectory = true;
break;
}
if (dir === '.')
dir = process.cwd();
if ($type === 5) {
if (!fs.existsSync(dir)) {
console.log('ERROR: file not found');
console.log('');
return;
}
var content = fs.readFileSync(dir).toString('utf8');
var extension = U.getExtension(dir);
var filename = dir.replace('.' + extension, '.min.' + extension);
switch (extension.toLowerCase()) {
case 'html':
fs.writeFileSync(filename, Utils.minifyHTML(content));
break;
case 'js':
fs.writeFileSync(filename, Utils.minifyScript(content));
break;
case 'css':
fs.writeFileSync(filename, Utils.minifyStyle(content));
break;
}
console.log('Minified: ' + filename);
return;
}
if ($type !== 4) {
if (!fs.existsSync(dir)) {
console.log('ERROR: directory does not exist');
console.log('');
return;
}
}
if ($type === 4) {
if (isDirectory) {
if (translateFile(dir))
return;
console.log('T' + dir.hash().padRight(17, ' ') + ': ' + dir);
return;
}
console.log('Total.js: creating translation');
Utils.ls(dir, function(files) {
var resource = {};
var texts = {};
var max = 0;
var count = 0;
for (var i = 0, length = files.length; i < length; i++) {
var filename = files[i];
var ext = Utils.getExtension(filename);
if (filename.indexOf('sitemap') === -1 && ext !== 'html' && ext !== 'js')
continue;
var content = fs.readFileSync(filename).toString('utf8');
var command = Internal.findLocalization(content, 0);
while (command !== null) {
// Skip for direct reading
if (command.command[0] === '#' && command.command[1] !== ' ') {
command = Internal.findLocalization(content, command.end);
continue;
}
var key = 'T' + command.command.hash();
var file = filename.substring(dir.length + 1);
texts[key] = command.command;
if (resource[key]) {
if (resource[key].indexOf(file) === -1)
resource[key] += ', ' + file;
}
else
resource[key] = file;
count++;
max = Math.max(max, key.length);
command = Internal.findLocalization(content, command.end);
}
}
var keys = Object.keys(resource);
var builder = [];
var output = {};
for (var i = 0, length = keys.length; i < length; i++) {
if (!output[resource[keys[i]]])
output[resource[keys[i]]] = [];
output[resource[keys[i]]].push(keys[i].padRight(max + 5, ' ') + ': ' + texts[keys[i]]);
}
keys = Object.keys(output);
for (var i = 0, length = keys.length; i < length; i++)
builder.push('\n// ' + keys[i] + '\n' + output[keys[i]].join('\n'));
fs.writeFileSync('translate.resource', '// Total.js translation file\n// Created: ' + new Date().format('yyyy-MM-dd HH:mm') + '\n' + builder.join('\n'));
console.log('Total.js: the translation was created (' + count + ' texts)');
}, (path, dir) => dir ? (path.endsWith('/node_modules') || path.endsWith('/tmp') || path.endsWith('/.git')) ? false : true : true);
return;
}
if ($type === 6) {
console.log('Total.js: creating translation to CSV');
Utils.ls(dir, function(files) {
var resource = {};
var texts = {};
var count = 0;
var output = ['Hash;Text;Translation'];
for (var i = 0, length = files.length; i < length; i++) {
var filename = files[i];
var ext = Utils.getExtension(filename);
if (ext !== 'html' && ext !== 'js')
continue;
var content = fs.readFileSync(filename).toString('utf8');
var command = Internal.findLocalization(content, 0);
while (command !== null) {
// Skip for direct reading
if (command.command[0] === '#' && command.command[1] !== ' ') {
command = Internal.findLocalization(content, command.end);
continue;
}
var key = 'T' + command.command.hash();
texts[key] = command.command;
if (!resource[key]) {
output.push(key + ';"' + command.command.replace(/"/g, '""') + '";');
resource[key] = true;
count++;
}
command = Internal.findLocalization(content, command.end);
}
}
fs.writeFileSync('translate.csv', output.join('\n'));
console.log('Total.js: the translation was created (' + count + ' texts)');
}, (path, dir) => dir ? (path.endsWith('/node_modules') && path.endsWith('/tmp') && path.endsWith('/.git')) ? false : true : true);
return;
}
var files = fs.readdirSync(dir);
if (files.length > 0) {
var can = true;
for (var i = 0; i < files.length; i++) {
var name = files[i];
if (name[0] !== '.')
can = false;
}
if (!can) {
console.log('ERROR: directory is not empty');
console.log('');
return;
}
}
git(dir, 'emptyproject');
}
function git(dir, type) {
var done = function() {
console.log('Installed: {0}'.format(type));
console.log();
};
U.ls(dir, function(fol, fil) {
if (fol.length || fil.length) {
console.log('Directory "{0}"" is not empty.'.format(dir));
console.log();
return;
}
F.path.mkdir(dir);
exec('git clone https://github.com/totaljs/{0}.git {1}'.format(type, dir), function() {
F.path.mkdir(path.join(dir, '/node_modules/'));
F.rmdir(path.join(dir, '.git'), function() {
F.unlink(path.join(dir, '.gitignore'), function() {
F.path.exists(path.join(dir, 'package.json'), function(e) {
if (e)
exec('npm install total.js --save', done);
else
exec('npm install', done);
});
});
});
});
});
}
main();