///
///
import * as fs from "fs";
import * as path from "path";
import * as typescript from "typescript";
declare var ts: typeof typescript;
var tsSourceDir = "../src";
var tsBuildDir = "../built/local";
var testOutputDir = "../built/benchmark";
var sourceFiles = [
"compiler/types.ts",
"compiler/core.ts",
"compiler/sys.ts",
"compiler/diagnosticInformationMap.generated.ts",
"compiler/scanner.ts",
"compiler/binder.ts",
"compiler/utilities.ts",
"compiler/parser.ts",
"compiler/checker.ts",
"compiler/declarationEmitter.ts",
"compiler/emitter.ts",
"compiler/program.ts",
"compiler/commandLineParser.ts",
"compiler/tsc.ts"];
// .ts sources for the compiler, used as a test input
var rawCompilerSources = "";
sourceFiles.forEach(f=> {
rawCompilerSources += "\r\n" + fs.readFileSync(path.join(tsSourceDir, f)).toString();
});
var compilerSoruces = `var compilerSources = ${JSON.stringify(rawCompilerSources) };`;
// .js code for the compiler, what we are actuallty testing
var rawCompilerJavaScript = fs.readFileSync(path.join(tsBuildDir, "tsc.js")).toString();
rawCompilerJavaScript = rawCompilerJavaScript.replace("ts.executeCommandLine(ts.sys.args);", "");
// lib.d.ts sources
var rawLibSources = fs.readFileSync(path.join(tsBuildDir, "lib.d.ts")).toString();
var libSoruces = `var libSources = ${JSON.stringify(rawLibSources) };`;
// write test output
if (!fs.existsSync(testOutputDir)) {
fs.mkdirSync(testOutputDir);
}
// 1. compiler ts sources, used to test
fs.writeFileSync(
path.join(testOutputDir, "compilerSources.js"),
`${ compilerSoruces } \r\n ${ libSoruces }`);
// 2. the compiler js sources + a call the compiler
fs.writeFileSync(
path.join(testOutputDir, "benchmarktsc.js"),
`${ rawCompilerJavaScript }\r\n${ compile.toString() }\r\ncompile(compilerSources, libSources);`);
// 3. test html file to drive the test
fs.writeFileSync(
path.join(testOutputDir, "benchmarktsc.html"),
`
Typescript 1.1 Compiler