@gregoriusrippenstein/node-red-contrib-nodedev 0.3.7 → 0.3.8

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.
@@ -108,6 +108,7 @@
108
108
  defaults: {
109
109
  name: {value:""},
110
110
  filename: { value: ""},
111
+ dirname: { value: "" },
111
112
  format: {value:"handlebars"},
112
113
  syntax: {value:"mustache"},
113
114
  template: {value:""},
@@ -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
- var ext = filename.split(".").at(-1);
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.toLowerCase()] || "text";
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
- var frmt = computeFormat(header.name.split("/").at(-1));
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: header.name.split("/").at(-1),
68
- filename: header.name.replace(/^package\//, ''),
70
+ name: filename,
71
+ filename: filenameWithPath,
72
+ dirname: pathUtil.dirname(filenameWithPath),
69
73
  template: Buffer.concat(buffer).toString(frmt == "base64" ? 'base64' : 'utf8'),
70
- syntax: header.name.replace(/^package\//, '') == "package.json" ? "mustache" : "plain",
74
+ syntax: filename == "package.json" ? "mustache" : "plain",
71
75
  format: frmt,
72
76
  output: "str",
73
- x: 250 * Math.floor(allFiles.length / 40),
74
- y: 50 * (allFiles.length % 40),
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
- // all entries read, wire them together
88
- for (var idx = 0; idx < allFiles.length - 1; idx++) {
89
- allFiles[idx].wires = [[allFiles[idx + 1].id]];
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)
@@ -66,6 +66,20 @@ module.exports = function (RED) {
66
66
  }
67
67
  }
68
68
 
69
+ function createGroupForDirectory(dirname, allIds) {
70
+ return {
71
+ "id": RED.util.generateId(),
72
+ "type": "group",
73
+ "name": `Dir: ${dirname}`,
74
+ "style": {
75
+ "label": true,
76
+ "label-position": "ne",
77
+ "color": "#001f60"
78
+ },
79
+ "nodes": allIds
80
+ }
81
+ }
82
+
69
83
  function createGroup(pkgname, pversion, allFiles) {
70
84
  return {
71
85
  "id": RED.util.generateId(),
@@ -136,19 +150,14 @@ module.exports = function (RED) {
136
150
  if ( msg.pkgname && msg.pkgversion ) {
137
151
  const onFinish = (allFiles) => {
138
152
 
139
- /* these are no templates, these are files - no mustache intrepretation */
140
- allFiles.forEach(function(element) {
141
- element.syntax = "plain"
142
- });
143
-
144
- var lastNode = allFiles[allFiles.length - 1];
153
+ var lastNode = allFiles.at(-1);
145
154
 
146
155
  var nodeDevOp = createDevOpsNode(msg.pkgname, msg.pkgversion, allFiles[0].x, allFiles[0].y, allFiles[0].id)
147
156
  var nrInstallNode = createNodeRedInstallNode(lastNode.x, lastNode.y)
148
157
  var tarballNode = createTarballNode(lastNode.x, lastNode.y, nrInstallNode.id)
149
158
 
150
159
  let pkgjson = allFiles.filter( a => {
151
- return a.filename == "package.json"
160
+ return a.filename == "package.json" && a.dirname == "."
152
161
  })[0];
153
162
 
154
163
  if ( pkgjson) {
@@ -161,13 +170,29 @@ module.exports = function (RED) {
161
170
 
162
171
  lastNode.wires[0].push(tarballNode.id)
163
172
 
164
- allFiles.push(nodeDevOp);
165
- allFiles.push(tarballNode);
166
- allFiles.push(nrInstallNode);
173
+
174
+ /* group by dirname */
175
+ let groupByDirectory = {}
176
+ let dirGroups = []
177
+ allFiles.forEach(a => {
178
+ (groupByDirectory[a.dirname] ||= []).push(a.id)
179
+ })
180
+
181
+ Object.keys(groupByDirectory).forEach(d => {
182
+ dirGroups.push(createGroupForDirectory(d, groupByDirectory[d]))
183
+ })
184
+
185
+ let nodeDevNodes = [
186
+ nodeDevOp,
187
+ tarballNode,
188
+ nrInstallNode
189
+ ]
167
190
 
168
191
  allFiles = [
169
- createGroup(msg.pkgname, nodeDevOp.pversion || msg.pkgversion, allFiles)
170
- ].concat(allFiles);
192
+ createGroup(msg.pkgname, nodeDevOp.pversion || msg.pkgversion, dirGroups.concat(nodeDevNodes))
193
+ // @ts-ignore
194
+ ].concat(dirGroups).concat(nodeDevNodes).concat(allFiles);
195
+
171
196
 
172
197
  RED.comms.publish(
173
198
  "nodedev:perform-autoimport-nodes",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name" : "@gregoriusrippenstein/node-red-contrib-nodedev",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "dependencies": {
5
5
  "pako": "^2.1.0",
6
6
  "tar-stream": "^3.1.6",