-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.js
More file actions
38 lines (38 loc) · 1.51 KB
/
convert.js
File metadata and controls
38 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
exports.__esModule = true;
var fs = require("fs/promises");
var path = require("path");
var shell = require("shelljs");
var fileName = process.argv[2];
function makeJsFileSrc() {
var getPath = function (fileName) {
return path.join('./src', fileName);
};
var tsName = getPath(fileName);
shell.exec("tsc ".concat(tsName));
var jsName = extChange(tsName, 'js');
return fs.readFile(jsName, 'utf8');
}
function extChange(fileName, ext) {
var _a = [path.dirname(fileName), path.basename(fileName, 'ts')], dirName = _a[0], baseName = _a[1];
return path.join(dirName, baseName + "".concat(ext));
}
function makeHtmlFile(jsSource, fileName) {
var attatchWords = function (src, item) {
return item[0] + '\n' + src + '\n' + item[1];
};
var sendSource = function (src, destination) {
var longName = extChange(path.join(destination, fileName), 'html');
fs.writeFile(longName, src)
.then(function () { return console.log('HTML made!'); })
.then(function () { return fs.unlink(extChange(path.join('./src', fileName), 'js')); })
.then(function () { return console.log('js file deleted'); })["catch"](function (err) { return console.error(err); });
};
jsSource.then(function (source) { return attatchWords(source, ['<script>', '</script>']); })
.then(function (source) { return sendSource(source, './dist'); });
}
function makeHtml() {
var jsSrc = makeJsFileSrc();
makeHtmlFile(jsSrc, fileName);
}
makeHtml();