Also generate features.ts from the monaco-editor npm module

This commit is contained in:
Alex Dima 2019-12-20 15:20:48 +01:00
parent 10a995c595
commit 6a5c30039f
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
4 changed files with 191 additions and 108 deletions

View file

@ -7,6 +7,22 @@ const glob = require('glob');
const path = require('path');
const fs = require('fs');
const customFeatureLabels = {
'vs/editor/browser/controller/coreCommands': 'coreCommands',
'vs/editor/contrib/caretOperations/caretOperations': 'caretOperations',
'vs/editor/contrib/caretOperations/transpose': 'transpose',
'vs/editor/contrib/colorPicker/colorDetector': 'colorDetector',
'vs/editor/contrib/goToDefinition/goToDefinitionCommands': 'goToDefinitionCommands',
'vs/editor/contrib/goToDefinition/goToDefinitionMouse': 'goToDefinitionMouse',
'vs/editor/contrib/snippet/snippetController2': 'snippets',
'vs/editor/standalone/browser/quickOpen/gotoLine': 'gotoLine',
'vs/editor/standalone/browser/quickOpen/quickCommand': 'quickCommand',
'vs/editor/standalone/browser/quickOpen/quickOutline': 'quickOutline',
};
generateLanguages();
generateFeatures();
/**
* @returns { Promise<{ label: string; entry: string; }[]> }
*/
@ -85,7 +101,8 @@ function getAdvancedLanguages() {
}
}
Promise.all([getBasicLanguages(), getAdvancedLanguages()]).then(([basicLanguages, advancedLanguages]) => {
function generateLanguages() {
return Promise.all([getBasicLanguages(), getAdvancedLanguages()]).then(([basicLanguages, advancedLanguages]) => {
basicLanguages.sort(strcmp);
advancedLanguages.sort(strcmp);
@ -123,24 +140,22 @@ Promise.all([getBasicLanguages(), getAdvancedLanguages()]).then(([basicLanguages
const code = `//
// THIS IS A GENERATED FILE. PLEASE DO NOT EDIT DIRECTLY.
// node scripts/import-editor.js
// GENERATED USING node scripts/import-editor.js
//
import { IFeatureDefinition } from "./types";
const languagesArr: IFeatureDefinition[] = ${
export const languagesArr: IFeatureDefinition[] = ${
JSON.stringify(result, null, ' ')
.replace(/"label":/g, 'label:')
.replace(/"entry":/g, 'entry:')
.replace(/"worker":/g, 'worker:')
.replace(/"id":/g, 'id:')
.replace(/"/g, '\'')
};
export const languagesById: { [language: string]: IFeatureDefinition; } = {};
languagesArr.forEach(language => languagesById[language.label] = language);
};
`
fs.writeFileSync(path.join(__dirname, '../src/languages.ts'), code);
});
fs.writeFileSync(path.join(__dirname, '../src/languages.ts'), code.replace(/\r\n/g, '\n'));
});
}
function strcmp(a, b) {
if (a < b) {
@ -152,7 +167,71 @@ function strcmp(a, b) {
return 0;
}
// getBasicLanguages().then((basicLanguages) => {
// console.log(basicLanguages);
// });
// getAdvancedLanguages().then(r => console.log(r));
/**
* @returns { string[] }
*/
function generateFeatures() {
const skipImports = [
'vs/editor/browser/widget/codeEditorWidget',
'vs/editor/browser/widget/diffEditorWidget',
'vs/editor/browser/widget/diffNavigator',
'vs/editor/common/standaloneStrings',
'vs/editor/contrib/tokenization/tokenization',
'vs/editor/editor.all',
];
let features = [];
const files = (
fs.readFileSync(path.join(__dirname, '../node_modules/monaco-editor/esm/vs/editor/edcore.main.js')).toString()
+ fs.readFileSync(path.join(__dirname, '../node_modules/monaco-editor/esm/vs/editor/editor.all.js')).toString()
);
files.split(/\r\n|\n/).forEach(line => {
const m = line.match(/import '([^']+)'/);
if (m) {
const tmp = path.posix.join('vs/editor', m[1]).replace(/\.js$/, '');
if (skipImports.indexOf(tmp) === -1) {
features.push(tmp);
}
}
});
let result = features.map((feature) => {
return {
label: customFeatureLabels[feature] || path.basename(path.dirname(feature)),
entry: feature
};
});
result.sort((a, b) => {
const labelCmp = strcmp(a.label, b.label);
if (labelCmp === 0) {
return strcmp(a.entry, b.entry);
}
return labelCmp;
});
for (let i = 0; i < result.length; i++) {
if (i + 1 < result.length && result[i].label === result[i + 1].label) {
if (typeof result[i].entry === 'string') {
result[i].entry = [result[i].entry];
}
result[i].entry.push(result[i + 1].entry);
result.splice(i + 1, 1);
}
}
const code = `//
// THIS IS A GENERATED FILE. PLEASE DO NOT EDIT DIRECTLY.
// GENERATED USING node scripts/import-editor.js
//
import { IFeatureDefinition } from "./types";
export const featuresArr: IFeatureDefinition[] = ${
JSON.stringify(result, null, ' ')
.replace(/"label":/g, 'label:')
.replace(/"entry":/g, 'entry:')
.replace(/"/g, '\'')
};
`
fs.writeFileSync(path.join(__dirname, '../src/features.ts'), code.replace(/\r\n/g, '\n'));
}

View file

@ -1,174 +1,175 @@
//
// THIS IS A GENERATED FILE. PLEASE DO NOT EDIT DIRECTLY.
// GENERATED USING node scripts/import-editor.js
//
import { IFeatureDefinition } from "./types";
const featuresArr: IFeatureDefinition[] = [
export const featuresArr: IFeatureDefinition[] = [
{
label: 'accessibilityHelp',
entry: 'vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp',
entry: 'vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp'
},
{
label: 'bracketMatching',
entry: 'vs/editor/contrib/bracketMatching/bracketMatching',
entry: 'vs/editor/contrib/bracketMatching/bracketMatching'
},
{
label: 'caretOperations',
entry: 'vs/editor/contrib/caretOperations/caretOperations',
entry: 'vs/editor/contrib/caretOperations/caretOperations'
},
{
label: 'clipboard',
entry: 'vs/editor/contrib/clipboard/clipboard',
entry: 'vs/editor/contrib/clipboard/clipboard'
},
{
label: 'codeAction',
entry: 'vs/editor/contrib/codeAction/codeActionContributions',
entry: 'vs/editor/contrib/codeAction/codeActionContributions'
},
{
label: 'codelens',
entry: 'vs/editor/contrib/codelens/codelensController',
entry: 'vs/editor/contrib/codelens/codelensController'
},
{
label: 'colorDetector',
entry: 'vs/editor/contrib/colorPicker/colorDetector',
entry: 'vs/editor/contrib/colorPicker/colorDetector'
},
{
label: 'comment',
entry: 'vs/editor/contrib/comment/comment',
entry: 'vs/editor/contrib/comment/comment'
},
{
label: 'contextmenu',
entry: 'vs/editor/contrib/contextmenu/contextmenu',
entry: 'vs/editor/contrib/contextmenu/contextmenu'
},
{
label: 'coreCommands',
entry: 'vs/editor/browser/controller/coreCommands',
entry: 'vs/editor/browser/controller/coreCommands'
},
{
label: 'cursorUndo',
entry: 'vs/editor/contrib/cursorUndo/cursorUndo',
entry: 'vs/editor/contrib/cursorUndo/cursorUndo'
},
{
label: 'dnd',
entry: 'vs/editor/contrib/dnd/dnd',
entry: 'vs/editor/contrib/dnd/dnd'
},
{
label: 'find',
entry: 'vs/editor/contrib/find/findController',
entry: 'vs/editor/contrib/find/findController'
},
{
label: 'folding',
entry: 'vs/editor/contrib/folding/folding',
entry: 'vs/editor/contrib/folding/folding'
},
{
label: 'fontZoom',
entry: 'vs/editor/contrib/fontZoom/fontZoom',
entry: 'vs/editor/contrib/fontZoom/fontZoom'
},
{
label: 'format',
entry: 'vs/editor/contrib/format/formatActions',
entry: 'vs/editor/contrib/format/formatActions'
},
{
label: 'goToDefinitionCommands',
entry: 'vs/editor/contrib/goToDefinition/goToDefinitionCommands',
entry: 'vs/editor/contrib/goToDefinition/goToDefinitionCommands'
},
{
label: 'goToDefinitionMouse',
entry: 'vs/editor/contrib/goToDefinition/goToDefinitionMouse',
entry: 'vs/editor/contrib/goToDefinition/goToDefinitionMouse'
},
{
label: 'gotoError',
entry: 'vs/editor/contrib/gotoError/gotoError',
entry: 'vs/editor/contrib/gotoError/gotoError'
},
{
label: 'gotoLine',
entry: 'vs/editor/standalone/browser/quickOpen/gotoLine',
entry: 'vs/editor/standalone/browser/quickOpen/gotoLine'
},
{
label: 'hover',
entry: 'vs/editor/contrib/hover/hover',
},
{
label: 'inPlaceReplace',
entry: 'vs/editor/contrib/inPlaceReplace/inPlaceReplace',
},
{
label: 'inspectTokens',
entry: 'vs/editor/standalone/browser/inspectTokens/inspectTokens',
entry: 'vs/editor/contrib/hover/hover'
},
{
label: 'iPadShowKeyboard',
entry: 'vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard',
entry: 'vs/editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard'
},
{
label: 'inPlaceReplace',
entry: 'vs/editor/contrib/inPlaceReplace/inPlaceReplace'
},
{
label: 'inspectTokens',
entry: 'vs/editor/standalone/browser/inspectTokens/inspectTokens'
},
{
label: 'linesOperations',
entry: 'vs/editor/contrib/linesOperations/linesOperations',
entry: 'vs/editor/contrib/linesOperations/linesOperations'
},
{
label: 'links',
entry: 'vs/editor/contrib/links/links',
entry: 'vs/editor/contrib/links/links'
},
{
label: 'multicursor',
entry: 'vs/editor/contrib/multicursor/multicursor',
entry: 'vs/editor/contrib/multicursor/multicursor'
},
{
label: 'parameterHints',
entry: 'vs/editor/contrib/parameterHints/parameterHints',
entry: 'vs/editor/contrib/parameterHints/parameterHints'
},
{
label: 'quickCommand',
entry: 'vs/editor/standalone/browser/quickOpen/quickCommand',
entry: 'vs/editor/standalone/browser/quickOpen/quickCommand'
},
{
label: 'quickOutline',
entry: 'vs/editor/standalone/browser/quickOpen/quickOutline',
entry: 'vs/editor/standalone/browser/quickOpen/quickOutline'
},
{
label: 'referenceSearch',
entry: [
'vs/editor/contrib/referenceSearch/referenceSearch',
'vs/editor/standalone/browser/referenceSearch/standaloneReferenceSearch',
],
'vs/editor/standalone/browser/referenceSearch/standaloneReferenceSearch'
]
},
{
label: 'rename',
entry: 'vs/editor/contrib/rename/rename',
entry: 'vs/editor/contrib/rename/rename'
},
{
label: 'smartSelect',
entry: 'vs/editor/contrib/smartSelect/smartSelect',
entry: 'vs/editor/contrib/smartSelect/smartSelect'
},
{
label: 'snippets',
entry: 'vs/editor/contrib/snippet/snippetController2',
entry: 'vs/editor/contrib/snippet/snippetController2'
},
{
label: 'suggest',
entry: 'vs/editor/contrib/suggest/suggestController',
entry: 'vs/editor/contrib/suggest/suggestController'
},
{
label: 'toggleHighContrast',
entry: 'vs/editor/standalone/browser/toggleHighContrast/toggleHighContrast',
entry: 'vs/editor/standalone/browser/toggleHighContrast/toggleHighContrast'
},
{
label: 'toggleTabFocusMode',
entry: 'vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode',
entry: 'vs/editor/contrib/toggleTabFocusMode/toggleTabFocusMode'
},
{
label: 'transpose',
entry: 'vs/editor/contrib/caretOperations/transpose',
entry: 'vs/editor/contrib/caretOperations/transpose'
},
{
label: 'wordHighlighter',
entry: 'vs/editor/contrib/wordHighlighter/wordHighlighter',
entry: 'vs/editor/contrib/wordHighlighter/wordHighlighter'
},
{
label: 'wordOperations',
entry: 'vs/editor/contrib/wordOperations/wordOperations',
entry: 'vs/editor/contrib/wordOperations/wordOperations'
},
{
label: 'wordPartOperations',
entry: 'vs/editor/contrib/wordPartOperations/wordPartOperations',
},
entry: 'vs/editor/contrib/wordPartOperations/wordPartOperations'
}
];
export const featuresById: { [feature: string]: IFeatureDefinition; } = {};
featuresArr.forEach(feature => featuresById[feature.label] = feature);

View file

@ -3,8 +3,8 @@ import * as webpack from 'webpack';
import * as loaderUtils from 'loader-utils';
import * as fs from 'fs';
import { AddWorkerEntryPointPlugin } from './plugins/AddWorkerEntryPointPlugin';
import { languagesById } from './languages';
import { featuresById } from './features';
import { languagesArr } from './languages';
import { featuresArr } from './features';
import { IFeatureDefinition } from './types';
const INCLUDE_LOADER_PATH = require.resolve('./loaders/include');
@ -18,6 +18,12 @@ const EDITOR_MODULE: IFeatureDefinition = {
},
};
const languagesById: { [language: string]: IFeatureDefinition; } = {};
languagesArr.forEach(language => languagesById[language.label] = language);
const featuresById: { [feature: string]: IFeatureDefinition; } = {};
featuresArr.forEach(feature => featuresById[feature.label] = feature);
/**
* Return a resolved path for a given Monaco file.
*/

View file

@ -1,10 +1,10 @@
//
// THIS IS A GENERATED FILE. PLEASE DO NOT EDIT DIRECTLY.
// node scripts/import-editor.js
// GENERATED USING node scripts/import-editor.js
//
import { IFeatureDefinition } from "./types";
const languagesArr: IFeatureDefinition[] = [
export const languagesArr: IFeatureDefinition[] = [
{
label: 'abap',
entry: 'vs/basic-languages/abap/abap.contribution'
@ -267,6 +267,3 @@ const languagesArr: IFeatureDefinition[] = [
entry: 'vs/basic-languages/yaml/yaml.contribution'
}
];
export const languagesById: { [language: string]: IFeatureDefinition; } = {};
languagesArr.forEach(language => languagesById[language.label] = language);