UNPKG

electron-compile

Version:

Electron supporting package to compile JS and CSS in Electron applications

113 lines (94 loc) 3.83 kB
// Generated by CoffeeScript 1.7.1 (function() { var EncodeFormView, Encoder, chmodSync, platform, spawn, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; $(function() { var form; form = new EncodeFormView({ logsElem: $("div.logs") }); return form.render().$el.appendTo($("div.form")); }); spawn = require("child_process").spawn; platform = require("os").platform; chmodSync = require("fs").chmodSync; Encoder = (function() { function Encoder(_arg) { this.source = _arg.source, this.bitrate = _arg.bitrate, this.target = _arg.target, this.log = _arg.log; this.target || (this.target = this.source.replace(/\.wav$/, ".mp3")); if (this.target === this.source) { this.target = this.target.replace(/\.([^.]+)$/, ' encoded.$1'); } this.bitrate || (this.bitrate = 128); switch (platform()) { case "darwin": this.pathToBin = __dirname + "/vendor/bin/osx/shineenc"; break; case "win32": this.pathToBin = __dirname + "/vendor/bin/win32/shineenc.exe"; } chmodSync(this.pathToBin, 0x1ed); } Encoder.prototype.process = function() { this.log("Starting encoding process.."); this.child = spawn(this.pathToBin, ["-b", this.bitrate, this.source, this.target]); this.child.stdout.on("data", (function(_this) { return function(data) { return _this.log("" + (data.toString().replace(/\n/g, '<br>'))); }; })(this)); this.child.stderr.on("data", (function(_this) { return function(data) { return _this.log("ERROR: " + (data.toString().replace(/\n/g, '<br>')), 'error'); }; })(this)); return this.child.on("exit", (function(_this) { return function(code) { var style; style = code === 0 ? 'good' : 'error'; return _this.log("Encoding process exited with code: " + code, style); }; })(this)); }; return Encoder; })(); EncodeFormView = (function(_super) { __extends(EncodeFormView, _super); function EncodeFormView() { return EncodeFormView.__super__.constructor.apply(this, arguments); } EncodeFormView.prototype.tagName = "form"; EncodeFormView.prototype.events = { "submit": "onSubmit" }; EncodeFormView.prototype.initialize = function(_arg) { this.logsElem = _arg.logsElem; }; EncodeFormView.prototype.render = function() { this.$el.html("File: <input class=\"file\" type=\"file\" accept=\".wav,.wave\"><br>\nBitrate: <input class=\"bitrate\" type=\"text\" value=\"128\"><br>\n<input type=\"submit\" value=\"Encode!\">"); return this; }; EncodeFormView.prototype.onSubmit = function(e) { var data; e.preventDefault(); data = { source: this.$("input.file").val(), bitrate: parseInt(this.$("input.bitrate").val()), log: (function(_this) { return function(data, type) { if (type == null) { type = 'info'; } return _this.logsElem.html("" + (_this.logsElem.html()) + "<br><span class='" + type + "'>" + data + "</span>"); }; })(this) }; if (data.source == null) { return console.log("no file!"); } return (new Encoder(data)).process(); }; return EncodeFormView; })(Backbone.View); }).call(this);