1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- const chalk = require('chalk');
- const path = require('path');
- module.exports = function progress(options = {}) {
- const scope = options.scope || {};
- scope.finished = scope.finished || 0;
- scope.total = scope.total || 0;
- return {
- name: 'progress',
- buildStart() {
- scope.finished = 0;
- scope.total = 0;
- },
- load() {
-
- scope.total++;
- },
- transform(code, id) {
- scope.finished++;
- const filePath = path.relative(process.cwd(), id).split(path.sep).join('/');
- const output = `[${scope.finished}/${scope.total}]: ${chalk.grey(filePath)}`;
- if (process.stdout.isTTY) {
- process.stdout.clearLine();
- process.stdout.cursorTo(0);
- process.stdout.write(output);
- }
- else {
- console.log(output);
- }
- },
- buildEnd() {
- if (process.stdout.isTTY) {
- process.stdout.clearLine();
- process.stdout.cursorTo(0);
- }
- else {
- console.log('');
- }
- }
- };
- };
|