Skip to content

Commit ba7da58

Browse files
authored
Merge pull request #8 from node-red/update-for-v4
Update prep for NR v4
2 parents 7094109 + 18a05db commit ba7da58

File tree

11 files changed

+733
-639
lines changed

11 files changed

+733
-639
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ and you should see monaco editor with the monokai theme and French menus (try op
6565
### Add to node-red src
6666

6767
```bash
68-
cp -r output/monaco/dist \
69-
<node-red-source-directory>/packages/node_modules/@node-red/editor-client/src/vendor/monaco/
68+
export nr_src=~/repos/github/node-red-org/node-red
69+
# clean up
70+
rm -rf $nr_src/packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/*
71+
rm -rf $nr_src/packages/node_modules/@node-red/editor-client/src/types/node/*
72+
rm -rf $nr_src/packages/node_modules/@node-red/editor-client/src/types/node-red/*
7073

74+
# copy
75+
cp -r output/monaco/dist \
76+
$nr_src/packages/node_modules/@node-red/editor-client/src/vendor/monaco/
7177
cp -r output/types \
72-
<node-red-source-directory>/packages/node_modules/@node-red/editor-client/src/
78+
$nr_src/packages/node_modules/@node-red/editor-client/src/
7379
```

demo.html

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ <h3>Things to check...</h3>
2929
(function () {
3030
const base = "./output/monaco/dist/";
3131
const types = "./output/types/";
32-
const defCode = `const fs = require("fs"); //<< should be of type fs & have intellisense
33-
const os = require("os"); //<< should be of type os & have intellisense
34-
const buf = Buffer.from([1,2,3]); //<< should be of type Buffer & have intellisense
35-
let m = RED.util.cloneMessage({}); //<< hover over cloneMessage - see rich tips
36-
let t = msg.topic; //<< see msg properties after entering msg.
37-
let e = env.get("host"); //<< hover over get - see rich tips
32+
const defCode = `const fs = require("fs/promises") //<< should be of type fs/promises & have intellisense
33+
const os = require("os") // << should be of type os & have intellisense
34+
const buf = Buffer.from([1,2,3]) // << should be of type Buffer & have intellisense
35+
let m = RED.util.cloneMessage({}) // << hover over cloneMessage - see rich tips
36+
let t = msg.topic // << see msg properties after entering msg.
37+
let e = env.get("host") // << hover over get - see rich tips
38+
const path = node.path // << should be recognised by editor
39+
node.status({fill:"red",shape:"ring",text:"hello"}) // << should be recognised by editor
40+
node.error("hello") // << should be recognised by editor
41+
node.warn("hello") // << should be recognised by editor
3842
`
3943

4044
const compilerOptions = {
@@ -49,7 +53,7 @@ <h3>Things to check...</h3>
4953
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
5054
module: monaco.languages.typescript.ModuleKind.CommonJS,
5155
typeRoots: ["types"],
52-
lib: ["esnext"] //dont load DOM by default,
56+
lib: ["esnext"] // don't load DOM by default,
5357
}
5458
monaco.languages.typescript.javascriptDefaults.setCompilerOptions(compilerOptions);
5559

@@ -74,7 +78,7 @@ <h3>Things to check...</h3>
7478
value: defCode,
7579
language: "javascript"
7680
});
77-
var themeName = "forge-dark"
81+
const themeName = "forge-dark"
7882
fetch(base + "theme/" + themeName + ".json").then(response => {
7983
return response.json();
8084
}).then(theme => {
@@ -92,8 +96,11 @@ <h3>Things to check...</h3>
9296
types + "node-red/func.d.ts",
9397
types + "node/globals.d.ts",
9498
types + "node/buffer.d.ts",
99+
types + "node/console.d.ts",
95100
types + "node/fs.d.ts",
101+
types + "node/fs/promises.d.ts",
96102
types + "node/os.d.ts",
103+
types + "node/timers.d.ts",
97104
]
98105
var promises = urls.map(url => fetch(url).then(y => y.text()));
99106
Promise.all(promises).then(results => {

generate-monaco-esm-i18n.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const {
1717
vsCodeLocDir,
1818
vsCodeLocI18nDir,
1919
generatedSourceLocaleDir,
20-
} = require("./paths");
20+
} = require("./setup");
2121

2222
const langDirPrefix = "vscode-language-pack-";
2323
const vsCodeRepository = "https://github.com/Microsoft/vscode-loc.git";
@@ -131,7 +131,7 @@ function injectSourcePath(monacoVersion, callback) {
131131
});
132132
}).catch(err => {
133133
callback(err);
134-
});
134+
})
135135
}
136136

137137
/**
@@ -213,7 +213,7 @@ async function main() {
213213
mkdirp.sync(gitDir);
214214
injectSourcePath(monacoVersion, err => {
215215
if (err) throw err;
216-
gitPullOrClone(vsCodeRepository, vsCodeLocDir, function (err) {
216+
gitPullOrClone(vsCodeRepository, vsCodeLocDir, { shell: true }, function (err) {
217217
if (err) throw err;
218218

219219
fs.readdir(vsCodeLocI18nDir, (err, langDirs) => {

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import * as monaco from 'monaco-editor-esm-i18n';
2-
const parent = self || window || globalThis;
1+
// import * as monaco from 'monaco-editor-esm-i18n';
2+
// window.monaco = monaco;
3+
// window.MonacoEnvironment = window.MonacoEnvironment || {};
4+
// if(!window.MonacoEnvironment.Locale) {
5+
// window.MonacoEnvironment.Locale = window.MonacoLocale
6+
// }
37

8+
import * as monaco from 'monaco-editor-esm-i18n';
9+
const parent = typeof globalThis === "object" ? globalThis : typeof window === "object" ? window : typeof self === "object" ? self : global;
410
parent.monaco = monaco;
511
monaco.parent = parent;
612
parent.MonacoEnvironment = parent.MonacoEnvironment || {};

nls-replace.js

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright (c) Microsoft Corporation. All rights reserved.
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*--------------------------------------------------------------------------------------------*/
6+
const globalScope = typeof globalThis === "object" ? globalThis : typeof window === "object" ? window : typeof self === "object" ? self : global;
7+
let isPseudo = (typeof document !== 'undefined' && document.location && document.location.hash.indexOf('pseudo=true') >= 0);
8+
69
function _format(message, args) {
710
let result;
811
if (args.length === 0) {
@@ -14,22 +17,55 @@ function _format(message, args) {
1417
return typeof args[index] !== 'undefined' ? args[index] : match;
1518
});
1619
}
20+
if (isPseudo) {
21+
// FF3B and FF3D is the Unicode zenkaku representation for [ and ]
22+
result = '\uFF3B' + result.replace(/[aouei]/g, '$&$&') + '\uFF3D';
23+
}
1724
return result;
1825
}
1926

20-
export function localize(path, data, defaultMessage) {
21-
const key = typeof data === "object" ? data.key : data;
22-
const localeData = ((self.MonacoLocale || {}) || {}).data || {};
27+
/**
28+
* @skipMangle
29+
*/
30+
export function localize(path, data, defaultMessage, ...args) {
31+
const key = typeof data=== "object" ? data.key : data;
32+
// data = ((globalScope.MonacoEnvironment||{}).Locale||{}).data||{};
33+
// data = ((globalScope.MonacoLocale || {}) || {}).data || {};
34+
// let message = (data[path]||{})[key];
35+
const localeData = ((globalScope.MonacoLocale || {}) || {}).data || {};
2336
let message = (localeData[path] || {})[key];
2437
if (!message) {
2538
message = defaultMessage;
2639
}
27-
const args = [];
40+
args = [];
2841
for (let _i = 3; _i < arguments.length; _i++) {
2942
args[_i - 3] = arguments[_i];
3043
}
3144
return _format(message, args);
3245
}
46+
/**
47+
* @skipMangle
48+
*/
49+
export function localize2(path, data, defaultMessage, ...args) {
50+
const key = typeof data=== "object" ? data.key : data;
51+
// data = ((globalScope.MonacoEnvironment||{}).Locale||{}).data||{};
52+
// data = ((globalScope.MonacoLocale || {}) || {}).data || {};
53+
// let message = (data[path]||{})[key];
54+
const localeData = ((globalScope.MonacoLocale || {}) || {}).data || {};
55+
let message = (localeData[path] || {})[key];
56+
if (!message) {
57+
message = defaultMessage;
58+
}
59+
args = [];
60+
for (let _i = 3; _i < arguments.length; _i++) {
61+
args[_i - 3] = arguments[_i];
62+
}
63+
const original = _format(message, args);
64+
return {
65+
value: original,
66+
original
67+
};
68+
}
3369

3470
export function loadMessageBundle(file) {
3571
return localize;
@@ -39,6 +75,10 @@ export function config(opt) {
3975
return loadMessageBundle;
4076
}
4177

78+
/**
79+
* @skipMangle
80+
*/
4281
export function getConfiguredDefaultLocale() {
4382
return (self.MonacoLocale || {}).language;
4483
}
84+

node-red-types/func.d.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interface NodeMessage {
22
topic?: string;
33
payload?: any;
4-
_msgid?: string;
4+
/** `_msgid` is generated internally. It not something you typically need to set or modify. */ _msgid?: string;
55
[other: string]: any; //permit other properties
66
}
77

@@ -16,15 +16,15 @@ declare const promisify:typeof import('util').promisify
1616
/**
1717
* @typedef NodeStatus
1818
* @type {object}
19-
* @property {string} [fill] The fill property can be: red, green, yellow, blue or grey.
20-
* @property {string} [shape] The shape property can be: ring or dot.
21-
* @property {string} [text] The text to display
19+
* @property {'red'|'green'|'yellow'|'blue'|'grey'|string} [fill] - The fill property can be: red, green, yellow, blue or grey.
20+
* @property {'ring'|'dot'|string} [shape] The shape property can be: ring or dot.
21+
* @property {string|boolean|number} [text] The text to display
2222
*/
2323
interface NodeStatus {
2424
/** The fill property can be: red, green, yellow, blue or grey */
25-
fill?: string,
25+
fill?: 'red'|'green'|'yellow'|'blue'|'grey'|string,
2626
/** The shape property can be: ring or dot */
27-
shape?: string,
27+
shape?: 'ring'|'dot'|string,
2828
/** The text to display */
2929
text?: string|boolean|number
3030
}
@@ -34,25 +34,24 @@ declare class node {
3434
* Send 1 or more messages asynchronously
3535
* @param {object | object[]} msg The msg object
3636
* @param {Boolean} [clone=true] Flag to indicate the `msg` should be cloned. Default = `true`
37-
* @see node-red documentation [writing-functions: sending messages asynchronously](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)
37+
* @see Node-RED documentation [writing-functions: sending messages asynchronously](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)
3838
*/
39-
static send(msg:object|object[], clone?:Boolean): void;
39+
static send(msg:NodeMessage|NodeMessage[], clone?:Boolean): void;
4040
/** Inform runtime this instance has completed its operation */
4141
static done();
4242
/** Send an error to the console and debug side bar. Include `msg` in the 2nd parameter to trigger the catch node. */
43-
static error(err:string|Error, msg?:object);
43+
static error(err:string|Error, msg?:NodeMessage);
4444
/** Log a warn message to the console and debug sidebar */
4545
static warn(warning:string|object);
4646
/** Log an info message to the console (not sent to sidebar)' */
4747
static log(info:string|object);
4848
/** Sets the status icon and text underneath the node.
4949
* @param {NodeStatus} status - The status object `{fill, shape, text}`
50-
* @see node-red documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
50+
* @see Node-RED documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
5151
*/
5252
static status(status:NodeStatus);
5353
/** Sets the status text underneath the node.
54-
* @param {string} status - The status to display
55-
* @see node-red documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
54+
* @see Node-RED documentation [writing-functions: adding-status](https://nodered.org/docs/user-guide/writing-functions#adding-status)
5655
*/
5756
static status(status:string|boolean|number);
5857
/** the id of this node */
@@ -261,9 +260,12 @@ declare class global {
261260
/** Get an array of the keys in the context store */
262261
static keys(store: string, callback: Function);
263262
}
263+
264+
// (string & {}) is a workaround for offering string type completion without enforcing it. See https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939
265+
type NR_ENV_NAME_STRING = 'NR_NODE_ID'|'NR_NODE_NAME'|'NR_NODE_PATH'|'NR_GROUP_ID'|'NR_GROUP_NAME'|'NR_FLOW_ID'|'NR_FLOW_NAME'|'NR_SUBFLOW_ID'|'NR_SUBFLOW_NAME'|'NR_SUBFLOW_PATH' | (string & {})
264266
declare class env {
265267
/**
266-
* Get an environment variable value
268+
* Get an environment variable value defined in the OS, or in the global/flow/subflow/group environment variables.
267269
*
268270
* Predefined node-red variables...
269271
* * `NR_NODE_ID` - the ID of the node
@@ -273,9 +275,16 @@ declare class env {
273275
* * `NR_GROUP_NAME` - the Name of the containing group
274276
* * `NR_FLOW_ID` - the ID of the flow the node is on
275277
* * `NR_FLOW_NAME` - the Name of the flow the node is on
276-
* @param name Name of the environment variable to get
278+
* * `NR_SUBFLOW_ID` - the ID of the subflow the node is in
279+
* * `NR_SUBFLOW_NAME` - the Name of the subflow the node is in
280+
* * `NR_SUBFLOW_PATH` - the Path of the subflow the node is in
281+
* @param name - The name of the environment variable
282+
* @example
283+
* ```const flowName = env.get("NR_FLOW_NAME") // get the name of the flow```
284+
* @example
285+
* ```const systemHomeDir = env.get("HOME") // get the user's home directory```
277286
* @example
278-
* ```const flowName = env.get("NR_FLOW_NAME");```
287+
* ```const systemHomeDir = env.get("LABEL1") // get the value of a global/flow/subflow/group defined variable named "LABEL1"```
279288
*/
280-
static get(name:string) :any;
289+
static get(name:NR_ENV_NAME_STRING) :any;
281290
}

0 commit comments

Comments
 (0)