mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 19:42:56 +01:00
Add all lib dts files
This commit is contained in:
parent
7b2cebe6a7
commit
fede24ed75
1 changed files with 10 additions and 51 deletions
|
|
@ -102,68 +102,27 @@ export = ts;
|
||||||
|
|
||||||
function importLibs() {
|
function importLibs() {
|
||||||
function getFileName(name) {
|
function getFileName(name) {
|
||||||
return (name === '' ? 'lib.d.ts' : `lib.${name}.d.ts`);
|
return name
|
||||||
}
|
}
|
||||||
function getVariableName(name) {
|
function getVariableName(name) {
|
||||||
return (name === '' ? 'lib_dts' : `lib_${name.replace(/\./g, '_')}_dts`);
|
return name.replace(/\./g, '_') + "_dts"
|
||||||
}
|
}
|
||||||
function readLibFile(name) {
|
function readLibFile(name) {
|
||||||
var srcPath = path.join(TYPESCRIPT_LIB_SOURCE, getFileName(name));
|
var srcPath = path.join(TYPESCRIPT_LIB_SOURCE, name);
|
||||||
return fs.readFileSync(srcPath).toString();
|
return fs.readFileSync(srcPath).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
var queue = [];
|
var dtsFiles = fs.readdirSync(TYPESCRIPT_LIB_SOURCE).filter(f => f.includes("lib."))
|
||||||
var in_queue = {};
|
|
||||||
|
|
||||||
var enqueue = function (name) {
|
|
||||||
if (in_queue[name]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
in_queue[name] = true;
|
|
||||||
queue.push(name);
|
|
||||||
};
|
|
||||||
|
|
||||||
enqueue('');
|
|
||||||
enqueue('es6');
|
|
||||||
enqueue('es2015');
|
|
||||||
|
|
||||||
var result = [];
|
var result = [];
|
||||||
while (queue.length > 0) {
|
while (dtsFiles.length > 0) {
|
||||||
var name = queue.shift();
|
var name = dtsFiles.shift();
|
||||||
var contents = readLibFile(name);
|
var output = readLibFile(name);
|
||||||
var lines = contents.split(/\r\n|\r|\n/);
|
|
||||||
|
|
||||||
var output = '';
|
|
||||||
var writeOutput = function (text) {
|
|
||||||
if (output.length === 0) {
|
|
||||||
output = text;
|
|
||||||
} else {
|
|
||||||
output += ` + ${text}`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
var outputLines = [];
|
|
||||||
var flushOutputLines = function () {
|
|
||||||
writeOutput(`"${escapeText(outputLines.join('\n'))}"`);
|
|
||||||
outputLines = [];
|
|
||||||
};
|
|
||||||
var deps = [];
|
|
||||||
for (let i = 0; i < lines.length; i++) {
|
|
||||||
let m = lines[i].match(/\/\/\/\s*<reference\s*lib="([^"]+)"/);
|
|
||||||
if (m) {
|
|
||||||
deps.push(getVariableName(m[1]));
|
|
||||||
enqueue(m[1]);
|
|
||||||
outputLines.push(lines[i]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
outputLines.push(lines[i]);
|
|
||||||
}
|
|
||||||
flushOutputLines();
|
|
||||||
|
|
||||||
result.push({
|
result.push({
|
||||||
name: getVariableName(name),
|
name: getVariableName(name),
|
||||||
filepath: getFileName(name),
|
filepath: name,
|
||||||
deps: deps,
|
deps: [],
|
||||||
output: output
|
output: '"' + escapeText(output) + '"'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue