Skip to content

Commit 9a5139f

Browse files
committed
Detect if there are no existing flows to migrate into a project
1 parent 2ee0c8c commit 9a5139f

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

editor/js/ui/projects/projects.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ RED.projects = (function() {
7777
var body = $('<div class="projects-dialog-screen-start-body"></div>').appendTo(container);
7878
$('<p>').text("Hello! We have introduced 'projects' to Node-RED.").appendTo(body);
7979
$('<p>').text("This is a new way for you to manage your flow files and includes version control of your flows.").appendTo(body);
80-
$('<p>').text("To get started you can create your first project using your current flow files in a few easy steps.").appendTo(body);
81-
$('<p>').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);
80+
$('<p>').text("To get started you can create your first project or clone an existing project from a git repository.").appendTo(body);
81+
$('<p>').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);
8282

8383
return container;
8484
},
@@ -313,9 +313,9 @@ RED.projects = (function() {
313313
var body = $('<div class="projects-dialog-screen-start-body"></div>').appendTo(container);
314314

315315
$('<p>').text("Create your project files").appendTo(body);
316-
$('<p>').text("A project contains your flow files, a README file, a package.json file and a settings file.").appendTo(body);
316+
$('<p>').text("A project contains your flow files, a README file and a package.json file.").appendTo(body);
317317
$('<p>').text("It can contain any other files you want to maintain in the Git repository.").appendTo(body);
318-
if (!options.existingProject) {
318+
if (!options.existingProject && RED.settings.files) {
319319
$('<p>').text("Your existing flow and credential files will be copied into the project.").appendTo(body);
320320
}
321321

@@ -349,14 +349,14 @@ RED.projects = (function() {
349349
var row = $('<div class="form-row"></div>').appendTo(body);
350350
$('<label for="projects-dialog-screen-create-project-file">Flow file</label>').appendTo(row);
351351
var subrow = $('<div style="position:relative;"></div>').appendTo(row);
352-
var defaultFlowFile = (createProjectOptions.files &&createProjectOptions.files.flow) || RED.settings.files.flow||"flow.json";
352+
var defaultFlowFile = (createProjectOptions.files &&createProjectOptions.files.flow) || (RED.settings.files && RED.settings.files.flow)||"flow.json";
353353
projectFlowFileInput = $('<input id="projects-dialog-screen-create-project-file" type="text">').val(defaultFlowFile)
354354
.on("change keyup paste",validateForm)
355355
.appendTo(subrow);
356356
$('<div class="projects-dialog-screen-input-status"></div>').appendTo(subrow);
357357
$('<label class="projects-edit-form-sublabel"><small>*.json</small></label>').appendTo(row);
358358

359-
var defaultCredentialsFile = (createProjectOptions.files &&createProjectOptions.files.credentials) || RED.settings.files.credentials||"flow_cred.json";
359+
var defaultCredentialsFile = (createProjectOptions.files &&createProjectOptions.files.credentials) || (RED.settings.files && RED.settings.files.credentials)||"flow_cred.json";
360360
row = $('<div class="form-row"></div>').appendTo(body);
361361
$('<label for="projects-dialog-screen-create-project-credfile">Credentials file</label>').appendTo(row);
362362
subrow = $('<div style="position:relative;"></div>').appendTo(row);

red/api/editor/settings.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ module.exports = {
5454
var activeProject = runtime.storage.projects.getActiveProject();
5555
if (activeProject) {
5656
safeSettings.project = activeProject;
57-
}
58-
safeSettings.files = {
59-
flow: runtime.storage.projects.getFlowFilename(),
60-
credentials: runtime.storage.projects.getCredentialsFilename()
57+
} else if (runtime.storage.projects.flowFileExists()) {
58+
safeSettings.files = {
59+
flow: runtime.storage.projects.getFlowFilename(),
60+
credentials: runtime.storage.projects.getCredentialsFilename()
61+
}
6162
}
6263
safeSettings.git = {
6364
globalUser: runtime.storage.projects.getGlobalGitUser()

red/runtime/storage/localfilesystem/projects/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ var initialFlowLoadComplete = false;
445445

446446
var flowsFile;
447447
var flowsFullPath;
448+
var flowsFileExists = false;
448449
var flowsFileBackup;
449450
var credentialsFile;
450451
var credentialsFileBackup;
@@ -492,7 +493,14 @@ function getFlows() {
492493
}
493494

494495
}
495-
return util.readFile(flowsFullPath,flowsFileBackup,[],'flow');
496+
return util.readFile(flowsFullPath,flowsFileBackup,null,'flow').then(function(result) {
497+
if (result === null) {
498+
flowsFileExists = false;
499+
return [];
500+
}
501+
flowsFileExists = true;
502+
return result;
503+
});
496504
}
497505

498506
function saveFlows(flows) {
@@ -505,6 +513,8 @@ function saveFlows(flows) {
505513
return when.reject(error);
506514
}
507515

516+
flowsFileExists = true;
517+
508518
try {
509519
fs.renameSync(flowsFullPath,flowsFileBackup);
510520
} catch(err) {
@@ -586,6 +596,7 @@ module.exports = {
586596
removeRemote: removeRemote,
587597
updateRemote: updateRemote,
588598
getFlowFilename: getFlowFilename,
599+
flowFileExists: function() { return flowsFileExists },
589600
getCredentialsFilename: getCredentialsFilename,
590601
getGlobalGitUser: function() { return globalGitUser },
591602
getFlows: getFlows,

0 commit comments

Comments
 (0)