mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add commit-diff view
This commit is contained in:
@@ -212,6 +212,13 @@ Project.prototype.getCommits = function(options) {
|
||||
Project.prototype.getCommit = function(sha) {
|
||||
return gitTools.getCommit(this.path,sha);
|
||||
}
|
||||
Project.prototype.getFile = function (filePath,treeish) {
|
||||
if (treeish !== "_") {
|
||||
return gitTools.getFile(this.path, filePath, treeish);
|
||||
} else {
|
||||
return fs.readFile(fspath.join(this.path,filePath),"utf8");
|
||||
}
|
||||
};
|
||||
|
||||
Project.prototype.getFlowFile = function() {
|
||||
console.log("Project.getFlowFile = ",this.paths.flowFile);
|
||||
@@ -255,7 +262,16 @@ Project.prototype.toJSON = function () {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function getCredentialsFilename(filename) {
|
||||
// TODO: DRY - ./index.js
|
||||
var ffDir = fspath.dirname(filename);
|
||||
var ffExt = fspath.extname(filename);
|
||||
var ffBase = fspath.basename(filename,ffExt);
|
||||
return fspath.join(ffDir,ffBase+"_cred"+ffExt);
|
||||
}
|
||||
function getBackupFilename(filename) {
|
||||
// TODO: DRY - ./index.js
|
||||
var ffName = fspath.basename(filename);
|
||||
var ffDir = fspath.dirname(filename);
|
||||
return fspath.join(ffDir,"."+ffName+".backup");
|
||||
@@ -287,8 +303,23 @@ function createDefaultProject(project) {
|
||||
promises.push(util.writeFile(fspath.join(projectPath,file),defaultFileSet[file](project)));
|
||||
}
|
||||
}
|
||||
if (project.files) {
|
||||
if (project.files.flow && !/\.\./.test(project.files.flow)) {
|
||||
var flowFilePath = fspath.join(projectPath,project.files.flow);
|
||||
promises.push(util.writeFile(flowFilePath,"[]"));
|
||||
var credsFilePath = getCredentialsFilename(flowFilePath);
|
||||
promises.push(util.writeFile(credsFilePath,"{}"));
|
||||
}
|
||||
}
|
||||
return when.all(promises).then(function() {
|
||||
return gitTools.stageFile(projectPath,Object.keys(defaultFileSet));
|
||||
var files = Object.keys(defaultFileSet);
|
||||
if (project.files) {
|
||||
if (project.files.flow && !/\.\./.test(project.files.flow)) {
|
||||
files.push(project.files.flow);
|
||||
files.push(getCredentialsFilename(flowFilePath))
|
||||
}
|
||||
}
|
||||
return gitTools.stageFile(projectPath,files);
|
||||
}).then(function() {
|
||||
return gitTools.commit(projectPath,"Create project");
|
||||
})
|
||||
@@ -339,7 +370,7 @@ function createProject(metadata) {
|
||||
createProjectDirectory(project).then(function() {
|
||||
var projects = settings.get('projects');
|
||||
projects.projects[project] = {};
|
||||
if (metadata.credentialSecret) {
|
||||
if (metadata.hasOwnProperty('credentialSecret')) {
|
||||
projects.projects[project].credentialSecret = metadata.credentialSecret;
|
||||
}
|
||||
if (metadata.remote) {
|
||||
|
||||
@@ -14,20 +14,43 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
|
||||
var fspath = require("path");
|
||||
|
||||
function getCredentialsFilename(filename) {
|
||||
// TODO: DRY - ./index.js
|
||||
var ffDir = fspath.dirname(filename);
|
||||
var ffExt = fspath.extname(filename);
|
||||
var ffBase = fspath.basename(filename,ffExt);
|
||||
return fspath.join(ffDir,ffBase+"_cred"+ffExt);
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
"package.json": function(project) {
|
||||
return JSON.stringify({
|
||||
var package = {
|
||||
"name": project.name,
|
||||
"description": project.summary||"A Node-RED Project",
|
||||
"version": "0.0.1",
|
||||
"dependencies": {}
|
||||
},"",4);
|
||||
"dependencies": {},
|
||||
"node-red": {
|
||||
"settings": {
|
||||
}
|
||||
}
|
||||
};
|
||||
if (project.files) {
|
||||
if (project.files.flow) {
|
||||
package['node-red'].settings.flowFile = project.files.flow;
|
||||
package['node-red'].settings.credentialsFile = getCredentialsFilename(project.files.flow);
|
||||
}
|
||||
}
|
||||
return JSON.stringify(package,"",4);
|
||||
},
|
||||
"README.md": function(project) {
|
||||
return project.name+"\n"+("=".repeat(project.name.length))+"\n\n"+(project.summary||"A Node-RED Project")+"\n\n";
|
||||
},
|
||||
"settings.json": function() { return "{}" },
|
||||
"flow.json": function() { return "[]" },
|
||||
"flow_cred.json": function() { return "{}" },
|
||||
// "flow.json": function() { return "[]" },
|
||||
// "flow_cred.json": function() { return "{}" },
|
||||
".gitignore": function() { return "*.backup" ;}
|
||||
}
|
||||
|
||||
@@ -215,6 +215,10 @@ module.exports = {
|
||||
return runCommand(gitCommand,args,cwd);
|
||||
},
|
||||
getFiles: getFiles,
|
||||
getFile: function(cwd, filePath, treeish) {
|
||||
var args = ["show",treeish+":"+filePath];
|
||||
return runCommand(gitCommand,args,cwd);
|
||||
},
|
||||
stageFile: function(cwd,file) {
|
||||
var args = ["add"];
|
||||
if (Array.isArray(file)) {
|
||||
|
||||
@@ -153,8 +153,9 @@ function getCommit(project,sha) {
|
||||
return activeProject.getCommit(sha);
|
||||
}
|
||||
|
||||
function getFile(project,path) {
|
||||
|
||||
function getFile(project,filePath,sha) {
|
||||
checkActiveProject(project);
|
||||
return activeProject.getFile(filePath,sha);
|
||||
}
|
||||
|
||||
function getActiveProject() {
|
||||
@@ -339,6 +340,7 @@ module.exports = {
|
||||
createProject: createProject,
|
||||
updateProject: updateProject,
|
||||
getFiles: getFiles,
|
||||
getFile: getFile,
|
||||
stageFile: stageFile,
|
||||
unstageFile: unstageFile,
|
||||
commit: commit,
|
||||
|
||||
Reference in New Issue
Block a user