add stats quiet update, inject options
This commit is contained in:
parent
824937e2c0
commit
ee500a2a1a
2 changed files with 84 additions and 71 deletions
92
js/kiri.js
92
js/kiri.js
|
|
@ -617,6 +617,56 @@ self.kiri.license = exports.LICENSE;
|
|||
* Stats accumulator
|
||||
******************************************************************* */
|
||||
|
||||
function Stats(db) {
|
||||
this.db = db;
|
||||
this.obj = js2o(db['stats'] || '{}');
|
||||
var o = this.obj, k;
|
||||
for (k in o) {
|
||||
if (!o.hasOwnProperty(k)) continue;
|
||||
if (k.indexOf('slice-') === 0) oremap(o,k,'s-');
|
||||
if (k.indexOf('prep-') === 0) oremap(o,k,'p-');
|
||||
if (k.indexOf('export-') === 0) oremap(o,k,'e-');
|
||||
if (k.indexOf('show-') === 0) oremap(o,k,'d-');
|
||||
}
|
||||
}
|
||||
|
||||
Stats.prototype.save = function(quiet) {
|
||||
this.db['stats'] = o2js(this.obj);
|
||||
if (!quiet) {
|
||||
sendOnEvent('stats', this.obj);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Stats.prototype.get = function(k) {
|
||||
return this.obj[k];
|
||||
};
|
||||
|
||||
Stats.prototype.set = function(k,v,quiet) {
|
||||
this.obj[k] = v;
|
||||
this.save(quiet);
|
||||
return this;
|
||||
};
|
||||
|
||||
Stats.prototype.add = function(k,v,quiet) {
|
||||
this.obj[k] = (this.obj[k] || 0) + (v || 1);
|
||||
this.save(quiet);
|
||||
return this;
|
||||
};
|
||||
|
||||
Stats.prototype.del = function(k, quiet) {
|
||||
delete this.obj[k];
|
||||
this.save(quiet);
|
||||
return this;
|
||||
};
|
||||
|
||||
STATS.set('upgrade', kiri.version !== STATS.get('kiri') && STATS.get('init') > 0);
|
||||
STATS.set('kiri', kiri.version);
|
||||
|
||||
/** ******************************************************************
|
||||
* Utility Functions
|
||||
******************************************************************* */
|
||||
|
||||
function clone(o) {
|
||||
return o ? JSON.parse(JSON.stringify(o)) : o;
|
||||
}
|
||||
|
|
@ -677,48 +727,6 @@ self.kiri.license = exports.LICENSE;
|
|||
}
|
||||
}
|
||||
|
||||
function Stats(db) {
|
||||
this.db = db;
|
||||
this.obj = js2o(db['stats'] || '{}');
|
||||
var o = this.obj, k;
|
||||
for (k in o) {
|
||||
if (!o.hasOwnProperty(k)) continue;
|
||||
if (k.indexOf('slice-') === 0) oremap(o,k,'s-');
|
||||
if (k.indexOf('prep-') === 0) oremap(o,k,'p-');
|
||||
if (k.indexOf('export-') === 0) oremap(o,k,'e-');
|
||||
if (k.indexOf('show-') === 0) oremap(o,k,'d-');
|
||||
}
|
||||
}
|
||||
Stats.prototype.save = function() {
|
||||
this.db['stats'] = o2js(this.obj);
|
||||
return this;
|
||||
};
|
||||
Stats.prototype.get = function(k) {
|
||||
return this.obj[k];
|
||||
}
|
||||
Stats.prototype.set = function(k,v) {
|
||||
this.obj[k] = v;
|
||||
this.save();
|
||||
return this;
|
||||
};
|
||||
Stats.prototype.add = function(k,v) {
|
||||
this.obj[k] = (this.obj[k] || 0) + (v || 1);
|
||||
this.save();
|
||||
return this;
|
||||
};
|
||||
Stats.prototype.del = function(k) {
|
||||
delete this.obj[k];
|
||||
this.save();
|
||||
return this;
|
||||
}
|
||||
|
||||
STATS.set('upgrade', kiri.version !== STATS.get('kiri') && STATS.get('init') > 0);
|
||||
STATS.set('kiri', kiri.version);
|
||||
|
||||
/** ******************************************************************
|
||||
* Utility Functions
|
||||
******************************************************************* */
|
||||
|
||||
function isSecure(proto) {
|
||||
return proto.toLowerCase().indexOf("https") === 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1019,9 +1019,14 @@ function initModule(file, dir) {
|
|||
level: level
|
||||
},
|
||||
inject: {
|
||||
kiri: file => {
|
||||
kiri: (file, options) => {
|
||||
let opt = options || {};
|
||||
if (opt.end) {
|
||||
script.kiri.push(dir + "/" + file);
|
||||
} else {
|
||||
script.kiri.splice(0, 0, dir + "/" + file);
|
||||
}
|
||||
}
|
||||
},
|
||||
path: {
|
||||
any: arg => { modPaths.push(arg) },
|
||||
|
|
|
|||
Loading…
Reference in a new issue