Improve code style and code quality

Just some little improvements that I found looking around the code.

Related 2410d5a
This commit is contained in:
Alberto Maturano 2018-10-23 16:23:34 -05:00
parent 20ee8f9e1e
commit 980b6d240d
7 changed files with 20 additions and 48 deletions

View File

@ -1,13 +1,7 @@
'use strict';
/**
* Module dependencies
*/
// Node.js core.
const path = require('path');
// Public node modules.
const _ = require('lodash');
const fs = require('fs-extra');
@ -18,7 +12,6 @@ const fs = require('fs-extra');
* @param {Object} scope
* @param {Function} cb
*/
module.exports = function (scope, cb) {
if (scope.developerMode) {
fs.mkdirsSync(path.resolve(scope.rootPath));

View File

@ -3,9 +3,8 @@ const shell = require('shelljs');
const pwd = shell.pwd();
const isDevelopmentMode = path.resolve(pwd.stdout).indexOf('strapi-admin') !== -1;
const isSetup = process.env.IS_MONOREPO || false;
const appPath = isDevelopmentMode ? path.resolve(process.env.PWD, '..') : path.resolve(pwd.stdout, '..');
// const isSetup = path.resolve(process.env.PWD, '..', '..') === path.resolve(process.env.INIT_CWD);
const isSetup = process.env.IS_MONOREPO;
// Load the app configurations only when :
// - starting the app in dev mode

View File

@ -14,15 +14,8 @@ const isAdmin = process.env.IS_ADMIN === 'true';
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const appPath = (() => {
if (process.env.APP_PATH) {
return process.env.APP_PATH;
}
return isAdmin ? path.resolve(process.env.PWD, '..') : path.resolve(process.env.PWD, '..', '..');
})();
// const isSetup = path.resolve(process.env.PWD, '..', '..') === path.resolve(process.env.INIT_CWD);
const isSetup = process.env.IS_MONOREPO;
const isSetup = process.env.IS_MONOREPO || false;
const appPath = process.env.APP_PATH || path.resolve(process.env.PWD, '..', ( isAdmin ? '' : '..' ));
const adminPath = (() => {
if (isAdmin && isSetup) {

View File

@ -16,19 +16,11 @@ const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const isAdmin = process.env.IS_ADMIN === 'true';
const isSetup = path.resolve(process.env.PWD, '..', '..') === path.resolve(process.env.INIT_CWD);
const appPath = (() => {
if (process.env.APP_PATH) {
return process.env.APP_PATH;
}
return isAdmin ? path.resolve(process.env.PWD, '..') : path.resolve(process.env.PWD, '..', '..');
})();
const appPath = process.env.APP_PATH || path.resolve(process.env.PWD, '..', ( isAdmin ? '' : '..' ));
const rootAdminpath = (() => {
if (isSetup) {
return isAdmin
? path.resolve(appPath, 'strapi-admin')
: path.resolve(appPath, 'packages', 'strapi-admin');
return isAdmin ? path.resolve(appPath, 'strapi-admin') : path.resolve(appPath, 'packages', 'strapi-admin');
}
return path.resolve(appPath, 'admin');
})();

View File

@ -9,8 +9,7 @@ const path = require('path');
const webpack = require('webpack');
const isAdmin = process.env.IS_ADMIN === 'true';
// const isSetup = path.resolve(process.env.PWD, '..', '..') === path.resolve(process.env.INIT_CWD);
const isSetup = process.env.IS_MONOREPO;
const isSetup = process.env.IS_MONOREPO || false;
const appPath = process.env.APP_PATH || path.resolve(process.env.PWD, '..', ( isAdmin ? '' : '..' ));
const rootAdminpath = (() => {

View File

@ -15,14 +15,8 @@ const base = require('./webpack.base.babel');
const isAdmin = process.env.IS_ADMIN === 'true';
// const isSetup = path.resolve(process.env.PWD, '..', '..') === path.resolve(process.env.INIT_CWD);
const isSetup = process.env.IS_MONOREPO;
const appPath = (() => {
if (process.env.APP_PATH) {
return process.env.APP_PATH;
}
return isAdmin ? path.resolve(process.env.PWD, '..') : path.resolve(process.env.PWD, '..', '..');
})();
const isSetup = process.env.IS_MONOREPO || false;
const appPath = process.env.APP_PATH || path.resolve(process.env.PWD, '..', ( isAdmin ? '' : '..' ));
const adminPath = (() => {
if (isSetup) {
return isAdmin ? path.resolve(appPath, 'strapi-admin') : path.resolve(process.env.PWD, '..');
@ -33,9 +27,7 @@ const adminPath = (() => {
const rootAdminpath = (() => {
if (isSetup) {
return isAdmin
? path.resolve(appPath, 'strapi-admin')
: path.resolve(appPath, 'packages', 'strapi-admin');
return isAdmin ? path.resolve(appPath, 'strapi-admin') : path.resolve(appPath, 'packages', 'strapi-admin');
}
return path.resolve(appPath, 'admin');
})();

View File

@ -6,17 +6,16 @@ const fs = require('fs-extra');
const _ = require('lodash');
module.exports = async function() {
const folder = ((url = _.get(strapi.config.currentEnvironment.server, 'admin.path', 'admin')) =>
url[0] === '/' ? url.substring(1) : url)().replace(/\/$/, '');
// The regex removes possible slashes from the beginning and end of the value
const folder = _.get(strapi.config.currentEnvironment.server, 'admin.path', 'admin').replace(/^\/|\/$/g, '');
const configuratePlugin = (acc, current, source, name) => {
switch (source) {
case 'host': {
const host =
_.get(this.config.environments[current].server, 'admin.build.host').replace(/\/$/, '') || '/';
const host = _.get(this.config.environments[current].server, 'admin.build.host').replace(/\/$/, '') || '/';
if (!host) {
throw new Error(`You can't use \`remote\` as a source without set the \`host\` configuration.`);
throw new Error("You can't use `remote` as a source without set the `host` configuration.");
}
const folder = _.get(this.config.environments[current].server, 'admin.build.plugins.folder', null);
@ -29,14 +28,16 @@ module.exports = async function() {
return `/${host}/${name}/main.js`.replace('//', '/');
}
case 'custom':
if (!_.isEmpty(_.get(this.plugins[name].config, `sources.${current}`, {}))) {
return (acc[current] = this.plugins[name].config.sources[current]);
}
throw new Error(
`You have to define the source URL for each environment in \`./plugins/**/config/sources.json\``,
"You have to define the source URL for each environment in `./plugins/**/config/sources.json`"
);
case 'backend': {
const backend = _.get(
this.config.environments[current],
@ -48,6 +49,7 @@ module.exports = async function() {
return `${backend}/${folder.replace(/\/$/, '')}/${name}/main.js`;
}
default:
return `/${name}/main.js`;
}
@ -79,7 +81,9 @@ module.exports = async function() {
);
const isAdmin = await fs.pathExists(path.resolve(this.config.appPath, 'admin', 'admin'));
if (!isAdmin) return;
if (!isAdmin) {
return;
}
// arrange system directories
await Promise.all([