@rosepetal/node-red-contrib-image-tools 1.2.2 → 1.3.0
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/.github/workflows/build-prebuild.yml +3 -0
- package/install.sh +8 -0
- package/node-red-contrib-image-tools/lib/node-utils.js +64 -0
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +242 -3
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +10 -3
- package/node-red-contrib-image-tools/nodes/blend/add-mask.html +282 -4
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +15 -8
- package/node-red-contrib-image-tools/nodes/blend/add-masks.html +206 -3
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +10 -3
- package/node-red-contrib-image-tools/nodes/blend/blend.html +332 -4
- package/node-red-contrib-image-tools/nodes/blend/blend.js +10 -3
- package/node-red-contrib-image-tools/nodes/io/folder-in.html +147 -3
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +2 -1
- package/node-red-contrib-image-tools/nodes/io/image-in.html +81 -2
- package/node-red-contrib-image-tools/nodes/io/image-in.js +2 -1
- package/node-red-contrib-image-tools/nodes/io/image-out.html +197 -3
- package/node-red-contrib-image-tools/nodes/io/image-out.js +2 -1
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +398 -3
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +11 -4
- package/node-red-contrib-image-tools/nodes/mix/concat.html +245 -5
- package/node-red-contrib-image-tools/nodes/mix/concat.js +10 -3
- package/node-red-contrib-image-tools/nodes/mix/mosaic.html +307 -3
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +10 -3
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +217 -4
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +11 -2
- package/node-red-contrib-image-tools/nodes/specialized/image-align.html +285 -4
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +9 -2
- package/node-red-contrib-image-tools/nodes/transform/color-convert.html +169 -6
- package/node-red-contrib-image-tools/nodes/transform/color-convert.js +11 -2
- package/node-red-contrib-image-tools/nodes/transform/crop.html +237 -5
- package/node-red-contrib-image-tools/nodes/transform/crop.js +11 -2
- package/node-red-contrib-image-tools/nodes/transform/draw.html +152 -3
- package/node-red-contrib-image-tools/nodes/transform/draw.js +10 -3
- package/node-red-contrib-image-tools/nodes/transform/filter.html +369 -4
- package/node-red-contrib-image-tools/nodes/transform/filter.js +11 -2
- package/node-red-contrib-image-tools/nodes/transform/padding.html +316 -5
- package/node-red-contrib-image-tools/nodes/transform/padding.js +11 -2
- package/node-red-contrib-image-tools/nodes/transform/resize.html +203 -5
- package/node-red-contrib-image-tools/nodes/transform/resize.js +11 -2
- package/node-red-contrib-image-tools/nodes/transform/rotate.html +164 -5
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +11 -2
- package/package.json +71 -71
- package/scripts/dual-register.js +267 -0
package/package.json
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"image-in": "node-red-contrib-image-tools/nodes/io/image-in.js",
|
|
48
|
-
"folder-in": "node-red-contrib-image-tools/nodes/io/folder-in.js",
|
|
49
|
-
"image-out": "node-red-contrib-image-tools/nodes/io/image-out.js",
|
|
50
|
-
"array-in": "node-red-contrib-image-tools/nodes/io/array-in.js",
|
|
51
|
-
"array-out": "node-red-contrib-image-tools/nodes/io/array-out.js",
|
|
52
|
-
"array-select": "node-red-contrib-image-tools/nodes/io/array-select.js",
|
|
53
|
-
"cropBB": "node-red-contrib-image-tools/nodes/specialized/cropBB.js",
|
|
54
|
-
"image-align": "node-red-contrib-image-tools/nodes/specialized/image-align.js",
|
|
55
|
-
"resize": "node-red-contrib-image-tools/nodes/transform/resize.js",
|
|
56
|
-
"rotate": "node-red-contrib-image-tools/nodes/transform/rotate.js",
|
|
57
|
-
"crop": "node-red-contrib-image-tools/nodes/transform/crop.js",
|
|
58
|
-
"concat": "node-red-contrib-image-tools/nodes/mix/concat.js",
|
|
59
|
-
"padding": "node-red-contrib-image-tools/nodes/transform/padding.js",
|
|
60
|
-
"filter": "node-red-contrib-image-tools/nodes/transform/filter.js",
|
|
61
|
-
"draw": "node-red-contrib-image-tools/nodes/transform/draw.js",
|
|
62
|
-
"color-convert": "node-red-contrib-image-tools/nodes/transform/color-convert.js",
|
|
63
|
-
"mosaic": "node-red-contrib-image-tools/nodes/mix/mosaic.js",
|
|
64
|
-
"advanced-mosaic": "node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js",
|
|
65
|
-
"blend": "node-red-contrib-image-tools/nodes/blend/blend.js",
|
|
66
|
-
"add-mask": "node-red-contrib-image-tools/nodes/blend/add-mask.js",
|
|
67
|
-
"add-masks": "node-red-contrib-image-tools/nodes/blend/add-masks.js",
|
|
68
|
-
"add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js",
|
|
69
|
-
"queue": "node-red-contrib-image-tools/nodes/io/queue.js",
|
|
70
|
-
"save-file": "node-red-contrib-image-tools/nodes/io/save-file.js",
|
|
71
|
-
"clean-debug": "node-red-contrib-image-tools/nodes/util/clean-debug.js",
|
|
72
|
-
"block-detect": "node-red-contrib-image-tools/nodes/util/block-detect.js"
|
|
2
|
+
"name": "@rosepetal/node-red-contrib-image-tools",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Node-RED Image Processing Toolkit",
|
|
5
|
+
"main": "install.sh",
|
|
6
|
+
"directories": {
|
|
7
|
+
"doc": "docs"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/rosepetal-ai/node-red-contrib-image-tools.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"node-red",
|
|
18
|
+
"image",
|
|
19
|
+
"opencv",
|
|
20
|
+
"performance"
|
|
21
|
+
],
|
|
22
|
+
"author": "Rosepetal SL (https://www.rosepetal.ai)",
|
|
23
|
+
"contributors": [
|
|
24
|
+
{
|
|
25
|
+
"name": "Nil Allue",
|
|
26
|
+
"email": "nil.allue@rosepetal.ai"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/rosepetal-ai/node-red-contrib-image-tools/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/rosepetal-ai/node-red-contrib-image-tools#readme",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"sharp": "^0.34.2"
|
|
36
|
+
},
|
|
37
|
+
"optionalDependencies": {
|
|
38
|
+
"@rosepetal/node-red-contrib-image-tools-linux-x64": "1.1.3",
|
|
39
|
+
"@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.1.3",
|
|
40
|
+
"@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.1.3",
|
|
41
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.1.3",
|
|
42
|
+
"@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.1.3"
|
|
43
|
+
},
|
|
44
|
+
"node-red": {
|
|
45
|
+
"version": ">=1.0.0",
|
|
46
|
+
"nodes": {
|
|
47
|
+
"rp-image-in": "node-red-contrib-image-tools/nodes/io/image-in.js",
|
|
48
|
+
"rp-folder-in": "node-red-contrib-image-tools/nodes/io/folder-in.js",
|
|
49
|
+
"rp-image-out": "node-red-contrib-image-tools/nodes/io/image-out.js",
|
|
50
|
+
"rp-array-in": "node-red-contrib-image-tools/nodes/io/array-in.js",
|
|
51
|
+
"rp-array-out": "node-red-contrib-image-tools/nodes/io/array-out.js",
|
|
52
|
+
"rp-array-select": "node-red-contrib-image-tools/nodes/io/array-select.js",
|
|
53
|
+
"rp-cropBB": "node-red-contrib-image-tools/nodes/specialized/cropBB.js",
|
|
54
|
+
"rp-image-align": "node-red-contrib-image-tools/nodes/specialized/image-align.js",
|
|
55
|
+
"rp-resize": "node-red-contrib-image-tools/nodes/transform/resize.js",
|
|
56
|
+
"rp-rotate": "node-red-contrib-image-tools/nodes/transform/rotate.js",
|
|
57
|
+
"rp-crop": "node-red-contrib-image-tools/nodes/transform/crop.js",
|
|
58
|
+
"rp-concat": "node-red-contrib-image-tools/nodes/mix/concat.js",
|
|
59
|
+
"rp-padding": "node-red-contrib-image-tools/nodes/transform/padding.js",
|
|
60
|
+
"rp-filter": "node-red-contrib-image-tools/nodes/transform/filter.js",
|
|
61
|
+
"rp-draw": "node-red-contrib-image-tools/nodes/transform/draw.js",
|
|
62
|
+
"rp-color-convert": "node-red-contrib-image-tools/nodes/transform/color-convert.js",
|
|
63
|
+
"rp-mosaic": "node-red-contrib-image-tools/nodes/mix/mosaic.js",
|
|
64
|
+
"rp-advanced-mosaic": "node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js",
|
|
65
|
+
"rp-blend": "node-red-contrib-image-tools/nodes/blend/blend.js",
|
|
66
|
+
"rp-add-mask": "node-red-contrib-image-tools/nodes/blend/add-mask.js",
|
|
67
|
+
"rp-add-masks": "node-red-contrib-image-tools/nodes/blend/add-masks.js",
|
|
68
|
+
"rp-add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js",
|
|
69
|
+
"rp-queue": "node-red-contrib-image-tools/nodes/io/queue.js",
|
|
70
|
+
"rp-save-file": "node-red-contrib-image-tools/nodes/io/save-file.js",
|
|
71
|
+
"rp-clean-debug": "node-red-contrib-image-tools/nodes/util/clean-debug.js",
|
|
72
|
+
"rp-block-detect": "node-red-contrib-image-tools/nodes/util/block-detect.js"
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Legacy Compatibility Injection Script (CI use)
|
|
4
|
+
*
|
|
5
|
+
* Runs on source files that already use 'rp-' prefixed type names.
|
|
6
|
+
* Adds legacy registrations under the OLD names (without 'rp-' prefix)
|
|
7
|
+
* so existing user flows keep working after upgrading.
|
|
8
|
+
*
|
|
9
|
+
* - Legacy types are hidden from palette (category: 'deprecated')
|
|
10
|
+
* - Legacy template/help blocks are duplicated for old type names
|
|
11
|
+
* - Source code in git stays clean (rp- only)
|
|
12
|
+
* - Run this in CI before npm publish
|
|
13
|
+
*
|
|
14
|
+
* Usage: node scripts/dual-register.js [--dry-run]
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
|
|
20
|
+
const DRY_RUN = process.argv.includes('--dry-run');
|
|
21
|
+
const BASE = path.join(__dirname, '..', 'node-red-contrib-image-tools', 'nodes');
|
|
22
|
+
|
|
23
|
+
// Maps old type name → file path (old name is what gets added as legacy)
|
|
24
|
+
const NODES = [
|
|
25
|
+
{ oldType: 'image-in', path: 'io/image-in' },
|
|
26
|
+
{ oldType: 'folder-in', path: 'io/folder-in' },
|
|
27
|
+
{ oldType: 'image-out', path: 'io/image-out' },
|
|
28
|
+
{ oldType: 'resize', path: 'transform/resize' },
|
|
29
|
+
{ oldType: 'crop', path: 'transform/crop' },
|
|
30
|
+
{ oldType: 'rotate', path: 'transform/rotate' },
|
|
31
|
+
{ oldType: 'padding', path: 'transform/padding' },
|
|
32
|
+
{ oldType: 'filter', path: 'transform/filter' },
|
|
33
|
+
{ oldType: 'draw', path: 'transform/draw' },
|
|
34
|
+
{ oldType: 'color-convert', path: 'transform/color-convert' },
|
|
35
|
+
{ oldType: 'concat', path: 'mix/concat' },
|
|
36
|
+
{ oldType: 'mosaic', path: 'mix/mosaic' },
|
|
37
|
+
{ oldType: 'advanced-mosaic', path: 'mix/advanced-mosaic' },
|
|
38
|
+
{ oldType: 'blend', path: 'blend/blend' },
|
|
39
|
+
{ oldType: 'add-mask', path: 'blend/add-mask' },
|
|
40
|
+
{ oldType: 'add-masks', path: 'blend/add-masks' },
|
|
41
|
+
{ oldType: 'add-bbs', path: 'blend/add-bbs' },
|
|
42
|
+
{ oldType: 'cropBB', path: 'specialized/cropBB' },
|
|
43
|
+
{ oldType: 'image-align', path: 'specialized/image-align' },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
function escapeRegex(str) {
|
|
47
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Find the position of the matching closing brace for an opening brace.
|
|
52
|
+
* Handles nested braces, strings (single/double/template), line and block comments.
|
|
53
|
+
*/
|
|
54
|
+
function findMatchingBrace(content, openPos) {
|
|
55
|
+
let depth = 0;
|
|
56
|
+
for (let i = openPos; i < content.length; i++) {
|
|
57
|
+
const ch = content[i];
|
|
58
|
+
|
|
59
|
+
// Skip single-quoted strings
|
|
60
|
+
if (ch === "'") {
|
|
61
|
+
i++;
|
|
62
|
+
while (i < content.length && content[i] !== "'") {
|
|
63
|
+
if (content[i] === '\\') i++;
|
|
64
|
+
i++;
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
// Skip double-quoted strings
|
|
69
|
+
if (ch === '"') {
|
|
70
|
+
i++;
|
|
71
|
+
while (i < content.length && content[i] !== '"') {
|
|
72
|
+
if (content[i] === '\\') i++;
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
// Skip template literals
|
|
78
|
+
if (ch === '`') {
|
|
79
|
+
i++;
|
|
80
|
+
while (i < content.length && content[i] !== '`') {
|
|
81
|
+
if (content[i] === '\\') i++;
|
|
82
|
+
i++;
|
|
83
|
+
}
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
// Skip line comments
|
|
87
|
+
if (ch === '/' && i + 1 < content.length && content[i + 1] === '/') {
|
|
88
|
+
i += 2;
|
|
89
|
+
while (i < content.length && content[i] !== '\n') i++;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
// Skip block comments
|
|
93
|
+
if (ch === '/' && i + 1 < content.length && content[i + 1] === '*') {
|
|
94
|
+
i += 2;
|
|
95
|
+
while (i < content.length && !(content[i] === '*' && content[i + 1] === '/')) i++;
|
|
96
|
+
i++;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (ch === '{') depth++;
|
|
101
|
+
else if (ch === '}') {
|
|
102
|
+
depth--;
|
|
103
|
+
if (depth === 0) return i;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return -1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ─────────────────────────────────────────────────────────────
|
|
110
|
+
// JS: Find registerType('rp-TYPE', C) → add registerType('TYPE', C)
|
|
111
|
+
// ─────────────────────────────────────────────────────────────
|
|
112
|
+
|
|
113
|
+
function addLegacyJs(filePath, oldType) {
|
|
114
|
+
const rpType = 'rp-' + oldType;
|
|
115
|
+
let content = fs.readFileSync(filePath, 'utf8');
|
|
116
|
+
|
|
117
|
+
// Find: RED.nodes.registerType('rp-TYPE', Constructor);
|
|
118
|
+
const regex = new RegExp(
|
|
119
|
+
`([ \\t]*)(RED\\.nodes\\.registerType\\s*\\(\\s*['"])${escapeRegex(rpType)}(['"]\\s*,\\s*)(\\w+)(\\s*\\)\\s*;)`,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const match = content.match(regex);
|
|
123
|
+
if (!match) {
|
|
124
|
+
console.error(` JS: ✗ Could not find registerType('${rpType}', ...) in ${path.basename(filePath)}`);
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const [fullMatch, indent, prefix, midQuote, constructor, suffix] = match;
|
|
129
|
+
|
|
130
|
+
// Add legacy registration on the next line
|
|
131
|
+
const legacyLine = `\n${indent}${prefix}${oldType}${midQuote}${constructor}${suffix} // legacy compat`;
|
|
132
|
+
|
|
133
|
+
content = content.replace(fullMatch, fullMatch + legacyLine);
|
|
134
|
+
|
|
135
|
+
if (!DRY_RUN) fs.writeFileSync(filePath, content);
|
|
136
|
+
console.log(` JS: ✓ Added legacy registerType('${oldType}', ${constructor})`);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ─────────────────────────────────────────────────────────────
|
|
141
|
+
// HTML: Add legacy registration + duplicate template/help
|
|
142
|
+
// ─────────────────────────────────────────────────────────────
|
|
143
|
+
|
|
144
|
+
function addLegacyHtmlRegistration(content, oldType) {
|
|
145
|
+
const rpType = 'rp-' + oldType;
|
|
146
|
+
|
|
147
|
+
// Find: RED.nodes.registerType('rp-TYPE',
|
|
148
|
+
const rtRegex = new RegExp(
|
|
149
|
+
`(RED\\.nodes\\.registerType\\s*\\(\\s*['"])${escapeRegex(rpType)}(['"]\\s*,\\s*)`,
|
|
150
|
+
);
|
|
151
|
+
const rtMatch = content.match(rtRegex);
|
|
152
|
+
if (!rtMatch) {
|
|
153
|
+
console.error(` HTML: ✗ Could not find registerType('${rpType}') in registration block`);
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const rtStart = rtMatch.index;
|
|
158
|
+
const afterComma = rtStart + rtMatch[0].length;
|
|
159
|
+
|
|
160
|
+
// Find the opening { of the config object
|
|
161
|
+
let openBrace = afterComma;
|
|
162
|
+
while (openBrace < content.length && content[openBrace] !== '{') openBrace++;
|
|
163
|
+
if (openBrace >= content.length) {
|
|
164
|
+
console.error(` HTML: ✗ Could not find config object opening brace`);
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Find the matching closing }
|
|
169
|
+
const closeBrace = findMatchingBrace(content, openBrace);
|
|
170
|
+
if (closeBrace === -1) {
|
|
171
|
+
console.error(` HTML: ✗ Could not match braces for config object`);
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Find the ); that closes the registerType call
|
|
176
|
+
let callEnd = closeBrace + 1;
|
|
177
|
+
while (callEnd < content.length && /\s/.test(content[callEnd])) callEnd++;
|
|
178
|
+
if (callEnd < content.length && content[callEnd] === ')') callEnd++;
|
|
179
|
+
if (callEnd < content.length && content[callEnd] === ';') callEnd++;
|
|
180
|
+
|
|
181
|
+
// Extract config object text (already has rp- labels — that's fine for legacy too)
|
|
182
|
+
const configText = content.substring(openBrace, closeBrace + 1);
|
|
183
|
+
|
|
184
|
+
// Get indentation of the registerType line
|
|
185
|
+
const lineStart = content.lastIndexOf('\n', rtStart) + 1;
|
|
186
|
+
const indentMatch = content.substring(lineStart, rtStart).match(/^(\s*)/);
|
|
187
|
+
const indent = indentMatch ? indentMatch[1] : ' ';
|
|
188
|
+
|
|
189
|
+
// Replace: original registerType → _rpNodeCfg variable + rp-TYPE registration + legacy registration
|
|
190
|
+
const replacement =
|
|
191
|
+
`var _rpNodeCfg = ${configText};\n` +
|
|
192
|
+
`${indent}RED.nodes.registerType('${rpType}', _rpNodeCfg);\n` +
|
|
193
|
+
`${indent}RED.nodes.registerType('${oldType}', Object.assign({}, _rpNodeCfg, { category: 'deprecated' }));`;
|
|
194
|
+
|
|
195
|
+
return content.substring(0, rtStart) + replacement + content.substring(callEnd);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function addLegacyScriptBlock(content, attrName, oldType) {
|
|
199
|
+
const rpType = 'rp-' + oldType;
|
|
200
|
+
|
|
201
|
+
// Find the rp-TYPE block: <script type="text/x-red" data-xxx-name="rp-TYPE"> ... </script>
|
|
202
|
+
const regex = new RegExp(
|
|
203
|
+
`(<script\\s+type="text/(?:x-red|html)"\\s+${escapeRegex(attrName)}=")${escapeRegex(rpType)}(">[\\s\\S]*?</script>)`,
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const match = content.match(regex);
|
|
207
|
+
if (!match) {
|
|
208
|
+
console.error(` HTML: ✗ Could not find ${attrName}="${rpType}" block`);
|
|
209
|
+
return content;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const fullBlock = match[0];
|
|
213
|
+
// Create legacy block with old type name (without rp- prefix)
|
|
214
|
+
const legacyBlock = match[1] + oldType + match[2];
|
|
215
|
+
|
|
216
|
+
// Append legacy block after the rp-TYPE block
|
|
217
|
+
return content.replace(fullBlock, fullBlock + '\n\n' + legacyBlock);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function addLegacyHtml(filePath, oldType) {
|
|
221
|
+
let content = fs.readFileSync(filePath, 'utf8');
|
|
222
|
+
|
|
223
|
+
// 1. Add legacy JS registration
|
|
224
|
+
const transformed = addLegacyHtmlRegistration(content, oldType);
|
|
225
|
+
if (transformed === null) return false;
|
|
226
|
+
content = transformed;
|
|
227
|
+
|
|
228
|
+
// 2. Duplicate template block for legacy type name
|
|
229
|
+
content = addLegacyScriptBlock(content, 'data-template-name', oldType);
|
|
230
|
+
|
|
231
|
+
// 3. Duplicate help block for legacy type name
|
|
232
|
+
content = addLegacyScriptBlock(content, 'data-help-name', oldType);
|
|
233
|
+
|
|
234
|
+
if (!DRY_RUN) fs.writeFileSync(filePath, content);
|
|
235
|
+
console.log(` HTML: ✓ Added legacy registration + template + help for '${oldType}'`);
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ─────────────────────────────────────────────────────────────
|
|
240
|
+
// Main
|
|
241
|
+
// ─────────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
console.log('=== Add Legacy Compatibility (CI) ===');
|
|
244
|
+
if (DRY_RUN) console.log('(DRY RUN — no files will be modified)\n');
|
|
245
|
+
else console.log('');
|
|
246
|
+
|
|
247
|
+
let jsOk = 0, htmlOk = 0, jsFail = 0, htmlFail = 0;
|
|
248
|
+
|
|
249
|
+
for (const node of NODES) {
|
|
250
|
+
console.log(`[${node.oldType}]`);
|
|
251
|
+
const jsFile = path.join(BASE, node.path + '.js');
|
|
252
|
+
const htmlFile = path.join(BASE, node.path + '.html');
|
|
253
|
+
|
|
254
|
+
if (addLegacyJs(jsFile, node.oldType)) jsOk++;
|
|
255
|
+
else jsFail++;
|
|
256
|
+
|
|
257
|
+
if (addLegacyHtml(htmlFile, node.oldType)) htmlOk++;
|
|
258
|
+
else htmlFail++;
|
|
259
|
+
|
|
260
|
+
console.log('');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
console.log('\n=== Summary ===');
|
|
264
|
+
console.log(` JS: ${jsOk} ok, ${jsFail} failed`);
|
|
265
|
+
console.log(` HTML: ${htmlOk} ok, ${htmlFail} failed`);
|
|
266
|
+
if (DRY_RUN) console.log('\n(Dry run — re-run without --dry-run to apply changes)');
|
|
267
|
+
else console.log('\nDone! Legacy compatibility added. Ready to publish.');
|