From a5dc07c0a5fb76f3ad0dba3ef8c48903b0cf6aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdo=CC=81n=20Rodri=CC=81guez=20Davila?= Date: Wed, 19 Dec 2018 19:25:52 +0100 Subject: [PATCH 1/4] Avoid write files if not development environment --- packages/strapi-plugin-graphql/services/Schema.js | 6 ++++-- packages/strapi/lib/core/plugins.js | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/strapi-plugin-graphql/services/Schema.js b/packages/strapi-plugin-graphql/services/Schema.js index d13249e3ed..dcb8a29949 100644 --- a/packages/strapi-plugin-graphql/services/Schema.js +++ b/packages/strapi-plugin-graphql/services/Schema.js @@ -266,8 +266,10 @@ module.exports = { resolvers, }); - // Write schema. - this.writeGenerateSchema(graphql.printSchema(schema)); + if (strapi.config.environment === 'development') { + // Write schema. + this.writeGenerateSchema(graphql.printSchema(schema)); + } // Remove custom scaler (like Upload); typeDefs = Types.removeCustomScalar(typeDefs, resolvers); diff --git a/packages/strapi/lib/core/plugins.js b/packages/strapi/lib/core/plugins.js index 51893e0f8b..d239e96b0a 100644 --- a/packages/strapi/lib/core/plugins.js +++ b/packages/strapi/lib/core/plugins.js @@ -88,6 +88,10 @@ module.exports = async function() { return; } + if (strapi.config.environment !== 'development') { + return; + } + // arrange system directories await Promise.all([ fs.remove(sourcePath), From df162c13878f0144c3bd82ec1a64e2cd2564104f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdo=CC=81n=20Rodri=CC=81guez=20Davila?= Date: Wed, 19 Dec 2018 19:42:10 +0100 Subject: [PATCH 2/4] Avoid write actions.json if not development environment --- .../services/UsersPermissions.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js index 397fb1221a..35ed7cfdf6 100644 --- a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js +++ b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js @@ -438,8 +438,10 @@ module.exports = { try { // Disable auto-reload. strapi.reload.isWatching = false; - // Rewrite actions.json file. - fs.writeFileSync(actionsPath, JSON.stringify({ actions: data }), 'utf8'); + if (strapi.config.environment === 'development') { + // Rewrite actions.json file. + fs.writeFileSync(actionsPath, JSON.stringify({ actions: data }), 'utf8'); + } // Set value to AST to avoid restart. _.set(strapi.plugins['users-permissions'], 'config.actions', data); // Disable auto-reload. From 7d039644fae62e63994546783fade20158db72ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdo=CC=81n=20Rodri=CC=81guez=20Davila?= Date: Sun, 23 Dec 2018 17:02:45 +0100 Subject: [PATCH 3/4] Check if plugins.json exists --- packages/strapi/lib/core/plugins.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/strapi/lib/core/plugins.js b/packages/strapi/lib/core/plugins.js index d239e96b0a..04e8b10625 100644 --- a/packages/strapi/lib/core/plugins.js +++ b/packages/strapi/lib/core/plugins.js @@ -88,8 +88,11 @@ module.exports = async function() { return; } - if (strapi.config.environment !== 'development') { + const existBuildPath = await fs.pathExists(buildPath); + if (strapi.config.environment !== 'development' && existBuildPath) { return; + } else if (strapi.config.environment !== 'development' && !existBuildPath) { + console.log('The plugins.json file is missing and the front-end cannot work without it. Please, create it first at development environment.'); } // arrange system directories @@ -97,7 +100,6 @@ module.exports = async function() { fs.remove(sourcePath), (async () => { - const existBuildPath = await fs.pathExists(buildPath); if (existBuildPath) { await fs.remove(buildPath); } else { From e41948de3f997e63db672a14f22a1ba7bb14d4a1 Mon Sep 17 00:00:00 2001 From: Jim LAURIE Date: Wed, 9 Jan 2019 14:19:39 +0100 Subject: [PATCH 4/4] Add setting for production environment --- .../files/config/environments/production/server.json | 1 + .../files/config/environments/staging/server.json | 1 + packages/strapi-plugin-graphql/services/Schema.js | 2 +- .../services/UsersPermissions.js | 2 +- packages/strapi/lib/core/plugins.js | 4 ++-- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/strapi-generate-new/files/config/environments/production/server.json b/packages/strapi-generate-new/files/config/environments/production/server.json index 4e5d9d1b5e..a72d469d48 100644 --- a/packages/strapi-generate-new/files/config/environments/production/server.json +++ b/packages/strapi-generate-new/files/config/environments/production/server.json @@ -1,6 +1,7 @@ { "host": "localhost", "port": "${process.env.PORT || 1337}", + "production": true, "proxy": { "enabled": false }, diff --git a/packages/strapi-generate-new/files/config/environments/staging/server.json b/packages/strapi-generate-new/files/config/environments/staging/server.json index 4e5d9d1b5e..a72d469d48 100644 --- a/packages/strapi-generate-new/files/config/environments/staging/server.json +++ b/packages/strapi-generate-new/files/config/environments/staging/server.json @@ -1,6 +1,7 @@ { "host": "localhost", "port": "${process.env.PORT || 1337}", + "production": true, "proxy": { "enabled": false }, diff --git a/packages/strapi-plugin-graphql/services/Schema.js b/packages/strapi-plugin-graphql/services/Schema.js index dcb8a29949..dc5d28261b 100644 --- a/packages/strapi-plugin-graphql/services/Schema.js +++ b/packages/strapi-plugin-graphql/services/Schema.js @@ -266,7 +266,7 @@ module.exports = { resolvers, }); - if (strapi.config.environment === 'development') { + if (!strapi.config.currentEnvironment.server.production) { // Write schema. this.writeGenerateSchema(graphql.printSchema(schema)); } diff --git a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js index 35ed7cfdf6..6df284bd8e 100644 --- a/packages/strapi-plugin-users-permissions/services/UsersPermissions.js +++ b/packages/strapi-plugin-users-permissions/services/UsersPermissions.js @@ -438,7 +438,7 @@ module.exports = { try { // Disable auto-reload. strapi.reload.isWatching = false; - if (strapi.config.environment === 'development') { + if (!strapi.config.currentEnvironment.server.production) { // Rewrite actions.json file. fs.writeFileSync(actionsPath, JSON.stringify({ actions: data }), 'utf8'); } diff --git a/packages/strapi/lib/core/plugins.js b/packages/strapi/lib/core/plugins.js index 04e8b10625..a22cf4dfec 100644 --- a/packages/strapi/lib/core/plugins.js +++ b/packages/strapi/lib/core/plugins.js @@ -89,9 +89,9 @@ module.exports = async function() { } const existBuildPath = await fs.pathExists(buildPath); - if (strapi.config.environment !== 'development' && existBuildPath) { + if (strapi.config.currentEnvironment.server.production && existBuildPath) { return; - } else if (strapi.config.environment !== 'development' && !existBuildPath) { + } else if (strapi.config.currentEnvironment.server.production && !existBuildPath) { console.log('The plugins.json file is missing and the front-end cannot work without it. Please, create it first at development environment.'); }