ts-add-js-extension
Version:
Add .js extension to each relative ESM import and export statement in JavaScript file
54 lines • 2.47 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var Log = /** @class */ (function () {
function Log(numberOfFiles, completedFiles) {
var _this = this;
this.numberOfFiles = numberOfFiles;
this.completedFiles = completedFiles;
// ref: https://chrisyeh96.github.io/2020/03/28/terminal-colors.html
this.redify = function (word) {
return "\u001B[31m".concat(word, "\u001B[0m");
};
this.cyanify = function (word) {
return "\u001B[36m".concat(word, "\u001B[0m");
};
this.boldify = function (word) {
return "\u001B[1:37m".concat(word, "\u001B[0m");
};
this.increment = function (props) {
if (_this.numberOfFiles <= _this.completedFiles) {
throw new Error("Number of files succeed: ".concat(_this.completedFiles, " cannot be the same as number of files: ").concat(_this.numberOfFiles));
}
else {
_this.completedFiles++;
console.log("".concat(_this.completedFiles, ". ").concat(' '.repeat(_this.numberOfFiles.toString().length -
_this.completedFiles.toString().length)).concat(_this.boldify(props.file)).concat(' '.repeat(props.repeat - props.file.length), " - ").concat(props.succeed
? _this.cyanify('SUCCEED')
: _this.redify('FAILED')));
}
};
this.end = function (props) {
if (props.errors.length) {
console.error("The following file".concat(props.errors.length === 1 ? '' : 's', " failed to add either .js file extension"));
console.error(Array.from(props.errors)
.sort(function (a, b) {
return a.file.length - b.file.length;
})
.map(function (_a, index) {
var file = _a.file, error = _a.error;
return "".concat(index, ". file: ").concat(file, ", reason: ").concat(error.message);
})
.join('\n'));
}
};
if (!this.numberOfFiles) {
throw new Error('Progress cannot be instantiated when there is no files to changes');
}
}
Log.fromNumberOfFiles = function (numberOfFiles) {
return new Log(numberOfFiles, 0);
};
return Log;
}());
exports.default = Log;
//# sourceMappingURL=log.js.map
;