UNPKG

ts-add-js-extension

Version:

Add .js extension to each relative ESM import and export statement in JavaScript file

50 lines 1.95 kB
export default class Log { numberOfFiles; completedFiles; static fromNumberOfFiles = (numberOfFiles) => { return new Log(numberOfFiles, 0); }; constructor(numberOfFiles, completedFiles) { this.numberOfFiles = numberOfFiles; this.completedFiles = completedFiles; if (!this.numberOfFiles) { throw new Error('Progress cannot be instantiated when there is no files to changes'); } } // ref: https://chrisyeh96.github.io/2020/03/28/terminal-colors.html redify = (word) => { return `\x1b[31m${word}\x1b[0m`; }; cyanify = (word) => { return `\x1b[36m${word}\x1b[0m`; }; boldify = (word) => { return `\x1b[1:37m${word}\x1b[0m`; }; increment = (props) => { if (this.numberOfFiles <= this.completedFiles) { throw new Error(`Number of files succeed: ${this.completedFiles} cannot be the same as number of files: ${this.numberOfFiles}`); } else { this.completedFiles++; console.log(`${this.completedFiles}. ${' '.repeat(this.numberOfFiles.toString().length - this.completedFiles.toString().length)}${this.boldify(props.file)}${' '.repeat(props.repeat - props.file.length)} - ${props.succeed ? this.cyanify('SUCCEED') : this.redify('FAILED')}`); } }; end = (props) => { if (props.errors.length) { console.error(`The following file${props.errors.length === 1 ? '' : 's'} failed to add either .js file extension`); console.error(Array.from(props.errors) .sort((a, b) => { return a.file.length - b.file.length; }) .map(({ file, error }, index) => { return `${index}. file: ${file}, reason: ${error.message}`; }) .join('\n')); } }; } //# sourceMappingURL=log.js.map