From 499d22daca97992c4d3bda3e77db7d71ec43ac1c Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Thu, 5 Apr 2018 11:30:16 +0100 Subject: [PATCH] Add start script to default project package --- .../storage/localfilesystem/projects/Project.js | 10 ++++++++++ .../storage/localfilesystem/projects/defaultFileSet.js | 5 +++-- red/runtime/storage/localfilesystem/util.js | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/red/runtime/storage/localfilesystem/projects/Project.js b/red/runtime/storage/localfilesystem/projects/Project.js index aa2693001..11aa32564 100644 --- a/red/runtime/storage/localfilesystem/projects/Project.js +++ b/red/runtime/storage/localfilesystem/projects/Project.js @@ -279,6 +279,11 @@ Project.prototype.update = function (user, data) { if (data.hasOwnProperty('dependencies')) { savePackage = true; this.package.dependencies = data.dependencies; + if (this.package.dependencies.hasOwnProperty("node-red")) { + this.package.scripts = {"start":"node node_modules/node-red/red.js -u . " + this.package['node-red'].settings.flowFile}; + } else { + delete(this.package.scripts.start); + } } if (data.hasOwnProperty('summary')) { savePackage = true; @@ -332,6 +337,11 @@ Project.prototype.update = function (user, data) { if (data.files.hasOwnProperty('flow') && this.package['node-red'].settings.flowFile !== data.files.flow) { this.paths.flowFile = data.files.flow; this.package['node-red'].settings.flowFile = data.files.flow; + if (this.package.dependencies.hasOwnProperty("node-red")) { + this.package.scripts = {"start":"node node_modules/node-red/red.js -u . " + data.files.flow}; + } else { + delete(this.package.scripts.start); + } savePackage = true; flowFilesChanged = true; } diff --git a/red/runtime/storage/localfilesystem/projects/defaultFileSet.js b/red/runtime/storage/localfilesystem/projects/defaultFileSet.js index 12368ec75..768b0e2fd 100644 --- a/red/runtime/storage/localfilesystem/projects/defaultFileSet.js +++ b/red/runtime/storage/localfilesystem/projects/defaultFileSet.js @@ -24,7 +24,8 @@ module.exports = { "node-red": { "settings": { } - } + }, + "scripts": {} }; if (project.files) { if (project.files.flow) { @@ -43,5 +44,5 @@ module.exports = { return content; }, - ".gitignore": function() { return "*.backup" ;} + ".gitignore": function() { return "*.backup\n" ;} } diff --git a/red/runtime/storage/localfilesystem/util.js b/red/runtime/storage/localfilesystem/util.js index 6fb75d255..422a06946 100644 --- a/red/runtime/storage/localfilesystem/util.js +++ b/red/runtime/storage/localfilesystem/util.js @@ -81,8 +81,8 @@ module.exports = { writeFile: function(path,content,backupPath) { if (backupPath) { try { - console.log(path); - console.log(backupPath); + // console.log(path); + // console.log(backupPath); fs.renameSync(path,backupPath); } catch(err) { console.log(err);