fs.readFile(newFilePath + "/" + fileName, function (err, fileData) { if (err) { gutil.log(gutil.colors.red('Error:'), 'couldn\'t read .trk file'); process.exit(); } // Variables to populate to later export var config = {}; var data = {}; // Convert to JSON var jsonData = JSON.parse(parser.toJson(fileData)); var property = jsonData["object"]["property"]; // Begin populating config config["application"] = {"name": fileName.split(".")[0]}; config["video"] = { height: 350, // minimum height for video width: 650 // minimum width for video } config['rightT'] = {visible: false}; config['rightB'] = {visible: false}; config['bottomL'] = {visible: false}; config['bottomR'] = {visible: false}; // Populate data var videoclip = property[findKey(property, {'name': 'videoclip'})]["object"]["property"]; var videoProperty = videoclip[findKey(videoclip, {'name': 'video'})]["object"]["property"]; //parseFloat(videoProperty[findKey(videoProperty, {'name': 'delta_t'})]["$t"]) // Get name of all frames var frames = []; var frameFiles = fs.readdirSync(compileToPath + "/frames"); frameFiles.forEach(file => { frames.push("frames" + "/" + file); }); data["video"] = { frameStart: parseInt(videoclip[findKey(videoclip, {'name': 'startframe'})]["$t"]), frameStep: parseInt(videoclip[findKey(videoclip, {'name': 'stepsize'})]["$t"]), frameRate: (1000 / parseInt(videoProperty[findKey(videoProperty, {'name': 'delta_t'})]["$t"])), // fps calculated from delta_t playRate: 1.0, // percentage frameCurrent: 0, // current frame frames: frames, height: parseInt(property[findKey(property, {'name': 'height'})]["$t"]), width: parseInt(property[findKey(property, {'name': 'width'})]["$t"]), }; data['matrix'] = { xorigin: 176.0, yorigin: 82.0, angle: 1.2188752351312977, xscale: 81.66386719485864, yscale: 81.66386719485864 }; data['axis'] = { visible: true }; data['objects'] = []; console.log(config); console.log("\n"); console.log(data); // Copy template and tracker to directory gutil.log(gutil.colors.green("Export"), 'copying tracker.js file...'); fs.copy("./tracker.js", compileToPath + "/tracker.js", function (err) { if (err) { gutil.log(gutil.colors.red('Error:'), 'couldn\'t copy tracker'); process.exit(); } gutil.log(gutil.colors.green("Export"), 'copying index.html file...'); fs.copy("./utils/tracker_template.html", compileToPath + "/index.html", function (err) { if (err) { gutil.log(gutil.colors.red('Error:'), 'couldn\'t copy tracker html'); process.exit(); } // Replace const options = { files: compileToPath + "/index.html", replace: ['[TRACKER_CONFIG_DICTIONARY]', '[TRACKER_DATA_DICTIONARY]'], with: [JSON.stringify(config), JSON.stringify(data)], allowEmptyPaths: false, encoding: 'utf8', }; gutil.log(gutil.colors.green("Export"), 'replacing placeholders with data...'); replace.sync(options); gutil.log(gutil.colors.green("Export"), 'Completed successfully!'); }); }); });
var detectFormat = function (file) { return findKey(serializers, function (serializer) { return serializer.test(file); }); };