-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·65 lines (52 loc) · 1.67 KB
/
index.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
#!/usr/bin/env node
var process = require('process'),
args = process.argv,
CSVReader = require('./lib/csv-reader'),
QRImage = require( './lib/qrcode-image-generator' ),
Util = require('findhit-util'),
fs = require('fs'),
mkpath = require('mkpath'),
path = require('path'),
qrCodeGenerator = module.exports = {},
DS = path.sep,
__file_ext = 'svg';
var generateCodes =
qrCodeGenerator.generateCodes =
function( csvList, savePath ){
var reader = fs.createReadStream( csvList );
CSVReader.readLine( reader , function processLine( filename, siteUrl ){
console.log(savePath + DS + filename + '.' + __file_ext);
var writer = fs.createWriteStream(
savePath + filename + '.' + __file_ext
);
QRImage.generate( writer, siteUrl , function(){
console.log( filename, siteUrl );
console.log('-> QR Code generated for ',filename);
} );
},
function processFinished(){
console.log('All lines processed');
}
);
};
var _csvList = '',
_imgPath = 'qr_images';
if(args.length == 2){
console.error('missing csv list to process');
return;
}
_csvList = args[2];
if(args.length == 4){
_imgPath = args[3];
if(_imgPath[0] != DS)
_imgPath = path.dirname(_csvList) + DS + _imgPath;
}
else
_imgPath = path.dirname(_csvList) + DS + _imgPath;
path.normalize(_imgPath);
if(_imgPath[_imgPath.length - 1] != DS)
_imgPath += DS;
if ( !fs.existsSync(_imgPath) ) {
mkpath.sync(_imgPath, 0755);
}
generateCodes( _csvList, _imgPath );