-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.js
760 lines (671 loc) · 22.3 KB
/
core.js
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
//loadash=require('loadash');
// Here client path has to be changed onces you get the value from the UI
module.exports={
//Removing all the duplicate paths coming from the directory
remove_duplicates: function (arry)
{
return Array.from(new Set(arry))
},
//Reading the manifest file
//Replaces the client path directory with the server path directory and vice versa
directorypathReplace: function (filesnfolders,pathvalue1,pathvalue2)
{
for(var u=0;u<filesnfolders.length;u++)
{
filesnfolders[u]=filesnfolders[u].replace(pathvalue1,pathvalue2);
}
return filesnfolders;
}
,
//Function outdated
//This function gives all the files in the directory
// without accessing the folders in the list
getFileDir: function(path)
{
const fs=require("fs");
console.log(path);
files=[];
files=fs.readdirSync(path,(err,files)=>{
if(err) throw err;console.log(err);
console.log(files);
return files;
});
/*
fs.readdir(path, function(err, files){
files = files.map(function (fileName) {
return {
name: fileName,
time: fs.statSync(path + '/' + fileName).mtime.getTime()
};
})
.sort(function (a, b) {
return a.time - b.time; })
.map(function (v) {
return v.name; });
*/
return files;
}
,
//finds the artifact numeric part
GetCheckSum:function(file_text)
{
const text=file_text;
const asc_arr=[];
const weights=[1,3,7,11,13]
for(var i=0;i<text.length;i++)
{
asc_arr.push(text.charCodeAt(i));
}
console.log(asc_arr);
var w_index=0,sum=0;
for(var j=0;j<asc_arr.length;j++)
{
if(w_index<weights.length)
{
//console.log("Adding "+asc_arr[j]+"*"+weights[w_index]+" to the sum");
w_index=0;
}
sum+=asc_arr[j]*weights[w_index];
w_index++;
}
//console.log("Sum: "+sum);
m=Math.pow(2,31)-1;
sum=sum%(m);
return sum; //to check the artifact id of data
},
//Create the artifact id complete name
GetArtifactName:function(file_text,file_name)
{
const text=file_text;
const asc_arr=[];
const weights=[1,3,7,11,13]
for(var i=0;i<text.length;i++)
{
asc_arr.push(text.charCodeAt(i));
}
console.log(asc_arr);
var w_index=0,sum=0;
for(var j=0;j<asc_arr.length;j++)
{
if(w_index<weights.length)
{
//console.log("Adding "+asc_arr[j]+"*"+weights[w_index]+" to the sum");
w_index=0;
}
sum+=asc_arr[j]*weights[w_index];
w_index++;
}
//console.log("Sum: "+sum);
m=Math.pow(2,31)-1;
sum=sum%(m);
//console.log("Modulus operator : "+m);
//console.log(sum);
return sum.toString()+"_L"+file_text.length.toString()+"."+GetExtension(file_name);
},
replaceAll:function(search, replacement) {
var target = this;
return target.split(search).join(replacement);
},
// Check if the directory exists in the path
// and if not create the directory
//makes all the folders at the server location
CheckDirExists:function(fold,server_path)
{
for(var k=0;k<fold.length;k++)
{
var str=fold[k];
//F:\\important files\\Website practise\\Nodejs Code\\server\\testfolder
//var str='server/Client1/New_test/new 1'
console.log("Path in checkdirexits function: "+str);
var strarr=str.split('\\')
var length_of_array=strarr.length;
var count_change_dir=0;
console.log(process.cwd());
for(var p=1;p<length_of_array;p++)
{
var exists=fs.existsSync(strarr[p-1]+'\\'+strarr[p]);
if(!exists)
{fs.mkdirSync(strarr[p-1]+'\\'+strarr[p]);}
count_change_dir=count_change_dir+1;
//if(process.cwd()!="F:\\important files\\Website practise\\Nodejs Code")
//{
process.chdir(strarr[p-1]);
//}
}
//console.log("Current path after traversing inside"+process.cwd());
//console.log('count_change_dir : '+count_change_dir);
for(var ch=0;ch<count_change_dir;ch++)
{
process.chdir('../');
}
console.log("Current path after coming outside the folder"+process.cwd());
process.chdir(server_path);
}
},
dateFormat:function(date, fstr, utc) {
utc = utc ? 'getUTC' : 'get';
return fstr.replace (/%[YmdHMS]/g, function (m) {
switch (m) {
case '%Y': return date[utc + 'FullYear'] (); // no leading zeros required
case '%m': m = 1 + date[utc + 'Month'] (); break;
case '%d': m = date[utc + 'Date'] (); break;
case '%H': m = date[utc + 'Hours'] (); break;
case '%M': m = date[utc + 'Minutes'] (); break;
case '%S': m = date[utc + 'Seconds'] (); break;
default: return m.slice (1); // unknown code, remove %
}
// add leading zero if required
return ('0' + m).slice (-2);
});
},
//function used to write the files to the path
Write_file_toserver:function(l_files,label_text='',server_path,client_path)
{
//console.log(process.cwd());
var sManifestStr='';
var fil1=l_files.slice(0);
fs=require('fs')
os=require('os')
console.log("Inside write_file function value of fil1 :"+fil1);
//console.log('before directorypathReplace:'+files);
l_files=directorypathReplace(l_files,client_path,server_path);
console.log("Inside write_file function value of files :"+l_files);
for(var i=0;i<fil1.length;i++)
{
//console.log("Inside write_file function value of files :"+files);
//console.log("Inside write_file function value of fil :"+fil1);
var file_path=fil1[i];var file_name=l_files[i].split('\\').pop();
console.log('fileName:'+file_name);
var modified_file_name='';
var file_text=""
console.log('File path : '+file_path);
file_text=fs.readFileSync(file_path, "utf8",function(err,data)
{
if (err) throw err;
console.log(" content is :"+data);
return data;
});
//Finds the artifact id and creates the name for it
modified_file_name=GetArtifactName(file_text,file_name);
var TAB="\t"
sManifestStr+='CR'+TAB+fil1[i]+TAB+" -> "+TAB+l_files[i]+"\\"+modified_file_name+os.EOL;
//Not needed yet to confirm with professor
//sManifestStr+='Source_path : '+fil1[i]+os.EOL;
//sManifestStr+='Dest_path : '+l_files[i]+'/'+modified_file_name+os.EOL;
//sManifestStr+='Text in the file : '+file_text+os.EOL;
sDatetime=dateFormat(new Date(),"%d%m%Y%H%M%S",true).toString();
sManifestStr+="Time stamp: "+dateFormat(new Date(),"%d%m%Y%H%M%S",true).toString()+os.EOL;;
//console.log('Inside write_file function with the filetext: '+file_text);
sManifestStr+='Aritifactid :'+modified_file_name+os.EOL;
// Working code of fs.writeline
/*
fs.writeFile(l_files[i]+'/'+modified_file_name, file_text, function (err) {
if (err) throw err;
console.log('Saved!');
});
*/
console.log('Modified file name '+modified_file_name);
console.log('File Path='+file_path);
console.log('New Path='+l_files[i]+'\\'+modified_file_name);
fs.copyFile(file_path, l_files[i]+'\\'+modified_file_name, (err) => {
if (err) throw err;
console.log('Source file got copied to Destination path');
});
console.log('Renaming files file 1 ='+fil1[i]);
console.log('Renaming files file 2 ='+l_files[i]);
//fs.renameSync(fil1[i],files[i]);
}
sManifestStr+='************************************************************'+os.EOL;
console.log(sManifestStr);
console.log("Before calling Create Manifest")
console.log("Server Path : "+server_path)
console.log("project_name : "+project_name)
label_text ='This is demo label'
CreateManifestFile(server_path,project_name,sManifestStr,sDatetime,label_text);
},
//  print the tab on the screen
//Generates the Manifest file and copy all the manifest content in the file
CreateManifestFile:function(ff_paths,project_name,sman_txt,sTimeStamp,labeltext)
{
os=require('os')
fs=require('fs')
console.log("Inside the Create Manifest file function")
path=ff_paths;
console.log("Inside the Create Manifest file function Path : "+path)
sManifestFileName='Manifest_'+sTimeStamp+'.txt'
file_path=path+'\\'+sManifestFileName
console.log(file_path)
fs.writeFile(file_path,sman_txt,function(err)
{
if (err) throw err;
console.log('Manifest file Saved!');
});
file_path=path+'\\labels.txt'
//file_path=path+"\\"+project_name+'\\labels.txt'
console.log(file_path)
fs=require('fs');
exists=fs.existsSync(file_path)
if(!exists)
{
if(labeltext!=null)
{
fs.writeFile(file_path,"\nManifest_"+sTimeStamp+'.txt'+" "+labeltext+os.crlf+"\n",function(err)
{
if (err) throw err;
console.log('Label file Saved!');
});
}
}
else {
if(labeltext!=null)
{
content = fs.readFileSync(path+'\\labels.txt','UTF8',function(data,err)
{
if(err) throw err;
return data
});
content=content+"\nManifest_"+sTimeStamp+'.txt'+" "+labeltext+os.crlf+"\n"
console.log(content)
fs.writeFile(path+'\\labels.txt', os.EOL+'Manifest_'+sTimeStamp+'.txt'+" "+labeltext+os.crlf+"\n", { flag: 'a+' }, (err) => {})
}
}
return sManifestFileName
/*
fs.appendFileSync(path+'\\labels.txt',os.EOL+'Manifest_'+sTimeStamp+'.txt'+" "+labeltext+os.EOL+" ","utf8",function(err)
{
if(err) throw err;
console.log('Label Saved!')
});
*/
},
// Get the file updated time of the file
getFileUpdatedDate : function(path){
const stats = fs.statSync(path)
return stats.mtime
},
// Get the extension of the file from the filenames
GetExtension:function(file_name)
{
arr=file_name.split(".");
return arr[arr.length-1];
},
// Find the directory under directory and list the directory in the string format
/*
var findfolder=function(client_path)
{
var folders=[];
fs.readdirSync(client_path).foreach(function(file)
{
var stats=fs.statSync(client_path+"/"+file);
if(stats.isDirectory())
{
findfolder(client_path+'/'+file);
var a=client_path+'/'+file;
folder.push(a);
}
})
}
*/
/*
// List of all the folder and files in one directory
var findFileAndFolder, jsFiles, rootDir;
var folder = [],file_path=[];
var dir='';var tcase='';
function findFileAndFolder(dir,tcase='')
{
console.log('Directory searching for'+dir);
Filesystem.readdirSync(dir).forEach(function(file) {
var stat;
stat = Filesystem.statSync("" + dir + "/" + file);
if (stat.isDirectory())
{
var a="" + dir + "/" + file;
folder.push(a);
console.log("Directory : "+a);
return findFileAndFolder(a,tcase);
}
else //if (file.split('.').pop() === 'js')
{
console.log("Files : "+"" + dir + "/" + file);
return file_path.push("" + dir + "/" + file);
}
});
console.log(os.EOL+"Tcase: "+tcase+os.EOL);
if(tcase=="client")
{
console.log('inside Client will display client directory');
folder=folder.filter(folder=>!folder.startsWith('./server'));
file_path=file_path.filter(file_path=>!file_path.startsWith('./server'));
}
else if(tcase=="server") {
console.log('inside server will display server directory');
//folder=folder.filter(folder=>!folder.startsWith('./Client'||'Client'));
folder=folder.filter(folder=>folder.startsWith('./server'||'server'));
//file_path=file_path.filter(file_path=>!file_path.startsWith('./Client'||'Client'));
file_path=file_path.filter(file_path=>file_path.startsWith('./server'||'server'));
}
return [file_path,folder];
};
*/
/* // Code that needs to be checked
Filesystem = require('fs');
// List of all the folder and files in one directory
var findFileAndFolder, jsFiles, rootDir;
var folder = [],file_path=[];
var dir='';var tcase='';
function findFileAndFolder(dir,tcase='')
{
console.log('Directory searching for'+dir);
Filesystem.readdirSync(dir).forEach(function(file) {
var stat;
stat = Filesystem.statSync("" + dir + "/" + file);
if (stat.isDirectory())
{
var a="" + dir + "/" + file;
folder.push(a);
console.log("Directory : "+a);
return findFileAndFolder(a,tcase);
}
else //if (file.split('.').pop() === 'js')
{
console.log("Files : "+"" + dir + "/" + file);
return file_path.push("" + dir + "/" + file);
}
});
console.log(os.EOL+"Tcase: "+tcase+os.EOL);
if(tcase=="client")
{
console.log('inside Client will display client directory');
folder=folder.filter(folder=>!folder.startsWith('./server'));
file_path=file_path.filter(file_path=>!file_path.startsWith('./server'));
}
else if(tcase=="server") {
console.log('inside server will display server directory');
//folder=folder.filter(folder=>!folder.startsWith('./Client'||'Client'));
folder=folder.filter(folder=>folder.startsWith('./server'||'server'));
//file_path=file_path.filter(file_path=>!file_path.startsWith('./Client'||'Client'));
file_path=file_path.filter(file_path=>file_path.startsWith('./server'||'server'));
}
return [file_path,folder];
};
*/
//Push to server code
//Pull
//Yet to be made
getClientDirectory:function()
{
var obj=findFileAndFolder(client_path,'client');
return obj;
},
getServerDirectory:function()
{
return findFileAndFolder(server_path,'server');
},
//Creates the empty directories in the server for a particular user
createServerDirectory:function(folders,client_path,server_path,project_path)
{
//console.log('Parameter Sent : '+ folders);
//folders=directorypathReplace(folders,'./Client','server');
folders=directorypathReplace(folders,client_path,server_path);
console.log("Inside the createServerDirectory : "+folders)
//CheckDirExists(folders,server_path,project_path);
return folders;
}
//module.exports=getClientDirectory(client_path);
//module.export=getServerDirectory(server_path);
//module.export=CheckDirExists(folders)
//module.exports=directorypathReplace(files,pathvalue1,pathvalue2)
// remove_duplicates,directorypathReplace,GetCheckSum,GetArtifactName,replaceAll,CheckDirExists,dateFormat,Write_file_toserver,CreateManifestFile,GetExtension,findFileAndFolder,createServerDirectory}
/// Output check
//var chk=0;
//chk=GetCheckSum("Hello World");
//files=getFileDir(path);
//console.log(process.cwd());
//print all the files with folder
//console.log(getFileDir(path));
//print all the folders inside the folders
//console.log("Checkdirinpath : "+checkdirinpath(path));
//print all the modified date of the files
//console.log(getFileUpdatedDate(path));
/*
for(var t=0;t<every_thing[0].length;t++)
{
console.log(every_thing[0][t]+os.EOL);
}
for(var t=0;t<every_thing[1].length;t++)
{
console.log(every_thing[1][t]+os.EOL);
}
*/
//print all the folders inside the folders
//var every_thing=findFileAndFolder(client_path,'client');
//console.log('*************************************************************************************')
//console.log('*********************Inside Client directory')
//console.log("files ="+every_thing[0]);
//console.log("folders="+every_thing[1])
//console.log("folders"+every_thing[1]);
//console.log('********************* Removing the duplicate paths from the array ')
//console.log(remove_duplicates(every_thing[0].concat(every_thing[1])))
//console.log('********************* before calling directorypathReplace')
//console.log(directorypathReplace(every_thing[1],'./Client','server'))
//console.log("Initial Stage at the server getserverdirectory: "+getServerDirectory(server_path));
//console.log("Initial Stage at the server getclientdirectory: "+getClientDirectory(client_path));
//result()
//console.log(module);
//console.log('********************* before calling createServerDirectory ')
//console.log(createServerDirectory(every_thing[0].concat(every_thing[1])));
//console.log(Write_file_toserver(remove_duplicates(every_thing[0])));
//console.log(file_text);
//var file_path=every_thing[0][0];
//.replace('./Client/Client1/1Def.txt','Client/Client1/1Def.txt');
//console.log(findFileAndFolder())
}
function directorypathReplace(filesnfolders,pathvalue1,pathvalue2)
{
for(var u=0;u<filesnfolders.length;u++)
{
filesnfolders[u]=filesnfolders[u].replace(pathvalue1,pathvalue2);
}
return filesnfolders;
}
function GetCheckSum(file_text)
{
const text=file_text;
const asc_arr=[];
const weights=[1,3,7,11,13]
for(var i=0;i<text.length;i++)
{
asc_arr.push(text.charCodeAt(i));
}
console.log(asc_arr);
var w_index=0,sum=0;
for(var j=0;j<asc_arr.length;j++)
{
if(w_index<weights.length)
{
//console.log("Adding "+asc_arr[j]+"*"+weights[w_index]+" to the sum");
w_index=0;
}
sum+=asc_arr[j]*weights[w_index];
w_index++;
}
//console.log("Sum: "+sum);
m=Math.pow(2,31)-1;
sum=sum%(m);
return sum; //to check the artifact id of data
}
function GetExtension(file_name)
{
arr=file_name.split(".");
return arr[arr.length-1];
}
//  print the tab on the screen
//Generates the Manifest file and copy all the manifest content in the file
/*
function CreateManifestFile(ff_paths,project_name,sman_txt,sTimeStamp,labeltext)
{
path=server_path+'/'+project_name;
fs.writeFile(path+'/Manifest_'+sTimeStamp+'.txt',sman_txt,function(err)
{
if (err) throw err;
console.log('Saved!');
});
fs.appendFile(path+'/labels.txt','Manifest_'+sTimeStamp+'.txt'+" "+labeltext,function(err)
{
if(err) throw err;
});
}
*/
//Create the artifact id complete name
function GetArtifactName(file_text,file_name)
{
const text=file_text;
const asc_arr=[];
const weights=[1,3,7,11,13]
for(var i=0;i<text.length;i++)
{
asc_arr.push(text.charCodeAt(i));
}
console.log(asc_arr);
var w_index=0,sum=0;
for(var j=0;j<asc_arr.length;j++)
{
if(w_index<weights.length)
{
//console.log("Adding "+asc_arr[j]+"*"+weights[w_index]+" to the sum");
w_index=0;
}
sum+=asc_arr[j]*weights[w_index];
w_index++;
}
//console.log("Sum: "+sum);
m=Math.pow(2,31)-1;
sum=sum%(m);
//console.log("Modulus operator : "+m);
//console.log(sum);
return sum.toString()+"_L"+file_text.length.toString()+"."+GetExtension(file_name);
}
// Check if the directory exists in the path
// and if not create the directory
//makes all the folders at the server location
function CheckDirExists(fold,server_path,project_path)
{
for(var k=0;k<fold.length;k++)
{
var str=fold[k];
//F:\\important files\\Website practise\\Nodejs Code\\server\\testfolder
//var str='server/Client1/New_test/new 1'
i=0
while(str.split('\\').pop()!='server')
{
i++
//console.log(i)
var exists=fs.existsSync(str);
if(!exists)
{
fs.mkdirSync(str);
}
arr=str.split('\\')
rem_str=str.split('\\').pop()
str=arr.splice(0,arr.length-1).join('\\')
console.log(str)
}
console.log("Path in checkdirexits function: "+str);
}
/*
for(var k=0;k<fold.length;k++)
{
var str=fold[k];
//var str='server/Client1/New_test/new 1'
console.log("Path in checkdirexits function: "+str);
var strarr=str.split('/')
var length_of_array=strarr.length;
var count_change_dir=0;
console.log(process.cwd());
for(var p=1;p<length_of_array;p++)
{
var exists=fs.existsSync(strarr[p-1]+'/'+strarr[p]);
if(!exists)
{fs.mkdirSync(strarr[p-1]+'/'+strarr[p]);}
count_change_dir=count_change_dir+1;
//if(process.cwd()!="F:\\important files\\Website practise\\Nodejs Code")
//{
process.chdir(strarr[p-1]);
//}
}
//console.log("Current path after traversing inside"+process.cwd());
//console.log('count_change_dir : '+count_change_dir);
for(var ch=0;ch<count_change_dir;ch++)
{
process.chdir('../');
}
console.log("Current path after coming outside the folder"+process.cwd());
process.chdir(server_path);
}
*/
}
function dateFormat(date, fstr, utc) {
utc = utc ? 'getUTC' : 'get';
return fstr.replace (/%[YmdHMS]/g, function (m) {
switch (m) {
case '%Y': return date[utc + 'FullYear'] (); // no leading zeros required
case '%m': m = 1 + date[utc + 'Month'] (); break;
case '%d': m = date[utc + 'Date'] (); break;
case '%H': m = date[utc + 'Hours'] (); break;
case '%M': m = date[utc + 'Minutes'] (); break;
case '%S': m = date[utc + 'Seconds'] (); break;
default: return m.slice (1); // unknown code, remove %
}
// add leading zero if required
return ('0' + m).slice (-2);
});
}
//Generates the Manifest file and copy all the manifest content in the file
function CreateManifestFile(ff_paths,project_name,sman_txt,sTimeStamp,labeltext)
{
console.log("Inside the Create Manifest file function")
path=ff_paths;
console.log("Inside the Create Manifest file function Path : "+path)
sManifestFileName='Manifest_'+sTimeStamp+'.txt'
file_path=path+'\\'+sManifestFileName
console.log(file_path)
fs.writeFile(file_path,sman_txt,function(err)
{
if (err) throw err;
console.log('Manifest file Saved!');
});
file_path=path+'\\labels.txt'
//file_path=path+"\\"+project_name+'\\labels.txt'
console.log(file_path)
exists=fs.existsSync(file_path)
if(!exists)
{
if(labeltext!=null)
{
fs.writeFile(file_path,"\nManifest_"+sTimeStamp+'.txt'+" "+labeltext+os.crlf+"\n",function(err)
{
if (err) throw err;
console.log('Label file Saved!');
});
}
}
else {
if(labeltext!=null)
{
content = fs.readFileSync(path+'\\labels.txt','UTF8',function(data,err)
{
if(err) throw err;
return data
});
content=content+"\nManifest_"+sTimeStamp+'.txt'+" "+labeltext+os.crlf+"\n"
console.log(content)
fs.writeFile(path+'\\labels.txt', os.EOL+'Manifest_'+sTimeStamp+'.txt'+" "+labeltext+os.crlf+"\n", { flag: 'a+' }, (err) => {})
}
return sManifestFileName
}
}
//Removing all the duplicate paths coming from the directory
function remove_duplicates(arry)
{
return Array.from(new Set(arry))
}