Skip to content

Commit

Permalink
Merge pull request #11 from node-red/monaco_0_52_0
Browse files Browse the repository at this point in the history
Updates to support newer Monaco (V0.52.0)
  • Loading branch information
Steve-Mcl authored Nov 1, 2024
2 parents ba7da58 + a55d512 commit 6ac2deb
Show file tree
Hide file tree
Showing 7 changed files with 1,400 additions and 457 deletions.
55 changes: 51 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ cd nr-monaco-build

### Prepare

#### Firstly
* Check & update `package.json` for latest version of `monaco-editor` (check [here](https://www.npmjs.com/package/monaco-editor)) and other dev dependencies
#### Step 1

#### Check + update node-red (function node/server-side) type defs
Prepare the build:

1. Check & update `package.json` for latest version of `monaco-editor` (check [here](https://www.npmjs.com/package/monaco-editor)) and other dev dependencies
2. Update the `package.json` `version` field to match the version of `monaco-editor` you are using.

#### Step 2

Check + update node-red (function node/server-side) type defs
* `./node-red-types/func.d.ts`
* `./node-red-types/util.d.ts`

### Build
### Step 3

Install dependencies, clean and build

```bash
npm install --include=dev
Expand Down Expand Up @@ -64,7 +72,20 @@ and you should see monaco editor with the monokai theme and French menus (try op

### Add to node-red src

#### Automatically

If your Node-RED source is relative to this repo, you can run the following helper script:

```bash
npm run copy
```

#### Manually

When your Node-RED source is not relative to this repo, you can copy the files manually:

```bash
# Set the path to your node-red source e.g.
export nr_src=~/repos/github/node-red-org/node-red
# clean up
rm -rf $nr_src/packages/node_modules/@node-red/editor-client/src/vendor/monaco/dist/*
Expand All @@ -76,4 +97,30 @@ cp -r output/monaco/dist \
$nr_src/packages/node_modules/@node-red/editor-client/src/vendor/monaco/
cp -r output/types \
$nr_src/packages/node_modules/@node-red/editor-client/src/

```

### Additional helper scripts

#### Build monaco in development mode

```bash
npm run build-dev
```


#### All in one (production mode)

This will run `npm run clean`, `npm run build`, `npm run copy` in sequence

```bash
npm run all
```

#### All in one (development mode)

This will run `npm run clean`, `npm run build-dev`, `npm run copy` in sequence

```bash
npm run all-dev
```
25 changes: 20 additions & 5 deletions generate-monaco-esm-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require("fs");
const path = require("path");
const recursive = require("recursive-readdir");
const mkdirp = require("mkdirp");
const replaceInFile = require("replace-in-file");
const { replaceInFileSync } = require("replace-in-file");
const ncp = require("ncp").ncp;
const { rimraf } = require("rimraf");
const readJson = require('read-package-json')
Expand Down Expand Up @@ -85,7 +85,7 @@ function injectSourcePath(monacoVersion, callback) {
//1b. Change to localize("path/to/translation/item", xxxx
//2a. Find localize.apply(
//2b. Change to localize.apply("path/to/translation/item", xxxxx
replaceInFile({
replaceInFileSync({
files: file,
from: [
/(?<!function )(localize\d*?\s*?\()/g, //match:- .localize( : localize( localize2( .localize2( etc
Expand All @@ -96,9 +96,24 @@ function injectSourcePath(monacoVersion, callback) {
`$1($2, ['${transPath}', `,
],
});
if (file.endsWith("iconLabels.js")) {
if (file.endsWith("actionList.js")) {
// node-red editor body has a client height of 0. This messes up the editor layout.
// need to replace
// * this.domNode.ownerDocument.body.clientHeight
// with
// * dom.getClientArea(this.domNode.ownerDocument.body).height
replaceInFileSync({
files: file,
from: [
'this.domNode.ownerDocument.body.clientHeight'
],
to: [
'dom.getClientArea(this.domNode.ownerDocument.body).height'
],
});
} else if (file.endsWith("iconLabels.js")) {
//if a translation is missing, prevent error in `stripIcons` (ensures command palette is populated)
replaceInFile({
replaceInFileSync({
files: file,
from: [
/stripIcons\(text\)\s?{/g
Expand All @@ -112,7 +127,7 @@ function injectSourcePath(monacoVersion, callback) {
//1. Find const api = createMonacoBaseAPI();
//2. Insert Object.defineProperty(api, 'version', {get: function() { return 'x.y.z' }});
// export const version = api.version;
replaceInFile({
replaceInFileSync({
files: file,
from: [
/(const\s+?)(\w*?)(\s+?=\s+?createMonacoBaseAPI\(\).*$)/gm
Expand Down
10 changes: 9 additions & 1 deletion nls-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,12 @@ export function config(opt) {
export function getConfiguredDefaultLocale() {
return (self.MonacoLocale || {}).language;
}

/**
* @skipMangle
*/
export function getNLSLanguage() {
return (self.MonacoLocale || {}).language;
}
export function getNLSMessages() {
return ((self.MonacoLocale || {}) || {}).data || {};
}
Loading

0 comments on commit 6ac2deb

Please sign in to comment.