Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit d917b65

Browse files
author
Fatme
authored
Compare webpack.config files (#485)
* 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. * PR comments
1 parent a61cff4 commit d917b65

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

postinstall.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
const { dirname } = require("path");
44
const hook = require("nativescript-hook")(__dirname);
55

6+
const { compareProjectFiles } = require("./projectFilesManager");
67
const { getProjectDir } = require("./projectHelpers");
78

8-
if (getProjectDir()) {
9+
const projectDir = getProjectDir();
10+
11+
if (projectDir) {
12+
compareProjectFiles(projectDir);
13+
914
hook.postinstall();
1015
const installer = require("./installer");
1116
installer.install();

projectFilesManager.js

+16
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ function forceUpdateProjectFiles(projectDir, appDir) {
3737
addProjectFiles(projectDir, appDir);
3838
}
3939

40+
function compareProjectFiles(projectDir) {
41+
const projectTemplates = getProjectTemplates(projectDir);
42+
Object.keys(projectTemplates).forEach(newTemplatePath => {
43+
const currentTemplatePath = projectTemplates[newTemplatePath];
44+
if (fs.existsSync(currentTemplatePath)) {
45+
const currentTemplate = fs.readFileSync(currentTemplatePath).toString();
46+
const newTemplate = fs.readFileSync(newTemplatePath).toString();
47+
if (newTemplate !== currentTemplate) {
48+
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.`;
49+
console.info(`\x1B[33;1m${message}\x1B[0m` );
50+
}
51+
}
52+
});
53+
}
54+
4055
function deleteFile(destinationPath) {
4156
if (fs.existsSync(destinationPath)) {
4257
console.info(`Deleting file: ${destinationPath}`);
@@ -108,5 +123,6 @@ module.exports = {
108123
addProjectFiles,
109124
removeProjectFiles,
110125
forceUpdateProjectFiles,
126+
compareProjectFiles,
111127
};
112128

0 commit comments

Comments
 (0)