Skip to content

Commit dfd5aac

Browse files
authored
Bundle the core files of the Monaco Editor
2 parents c4b35c0 + f8afaad commit dfd5aac

File tree

95 files changed

+338
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+338
-179
lines changed

.distignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/.github
33
/.wordpress-org
44
/artifacts
5+
/bin
56
/node_modules
67
/test
78
/vendor
@@ -10,13 +11,14 @@
1011
.eslintignore
1112
.eslintrc.js
1213
.gitignore
14+
.prettierrc.js
1315
.stylelintrc.js
1416
.wp-env.json
1517
composer.json
1618
composer.lock
1719
jest-puppeteer.config.js
18-
package-lock.json
1920
package.json
21+
package-lock.json
2022
phpcs.ruleset.xml
2123
README.md
2224
webpack.config.js

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ build/
33
node_modules/
44
vendor/
55
.wp-env.override.json
6-
/artifacts/
6+
artifacts/

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ $ npm run build
155155

156156
## Resources
157157

158+
### monaco-editor
159+
* License: MIT License
160+
* Source: https://github.com/microsoft/monaco-editor
161+
162+
### react-notifications-component
163+
* License: MIT License
164+
* Source: https://github.com/teodosii/react-notifications-component
165+
158166
### emmet-monaco-es
159167
* License: MIT License
160168
* Source: https://github.com/troy351/emmet-monaco-es

bin/delete-sourcemaps.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Remove commented lines in the source map URL from Monaco Editor core files.
3+
*/
4+
5+
const path = require( 'path' );
6+
const fs = require( 'fs' );
7+
8+
function deleteMaps( dir ) {
9+
fs.readdir( dir, function ( dirError, files ) {
10+
files.forEach( ( file ) => {
11+
const target = path.join( dir, file );
12+
const stats = fs.statSync( target );
13+
14+
if ( stats.isDirectory() ) {
15+
deleteMaps( target );
16+
} else {
17+
const extname = path.extname( target );
18+
19+
if ( extname === '.js' ) {
20+
fs.readFile( target, 'utf8', ( fileError, data ) => {
21+
const lines = data.split( '\n' );
22+
const lastLine = lines[ lines.length - 1 ];
23+
const hasSourceMappingLine =
24+
lastLine.includes( 'sourceMappingURL' ) && lines.length > 1;
25+
26+
if ( hasSourceMappingLine ) {
27+
fs.writeFileSync( target, lines.slice( 0, lines.length - 1 ).join( '\n' ) );
28+
}
29+
} );
30+
}
31+
}
32+
} );
33+
} );
34+
}
35+
36+
[ './build/lib/' ].map( deleteMaps );

classes/class-admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function admin_enqueue_scripts( $hook_suffix ) {
108108
CHBE_NAMESPACE . '-admin',
109109
'chbeObj',
110110
array(
111-
'assetPath' => CHBE_URL,
111+
'pluginUrl' => CHBE_URL,
112112
'version' => CHBE_VERSION,
113113
'editorSettings' => Settings::get_editor_settings(),
114114
'editorOptions' => Settings::get_editor_options(),

classes/class-block-editor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function enqueue_editor_scripts() {
5555
CHBE_NAMESPACE,
5656
'chbeObj',
5757
array(
58+
'pluginUrl' => CHBE_URL,
5859
'editorSettings' => Settings::get_editor_settings(),
5960
'editorOptions' => Settings::get_editor_options(),
6061
'fontFamily' => Settings::get_font_families(),

classes/class-classic-editor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function admin_enqueue_scripts( $hook_suffix ) {
8484
CHBE_NAMESPACE,
8585
'chbeObj',
8686
array(
87+
'pluginUrl' => CHBE_URL,
8788
'editorSettings' => Settings::get_editor_settings(),
8889
'editorOptions' => Settings::get_editor_options(),
8990
'fontFamily' => Settings::get_font_families(),

classes/class-theme-plugin-editor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function admin_enqueue_scripts( $hook_suffix ) {
9999
CHBE_NAMESPACE,
100100
'chbeObj',
101101
array(
102+
'pluginUrl' => CHBE_URL,
102103
'editorSettings' => Settings::get_editor_settings(),
103104
'editorOptions' => Settings::get_editor_options(),
104105
'fontFamily' => Settings::get_font_families(),

package-lock.json

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"open": "wp-env start && opener http://localhost:8888",
88
"stop": "wp-env stop",
99
"start": "wp-scripts start src/admin src/block-editor src/classic-editor src/theme-plugin-editor --output-path build",
10-
"build": "npm run clean && wp-scripts build src/admin src/block-editor src/classic-editor src/theme-plugin-editor --output-path build",
10+
"build": "npm run clean && wp-scripts build src/admin src/block-editor src/classic-editor src/theme-plugin-editor --output-path build && npm run copy-lib",
11+
"copy-lib": "cpx -C \"node_modules/monaco-editor/min/**\" \"build/lib/monaco-editor/min\" && node bin/delete-sourcemaps.js",
1112
"clean": "rimraf build",
1213
"lint": "npm run lint:php && npm run lint:style && npm run lint:js",
1314
"lint:php": "composer lint",
@@ -17,6 +18,7 @@
1718
"test:e2e": "wp-scripts test-e2e --config test/e2e/jest.config.js"
1819
},
1920
"devDependencies": {
21+
"@deboxsoft/cpx": "^1.5.0",
2022
"@wordpress/e2e-test-utils": "^7.5.0",
2123
"@wordpress/env": "^4.7.0",
2224
"@wordpress/scripts": "^23.1.0",
@@ -29,6 +31,7 @@
2931
"dependencies": {
3032
"@wordpress/icons": "^9.0.0",
3133
"emmet-monaco-es": "^4.6.2",
34+
"monaco-editor": "^0.28.1",
3235
"react-notifications-component": "^4.0.1",
3336
"webfontloader": "^1.6.28"
3437
}

0 commit comments

Comments
 (0)