108 lines
4.3 KiB
JavaScript
108 lines
4.3 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.transform = transform;
|
|
exports.stringContainsAny = stringContainsAny;
|
|
exports.getFsFileOut = getFsFileOut;
|
|
exports.emitFsFileOut = emitFsFileOut;
|
|
exports.emitFsFileOutAsLines = emitFsFileOutAsLines;
|
|
exports.writeFile = writeFile;
|
|
|
|
var _transform = require("./transform");
|
|
|
|
var _Seq = require("./fable-core/Seq");
|
|
|
|
var _typescript = require("typescript");
|
|
|
|
var typescript = _interopRequireWildcard(_typescript);
|
|
|
|
var _List = require("./fable-core/List");
|
|
|
|
var _List2 = _interopRequireDefault(_List);
|
|
|
|
var _String = require("./fable-core/String");
|
|
|
|
var _naming = require("./naming");
|
|
|
|
var _read = require("./read");
|
|
|
|
var _syntax = require("./syntax");
|
|
|
|
var _path = require("path");
|
|
|
|
var path = _interopRequireWildcard(_path);
|
|
|
|
var _fs = require("fs");
|
|
|
|
var fs = _interopRequireWildcard(_fs);
|
|
|
|
var _print = require("./print");
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
|
|
function transform(file) {
|
|
return (0, _transform.addAliasUnionHelpers)((0, _transform.extractTypeLiterals)((0, _transform.removeDuplicateOptions)((0, _transform.removeDuplicateFunctions)((0, _transform.removeTypeParamsFromStatic)((0, _transform.addTicForGenericTypes)((0, _transform.addTicForGenericFunctions)((0, _transform.fixNamespace)((0, _transform.fixEscapeWords)((0, _transform.fixDuplicatesInUnion)((0, _transform.fixEnumReferences)((0, _transform.fixOverloadingOnStringParameters)((0, _transform.createIExports)((0, _transform.fixStatic)((0, _transform.fixDateTime)((0, _transform.fixReadonlyArray)((0, _transform.fixNodeArray)((0, _transform.fixThis)((0, _transform.addConstructors)((0, _transform.extractTypesInGlobalModules)((0, _transform.fixTypesHasESKeywords)((0, _transform.extractGenericParameterDefaults)((0, _transform.aliasToInterfacePartly)((0, _transform.mergeModulesInFile)((0, _transform.removeInternalModules)(file)))))))))))))))))))))))));
|
|
}
|
|
|
|
function stringContainsAny(b, a) {
|
|
return (0, _Seq.exists)(function (arg00) {
|
|
return a.indexOf(arg00) >= 0;
|
|
}, b);
|
|
}
|
|
|
|
function getFsFileOut(fsPath, tsPaths, exports) {
|
|
const options = {
|
|
module: 1,
|
|
target: 2
|
|
};
|
|
const host = typescript.createCompilerHost(options, true);
|
|
const program = typescript.createProgram(Array.from(tsPaths), options, host);
|
|
const exportFiles = exports.length === 0 ? tsPaths : (0, _List.filter)(function (a) {
|
|
return stringContainsAny(exports, a);
|
|
}, (0, _List.map)(function (sf) {
|
|
return sf.fileName;
|
|
}, (0, _Seq.toList)(program.getSourceFiles())));
|
|
|
|
for (let _export of exportFiles) {
|
|
(0, _String.toConsole)((0, _String.printf)("export %s"))(_export);
|
|
}
|
|
|
|
const tsFiles = (0, _List.map)(program.getSourceFile.bind(program), exportFiles);
|
|
const checker = program.getTypeChecker();
|
|
const moduleNameMap = new Map((0, _Seq.map)(function (sf_1) {
|
|
return [sf_1.fileName, (0, _naming.getJsModuleName)(sf_1.fileName)];
|
|
}, program.getSourceFiles()));
|
|
const fsFiles = (0, _List.map)(function (tsFile) {
|
|
return transform(function (file) {
|
|
return (0, _read.readSourceFile)(checker, tsFile, file);
|
|
}(new _syntax.FsFile(tsFile.fileName, moduleNameMap.get(tsFile.fileName), new _List2.default())));
|
|
}, tsFiles);
|
|
return (0, _transform.fixFsFileOut)(new _syntax.FsFileOut(path.basename(fsPath, path.extname(fsPath)), (0, _List.ofArray)(["System", "Fable.Core", "Fable.Import.JS"]), fsFiles));
|
|
}
|
|
|
|
function emitFsFileOut(fsPath, fsFileOut) {
|
|
emitFsFileOutAsLines(fsPath, fsFileOut), void 0;
|
|
}
|
|
|
|
function emitFsFileOutAsLines(fsPath, fsFileOut) {
|
|
const file = fs.createWriteStream(fsPath);
|
|
const lines = Array.from(new _List2.default());
|
|
const inputSequence = (0, _print.printFsFile)(fsFileOut);
|
|
|
|
for (let line of inputSequence) {
|
|
lines.push(line);
|
|
file.write((0, _String.toText)((0, _String.printf)("%s%c"))(line, "\n")), void 0;
|
|
}
|
|
|
|
file.end();
|
|
return (0, _Seq.toList)(lines);
|
|
}
|
|
|
|
function writeFile(tsPaths, fsPath, exports) {
|
|
const fsFileOut = getFsFileOut(fsPath, tsPaths, exports);
|
|
emitFsFileOut(fsPath, fsFileOut);
|
|
} |