@gregoriusrippenstein/node-red-contrib-nodedev 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/nodes/20-pkg-file.html +1 -0
- package/nodes/lib/tarhelpers.js +19 -14
- package/nodes/node-factory-sidebar-cfg.js +96 -12
- package/package.json +1 -1
package/nodes/20-pkg-file.html
CHANGED
package/nodes/lib/tarhelpers.js
CHANGED
|
@@ -3,13 +3,14 @@ module.exports = (function () {
|
|
|
3
3
|
var tarStream = require('tar-stream');
|
|
4
4
|
var streamx = require('streamx');
|
|
5
5
|
var pakoGzip = require('pako');
|
|
6
|
+
let pathUtil = require('path')
|
|
6
7
|
|
|
7
8
|
/*
|
|
8
9
|
* there is no indication in a tar file of whether a file is binary or textual.
|
|
9
10
|
* we can only make a guess by the extension of the filename.
|
|
10
11
|
***/
|
|
11
12
|
var computeFormat = (filename) => {
|
|
12
|
-
|
|
13
|
+
let ext = pathUtil.extname(filename).substr(1).toLowerCase()
|
|
13
14
|
|
|
14
15
|
return {
|
|
15
16
|
"html": "html",
|
|
@@ -39,7 +40,7 @@ module.exports = (function () {
|
|
|
39
40
|
"mov": "base64",
|
|
40
41
|
"ico": "base64",
|
|
41
42
|
"eot": "base64",
|
|
42
|
-
}[ext
|
|
43
|
+
}[ext] || "text";
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
var convertTarFile = (RED, tgzData, onFinish, onError) => {
|
|
@@ -59,22 +60,23 @@ module.exports = (function () {
|
|
|
59
60
|
});
|
|
60
61
|
|
|
61
62
|
stream.on('end', function () {
|
|
62
|
-
|
|
63
|
+
let filenameWithPath = header.name.replace(/^package\//, '')
|
|
64
|
+
let filename = pathUtil.basename(filenameWithPath)
|
|
65
|
+
let frmt = computeFormat(filename);
|
|
63
66
|
|
|
64
67
|
allFiles.push({
|
|
65
68
|
id: RED.util.generateId(),
|
|
66
69
|
type: "PkgFile",
|
|
67
|
-
name:
|
|
68
|
-
filename:
|
|
70
|
+
name: filename,
|
|
71
|
+
filename: filenameWithPath,
|
|
72
|
+
dirname: pathUtil.dirname(filenameWithPath),
|
|
69
73
|
template: Buffer.concat(buffer).toString(frmt == "base64" ? 'base64' : 'utf8'),
|
|
70
|
-
syntax:
|
|
74
|
+
syntax: filename == "package.json" ? "mustache" : "plain",
|
|
71
75
|
format: frmt,
|
|
72
76
|
output: "str",
|
|
73
|
-
x:
|
|
74
|
-
y:
|
|
75
|
-
wires: [
|
|
76
|
-
[]
|
|
77
|
-
]
|
|
77
|
+
x: 0,
|
|
78
|
+
y: 0,
|
|
79
|
+
wires: [[]]
|
|
78
80
|
})
|
|
79
81
|
|
|
80
82
|
next() // ready for next entry
|
|
@@ -84,9 +86,12 @@ module.exports = (function () {
|
|
|
84
86
|
})
|
|
85
87
|
|
|
86
88
|
extract.on('finish', function () {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
allFiles = allFiles.sort((a, b) => { return a.dirname < b.dirname ? -1 : (a.dirname > b.dirname ? 1 : 0) } )
|
|
90
|
+
|
|
91
|
+
for (var idx = 0; idx < allFiles.length; idx++) {
|
|
92
|
+
allFiles[idx].x = 250 * Math.floor(idx / 40)
|
|
93
|
+
allFiles[idx].y = 50 * (idx % 40)
|
|
94
|
+
allFiles[idx].wires = allFiles[idx + 1] ? [[allFiles[idx + 1].id]] : [[]]
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
onFinish(allFiles)
|
|
@@ -2,6 +2,64 @@ module.exports = function (RED) {
|
|
|
2
2
|
let pacote = require('pacote');
|
|
3
3
|
let tarHelpers = require('./lib/tarhelpers.js');
|
|
4
4
|
|
|
5
|
+
let dirGrpColours = (dirname) => {
|
|
6
|
+
|
|
7
|
+
dirname = (dirname.startsWith("dist/") || dirname == "dist") ? "dist" : dirname
|
|
8
|
+
dirname = (dirname.startsWith("nodes/locales/") || dirname == "nodes/locales" ) ? "nodes/locales" : dirname
|
|
9
|
+
dirname = (dirname.startsWith("locales/") || dirname == "locales") ? "nodes/locales" : dirname
|
|
10
|
+
dirname = (dirname.startsWith("samples/") || dirname == "samples") ? "examples" : dirname
|
|
11
|
+
dirname = (dirname != "." && dirname.startsWith(".")) ? ".dir" : dirname
|
|
12
|
+
|
|
13
|
+
let lookup = {
|
|
14
|
+
".dir": {
|
|
15
|
+
"stroke": "#dbcbe7",
|
|
16
|
+
"fill": "#dbcbe7",
|
|
17
|
+
},
|
|
18
|
+
".": {
|
|
19
|
+
"stroke": "#ffefbf",
|
|
20
|
+
"fill": "#ffefbf",
|
|
21
|
+
},
|
|
22
|
+
"examples": {
|
|
23
|
+
"stroke": "#addb7b",
|
|
24
|
+
"fill": "#addb7b",
|
|
25
|
+
},
|
|
26
|
+
"nodes": {
|
|
27
|
+
"stroke": "#c8e7a7",
|
|
28
|
+
"fill": "#c8e7a7",
|
|
29
|
+
},
|
|
30
|
+
"plugins": {
|
|
31
|
+
"stroke": "#92d04f",
|
|
32
|
+
"fill": "#92d04f",
|
|
33
|
+
},
|
|
34
|
+
"nodes/lib": {
|
|
35
|
+
"stroke": "#e3f3d3",
|
|
36
|
+
"fill": "#e3f3d3",
|
|
37
|
+
},
|
|
38
|
+
"assets": {
|
|
39
|
+
"stroke": "#0070c0",
|
|
40
|
+
"fill": "#0070c0",
|
|
41
|
+
},
|
|
42
|
+
"icons": {
|
|
43
|
+
"stroke": "#3f93cf",
|
|
44
|
+
"fill": "#3f93cf",
|
|
45
|
+
},
|
|
46
|
+
"nodes/icons": {
|
|
47
|
+
"stroke": "#3f93cf",
|
|
48
|
+
"fill": "#3f93cf",
|
|
49
|
+
},
|
|
50
|
+
"dist": {
|
|
51
|
+
"stroke": "#ffbfbf",
|
|
52
|
+
"fill": "#ffbfbf"
|
|
53
|
+
},
|
|
54
|
+
"nodes/locales": {
|
|
55
|
+
"stroke": "#bfdbef",
|
|
56
|
+
"fill": "#bfdbef",
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return lookup[dirname] || {}
|
|
61
|
+
}
|
|
62
|
+
|
|
5
63
|
function ConfigNodeFactorySidebarFunctionality(config) {
|
|
6
64
|
RED.nodes.createNode(this, config)
|
|
7
65
|
}
|
|
@@ -66,6 +124,24 @@ module.exports = function (RED) {
|
|
|
66
124
|
}
|
|
67
125
|
}
|
|
68
126
|
|
|
127
|
+
function createGroupForDirectory(dirname, allIds) {
|
|
128
|
+
// no label position means that the label goes top-left.
|
|
129
|
+
return {
|
|
130
|
+
"id": RED.util.generateId(),
|
|
131
|
+
"type": "group",
|
|
132
|
+
"name": `Dir: ${dirname}`,
|
|
133
|
+
"style": {
|
|
134
|
+
"label": true,
|
|
135
|
+
// "label-position": "ne",
|
|
136
|
+
"color": "#001f60",
|
|
137
|
+
"stroke-opacity": "0.75",
|
|
138
|
+
"fill-opacity": "0.5",
|
|
139
|
+
...dirGrpColours(dirname)
|
|
140
|
+
},
|
|
141
|
+
"nodes": allIds
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
69
145
|
function createGroup(pkgname, pversion, allFiles) {
|
|
70
146
|
return {
|
|
71
147
|
"id": RED.util.generateId(),
|
|
@@ -136,19 +212,14 @@ module.exports = function (RED) {
|
|
|
136
212
|
if ( msg.pkgname && msg.pkgversion ) {
|
|
137
213
|
const onFinish = (allFiles) => {
|
|
138
214
|
|
|
139
|
-
|
|
140
|
-
allFiles.forEach(function(element) {
|
|
141
|
-
element.syntax = "plain"
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
var lastNode = allFiles[allFiles.length - 1];
|
|
215
|
+
var lastNode = allFiles.at(-1);
|
|
145
216
|
|
|
146
217
|
var nodeDevOp = createDevOpsNode(msg.pkgname, msg.pkgversion, allFiles[0].x, allFiles[0].y, allFiles[0].id)
|
|
147
218
|
var nrInstallNode = createNodeRedInstallNode(lastNode.x, lastNode.y)
|
|
148
219
|
var tarballNode = createTarballNode(lastNode.x, lastNode.y, nrInstallNode.id)
|
|
149
220
|
|
|
150
221
|
let pkgjson = allFiles.filter( a => {
|
|
151
|
-
return a.filename == "package.json"
|
|
222
|
+
return a.filename == "package.json" && a.dirname == "."
|
|
152
223
|
})[0];
|
|
153
224
|
|
|
154
225
|
if ( pkgjson) {
|
|
@@ -161,13 +232,26 @@ module.exports = function (RED) {
|
|
|
161
232
|
|
|
162
233
|
lastNode.wires[0].push(tarballNode.id)
|
|
163
234
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
235
|
+
/* group by dirname */
|
|
236
|
+
let groupByDirectory = {}
|
|
237
|
+
let dirGroups = []
|
|
238
|
+
allFiles.forEach(a => {
|
|
239
|
+
(groupByDirectory[a.dirname] ||= []).push(a.id)
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
Object.keys(groupByDirectory).forEach(d => {
|
|
243
|
+
dirGroups.push(createGroupForDirectory(d, groupByDirectory[d]))
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
let nodeDevNodes = [
|
|
247
|
+
nodeDevOp,
|
|
248
|
+
tarballNode,
|
|
249
|
+
nrInstallNode
|
|
250
|
+
]
|
|
167
251
|
|
|
168
252
|
allFiles = [
|
|
169
|
-
createGroup(msg.pkgname, nodeDevOp.pversion || msg.pkgversion,
|
|
170
|
-
].concat(allFiles)
|
|
253
|
+
createGroup(msg.pkgname, nodeDevOp.pversion || msg.pkgversion, dirGroups.concat(nodeDevNodes))
|
|
254
|
+
].concat(dirGroups).concat(nodeDevNodes).concat(allFiles)
|
|
171
255
|
|
|
172
256
|
RED.comms.publish(
|
|
173
257
|
"nodedev:perform-autoimport-nodes",
|