Use absolute flow file path in project settings

This ensures the diff logic can recognise the project flow file
and apply merge resolution to paths that git knows
This commit is contained in:
Nick O'Leary
2019-02-17 22:18:40 +00:00
parent e05ff01d57
commit 9d673a213e
2 changed files with 47 additions and 38 deletions

View File

@@ -84,14 +84,15 @@ Project.prototype.load = function () {
return checkProjectFiles(project).then(function(missingFiles) {
project.missingFiles = missingFiles;
if (missingFiles.indexOf('package.json') === -1) {
// We have a package.json in project.path+project.paths.root+"package.json"
project.paths['package.json'] = fspath.join(project.paths.root,"package.json");
promises.push(fs.readFile(fspath.join(project.path,project.paths['package.json']),"utf8").then(function(content) {
try {
project.package = util.parseJSON(content);
if (project.package.hasOwnProperty('node-red')) {
if (project.package['node-red'].hasOwnProperty('settings')) {
project.paths.flowFile = project.package['node-red'].settings.flowFile;
project.paths.credentialsFile = project.package['node-red'].settings.credentialsFile;
project.paths.flowFile = fspath.join(project.paths.root,project.package['node-red'].settings.flowFile);
project.paths.credentialsFile = fspath.join(project.paths.root,project.package['node-red'].settings.credentialsFile);
}
} else {
// TODO: package.json doesn't have a node-red section
@@ -134,10 +135,6 @@ Project.prototype.load = function () {
});
};
Project.prototype.getFilePath = function(file) {
return fspath.join(this.path,this.paths.root,this.paths[file])
}
Project.prototype.initialise = function(user,data) {
var project = this;
// if (!this.empty) {
@@ -296,40 +293,39 @@ Project.prototype.update = function (user, data) {
if (data.hasOwnProperty('files')) {
this.package['node-red'] = this.package['node-red'] || { settings: {}};
if (data.files.hasOwnProperty('package') && data.files.package !== fspath.join(this.paths.root,"package.json")) {
// We have a package file. It could be one that doesn't exist yet, or
// does exist and we need to load it.
// We have a package file. It could be one that doesn't exist yet,
// or it does exist and we need to load it.
if (!/package\.json$/.test(data.files.package)) {
return Promise.reject("Invalid package file: "+data.files.package)
}
var root = data.files.package.substring(0,data.files.package.length-12);
this.paths.root = root;
this.paths['package.json'] = 'package.json';
this.paths['package.json'] = data.files.package;
globalProjectSettings.projects[this.name].rootPath = root;
saveSettings = true;
// 1. check if it exists
if (fs.existsSync(fspath.join(this.path,this.paths.root,this.paths['package.json']))) {
if (fs.existsSync(fspath.join(this.path,this.paths['package.json']))) {
// Load the existing one....
} else {
var newPackage = defaultFileSet["package.json"](this);
fs.writeFileSync(fspath.join(this.path,this.paths.root,this.paths['package.json']),newPackage);
fs.writeFileSync(fspath.join(this.path,this.paths['package.json']),newPackage);
this.package = JSON.parse(newPackage);
}
reloadProject = true;
flowFilesChanged = true;
}
if (data.files.hasOwnProperty('flow') && this.package['node-red'].settings.flowFile !== data.files.flow) {
if (data.files.hasOwnProperty('flow') && this.package['node-red'].settings.flowFile !== data.files.flow.substring(this.paths.root.length)) {
this.paths.flowFile = data.files.flow;
this.package['node-red'].settings.flowFile = data.files.flow;
this.package['node-red'].settings.flowFile = data.files.flow.substring(this.paths.root.length);
savePackage = true;
flowFilesChanged = true;
}
if (data.files.hasOwnProperty('credentials') && this.package['node-red'].settings.credentialsFile !== data.files.credentials) {
if (data.files.hasOwnProperty('credentials') && this.package['node-red'].settings.credentialsFile !== data.files.credentials.substring(this.paths.root.length)) {
this.paths.credentialsFile = data.files.credentials;
this.package['node-red'].settings.credentialsFile = data.files.credentials;
this.package['node-red'].settings.credentialsFile = data.files.credentials.substring(this.paths.root.length);
// Don't know if the credSecret is invalid or not so clear the flag
delete this.credentialSecretInvalid;
savePackage = true;
flowFilesChanged = true;
}
@@ -779,7 +775,7 @@ Project.prototype.removeRemote = function(user, remote) {
Project.prototype.getFlowFile = function() {
// console.log("Project.getFlowFile = ",this.paths.flowFile);
if (this.paths.flowFile) {
return fspath.join(this.path,this.paths.root,this.paths.flowFile);
return fspath.join(this.path,this.paths.flowFile);
} else {
return null;
}
@@ -796,7 +792,7 @@ Project.prototype.getFlowFileBackup = function() {
Project.prototype.getCredentialsFile = function() {
// console.log("Project.getCredentialsFile = ",this.paths.credentialsFile);
if (this.paths.credentialsFile) {
return fspath.join(this.path,this.paths.root,this.paths.credentialsFile);
return fspath.join(this.path,this.paths.credentialsFile);
} else {
return this.paths.credentialsFile;
}
@@ -920,14 +916,12 @@ function createDefaultProject(user, project) {
});
}
function checkProjectFiles(project) {
var projectPath = project.path;
var projectRoot = project.paths.root;
var promises = [];
var paths = [];
for (var file in defaultFileSet) {
if (defaultFileSet.hasOwnProperty(file)) {
paths.push(file);
promises.push(fs.stat(fspath.join(projectPath,projectRoot,file)));
promises.push(fs.stat(fspath.join(project.path,project.paths.root,file)));
}
}
return when.settle(promises).then(function(results) {