11// run as
22// node generate.js > countly.device.list.js
3+ // resulting file should be copied to "/frontend/express/public/javascripts/countly"
34
45//https://www.theiphonewiki.com/wiki/Models
56//https://gist.github.com/adamawolf/3048717
@@ -15,11 +16,17 @@ var amazon = require("./amazon.json");
1516for ( var i in amazon ) {
1617 devices [ i ] = amazon [ i ] ;
1718}
19+
20+ // Informative messages are writer to stderr so they don't interfere with the stdout piping to a file
21+ // When downloading the CSV file it will be UTF-16 LE. It needs to be transformed to UTF-8 (non BOM version)
22+ // converting with notepad++ or vscode might not work on a windows device. Try on a mac device
23+ process . stderr . write ( "Starting CSV parsing\n" ) ;
1824var csv = require ( 'csvtojson' ) ;
1925csv ( )
2026//from https://support.google.com/googleplay/answer/1727131?hl=en-GB
2127 . fromFile ( "./supported_devices.csv" )
2228 . on ( 'json' , ( jsonObj ) => {
29+ //process.stderr.write("Parsed data/json line: " + jsonObj);
2330 var d = jsonObj [ "Marketing Name" ] + "" ;
2431 var i = jsonObj [ "Model" ] + "" ;
2532 if ( i != d && d . trim ( ) . length ) {
3340 }
3441 }
3542 } )
43+ // .on('data', (data)=>{
44+ // //process.stderr.write("Parsed data line: " + data);
45+ // })
46+ // .on('error', (err)=>{
47+ // process.stderr.write("Error while parsing: " + err);
48+ // })
3649 . on ( 'done' , ( ) => {
50+ process . stderr . write ( "CSV parsing 'done' trigger\n" ) ;
3751 process . stdout . write ( "/**\n * Object with device models as keys and pretty/marketing device names as values\n * @name countlyDeviceList\n * @global\n * @namespace countlyDeviceList\n */\nvar countlyDeviceList = " + JSON . stringify ( devices , null , 4 ) + ";\n/*global module*/\nif (typeof module !== 'undefined' && module.exports) {\n module.exports = countlyDeviceList;\n}" ) ;
38- } ) ;
52+ } ) ;
53+ process . stderr . write ( "Ending CSV parsing\n" ) ;
0 commit comments