Permalink
Browse files

record commands run time

  • Loading branch information...
1 parent e4b5bd1 commit ef2393160f39904fedf112ff9e4ea26a5737c951 @lepture lepture committed Apr 11, 2013
Showing with 43 additions and 0 deletions.
  1. +1 −0 bin/spm
  2. +1 −0 index.js
  3. +41 −0 lib/utils/run.js
View
@@ -114,6 +114,7 @@ if (subcmd === 'help') {
} else {
bin = executable(subcmd);
if (bin) {
+ spm.run.record(subcmd);
spawn(bin, args, {stdio: 'inherit', customFds: [0, 1, 2]});
}
}
View
@@ -18,6 +18,7 @@ exports.search = require('./lib/search');
// plugins should use spm.log
exports.log = require('./lib/utils/log');
+exports.run = require('./lib/utils/run');
// register sdk
exports.sdk = {};
View
@@ -0,0 +1,41 @@
+var path = require('path');
+var spmrc = require('spmrc');
+var request = require('request');
+var file = require('../sdk/file');
+var runfile = path.join(spmrc.get('user.home'), '.spm', 'run.json');
+
+function info(name) {
+ var data = {};
+ if (file.exists(runfile)) {
+ data = file.readJSON(runfile);
+ }
+ if (!name) {
+ return data || {};
+ }
+ return data[name] || {};
+}
+
+exports.info = info;
+
+function record(name, options) {
+ var data = info();
+ var ret = data[name] || {};
+
+ if (options) {
+ Object.keys(options).forEach(function(key) {
+ ret[key] = options[key];
+ });
+ }
+
+ ret.name = name;
+ if (ret.count) {
+ ret.count += 1;
+ } else {
+ ret.count = 1;
+ }
+ ret.time = new Date();
+ data[name] = ret;
+ file.writeJSON(runfile, data);
+}
+
+exports.record = record;

0 comments on commit ef23931

Please sign in to comment.