From 3524cc45ac02c47f7432456184e0d6af4728e2a4 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 4 Apr 2018 15:49:47 +0300 Subject: [PATCH 1/2] Compare current webpack.config.js and the one that will come from the installing version of nativescript-dev-webpack plugin and in case when they are different print a warning message. --- postinstall.js | 7 ++++++- projectFilesManager.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/postinstall.js b/postinstall.js index f8abf936..54d6b163 100644 --- a/postinstall.js +++ b/postinstall.js @@ -3,9 +3,14 @@ const { dirname } = require("path"); const hook = require("nativescript-hook")(__dirname); +const { compareProjectFiles } = require("./projectFilesManager"); const { getProjectDir } = require("./projectHelpers"); -if (getProjectDir()) { +const projectDir = getProjectDir(); + +if (projectDir) { + compareProjectFiles(projectDir); + hook.postinstall(); const installer = require("./installer"); installer.install(); diff --git a/projectFilesManager.js b/projectFilesManager.js index 9895406f..72c15787 100644 --- a/projectFilesManager.js +++ b/projectFilesManager.js @@ -37,6 +37,21 @@ function forceUpdateProjectFiles(projectDir, appDir) { addProjectFiles(projectDir, appDir); } +function compareProjectFiles(projectDir) { + const projectTemplates = getProjectTemplates(projectDir); + Object.keys(projectTemplates).forEach(function(newTemplatePath){ + const currentTemplatePath = projectTemplates[newTemplatePath]; + if (fs.existsSync(currentTemplatePath)) { + const currentTemplate = fs.readFileSync(currentTemplatePath).toString(); + const newTemplate = fs.readFileSync(newTemplatePath).toString(); + if (newTemplate !== currentTemplate) { + const message = `The current project contains a ${path.basename(currentTemplatePath)} file located at ${currentTemplatePath} that differs from the one in the new version of the nativescript-dev-webpack plugin located at ${newTemplatePath}. Some of the plugin features may not work as expected until you manually update the ${path.basename(currentTemplatePath)} file.`; + console.info(`\x1B[33;1m${message}\x1B[0m` ); + } + } + }); +} + function deleteFile(destinationPath) { if (fs.existsSync(destinationPath)) { console.info(`Deleting file: ${destinationPath}`); @@ -108,5 +123,6 @@ module.exports = { addProjectFiles, removeProjectFiles, forceUpdateProjectFiles, + compareProjectFiles, }; From 8460b885784952dcce1178ea2cd089f9b324e052 Mon Sep 17 00:00:00 2001 From: fatme Date: Wed, 4 Apr 2018 16:20:20 +0300 Subject: [PATCH 2/2] PR comments --- projectFilesManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projectFilesManager.js b/projectFilesManager.js index 72c15787..0409b860 100644 --- a/projectFilesManager.js +++ b/projectFilesManager.js @@ -39,13 +39,13 @@ function forceUpdateProjectFiles(projectDir, appDir) { function compareProjectFiles(projectDir) { const projectTemplates = getProjectTemplates(projectDir); - Object.keys(projectTemplates).forEach(function(newTemplatePath){ + Object.keys(projectTemplates).forEach(newTemplatePath => { const currentTemplatePath = projectTemplates[newTemplatePath]; if (fs.existsSync(currentTemplatePath)) { const currentTemplate = fs.readFileSync(currentTemplatePath).toString(); const newTemplate = fs.readFileSync(newTemplatePath).toString(); if (newTemplate !== currentTemplate) { - const message = `The current project contains a ${path.basename(currentTemplatePath)} file located at ${currentTemplatePath} that differs from the one in the new version of the nativescript-dev-webpack plugin located at ${newTemplatePath}. Some of the plugin features may not work as expected until you manually update the ${path.basename(currentTemplatePath)} file.`; + const message = `The current project contains a ${path.basename(currentTemplatePath)} file located at ${currentTemplatePath} that differs from the one in the new version of the nativescript-dev-webpack plugin located at ${newTemplatePath}. Some of the plugin features may not work as expected until you manually update the ${path.basename(currentTemplatePath)} file or automatically update it using "./node_modules/.bin/update-ns-webpack --configs" command.`; console.info(`\x1B[33;1m${message}\x1B[0m` ); } }