From 9a5139f4526f7f3e1b977f3bd789e17dc04d618f Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Tue, 20 Feb 2018 14:30:37 -0800 Subject: [PATCH] Detect if there are no existing flows to migrate into a project --- editor/js/ui/projects/projects.js | 12 ++++++------ red/api/editor/settings.js | 9 +++++---- .../storage/localfilesystem/projects/index.js | 13 ++++++++++++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/editor/js/ui/projects/projects.js b/editor/js/ui/projects/projects.js index ce9c9a8c4..95c2344b7 100644 --- a/editor/js/ui/projects/projects.js +++ b/editor/js/ui/projects/projects.js @@ -77,8 +77,8 @@ RED.projects = (function() { var body = $('
').appendTo(container); $('

').text("Hello! We have introduced 'projects' to Node-RED.").appendTo(body); $('

').text("This is a new way for you to manage your flow files and includes version control of your flows.").appendTo(body); - $('

').text("To get started you can create your first project using your current flow files in a few easy steps.").appendTo(body); - $('

').text("If you are not sure, you can skip this for now. You will still be able to create your first project from the 'Projects' menu option at any time.").appendTo(body); + $('

').text("To get started you can create your first project or clone an existing project from a git repository.").appendTo(body); + $('

').text("If you are not sure, you can skip this for now. You will still be able to create your first project from the 'Projects' menu at any time.").appendTo(body); return container; }, @@ -313,9 +313,9 @@ RED.projects = (function() { var body = $('

').appendTo(container); $('

').text("Create your project files").appendTo(body); - $('

').text("A project contains your flow files, a README file, a package.json file and a settings file.").appendTo(body); + $('

').text("A project contains your flow files, a README file and a package.json file.").appendTo(body); $('

').text("It can contain any other files you want to maintain in the Git repository.").appendTo(body); - if (!options.existingProject) { + if (!options.existingProject && RED.settings.files) { $('

').text("Your existing flow and credential files will be copied into the project.").appendTo(body); } @@ -349,14 +349,14 @@ RED.projects = (function() { var row = $('

').appendTo(body); $('').appendTo(row); var subrow = $('
').appendTo(row); - var defaultFlowFile = (createProjectOptions.files &&createProjectOptions.files.flow) || RED.settings.files.flow||"flow.json"; + var defaultFlowFile = (createProjectOptions.files &&createProjectOptions.files.flow) || (RED.settings.files && RED.settings.files.flow)||"flow.json"; projectFlowFileInput = $('').val(defaultFlowFile) .on("change keyup paste",validateForm) .appendTo(subrow); $('
').appendTo(subrow); $('').appendTo(row); - var defaultCredentialsFile = (createProjectOptions.files &&createProjectOptions.files.credentials) || RED.settings.files.credentials||"flow_cred.json"; + var defaultCredentialsFile = (createProjectOptions.files &&createProjectOptions.files.credentials) || (RED.settings.files && RED.settings.files.credentials)||"flow_cred.json"; row = $('
').appendTo(body); $('').appendTo(row); subrow = $('
').appendTo(row); diff --git a/red/api/editor/settings.js b/red/api/editor/settings.js index 31fe01c1b..f76d4b659 100644 --- a/red/api/editor/settings.js +++ b/red/api/editor/settings.js @@ -54,10 +54,11 @@ module.exports = { var activeProject = runtime.storage.projects.getActiveProject(); if (activeProject) { safeSettings.project = activeProject; - } - safeSettings.files = { - flow: runtime.storage.projects.getFlowFilename(), - credentials: runtime.storage.projects.getCredentialsFilename() + } else if (runtime.storage.projects.flowFileExists()) { + safeSettings.files = { + flow: runtime.storage.projects.getFlowFilename(), + credentials: runtime.storage.projects.getCredentialsFilename() + } } safeSettings.git = { globalUser: runtime.storage.projects.getGlobalGitUser() diff --git a/red/runtime/storage/localfilesystem/projects/index.js b/red/runtime/storage/localfilesystem/projects/index.js index 361784987..781c8434b 100644 --- a/red/runtime/storage/localfilesystem/projects/index.js +++ b/red/runtime/storage/localfilesystem/projects/index.js @@ -445,6 +445,7 @@ var initialFlowLoadComplete = false; var flowsFile; var flowsFullPath; +var flowsFileExists = false; var flowsFileBackup; var credentialsFile; var credentialsFileBackup; @@ -492,7 +493,14 @@ function getFlows() { } } - return util.readFile(flowsFullPath,flowsFileBackup,[],'flow'); + return util.readFile(flowsFullPath,flowsFileBackup,null,'flow').then(function(result) { + if (result === null) { + flowsFileExists = false; + return []; + } + flowsFileExists = true; + return result; + }); } function saveFlows(flows) { @@ -505,6 +513,8 @@ function saveFlows(flows) { return when.reject(error); } + flowsFileExists = true; + try { fs.renameSync(flowsFullPath,flowsFileBackup); } catch(err) { @@ -586,6 +596,7 @@ module.exports = { removeRemote: removeRemote, updateRemote: updateRemote, getFlowFilename: getFlowFilename, + flowFileExists: function() { return flowsFileExists }, getCredentialsFilename: getCredentialsFilename, getGlobalGitUser: function() { return globalGitUser }, getFlows: getFlows,