- scss compilation moved to main process, generates css static files, can be called with "-c" command argument

This commit is contained in:
jean-emmanuel 2015-09-16 23:50:33 +02:00 • committed by bordun
parent 9a42073c7f
commit a93e8dc9c8
8 changed files with 100 additions and 320 deletions

File diff suppressed because one or more lines are too long

View file

@ -3,16 +3,7 @@
<head>
<title>OSCGUI</title>
<link rel="stylesheet" href="fonts/font-awesome.min.css"/>
<style>
/* Preloading style */
html {
background:#21252b;
overflow: hidden;
}
body {
opacity:0;
}
</style>
<link rel="stylesheet" href="css/style.css"/>
<script>
require( __dirname + "/js/browser.js")
</script>

View file

@ -17,30 +17,4 @@ require( __dirname + "/jquery/jquery.ba-resize.js")
// main js
require( __dirname + "/app/app.js")
// Sass (add stylesheets to var styles)
var Sass = require( __dirname + "/sass/sass.js")
Sass.setWorkerUrl(__dirname + "/sass/sass.worker.js");
var sass = new Sass()
sass.options({style: Sass.style.compact})
var styles = ["/../css/style.scss"]
, stylesdata = ''
, done = 0;
for (i in styles) {
fs.readFile(__dirname + styles[i], 'utf8', function (err,data) {
if (err) {return console.log(err);}
stylesdata += "\n" + data;
done += 1;
if (done==styles.length) {
sass.compile(stylesdata,function(d){
$('body').append('<style>'+d.text+'<\/style>')
ipc.send('ready');
})
}
});
}
ipc.send('ready');

View file

@ -1,202 +0,0 @@
/*! sass.js - v0.9.2 (e355668) - built 2015-06-14
providing libsass 3.2.5 (0e6b4a2)
via emscripten 1.33.1 (ae2f801)
*/
(function (root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Sass = factory();
}
}(this, function () {/*global document*/
// identify the path sass.js is located at in case we're loaded by a simple
// <script src="path/to/sass.js"></script>
// this path can be used to identify the location of
// * sass.worker.js from sass.js
// * libsass.js.mem from sass.sync.js
// see https://github.com/medialize/sass.js/pull/32#issuecomment-103142214
// see https://github.com/medialize/sass.js/issues/33
var SASSJS_RELATIVE_PATH = (function() {
'use strict';
// in Node things are rather simple
if (typeof __dirname !== 'undefined') {
return __dirname;
}
// we can only run this test in the browser,
// so make sure we actually have a DOM to work with.
if (typeof document === 'undefined' || !document.getElementsByTagName) {
return null;
}
// http://www.2ality.com/2014/05/current-script.html
var currentScript = document.currentScript || (function() {
var scripts = document.getElementsByTagName('script');
return scripts[scripts.length - 1];
})();
var path = currentScript && currentScript.src;
if (!path) {
return null;
}
// [worker] make sure we're not running in some concatenated thing
if (path.slice(-8) === '/sass.js') {
return path.slice(0, -8);
}
// [sync] make sure we're not running in some concatenated thing
if (path.slice(-13) === '/sass.sync.js') {
return path.slice(0, -13);
}
return null;
})() || '.';
/*global Worker, SASSJS_RELATIVE_PATH*/
'use strict';
var noop = function(){};
var slice = [].slice;
// defined upon first Sass.initialize() call
var globalWorkerUrl;
function Sass(workerUrl) {
if (!workerUrl && !globalWorkerUrl) {
/*jshint laxbreak:true */
throw new Error(
'Sass needs to be initialized with the URL of sass.worker.js - '
+ 'either via Sass.setWorkerUrl(url) or by new Sass(url)'
);
/*jshint laxbreak:false */
}
if (!globalWorkerUrl) {
globalWorkerUrl = workerUrl;
}
// bind all functions
// we're doing this because we used to have a single hard-wired instance that allowed
// [].map(Sass.removeFile) and we need to maintain that for now (at least until 1.0.0)
for (var key in this) {
if (typeof this[key] === 'function') {
this[key] = this[key].bind(this);
}
}
this._callbacks = {};
this._worker = new Worker(workerUrl || globalWorkerUrl);
this._worker.addEventListener('message', this._handleWorkerMessage, false);
}
// allow setting the workerUrl before the first Sass instance is initialized,
// where registering the global workerUrl would've happened automatically
Sass.setWorkerUrl = function(workerUrl) {
globalWorkerUrl = workerUrl;
};
Sass.style = {
nested: 0,
expanded: 1,
compact: 2,
compressed: 3
};
Sass.comments = {
'none': 0,
'default': 1
};
Sass.prototype = {
style: Sass.style,
comments: Sass.comments,
destroy: function() {
this._worker && this._worker.terminate();
this._worker = null;
this._callbacks = {};
this._importer = null;
},
_handleWorkerMessage: function(event) {
if (event.data.command) {
this[event.data.command](event.data.args);
}
this._callbacks[event.data.id] && this._callbacks[event.data.id](event.data.result);
delete this._callbacks[event.data.id];
},
_dispatch: function(options, callback) {
if (!this._worker) {
throw new Error('Sass worker has been terminated');
}
options.id = 'cb' + Date.now() + Math.random();
this._callbacks[options.id] = callback;
this._worker.postMessage(options);
},
_importerInit: function(args) {
// importer API done callback pushing results
// back to the worker
var done = function done(result) {
this._worker.postMessage({
command: '_importerFinish',
args: [result]
});
}.bind(this);
try {
this._importer(args[0], done);
} catch(e) {
done({ error: e.message });
throw e;
}
},
importer: function(importerCallback, callback) {
if (typeof importerCallback !== 'function' && importerCallback !== null) {
throw new Error('importer callback must either be a function or null');
}
// callback is executed in the main EventLoop
this._importer = importerCallback;
// tell worker to activate importer callback
this._worker.postMessage({
command: 'importer',
args: [Boolean(importerCallback)]
});
callback && callback();
},
};
var commands = 'writeFile readFile listFiles removeFile clearFiles lazyFiles preloadFiles options compile compileFile';
commands.split(' ').forEach(function(command) {
Sass.prototype[command] = function() {
var callback = slice.call(arguments, -1)[0];
var args = slice.call(arguments, 0, -1);
if (typeof callback !== 'function') {
args.push(callback);
callback = noop;
}
this._dispatch({
command: command,
args: args
}, callback);
};
});
// automatically set the workerUrl in case we're loaded by a simple
// <script src="path/to/sass.js"></script>
// see https://github.com/medialize/sass.js/pull/32#issuecomment-103142214
Sass.setWorkerUrl(SASSJS_RELATIVE_PATH + '/sass.worker.js');
return Sass;
}));

View file

@ -2,11 +2,74 @@
providing libsass 3.2.5 (0e6b4a2)
via emscripten 1.33.1 (ae2f801)
*/
/*global Sass*/
(function (root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Sass = factory();
}
}(this, function () {/*global document*/
// identify the path sass.js is located at in case we're loaded by a simple
// <script src="path/to/sass.js"></script>
// this path can be used to identify the location of
// * sass.worker.js from sass.js
// * libsass.js.mem from sass.sync.js
// see https://github.com/medialize/sass.js/pull/32#issuecomment-103142214
// see https://github.com/medialize/sass.js/issues/33
var SASSJS_RELATIVE_PATH = (function() {
'use strict';
// in Node things are rather simple
if (typeof __dirname !== 'undefined') {
return __dirname;
}
// we can only run this test in the browser,
// so make sure we actually have a DOM to work with.
if (typeof document === 'undefined' || !document.getElementsByTagName) {
return null;
}
// http://www.2ality.com/2014/05/current-script.html
var currentScript = document.currentScript || (function() {
var scripts = document.getElementsByTagName('script');
return scripts[scripts.length - 1];
})();
var path = currentScript && currentScript.src;
if (!path) {
return null;
}
// [worker] make sure we're not running in some concatenated thing
if (path.slice(-8) === '/sass.js') {
return path.slice(0, -8);
}
// [sync] make sure we're not running in some concatenated thing
if (path.slice(-13) === '/sass.sync.js') {
return path.slice(0, -13);
}
return null;
})() || '.';
/*global Sass, SASSJS_RELATIVE_PATH*/
// NOTE: this will load "./libsass.js.mem" relative to CWD,
// that's fine in Node, but catastrophic in the browser.
// That's fine, since sass.sync.js is NOT recommended
// to be used in the browser anyway.
var Module = {
memoryInitializerPrefixURL: SASSJS_RELATIVE_PATH + '/',
onRuntimeInitialized: function() {
'use strict';
Sass._ready();
// NodeJS resolves immediately, but the browser does not
Module._sassFullyInitialized = true;
typeof Sass !== 'undefined' && Sass._ready();
}
};
@ -742,74 +805,5 @@ if (Module._sassFullyInitialized) {
// react to emscripten in sync loading mode (NodeJS)
Sass._ready();
}
'use strict';
/*global Sass, postMessage, onmessage:true, importScripts*/
var _importerDone;
var _importerInit = function(request, done) {
_importerDone = done;
postMessage({
command: '_importerInit',
args: [request]
});
};
var methods = {
_importerFinish: function(result) {
_importerDone && _importerDone(result);
_importerDone = null;
},
importer: function(callback) {
// an importer was un/set
// we need to register a callback that will pipe
// things through the worker
Sass.importer(callback ? _importerInit : null);
},
};
onmessage = function (event) {
function done(result) {
try {
// may throw DataCloneError: Failed to execute 'postMessage' on 'WorkerGlobalScope': An object could not be cloned.
// because of Error instances not being clonable (wtf?)
postMessage({
id: event.data.id,
result: result
});
} catch (e) {
if (!result.error) {
// unless we're dealing with a DataCloneError because of an Error instance,
// we have no idea what is going on, so give up.
throw e;
} else {
// for whatever reason Error instances may not always be serializable,
// in which case we simply return the error data as a plain object
result.error = {
code: result.error.code,
message: result.error.message,
stack: result.error.stack,
};
}
postMessage({
id: event.data.id,
result: result
});
}
}
var method = methods[event.data.command] || Sass[event.data.command];
if (!method) {
return done({
line: 0,
message: 'Unknown command ' + event.action
});
}
method.apply(Sass, (event.data.args || []).concat([done]));
};
return Sass;
}));

View file

@ -10,9 +10,26 @@ var app = require('app')
, ipc = require('ipc')
, configPath = __dirname + '/config.json'
, config = require(configPath)
, args = process.argv.slice(0);
, args = process.argv.slice(0)
compileScss = function(){
var sass = require(__dirname + '/../browser/js/sass/sass.sync.js')
var filenames = fs.readdirSync(__dirname + '/../browser/scss/')
for (i in filenames) {
if (filenames[i].indexOf('.scss')!=-1)
var file = __dirname + '/../browser/scss/' + filenames[i]
var content = fs.readFileSync(file,'utf8')
sass.compile(content,{style: sass.style.compact,linefeed: ''}, function(result) {
fs.writeFileSync(__dirname + '/../browser/css/'+filenames[i].replace('.scss','.css'),result.text,'utf8')
});
}
}
if (args.indexOf('-c')!=-1) {
compileScss()
}
dialog.showErrorBox = function(title,err) {
console.log(title + ': ' + err)
}

View file

@ -14,20 +14,25 @@ TABS = function(){
type:'strip',
widgets: [
{
id:'knob_'+i,
id:'w0'+i,
type:"knob",
target:target
},
{
id:'fader_'+i,
type:"fader",
range:db,
id:'w1'+i,
type:"switch",
values:['ozehfozeizadz',1,2],
target:target
},
{
id:'toggle1_'+i,
label:'Mute',
id:'w2'+i,
type:"fader",
target:target
},
{
id:'w3'+i,
type:"toggle",
mode:"horizontal",
target:target
// color:'orange'
}
@ -43,7 +48,7 @@ TABS = function(){
return tab
}())
tabs.push({id:'test'})
return tabs
}()