fix line endings
This commit is contained in:
parent
12ab70d329
commit
8ba5faed36
3 changed files with 26 additions and 27 deletions
|
@ -210,7 +210,8 @@ function createReplacer(data) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function generateDeclarationFile(out, inputFiles, recipe) {
|
function generateDeclarationFile(out, inputFiles, recipe) {
|
||||||
var lines = recipe.split(/\r\n|\n|\r/);
|
var endl = /\r\n/.test(recipe) ? '\r\n' : '\n';
|
||||||
|
var lines = recipe.split(endl);
|
||||||
var result = [];
|
var result = [];
|
||||||
lines.forEach(function (line) {
|
lines.forEach(function (line) {
|
||||||
var m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
|
var m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
|
||||||
|
@ -278,12 +279,11 @@ function generateDeclarationFile(out, inputFiles, recipe) {
|
||||||
}
|
}
|
||||||
result.push(line);
|
result.push(line);
|
||||||
});
|
});
|
||||||
var resultTxt = result.join('\n');
|
var resultTxt = result.join(endl);
|
||||||
resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri');
|
resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri');
|
||||||
resultTxt = resultTxt.replace(/\bEvent</g, 'IEvent<');
|
resultTxt = resultTxt.replace(/\bEvent</g, 'IEvent<');
|
||||||
resultTxt = resultTxt.replace(/\bTPromise</g, 'Promise<');
|
resultTxt = resultTxt.replace(/\bTPromise</g, 'Promise<');
|
||||||
resultTxt = format(resultTxt);
|
resultTxt = format(resultTxt);
|
||||||
resultTxt = resultTxt.replace(/\r\n/g, '\n');
|
|
||||||
return resultTxt;
|
return resultTxt;
|
||||||
}
|
}
|
||||||
function getFilesToWatch(out) {
|
function getFilesToWatch(out) {
|
||||||
|
|
|
@ -24,15 +24,15 @@ function logErr(message: any, ...rest: any[]): void {
|
||||||
util.log(util.colors.red('[monaco.d.ts]'), message, ...rest);
|
util.log(util.colors.red('[monaco.d.ts]'), message, ...rest);
|
||||||
}
|
}
|
||||||
|
|
||||||
function moduleIdToPath(out:string, moduleId:string): string {
|
function moduleIdToPath(out: string, moduleId: string): string {
|
||||||
if (/\.d\.ts/.test(moduleId)) {
|
if (/\.d\.ts/.test(moduleId)) {
|
||||||
return path.join(SRC, moduleId);
|
return path.join(SRC, moduleId);
|
||||||
}
|
}
|
||||||
return path.join(OUT_ROOT, out, moduleId) + '.d.ts';
|
return path.join(OUT_ROOT, out, moduleId) + '.d.ts';
|
||||||
}
|
}
|
||||||
|
|
||||||
let SOURCE_FILE_MAP: {[moduleId:string]:ts.SourceFile;} = {};
|
let SOURCE_FILE_MAP: { [moduleId: string]: ts.SourceFile; } = {};
|
||||||
function getSourceFile(out:string, inputFiles: { [file: string]: string; }, moduleId:string): ts.SourceFile {
|
function getSourceFile(out: string, inputFiles: { [file: string]: string; }, moduleId: string): ts.SourceFile {
|
||||||
if (!SOURCE_FILE_MAP[moduleId]) {
|
if (!SOURCE_FILE_MAP[moduleId]) {
|
||||||
let filePath = path.normalize(moduleIdToPath(out, moduleId));
|
let filePath = path.normalize(moduleIdToPath(out, moduleId));
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ function getSourceFile(out:string, inputFiles: { [file: string]: string; }, modu
|
||||||
type TSTopLevelDeclaration = ts.InterfaceDeclaration | ts.EnumDeclaration | ts.ClassDeclaration | ts.TypeAliasDeclaration | ts.FunctionDeclaration | ts.ModuleDeclaration;
|
type TSTopLevelDeclaration = ts.InterfaceDeclaration | ts.EnumDeclaration | ts.ClassDeclaration | ts.TypeAliasDeclaration | ts.FunctionDeclaration | ts.ModuleDeclaration;
|
||||||
type TSTopLevelDeclare = TSTopLevelDeclaration | ts.VariableStatement;
|
type TSTopLevelDeclare = TSTopLevelDeclaration | ts.VariableStatement;
|
||||||
|
|
||||||
function isDeclaration(a:TSTopLevelDeclare): a is TSTopLevelDeclaration {
|
function isDeclaration(a: TSTopLevelDeclare): a is TSTopLevelDeclaration {
|
||||||
return (
|
return (
|
||||||
a.kind === ts.SyntaxKind.InterfaceDeclaration
|
a.kind === ts.SyntaxKind.InterfaceDeclaration
|
||||||
|| a.kind === ts.SyntaxKind.EnumDeclaration
|
|| a.kind === ts.SyntaxKind.EnumDeclaration
|
||||||
|
@ -64,7 +64,7 @@ function isDeclaration(a:TSTopLevelDeclare): a is TSTopLevelDeclaration {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function visitTopLevelDeclarations(sourceFile:ts.SourceFile, visitor:(node:TSTopLevelDeclare)=>boolean): void {
|
function visitTopLevelDeclarations(sourceFile: ts.SourceFile, visitor: (node: TSTopLevelDeclare) => boolean): void {
|
||||||
let stop = false;
|
let stop = false;
|
||||||
|
|
||||||
let visit = (node: ts.Node): void => {
|
let visit = (node: ts.Node): void => {
|
||||||
|
@ -100,8 +100,8 @@ function visitTopLevelDeclarations(sourceFile:ts.SourceFile, visitor:(node:TSTop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getAllTopLevelDeclarations(sourceFile:ts.SourceFile): TSTopLevelDeclare[] {
|
function getAllTopLevelDeclarations(sourceFile: ts.SourceFile): TSTopLevelDeclare[] {
|
||||||
let all:TSTopLevelDeclare[] = [];
|
let all: TSTopLevelDeclare[] = [];
|
||||||
visitTopLevelDeclarations(sourceFile, (node) => {
|
visitTopLevelDeclarations(sourceFile, (node) => {
|
||||||
if (node.kind === ts.SyntaxKind.InterfaceDeclaration || node.kind === ts.SyntaxKind.ClassDeclaration || node.kind === ts.SyntaxKind.ModuleDeclaration) {
|
if (node.kind === ts.SyntaxKind.InterfaceDeclaration || node.kind === ts.SyntaxKind.ClassDeclaration || node.kind === ts.SyntaxKind.ModuleDeclaration) {
|
||||||
let interfaceDeclaration = <ts.InterfaceDeclaration>node;
|
let interfaceDeclaration = <ts.InterfaceDeclaration>node;
|
||||||
|
@ -128,8 +128,8 @@ function getAllTopLevelDeclarations(sourceFile:ts.SourceFile): TSTopLevelDeclare
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getTopLevelDeclaration(sourceFile:ts.SourceFile, typeName:string): TSTopLevelDeclare {
|
function getTopLevelDeclaration(sourceFile: ts.SourceFile, typeName: string): TSTopLevelDeclare {
|
||||||
let result:TSTopLevelDeclare = null;
|
let result: TSTopLevelDeclare = null;
|
||||||
visitTopLevelDeclarations(sourceFile, (node) => {
|
visitTopLevelDeclarations(sourceFile, (node) => {
|
||||||
if (isDeclaration(node)) {
|
if (isDeclaration(node)) {
|
||||||
if (node.name.text === typeName) {
|
if (node.name.text === typeName) {
|
||||||
|
@ -149,12 +149,12 @@ function getTopLevelDeclaration(sourceFile:ts.SourceFile, typeName:string): TSTo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getNodeText(sourceFile:ts.SourceFile, node:{pos:number; end:number;}): string {
|
function getNodeText(sourceFile: ts.SourceFile, node: { pos: number; end: number; }): string {
|
||||||
return sourceFile.getFullText().substring(node.pos, node.end);
|
return sourceFile.getFullText().substring(node.pos, node.end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getMassagedTopLevelDeclarationText(sourceFile:ts.SourceFile, declaration: TSTopLevelDeclare): string {
|
function getMassagedTopLevelDeclarationText(sourceFile: ts.SourceFile, declaration: TSTopLevelDeclare): string {
|
||||||
let result = getNodeText(sourceFile, declaration);
|
let result = getNodeText(sourceFile, declaration);
|
||||||
// if (result.indexOf('MonacoWorker') >= 0) {
|
// if (result.indexOf('MonacoWorker') >= 0) {
|
||||||
// console.log('here!');
|
// console.log('here!');
|
||||||
|
@ -163,7 +163,7 @@ function getMassagedTopLevelDeclarationText(sourceFile:ts.SourceFile, declaratio
|
||||||
if (declaration.kind === ts.SyntaxKind.InterfaceDeclaration || declaration.kind === ts.SyntaxKind.ClassDeclaration) {
|
if (declaration.kind === ts.SyntaxKind.InterfaceDeclaration || declaration.kind === ts.SyntaxKind.ClassDeclaration) {
|
||||||
let interfaceDeclaration = <ts.InterfaceDeclaration | ts.ClassDeclaration>declaration;
|
let interfaceDeclaration = <ts.InterfaceDeclaration | ts.ClassDeclaration>declaration;
|
||||||
|
|
||||||
let members:ts.NodeArray<ts.Node> = interfaceDeclaration.members;
|
let members: ts.NodeArray<ts.Node> = interfaceDeclaration.members;
|
||||||
members.forEach((member) => {
|
members.forEach((member) => {
|
||||||
try {
|
try {
|
||||||
let memberText = getNodeText(sourceFile, member);
|
let memberText = getNodeText(sourceFile, member);
|
||||||
|
@ -182,7 +182,7 @@ function getMassagedTopLevelDeclarationText(sourceFile:ts.SourceFile, declaratio
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function format(text:string): string {
|
function format(text: string): string {
|
||||||
|
|
||||||
// Parse the source text
|
// Parse the source text
|
||||||
let sourceFile = ts.createSourceFile('file.ts', text, ts.ScriptTarget.Latest, /*setParentPointers*/ true);
|
let sourceFile = ts.createSourceFile('file.ts', text, ts.ScriptTarget.Latest, /*setParentPointers*/ true);
|
||||||
|
@ -214,10 +214,10 @@ function format(text:string): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createReplacer(data:string): (str:string)=>string {
|
function createReplacer(data: string): (str: string) => string {
|
||||||
data = data || '';
|
data = data || '';
|
||||||
let rawDirectives = data.split(';');
|
let rawDirectives = data.split(';');
|
||||||
let directives: [RegExp,string][] = [];
|
let directives: [RegExp, string][] = [];
|
||||||
rawDirectives.forEach((rawDirective) => {
|
rawDirectives.forEach((rawDirective) => {
|
||||||
if (rawDirective.length === 0) {
|
if (rawDirective.length === 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -231,7 +231,7 @@ function createReplacer(data:string): (str:string)=>string {
|
||||||
directives.push([new RegExp(findStr, 'g'), replaceStr]);
|
directives.push([new RegExp(findStr, 'g'), replaceStr]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (str:string)=> {
|
return (str: string) => {
|
||||||
for (let i = 0; i < directives.length; i++) {
|
for (let i = 0; i < directives.length; i++) {
|
||||||
str = str.replace(directives[i][0], directives[i][1]);
|
str = str.replace(directives[i][0], directives[i][1]);
|
||||||
}
|
}
|
||||||
|
@ -239,10 +239,11 @@ function createReplacer(data:string): (str:string)=>string {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateDeclarationFile(out: string, inputFiles: { [file: string]: string; }, recipe:string): string {
|
function generateDeclarationFile(out: string, inputFiles: { [file: string]: string; }, recipe: string): string {
|
||||||
let lines = recipe.split(/\r\n|\n|\r/);
|
const endl = /\r\n/.test(recipe) ? '\r\n' : '\n';
|
||||||
let result = [];
|
|
||||||
|
|
||||||
|
let lines = recipe.split(endl);
|
||||||
|
let result = [];
|
||||||
|
|
||||||
lines.forEach(line => {
|
lines.forEach(line => {
|
||||||
|
|
||||||
|
@ -285,7 +286,7 @@ function generateDeclarationFile(out: string, inputFiles: { [file: string]: stri
|
||||||
let replacer = createReplacer(m2[2]);
|
let replacer = createReplacer(m2[2]);
|
||||||
|
|
||||||
let typeNames = m2[3].split(/,/);
|
let typeNames = m2[3].split(/,/);
|
||||||
let typesToExcludeMap: {[typeName:string]:boolean;} = {};
|
let typesToExcludeMap: { [typeName: string]: boolean; } = {};
|
||||||
let typesToExcludeArr: string[] = [];
|
let typesToExcludeArr: string[] = [];
|
||||||
typeNames.forEach((typeName) => {
|
typeNames.forEach((typeName) => {
|
||||||
typeName = typeName.trim();
|
typeName = typeName.trim();
|
||||||
|
@ -318,18 +319,17 @@ function generateDeclarationFile(out: string, inputFiles: { [file: string]: stri
|
||||||
result.push(line);
|
result.push(line);
|
||||||
});
|
});
|
||||||
|
|
||||||
let resultTxt = result.join('\n');
|
let resultTxt = result.join(endl);
|
||||||
resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri');
|
resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri');
|
||||||
resultTxt = resultTxt.replace(/\bEvent</g, 'IEvent<');
|
resultTxt = resultTxt.replace(/\bEvent</g, 'IEvent<');
|
||||||
resultTxt = resultTxt.replace(/\bTPromise</g, 'Promise<');
|
resultTxt = resultTxt.replace(/\bTPromise</g, 'Promise<');
|
||||||
|
|
||||||
resultTxt = format(resultTxt);
|
resultTxt = format(resultTxt);
|
||||||
|
|
||||||
resultTxt = resultTxt.replace(/\r\n/g, '\n');
|
|
||||||
return resultTxt;
|
return resultTxt;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFilesToWatch(out:string): string[] {
|
export function getFilesToWatch(out: string): string[] {
|
||||||
let recipe = fs.readFileSync(RECIPE_PATH).toString();
|
let recipe = fs.readFileSync(RECIPE_PATH).toString();
|
||||||
let lines = recipe.split(/\r\n|\n|\r/);
|
let lines = recipe.split(/\r\n|\n|\r/);
|
||||||
let result = [];
|
let result = [];
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
"preserveConstEnums": true,
|
"preserveConstEnums": true,
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"newLine": "LF",
|
|
||||||
// enable JavaScript type checking for the language service
|
// enable JavaScript type checking for the language service
|
||||||
// use the tsconfig.build.json for compiling wich disable JavaScript
|
// use the tsconfig.build.json for compiling wich disable JavaScript
|
||||||
// type checking so that JavaScript file are not transpiled
|
// type checking so that JavaScript file are not transpiled
|
||||||
|
|
Loading…
Reference in a new issue