80 lines
2.5 KiB
JavaScript
Executable File
80 lines
2.5 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.exports = exports.fsfile = exports.tsfiles = exports.files = exports.argv = undefined;
|
|
|
|
var _yargs = require("yargs");
|
|
|
|
var yargs = _interopRequireWildcard(_yargs);
|
|
|
|
var _List = require("./fable-core/List");
|
|
|
|
var _List2 = _interopRequireDefault(_List);
|
|
|
|
var _Option = require("./fable-core/Option");
|
|
|
|
var _String = require("./fable-core/String");
|
|
|
|
var _Seq = require("./fable-core/Seq");
|
|
|
|
var _version = require("./version");
|
|
|
|
var _fs = require("fs");
|
|
|
|
var fs = _interopRequireWildcard(_fs);
|
|
|
|
var _write = require("./write");
|
|
|
|
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; } }
|
|
|
|
const argv = exports.argv = yargs.usage("Usage: ts2fable some.d.ts src/Some.fs").command("$0 [files..]", "").option("files", {
|
|
type: "array",
|
|
description: "input ts files and output fs file",
|
|
alias: "f"
|
|
}).option("exports", {
|
|
type: "array",
|
|
description: "export types from files that contain the string",
|
|
alias: "e"
|
|
}).help().argv;
|
|
const files = exports.files = (0, _List.ofArray)((0, _Option.getValue)(argv["files"]));
|
|
const tsfiles = exports.tsfiles = (0, _List.filter)(function (s) {
|
|
return (0, _String.endsWith)(s, ".ts");
|
|
}, files);
|
|
const fsfile = exports.fsfile = (0, _Seq.tryFind)(function (s) {
|
|
return (0, _String.endsWith)(s, ".fs");
|
|
}, files);
|
|
|
|
const _exports = (() => {
|
|
const matchValue = argv["exports"];
|
|
|
|
if (matchValue != null) {
|
|
return (0, _List.ofArray)((0, _Option.getValue)(matchValue));
|
|
} else {
|
|
return new _List2.default();
|
|
}
|
|
})();
|
|
|
|
exports.exports = _exports;
|
|
const matchValue = [tsfiles.length, fsfile];
|
|
|
|
if (matchValue[0] === 0) {
|
|
(0, _String.toFail)((0, _String.printf)("Please provide the path to a TypeScript file"));
|
|
} else if (matchValue[1] != null) {
|
|
const fsf = (0, _Option.getValue)(matchValue[1]);
|
|
(0, _String.toConsole)((0, _String.printf)("ts2fable %s"))(_version.version);
|
|
|
|
for (let ts of tsfiles) {
|
|
if (!fs.existsSync(ts)) {
|
|
(0, _String.toFail)((0, _String.printf)("TypeScript file not found: %s"))(ts);
|
|
}
|
|
}
|
|
|
|
(0, _write.writeFile)(tsfiles, fsf, _exports);
|
|
} else {
|
|
(0, _String.toFail)((0, _String.printf)("Please provide the path to the F# file to be written "));
|
|
} |