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

Compare webpack.config files #485

Merged
merged 2 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions projectFilesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ function forceUpdateProjectFiles(projectDir, appDir) {
addProjectFiles(projectDir, appDir);
}

function compareProjectFiles(projectDir) {
const projectTemplates = getProjectTemplates(projectDir);
Object.keys(projectTemplates).forEach(function(newTemplatePath){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use lamda syntax here:

 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.`;
console.info(`\x1B[33;1m${message}\x1B[0m` );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Developers can also use this script to overwrite the existing configuration files:

./node_modules/.bin/update-ns-webpack --configs

}
}
});
}

function deleteFile(destinationPath) {
if (fs.existsSync(destinationPath)) {
console.info(`Deleting file: ${destinationPath}`);
Expand Down Expand Up @@ -108,5 +123,6 @@ module.exports = {
addProjectFiles,
removeProjectFiles,
forceUpdateProjectFiles,
compareProjectFiles,
};