diff --git a/lib/classes/Utils.js b/lib/classes/Utils.js index f6f8249fe..01dbc1566 100644 --- a/lib/classes/Utils.js +++ b/lib/classes/Utils.js @@ -161,7 +161,10 @@ class Utils { return servicePath; } - logStat(serverless) { + logStat(serverless, context) { + // the context in which serverless was executed (e.g. "install", "usage", "uninstall", ...) + context = context || 'usage'; //eslint-disable-line + const log = (data) => { const writeKey = 'XXXX'; // TODO: Replace me before release const auth = `${writeKey}:`; @@ -326,6 +329,7 @@ class Utils { }, general: { userId, + context, timestamp: (new Date()).getTime(), timezone: (new Date()).toString().match(/([A-Z]+[+-][0-9]+)/)[1], operatingSystem: process.platform, diff --git a/package.json b/package.json index 214315ac4..b13be78a5 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,9 @@ "lint": "eslint .", "docs": "node scripts/generate-readme.js", "simple-integration-test": "jest --maxWorkers=5 simple-suite", - "complex-integration-test": "jest --maxWorkers=5 integration" + "complex-integration-test": "jest --maxWorkers=5 integration", + "postinstall": "node ./scripts/postinstall.js", + "postuninstall": "node ./scripts/postuninstall.js" }, "jest": { "testRegex": "(\\.|/)(tests)\\.js$", diff --git a/scripts/postinstall.js b/scripts/postinstall.js new file mode 100644 index 000000000..fde4a3cbc --- /dev/null +++ b/scripts/postinstall.js @@ -0,0 +1,10 @@ +const BbPromise = require('bluebird'); +const Serverless = require('../lib/Serverless'); + +const serverless = new Serverless(); + +(() => { + serverless.init().then(() => { + serverless.utils.logStat(serverless, 'install').catch(() => BbPromise.resolve()); + }); +})(); diff --git a/scripts/postuninstall.js b/scripts/postuninstall.js new file mode 100644 index 000000000..085d6c2b4 --- /dev/null +++ b/scripts/postuninstall.js @@ -0,0 +1,10 @@ +const BbPromise = require('bluebird'); +const Serverless = require('../lib/Serverless'); + +const serverless = new Serverless(); + +(() => { + serverless.init().then(() => { + serverless.utils.logStat(serverless, 'uninstall').catch(() => BbPromise.resolve()); + }); +})();