smartgulp/ts/smartgulp.gulpapi.ts

49 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-04-29 22:25:31 +00:00
// this file contains the implementation of the standard gulp api
2022-06-09 17:59:21 +00:00
import * as plugins from './smartgulp.plugins.js';
import { GulpStream } from './smartgulp.classes.gulpstream.js';
2018-03-03 12:57:55 +00:00
import { Transform } from 'stream';
2017-04-29 22:25:31 +00:00
2023-11-25 17:11:31 +00:00
import { SmartFile } from '@push.rocks/smartfile';
2017-04-29 22:25:31 +00:00
export let src = (minimatchPathArrayArg: string[]): Transform => {
2018-03-03 12:57:55 +00:00
let gulpStream = new GulpStream();
2017-04-29 22:25:31 +00:00
let handleFiles = async () => {
2023-11-25 17:11:31 +00:00
let smartfileArray: SmartFile[] = [];
2017-04-29 22:25:31 +00:00
for (let minimatchPath of minimatchPathArrayArg) {
2018-03-03 12:57:55 +00:00
let localSmartfileArray = await plugins.smartfile.fs.fileTreeToObject(
process.cwd(),
minimatchPath
);
2019-02-20 22:54:38 +00:00
smartfileArray = [...smartfileArray, ...localSmartfileArray];
2017-04-29 22:25:31 +00:00
}
2018-03-03 12:57:55 +00:00
gulpStream.pipeSmartfileArray(smartfileArray);
};
2022-06-09 17:59:21 +00:00
handleFiles().catch((err) => {
2018-03-03 12:57:55 +00:00
console.log(err);
});
return gulpStream.stream;
};
2017-04-29 22:25:31 +00:00
2023-11-25 17:11:31 +00:00
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);
}
});
return stream;
};
2018-02-15 23:46:55 +00:00
export let replace = () => {
2023-11-25 17:11:31 +00:00
const stream = new plugins.smartstream.SmartDuplex({
objectMode: true,
writeFunction: async (fileArg: SmartFile) => {
await fileArg.write();
2018-03-03 12:57:55 +00:00
}
2023-11-25 17:11:31 +00:00
});
return stream;
2018-03-03 12:57:55 +00:00
};