feat(smartgulp): modernize file glob handling and refresh package metadata

This commit is contained in:
2026-05-01 22:17:09 +00:00
parent fa76cec8b4
commit 63c5e20391
22 changed files with 7806 additions and 5150 deletions
+36 -14
View File
@@ -1,22 +1,47 @@
// this file contains the implementation of the standard gulp api
import * as plugins from './smartgulp.plugins.js';
import { GulpStream } from './smartgulp.classes.gulpstream.js';
import { Transform } from 'stream';
import { Transform } from 'node:stream';
import { SmartFile } from '@push.rocks/smartfile';
const smartFileFactory = plugins.smartfile.SmartFileFactory.nodeFs();
const toPosixPath = (pathArg: string): string => pathArg.split(plugins.path.sep).join('/');
const getGlobBaseAndPattern = (globPatternArg: string): { baseDir: string; matchPattern: string } => {
const normalizedPattern = toPosixPath(globPatternArg);
const pathParts = normalizedPattern.split('/');
const firstGlobIndex = pathParts.findIndex((pathPartArg) => /[*?[\]{}]/.test(pathPartArg));
if (firstGlobIndex === -1) {
return {
baseDir: plugins.path.dirname(globPatternArg),
matchPattern: plugins.path.basename(globPatternArg),
};
}
return {
baseDir: pathParts.slice(0, firstGlobIndex).join('/') || '.',
matchPattern: pathParts.slice(firstGlobIndex).join('/'),
};
};
export let src = (minimatchPathArrayArg: string[]): Transform => {
let gulpStream = new GulpStream();
let handleFiles = async () => {
const gulpStream = new GulpStream();
const handleFiles = async (): Promise<void> => {
let smartfileArray: SmartFile[] = [];
for (let minimatchPath of minimatchPathArrayArg) {
let localSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(
process.cwd(),
minimatchPath
for (const minimatchPath of minimatchPathArrayArg) {
const { baseDir, matchPattern } = getGlobBaseAndPattern(minimatchPath);
const virtualDirectory = await smartFileFactory.virtualDirectoryFromPath(
plugins.path.resolve(process.cwd(), baseDir)
);
const localSmartfileArray = virtualDirectory
.listFiles()
.filter((fileArg) => plugins.minimatch(toPosixPath(fileArg.relative), matchPattern, { dot: true }));
smartfileArray = [...smartfileArray, ...localSmartfileArray];
}
gulpStream.pipeSmartfileArray(smartfileArray);
await gulpStream.pipeSmartfileArray(smartfileArray);
};
handleFiles().catch((err) => {
console.log(err);
@@ -28,11 +53,8 @@ export let dest = (dirArg: string) => {
const stream = new plugins.smartstream.SmartDuplex({
objectMode: true,
writeFunction: async (fileArg: SmartFile) => {
const filePath = plugins.path.join(dirArg, fileArg.relative);
const dirPath = plugins.path.dirname(filePath);
await plugins.smartfile.fs.ensureDir(dirPath);
await plugins.smartfile.memory.toFs(fileArg.contentBuffer, filePath);
}
await fileArg.writeToDir(dirArg);
},
});
return stream;
};
@@ -42,7 +64,7 @@ export let replace = () => {
objectMode: true,
writeFunction: async (fileArg: SmartFile) => {
await fileArg.write();
}
},
});
return stream;
};