mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add file extension into flow name of library automatically (#1331)
This commit is contained in:
parent
c93870316c
commit
b3ffd33507
@ -419,6 +419,9 @@ var localfilesystem = {
|
|||||||
if (settings.readOnly) {
|
if (settings.readOnly) {
|
||||||
return when.resolve();
|
return when.resolve();
|
||||||
}
|
}
|
||||||
|
if (type === "flows" && !path.endsWith(".json")) {
|
||||||
|
path += ".json";
|
||||||
|
}
|
||||||
var fn = fspath.join(libDir, type, path);
|
var fn = fspath.join(libDir, type, path);
|
||||||
var headers = "";
|
var headers = "";
|
||||||
for (var i in meta) {
|
for (var i in meta) {
|
||||||
|
@ -587,9 +587,13 @@ describe('LocalFileSystem', function() {
|
|||||||
fs.mkdirSync(path.join(objLib,"A"));
|
fs.mkdirSync(path.join(objLib,"A"));
|
||||||
fs.mkdirSync(path.join(objLib,"B"));
|
fs.mkdirSync(path.join(objLib,"B"));
|
||||||
fs.mkdirSync(path.join(objLib,"B","C"));
|
fs.mkdirSync(path.join(objLib,"B","C"));
|
||||||
fs.writeFileSync(path.join(objLib,"file1.js"),"// abc: def\n// not a metaline \n\n Hi",'utf8');
|
if (type === "functions" || type === "object") {
|
||||||
fs.writeFileSync(path.join(objLib,"B","file2.js"),"// ghi: jkl\n// not a metaline \n\n Hi",'utf8');
|
fs.writeFileSync(path.join(objLib,"file1.js"),"// abc: def\n// not a metaline \n\n Hi",'utf8');
|
||||||
fs.writeFileSync(path.join(objLib,"B","flow.json"),"Hi",'utf8');
|
fs.writeFileSync(path.join(objLib,"B","file2.js"),"// ghi: jkl\n// not a metaline \n\n Hi",'utf8');
|
||||||
|
}
|
||||||
|
if (type === "flows" || type === "object") {
|
||||||
|
fs.writeFileSync(path.join(objLib,"B","flow.json"),"Hi",'utf8');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should return a directory listing of library objects',function(done) {
|
it('should return a directory listing of library objects',function(done) {
|
||||||
@ -644,17 +648,17 @@ describe('LocalFileSystem', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a newly saved library object',function(done) {
|
it('should return a newly saved library function',function(done) {
|
||||||
localfilesystem.init({userDir:userDir}).then(function() {
|
localfilesystem.init({userDir:userDir}).then(function() {
|
||||||
createObjectLibrary();
|
createObjectLibrary("functions");
|
||||||
localfilesystem.getLibraryEntry('object','B').then(function(flows) {
|
localfilesystem.getLibraryEntry('functions','B').then(function(flows) {
|
||||||
flows.should.eql([ 'C', { ghi: 'jkl', fn: 'file2.js' }, {fn:'flow.json'} ]);
|
flows.should.eql([ 'C', { ghi: 'jkl', fn: 'file2.js' } ]);
|
||||||
var ft = path.join("B","D","file3.js");
|
var ft = path.join("B","D","file3.js");
|
||||||
localfilesystem.saveLibraryEntry('object',ft,{mno:'pqr'},"// another non meta line\n\n Hi There").then(function() {
|
localfilesystem.saveLibraryEntry('functions',ft,{mno:'pqr'},"// another non meta line\n\n Hi There").then(function() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
localfilesystem.getLibraryEntry('object',path.join("B","D")).then(function(flows) {
|
localfilesystem.getLibraryEntry('functions',path.join("B","D")).then(function(flows) {
|
||||||
flows.should.eql([ { mno: 'pqr', fn: 'file3.js' } ]);
|
flows.should.eql([ { mno: 'pqr', fn: 'file3.js' } ]);
|
||||||
localfilesystem.getLibraryEntry('object',ft).then(function(body) {
|
localfilesystem.getLibraryEntry('functions',ft).then(function(body) {
|
||||||
body.should.eql("// another non meta line\n\n Hi There");
|
body.should.eql("// another non meta line\n\n Hi There");
|
||||||
done();
|
done();
|
||||||
}).otherwise(function(err) {
|
}).otherwise(function(err) {
|
||||||
@ -675,4 +679,35 @@ describe('LocalFileSystem', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return a newly saved library flow',function(done) {
|
||||||
|
localfilesystem.init({userDir:userDir}).then(function() {
|
||||||
|
createObjectLibrary("flows");
|
||||||
|
localfilesystem.getLibraryEntry('flows','B').then(function(flows) {
|
||||||
|
flows.should.eql([ 'C', {fn:'flow.json'} ]);
|
||||||
|
var ft = path.join("B","D","file3");
|
||||||
|
localfilesystem.saveLibraryEntry('flows',ft,{mno:'pqr'},"Hi").then(function() {
|
||||||
|
setTimeout(function() {
|
||||||
|
localfilesystem.getLibraryEntry('flows',path.join("B","D")).then(function(flows) {
|
||||||
|
flows.should.eql([ { mno: 'pqr', fn: 'file3.json' } ]);
|
||||||
|
localfilesystem.getLibraryEntry('flows',ft+".json").then(function(body) {
|
||||||
|
body.should.eql("Hi");
|
||||||
|
done();
|
||||||
|
}).otherwise(function(err) {
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
}).otherwise(function(err) {
|
||||||
|
done(err);
|
||||||
|
})}
|
||||||
|
, 50);
|
||||||
|
}).otherwise(function(err) {
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
}).otherwise(function(err) {
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
}).otherwise(function(err) {
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user