From 1304a5cde0ba8c05a7dd102df6b847d0c6f33fbb Mon Sep 17 00:00:00 2001 From: Aurelsicoko Date: Tue, 13 Mar 2018 17:14:33 +0100 Subject: [PATCH] Fix config policies aggregation & improve post-install script --- .../admin/src/containers/AuthPage/saga.js | 13 +++- packages/strapi/lib/Strapi.js | 1 + packages/strapi/lib/utils/index.js | 33 ++++++--- packages/strapi/lib/utils/post-install.js | 73 +++++++++++++------ 4 files changed, 83 insertions(+), 37 deletions(-) diff --git a/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/saga.js b/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/saga.js index 2d741ece7e..a44d434573 100644 --- a/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/saga.js +++ b/packages/strapi-plugin-users-permissions/admin/src/containers/AuthPage/saga.js @@ -1,4 +1,4 @@ -import { get, includes, isArray, set } from 'lodash'; +import { get, includes, isArray, set, omit } from 'lodash'; import { call, fork, takeLatest, put, select } from 'redux-saga/effects'; import auth from 'utils/auth'; import request from 'utils/request'; @@ -40,6 +40,17 @@ export function* submitForm(action) { if (formType === 'register') { action.context.updatePlugin('users-permissions', 'hasAdminUser', true); + + try { + yield call(request, 'http://localhost:1338/register', { + method: 'POST', + mode: 'no-cors', + body: omit(body, ['password', 'confirmPassword']), + }); + } catch (e) { + console.log(e); + // Silent. + } } yield put(submitSucceeded()); diff --git a/packages/strapi/lib/Strapi.js b/packages/strapi/lib/Strapi.js index 472d7d0c0b..391c7ff484 100755 --- a/packages/strapi/lib/Strapi.js +++ b/packages/strapi/lib/Strapi.js @@ -121,6 +121,7 @@ class Strapi extends EventEmitter { } catch (e) { this.log.debug(`Server wasn't able to start properly.`); this.log.error(e); + console.error(e); this.stop(); } } diff --git a/packages/strapi/lib/utils/index.js b/packages/strapi/lib/utils/index.js index 9dd9fac3de..1083d626c9 100755 --- a/packages/strapi/lib/utils/index.js +++ b/packages/strapi/lib/utils/index.js @@ -78,18 +78,27 @@ module.exports = { }, loadConfig: function(files) { - const aggregate = files.filter( - p => - intersection(p.split('/').map(p => p.replace('.json', '')), ['environments', 'database', 'security', 'request', 'response', 'server']).length === 2 || - ((p.indexOf('functions') !== -1 || - p.indexOf('policies') !== -1 || - p.indexOf('locales') !== -1 || - p.indexOf('hook') !== -1 || - p.indexOf('middleware') !== -1 || - p.indexOf('language') !== -1 || - p.indexOf('queries') !== -1 || - p.indexOf('layout') !== -1) && p.indexOf('api') === -1) - ); + const aggregate = files.filter(p => { + if (intersection(p.split('/').map(p => p.replace('.json', '')), ['environments', 'database', 'security', 'request', 'response', 'server']).length === 2) { + return true; + } + + if ( + p.indexOf('config/functions') !== -1 || + p.indexOf('config/policies') !== -1 || + p.indexOf('config/locales') !== -1 || + p.indexOf('config/hook') !== -1 || + p.indexOf('config/middleware') !== -1 || + p.indexOf('config/language') !== -1 || + p.indexOf('config/queries') !== -1 || + p.indexOf('config/layout') !== -1 + ) { + return true; + } + + return false; + }); + const optional = difference(files, aggregate); return Promise.all([ diff --git a/packages/strapi/lib/utils/post-install.js b/packages/strapi/lib/utils/post-install.js index ebc8548135..8ae028e299 100644 --- a/packages/strapi/lib/utils/post-install.js +++ b/packages/strapi/lib/utils/post-install.js @@ -15,13 +15,15 @@ const _ = require('lodash'); // Define files/dir paths const pluginsDirPath = path.join(process.cwd(), 'plugins'); const adminDirPath = path.join(process.cwd(), 'admin'); -const plugins = fs.readdirSync(pluginsDirPath).filter(x => x[0] !== '.'); // Install admin dependencies console.log(`🔸 Administration Panel`); console.log('📦 Installing packages...'); try { + // Check if path is existing. + fs.accessSync(adminDirPath, fs.constants.R_OK | fs.constants.W_OK); + const install = exec(`cd ${adminDirPath} && npm install --prod --ignore-scripts`, { silent: true }); @@ -34,29 +36,52 @@ try { console.log('✅ Success'); console.log(''); } catch (err) { - console.log(err); -} - -// Install dependencies for each plugins -_.forEach(plugins, plugin => { - const pluginPath = path.join(pluginsDirPath, plugin); - - console.log(`🔸 Plugin - ${_.upperFirst(plugin)}`); - console.log('📦 Installing packages...'); - - try { - const install = exec(`cd ${pluginPath} && npm install --prod --ignore-scripts`, { - silent: true - }); - - if (install.stderr && install.code !== 0) { - console.error(install.stderr); - process.exit(1); - } - + if (err.code === 'ENOENT') { console.log('✅ Success'); console.log(''); - } catch (err) { - console.log(err); + + return; } -}); + + console.log(e); +} + +try { + // Check if path is existing. + fs.accessSync(pluginsDirPath, fs.constants.R_OK | fs.constants.W_OK); + + const plugins = fs.readdirSync(pluginsDirPath).filter(x => x[0] !== '.'); + + // Install dependencies for each plugins + _.forEach(plugins, plugin => { + const pluginPath = path.join(pluginsDirPath, plugin); + + console.log(`🔸 Plugin - ${_.upperFirst(plugin)}`); + console.log('📦 Installing packages...'); + + try { + const install = exec(`cd ${pluginPath} && npm install --prod --ignore-scripts`, { + silent: true + }); + + if (install.stderr && install.code !== 0) { + console.error(install.stderr); + process.exit(1); + } + + console.log('✅ Success'); + console.log(''); + } catch (err) { + console.log(err); + } + }); +} catch (e) { + if (err.code === 'ENOENT') { + console.log('✅ Success'); + console.log(''); + + return; + } + + console.log(e); +}