Files
Hydro/packages/ui-default/build/plugins/gulpTouch.js
T
undefined 5faa54c7ca ui-default: init
将ui-default合并至主存储库便于维护
2021-04-03 01:44:22 +08:00

36 lines
827 B
JavaScript

/* eslint-disable import/no-extraneous-dependencies */
import PluginError from 'plugin-error';
import through from 'through2';
import fs from 'fs-extra';
export default function touch(mtime) {
async function touchFile(file) {
const fd = await fs.open(file.path, 'a');
try {
await fs.futimes(fd, mtime, mtime);
} finally {
await fs.close(fd);
}
}
function processStream(file, encoding, callback) {
if (file.isNull()) {
callback();
return;
}
if (file.isStream()) {
this.emit('error', new PluginError('gulpTouch', 'Stream not supported'));
callback();
return;
}
touchFile(file)
.catch((err) => this.emit('error', err))
.then(() => {
this.push(file);
callback();
});
}
return through.obj(processStream);
}