@harmoniclabs/monaco-editor 0.1.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/LICENSE.txt +21 -0
- package/README.md +122 -0
- package/build/build-languages.ts +212 -0
- package/build/build-monaco-editor.ts +463 -0
- package/build/check-samples.ts +53 -0
- package/build/fillers/vscode-nls.ts +46 -0
- package/build/fs.ts +80 -0
- package/build/importTypescript.ts +192 -0
- package/build/npm/installAll.ts +44 -0
- package/build/npm/removeAll.ts +20 -0
- package/build/postinstall.ts +28 -0
- package/build/releaseMetadata.ts +280 -0
- package/build/simpleserver.ts +69 -0
- package/build/tsconfig.json +8 -0
- package/build/utils.ts +291 -0
- package/package.json +87 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import path = require('path');
|
|
7
|
+
import fs = require('fs');
|
|
8
|
+
import child_process = require('child_process');
|
|
9
|
+
import { REPO_ROOT } from './utils';
|
|
10
|
+
|
|
11
|
+
const generatedNote = `//
|
|
12
|
+
// **NOTE**: Do not edit directly! This file is generated using \`npm run import-typescript\`
|
|
13
|
+
//
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
const TYPESCRIPT_LIB_SOURCE = path.join(REPO_ROOT, 'node_modules/typescript/lib');
|
|
17
|
+
const TYPESCRIPT_LIB_DESTINATION = path.join(REPO_ROOT, 'src/language/typescript/lib');
|
|
18
|
+
|
|
19
|
+
(function () {
|
|
20
|
+
try {
|
|
21
|
+
fs.statSync(TYPESCRIPT_LIB_DESTINATION);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
fs.mkdirSync(TYPESCRIPT_LIB_DESTINATION);
|
|
24
|
+
}
|
|
25
|
+
importLibs();
|
|
26
|
+
|
|
27
|
+
const npmLsOutput = JSON.parse(
|
|
28
|
+
child_process.execSync('npm ls typescript --depth=0 --json=true', { cwd: REPO_ROOT }).toString()
|
|
29
|
+
);
|
|
30
|
+
const typeScriptDependencyVersion = npmLsOutput.dependencies.typescript.version;
|
|
31
|
+
|
|
32
|
+
fs.writeFileSync(
|
|
33
|
+
path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServicesMetadata.ts'),
|
|
34
|
+
`${generatedNote}
|
|
35
|
+
export const typescriptVersion = "${typeScriptDependencyVersion}";\n`
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
let tsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescript.js')).toString();
|
|
39
|
+
|
|
40
|
+
tsServices = tsServices
|
|
41
|
+
.replace(
|
|
42
|
+
'const path = matchedStar ? subst.replace("*", matchedStar) : subst;',
|
|
43
|
+
'const path = matchedStar ? subst.replace("*", matchedStar) : subst; // CodeQL [SM02383] This is a false positive, the code is from the TypeScript compiler'
|
|
44
|
+
)
|
|
45
|
+
.replace(
|
|
46
|
+
'return key.replace("*", matchedStar);',
|
|
47
|
+
'return key.replace("*", matchedStar); // CodeQL [SM02383] This is a false positive, the code is from the TypeScript compiler'
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// The output from this build will only be accessible via ESM; rather than removing
|
|
51
|
+
// references to require/module, define them as dummy variables that bundlers will ignore.
|
|
52
|
+
// The TS code can figure out that it's not running under Node even with these defined.
|
|
53
|
+
tsServices =
|
|
54
|
+
`
|
|
55
|
+
/* MONACOCHANGE */
|
|
56
|
+
var require = undefined;
|
|
57
|
+
var module = { exports: {} };
|
|
58
|
+
/* END MONACOCHANGE */
|
|
59
|
+
` + tsServices;
|
|
60
|
+
|
|
61
|
+
const tsServices_esm =
|
|
62
|
+
generatedNote +
|
|
63
|
+
tsServices +
|
|
64
|
+
`
|
|
65
|
+
// MONACOCHANGE
|
|
66
|
+
export var createClassifier = ts.createClassifier;
|
|
67
|
+
export var createLanguageService = ts.createLanguageService;
|
|
68
|
+
export var displayPartsToString = ts.displayPartsToString;
|
|
69
|
+
export var EndOfLineState = ts.EndOfLineState;
|
|
70
|
+
export var flattenDiagnosticMessageText = ts.flattenDiagnosticMessageText;
|
|
71
|
+
export var IndentStyle = ts.IndentStyle;
|
|
72
|
+
export var ScriptKind = ts.ScriptKind;
|
|
73
|
+
export var ScriptTarget = ts.ScriptTarget;
|
|
74
|
+
export var TokenClass = ts.TokenClass;
|
|
75
|
+
export var typescript = ts;
|
|
76
|
+
// END MONACOCHANGE
|
|
77
|
+
`;
|
|
78
|
+
fs.writeFileSync(
|
|
79
|
+
path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.js'),
|
|
80
|
+
stripSourceMaps(tsServices_esm)
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
let dtsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescript.d.ts')).toString();
|
|
84
|
+
|
|
85
|
+
fs.writeFileSync(
|
|
86
|
+
path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.d.ts'),
|
|
87
|
+
generatedNote + dtsServices
|
|
88
|
+
);
|
|
89
|
+
})();
|
|
90
|
+
|
|
91
|
+
function importLibs() {
|
|
92
|
+
function readLibFile(name) {
|
|
93
|
+
const srcPath = path.join(TYPESCRIPT_LIB_SOURCE, name);
|
|
94
|
+
return fs.readFileSync(srcPath).toString();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let strLibResult = `/*---------------------------------------------------------------------------------------------
|
|
98
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
99
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
100
|
+
*--------------------------------------------------------------------------------------------*/
|
|
101
|
+
${generatedNote}
|
|
102
|
+
|
|
103
|
+
/** Contains all the lib files */
|
|
104
|
+
export const libFileMap: Record<string, string> = {}
|
|
105
|
+
`;
|
|
106
|
+
let strIndexResult = `/*---------------------------------------------------------------------------------------------
|
|
107
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
108
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
109
|
+
*--------------------------------------------------------------------------------------------*/
|
|
110
|
+
${generatedNote}
|
|
111
|
+
|
|
112
|
+
/** Contains all the lib files */
|
|
113
|
+
export const libFileSet: Record<string, boolean> = {}
|
|
114
|
+
`;
|
|
115
|
+
const dtsFiles = fs.readdirSync(TYPESCRIPT_LIB_SOURCE).filter((f) => f.includes('lib.'));
|
|
116
|
+
while (dtsFiles.length > 0) {
|
|
117
|
+
const name = dtsFiles.shift();
|
|
118
|
+
const output = readLibFile(name).replace(/\r\n/g, '\n');
|
|
119
|
+
strLibResult += `libFileMap['${name}'] = "${escapeText(output)}";\n`;
|
|
120
|
+
strIndexResult += `libFileSet['${name}'] = true;\n`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'lib.ts'), strLibResult);
|
|
124
|
+
fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'lib.index.ts'), strIndexResult);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Escape text such that it can be used in a javascript string enclosed by double quotes (")
|
|
129
|
+
*/
|
|
130
|
+
function escapeText(text) {
|
|
131
|
+
// See http://www.javascriptkit.com/jsref/escapesequence.shtml
|
|
132
|
+
const _backspace = '\b'.charCodeAt(0);
|
|
133
|
+
const _formFeed = '\f'.charCodeAt(0);
|
|
134
|
+
const _newLine = '\n'.charCodeAt(0);
|
|
135
|
+
const _nullChar = 0;
|
|
136
|
+
const _carriageReturn = '\r'.charCodeAt(0);
|
|
137
|
+
const _tab = '\t'.charCodeAt(0);
|
|
138
|
+
const _verticalTab = '\v'.charCodeAt(0);
|
|
139
|
+
const _backslash = '\\'.charCodeAt(0);
|
|
140
|
+
const _doubleQuote = '"'.charCodeAt(0);
|
|
141
|
+
|
|
142
|
+
const len = text.length;
|
|
143
|
+
let startPos = 0;
|
|
144
|
+
let chrCode;
|
|
145
|
+
let replaceWith = null;
|
|
146
|
+
let resultPieces = [];
|
|
147
|
+
|
|
148
|
+
for (let i = 0; i < len; i++) {
|
|
149
|
+
chrCode = text.charCodeAt(i);
|
|
150
|
+
switch (chrCode) {
|
|
151
|
+
case _backspace:
|
|
152
|
+
replaceWith = '\\b';
|
|
153
|
+
break;
|
|
154
|
+
case _formFeed:
|
|
155
|
+
replaceWith = '\\f';
|
|
156
|
+
break;
|
|
157
|
+
case _newLine:
|
|
158
|
+
replaceWith = '\\n';
|
|
159
|
+
break;
|
|
160
|
+
case _nullChar:
|
|
161
|
+
replaceWith = '\\0';
|
|
162
|
+
break;
|
|
163
|
+
case _carriageReturn:
|
|
164
|
+
replaceWith = '\\r';
|
|
165
|
+
break;
|
|
166
|
+
case _tab:
|
|
167
|
+
replaceWith = '\\t';
|
|
168
|
+
break;
|
|
169
|
+
case _verticalTab:
|
|
170
|
+
replaceWith = '\\v';
|
|
171
|
+
break;
|
|
172
|
+
case _backslash:
|
|
173
|
+
replaceWith = '\\\\';
|
|
174
|
+
break;
|
|
175
|
+
case _doubleQuote:
|
|
176
|
+
replaceWith = '\\"';
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
if (replaceWith !== null) {
|
|
180
|
+
resultPieces.push(text.substring(startPos, i));
|
|
181
|
+
resultPieces.push(replaceWith);
|
|
182
|
+
startPos = i + 1;
|
|
183
|
+
replaceWith = null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
resultPieces.push(text.substring(startPos, len));
|
|
187
|
+
return resultPieces.join('');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function stripSourceMaps(str) {
|
|
191
|
+
return str.replace(/\/\/# sourceMappingURL[^\n]+/gm, '');
|
|
192
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import glob = require('glob');
|
|
7
|
+
import path = require('path');
|
|
8
|
+
import fs = require('fs');
|
|
9
|
+
import cp = require('child_process');
|
|
10
|
+
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
11
|
+
import { REPO_ROOT } from '../utils';
|
|
12
|
+
|
|
13
|
+
const files = glob.sync('**/package.json', {
|
|
14
|
+
cwd: REPO_ROOT,
|
|
15
|
+
ignore: ['**/node_modules/**', '**/dist/**', '**/out/**']
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
for (const file of files) {
|
|
19
|
+
const filePath = path.join(REPO_ROOT, file);
|
|
20
|
+
const contents = JSON.parse(fs.readFileSync(filePath).toString());
|
|
21
|
+
if (!contents.dependencies && !contents.devDependencies && !contents.optionalDependencies) {
|
|
22
|
+
// nothing to install
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
npmInstall(path.dirname(file));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function npmInstall(location) {
|
|
30
|
+
const stdio = 'inherit';
|
|
31
|
+
const args = ['install'];
|
|
32
|
+
|
|
33
|
+
console.log(`Installing dependencies in ${location}...`);
|
|
34
|
+
console.log(`$ npm ${args.join(' ')}`);
|
|
35
|
+
const result = cp.spawnSync(npm, args, {
|
|
36
|
+
env: process.env,
|
|
37
|
+
cwd: location,
|
|
38
|
+
stdio
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (result.error || result.status !== 0) {
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import glob from 'glob';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import { REPO_ROOT } from '../utils';
|
|
10
|
+
|
|
11
|
+
const files = glob.sync('**/package-lock.json', {
|
|
12
|
+
cwd: REPO_ROOT,
|
|
13
|
+
ignore: ['**/node_modules/**', '**/out/**']
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
for (const file of files) {
|
|
17
|
+
const filePath = path.join(REPO_ROOT, file);
|
|
18
|
+
console.log(`Deleting ${file}...`);
|
|
19
|
+
fs.unlinkSync(filePath);
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import cp = require('child_process');
|
|
6
|
+
import path = require('path');
|
|
7
|
+
import fs = require('fs');
|
|
8
|
+
|
|
9
|
+
function huskyInstall() {
|
|
10
|
+
const huskyBin = path.join(__dirname, '../node_modules/husky/lib/bin.js');
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(huskyBin)) {
|
|
13
|
+
console.warn('⚠️ Husky not found. Skipping husky install.');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
console.log('Installing husky hooks...');
|
|
18
|
+
console.log('$ husky install');
|
|
19
|
+
|
|
20
|
+
const result = cp.spawnSync(process.execPath, [huskyBin, 'install'], { stdio: 'inherit' });
|
|
21
|
+
|
|
22
|
+
if (result.error || result.status !== 0) {
|
|
23
|
+
console.error('❌ Husky install failed.');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
huskyInstall();
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See LICENSE in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import glob = require('glob');
|
|
7
|
+
import path = require('path');
|
|
8
|
+
import fs = require('fs');
|
|
9
|
+
import { REPO_ROOT } from './utils';
|
|
10
|
+
import { ensureDir } from './fs';
|
|
11
|
+
|
|
12
|
+
const customFeatureLabels = {
|
|
13
|
+
'vs/editor/browser/controller/coreCommands': 'coreCommands',
|
|
14
|
+
'vs/editor/contrib/caretOperations/caretOperations': 'caretOperations',
|
|
15
|
+
'vs/editor/contrib/caretOperations/transpose': 'transpose',
|
|
16
|
+
'vs/editor/contrib/colorPicker/colorDetector': 'colorDetector',
|
|
17
|
+
'vs/editor/contrib/rename/onTypeRename': 'onTypeRename',
|
|
18
|
+
'vs/editor/contrib/gotoSymbol/link/goToDefinitionAtPosition': 'gotoSymbol',
|
|
19
|
+
'vs/editor/contrib/snippet/snippetController2': 'snippets',
|
|
20
|
+
'vs/editor/standalone/browser/quickAccess/standaloneGotoLineQuickAccess': 'gotoLine',
|
|
21
|
+
'vs/editor/standalone/browser/quickAccess/standaloneCommandsQuickAccess': 'quickCommand',
|
|
22
|
+
'vs/editor/standalone/browser/quickAccess/standaloneGotoSymbolQuickAccess': 'quickOutline',
|
|
23
|
+
'vs/editor/standalone/browser/quickAccess/standaloneHelpQuickAccess': 'quickHelp'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function getBasicLanguages(): Promise<{ label: string; entry: string }[]> {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
glob(
|
|
29
|
+
'./out/monaco-editor/esm/vs/basic-languages/*/*.contribution.js',
|
|
30
|
+
{ cwd: path.dirname(__dirname) },
|
|
31
|
+
(err, files) => {
|
|
32
|
+
if (err) {
|
|
33
|
+
reject(err);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
resolve(
|
|
38
|
+
files.map((file) => {
|
|
39
|
+
const entry = file.substring('./out/monaco-editor/esm/'.length).replace(/\.js$/, '');
|
|
40
|
+
const label = path.basename(file).replace(/\.contribution\.js$/, '');
|
|
41
|
+
return {
|
|
42
|
+
label: label,
|
|
43
|
+
entry: entry
|
|
44
|
+
};
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function readAdvancedLanguages(): Promise<string[]> {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
glob(
|
|
55
|
+
'./out/monaco-editor/esm/vs/language/*/monaco.contribution.js',
|
|
56
|
+
{ cwd: path.dirname(__dirname) },
|
|
57
|
+
(err, files) => {
|
|
58
|
+
if (err) {
|
|
59
|
+
reject(err);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
resolve(
|
|
64
|
+
files
|
|
65
|
+
.map((file) => file.substring('./out/monaco-editor/esm/vs/language/'.length))
|
|
66
|
+
.map((file) => file.substring(0, file.length - '/monaco.contribution.js'.length))
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getAdvancedLanguages(): Promise<
|
|
74
|
+
{ label: string; entry: string; worker: { id: string; entry: string } }[]
|
|
75
|
+
> {
|
|
76
|
+
return readAdvancedLanguages().then((languages) => {
|
|
77
|
+
let result = [];
|
|
78
|
+
for (const lang of languages) {
|
|
79
|
+
let shortLang = lang === 'typescript' ? 'ts' : lang;
|
|
80
|
+
const entry = `vs/language/${lang}/monaco.contribution`;
|
|
81
|
+
checkFileExists(entry);
|
|
82
|
+
const workerId = `vs/language/${lang}/${shortLang}Worker`;
|
|
83
|
+
const workerEntry = `vs/language/${lang}/${shortLang}.worker`;
|
|
84
|
+
checkFileExists(workerEntry);
|
|
85
|
+
result.push({
|
|
86
|
+
label: lang,
|
|
87
|
+
entry: entry,
|
|
88
|
+
worker: {
|
|
89
|
+
id: workerId,
|
|
90
|
+
entry: workerEntry
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
function checkFileExists(moduleName) {
|
|
98
|
+
const filePath = path.join(REPO_ROOT, 'out/monaco-editor/esm', `${moduleName}.js`);
|
|
99
|
+
if (!fs.existsSync(filePath)) {
|
|
100
|
+
console.error(`Could not find ${filePath}.`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function generateMetadata() {
|
|
107
|
+
return Promise.all([getBasicLanguages(), getAdvancedLanguages()]).then(
|
|
108
|
+
([basicLanguages, advancedLanguages]) => {
|
|
109
|
+
basicLanguages.sort((a, b) => strcmp(a.entry, b.entry));
|
|
110
|
+
advancedLanguages.sort((a, b) => strcmp(a.entry, b.entry));
|
|
111
|
+
|
|
112
|
+
let i = 0,
|
|
113
|
+
len = basicLanguages.length;
|
|
114
|
+
let j = 0,
|
|
115
|
+
lenJ = advancedLanguages.length;
|
|
116
|
+
let languages = [];
|
|
117
|
+
while (i < len || j < lenJ) {
|
|
118
|
+
if (i < len && j < lenJ) {
|
|
119
|
+
if (basicLanguages[i].label === advancedLanguages[j].label) {
|
|
120
|
+
let entry = [];
|
|
121
|
+
entry.push(basicLanguages[i].entry);
|
|
122
|
+
entry.push(advancedLanguages[j].entry);
|
|
123
|
+
languages.push({
|
|
124
|
+
label: basicLanguages[i].label,
|
|
125
|
+
entry: entry,
|
|
126
|
+
worker: advancedLanguages[j].worker
|
|
127
|
+
});
|
|
128
|
+
i++;
|
|
129
|
+
j++;
|
|
130
|
+
} else if (basicLanguages[i].label < advancedLanguages[j].label) {
|
|
131
|
+
languages.push(basicLanguages[i]);
|
|
132
|
+
i++;
|
|
133
|
+
} else {
|
|
134
|
+
languages.push(advancedLanguages[j]);
|
|
135
|
+
j++;
|
|
136
|
+
}
|
|
137
|
+
} else if (i < len) {
|
|
138
|
+
languages.push(basicLanguages[i]);
|
|
139
|
+
i++;
|
|
140
|
+
} else {
|
|
141
|
+
languages.push(advancedLanguages[j]);
|
|
142
|
+
j++;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const features = getFeatures();
|
|
147
|
+
|
|
148
|
+
const dtsContents = `
|
|
149
|
+
/*!----------------------------------------------------------------
|
|
150
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
151
|
+
* Released under the MIT license
|
|
152
|
+
* https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
|
|
153
|
+
*----------------------------------------------------------------*/
|
|
154
|
+
|
|
155
|
+
export interface IWorkerDefinition {
|
|
156
|
+
id: string;
|
|
157
|
+
entry: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface IFeatureDefinition {
|
|
161
|
+
label: string;
|
|
162
|
+
entry: string | string[] | undefined;
|
|
163
|
+
worker?: IWorkerDefinition;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export const features: IFeatureDefinition[];
|
|
167
|
+
|
|
168
|
+
export const languages: IFeatureDefinition[];
|
|
169
|
+
|
|
170
|
+
export type EditorLanguage = ${languages.map((el) => `'${el.label}'`).join(' | ')};
|
|
171
|
+
|
|
172
|
+
export type EditorFeature = ${features.map((el) => `'${el.label}'`).join(' | ')};
|
|
173
|
+
|
|
174
|
+
export type NegatedEditorFeature = ${features.map((el) => `'!${el.label}'`).join(' | ')};
|
|
175
|
+
|
|
176
|
+
`;
|
|
177
|
+
const dtsDestination = path.join(REPO_ROOT, 'out/monaco-editor/esm/metadata.d.ts');
|
|
178
|
+
ensureDir(path.dirname(dtsDestination));
|
|
179
|
+
fs.writeFileSync(dtsDestination, dtsContents.replace(/\r\n/g, '\n'));
|
|
180
|
+
|
|
181
|
+
const jsContents = `
|
|
182
|
+
exports.features = ${JSON.stringify(features, null, ' ')};
|
|
183
|
+
exports.languages = ${JSON.stringify(languages, null, ' ')};
|
|
184
|
+
`;
|
|
185
|
+
const jsDestination = path.join(REPO_ROOT, 'out/monaco-editor/esm/metadata.js');
|
|
186
|
+
ensureDir(path.dirname(jsDestination));
|
|
187
|
+
fs.writeFileSync(jsDestination, jsContents.replace(/\r\n/g, '\n'));
|
|
188
|
+
|
|
189
|
+
for (const feature of [...features, ...languages]) {
|
|
190
|
+
const entries = [].concat(feature.entry);
|
|
191
|
+
for (const entry of entries) {
|
|
192
|
+
const dtsDestination = path.join(REPO_ROOT, 'out/monaco-editor/esm', entry) + '.d.ts';
|
|
193
|
+
ensureDir(path.dirname(dtsDestination));
|
|
194
|
+
fs.writeFileSync(dtsDestination, 'export {}\n');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function strcmp(a: string, b: string) {
|
|
202
|
+
if (a < b) {
|
|
203
|
+
return -1;
|
|
204
|
+
}
|
|
205
|
+
if (a > b) {
|
|
206
|
+
return 1;
|
|
207
|
+
}
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function getFeatures(): { label: string; entry: string | string[] }[] {
|
|
212
|
+
const skipImports = [
|
|
213
|
+
'vs/editor/browser/widget/codeEditorWidget',
|
|
214
|
+
'vs/editor/browser/widget/diffEditorWidget',
|
|
215
|
+
'vs/editor/browser/widget/diffNavigator',
|
|
216
|
+
'vs/editor/common/standaloneStrings',
|
|
217
|
+
'vs/editor/contrib/tokenization/tokenization',
|
|
218
|
+
'vs/editor/editor.all',
|
|
219
|
+
'vs/base/browser/ui/codicons/codiconStyles',
|
|
220
|
+
'vs/editor/contrib/gotoSymbol/documentSymbols'
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
let features: string[] = [];
|
|
224
|
+
const files =
|
|
225
|
+
fs
|
|
226
|
+
.readFileSync(path.join(REPO_ROOT, 'out/monaco-editor/esm/vs/editor/edcore.main.js'))
|
|
227
|
+
.toString() +
|
|
228
|
+
fs
|
|
229
|
+
.readFileSync(path.join(REPO_ROOT, 'out/monaco-editor/esm/vs/editor/editor.all.js'))
|
|
230
|
+
.toString();
|
|
231
|
+
files.split(/\r\n|\n/).forEach((line) => {
|
|
232
|
+
const m = line.match(/import '([^']+)'/);
|
|
233
|
+
if (m) {
|
|
234
|
+
const tmp = path.posix.join('vs/editor', m[1]).replace(/\.js$/, '');
|
|
235
|
+
if (skipImports.indexOf(tmp) === -1) {
|
|
236
|
+
features.push(tmp);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
let result: { label: string; entry: any }[] = features.map((feature) => {
|
|
242
|
+
/** @type {string} */ let label;
|
|
243
|
+
if (customFeatureLabels[feature]) {
|
|
244
|
+
label = customFeatureLabels[feature];
|
|
245
|
+
} else {
|
|
246
|
+
const m1 = feature.match(/^vs\/editor\/contrib\/([^\/]+)/);
|
|
247
|
+
if (m1) {
|
|
248
|
+
// for editor/contrib features, use the first segment
|
|
249
|
+
label = m1[1];
|
|
250
|
+
} else {
|
|
251
|
+
// for everything else, use the last segment folder
|
|
252
|
+
label = path.basename(path.dirname(feature));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
label: label,
|
|
257
|
+
entry: feature
|
|
258
|
+
};
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
result.sort((a, b) => {
|
|
262
|
+
const labelCmp = strcmp(a.label, b.label);
|
|
263
|
+
if (labelCmp === 0) {
|
|
264
|
+
return strcmp(a.entry, b.entry);
|
|
265
|
+
}
|
|
266
|
+
return labelCmp;
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
for (let i = 0; i < result.length; i++) {
|
|
270
|
+
if (i + 1 < result.length && result[i].label === result[i + 1].label) {
|
|
271
|
+
if (typeof result[i].entry === 'string') {
|
|
272
|
+
result[i].entry = [result[i].entry];
|
|
273
|
+
}
|
|
274
|
+
result[i].entry.push(result[i + 1].entry);
|
|
275
|
+
result.splice(i + 1, 1);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import fs = require('fs');
|
|
7
|
+
import path = require('path');
|
|
8
|
+
import http = require('http');
|
|
9
|
+
import yaserver = require('yaserver');
|
|
10
|
+
import { REPO_ROOT } from './utils';
|
|
11
|
+
import { ensureDir } from './fs';
|
|
12
|
+
|
|
13
|
+
generateTestSamplesTask();
|
|
14
|
+
|
|
15
|
+
const SERVER_ROOT = path.normalize(path.join(REPO_ROOT, '../'));
|
|
16
|
+
createSimpleServer(SERVER_ROOT, 8080);
|
|
17
|
+
createSimpleServer(SERVER_ROOT, 8088);
|
|
18
|
+
|
|
19
|
+
function generateTestSamplesTask() {
|
|
20
|
+
const sampleNames = fs.readdirSync(path.join(REPO_ROOT, 'test/manual/samples'));
|
|
21
|
+
let samples = sampleNames.map((sampleName) => {
|
|
22
|
+
const samplePath = path.join(REPO_ROOT, 'test/manual/samples', sampleName);
|
|
23
|
+
const sampleContent = fs.readFileSync(samplePath).toString();
|
|
24
|
+
return {
|
|
25
|
+
name: sampleName,
|
|
26
|
+
content: sampleContent
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Add samples from website
|
|
31
|
+
{
|
|
32
|
+
let sampleNames = fs.readdirSync(path.join(REPO_ROOT, 'website/index/samples'));
|
|
33
|
+
sampleNames = sampleNames.filter((name) => /^sample/.test(name));
|
|
34
|
+
|
|
35
|
+
samples = samples.concat(
|
|
36
|
+
sampleNames.map((sampleName) => {
|
|
37
|
+
const samplePath = path.join(REPO_ROOT, 'website/index/samples', sampleName);
|
|
38
|
+
const sampleContent = fs.readFileSync(samplePath).toString();
|
|
39
|
+
return {
|
|
40
|
+
name: sampleName,
|
|
41
|
+
content: sampleContent
|
|
42
|
+
};
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const prefix =
|
|
48
|
+
'//This is a generated file via `npm run simpleserver`\ndefine([], function() { return';
|
|
49
|
+
const suffix = '; });';
|
|
50
|
+
|
|
51
|
+
const destination = path.join(REPO_ROOT, 'test/manual/generated/all-samples.js');
|
|
52
|
+
ensureDir(path.dirname(destination));
|
|
53
|
+
fs.writeFileSync(destination, prefix + JSON.stringify(samples, null, '\t') + suffix);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function createSimpleServer(rootDir: string, port: number) {
|
|
57
|
+
yaserver
|
|
58
|
+
.createServer({
|
|
59
|
+
rootDir: rootDir
|
|
60
|
+
})
|
|
61
|
+
.then((staticServer) => {
|
|
62
|
+
const server = http.createServer((request, response) => {
|
|
63
|
+
return staticServer.handle(request, response);
|
|
64
|
+
});
|
|
65
|
+
server.listen(port, '127.0.0.1', () => {
|
|
66
|
+
console.log(`Running at http://127.0.0.1:${port}`);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|