feat(smartgulp): modernize file glob handling and refresh package metadata
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartgulp',
|
||||
version: '3.0.4',
|
||||
description: 'lightweight gulp replacement'
|
||||
version: '3.1.0',
|
||||
description: 'A lightweight replacement for gulp, featuring smart stream handling and file manipulation.'
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import * as plugins from './smartgulp.plugins.js';
|
||||
import { SmartFile } from '@push.rocks/smartfile';
|
||||
|
||||
import { Transform } from 'stream';
|
||||
import { Transform } from 'node:stream';
|
||||
|
||||
export class GulpStream {
|
||||
stream = new Transform({ objectMode: true });
|
||||
@@ -11,13 +11,13 @@ export class GulpStream {
|
||||
/**
|
||||
* allows you to pipe a SmartfileArray into the stream
|
||||
*/
|
||||
async pipeSmartfileArray(smartfileArray: SmartFile[]) {
|
||||
async pipeSmartfileArray(smartfileArray: SmartFile[]): Promise<void> {
|
||||
// ensure what we get is an array
|
||||
if (!Array.isArray(smartfileArray)) {
|
||||
throw new Error('fileArg has unknown format');
|
||||
}
|
||||
for (let smartfile of smartfileArray) {
|
||||
let hasWritten = this.stream.push(smartfile);
|
||||
for (const smartfile of smartfileArray) {
|
||||
const hasWritten = this.stream.push(smartfile);
|
||||
if (!hasWritten) {
|
||||
await plugins.smartevent.once(this.stream, 'drain');
|
||||
}
|
||||
|
||||
+36
-14
@@ -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;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// node native scope
|
||||
import * as path from 'path';
|
||||
import * as path from 'node:path';
|
||||
|
||||
export {
|
||||
path
|
||||
@@ -9,6 +9,6 @@ export {
|
||||
import * as smartevent from '@push.rocks/smartevent';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartstream from '@push.rocks/smartstream';
|
||||
import * as through2 from 'through2';
|
||||
import { minimatch } from 'minimatch';
|
||||
|
||||
export { smartevent, smartfile, smartstream, through2 };
|
||||
export { smartevent, smartfile, smartstream, minimatch };
|
||||
|
||||
Reference in New Issue
Block a user