Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
create.js77 linesDownload Raw Back to esm
1import { WriteStream, WriteStreamSync } from '@isaacs/fs-minipass';
2import path from 'node:path';
3import { list } from './list.js';
4import { makeCommand } from './make-command.js';
5import { Pack, PackSync } from './pack.js';
6const createFileSync = (opt, files) => {
7    const p = new PackSync(opt);
8    const stream = new WriteStreamSync(opt.file, {
9        mode: opt.mode || 0o666,
10    });
11    p.pipe(stream);
12    addFilesSync(p, files);
13};
14const createFile = (opt, files) => {
15    const p = new Pack(opt);
16    const stream = new WriteStream(opt.file, {
17        mode: opt.mode || 0o666,
18    });
19    p.pipe(stream);
20    const promise = new Promise((res, rej) => {
21        stream.on('error', rej);
22        stream.on('close', res);
23        p.on('error', rej);
24    });
25    addFilesAsync(p, files);
26    return promise;
27};
28const addFilesSync = (p, files) => {
29    files.forEach(file => {
30        if (file.charAt(0) === '@') {
31            list({
32                file: path.resolve(p.cwd, file.slice(1)),
33                sync: true,
34                noResume: true,
35                onReadEntry: entry => p.add(entry),
36            });
37        }
38        else {
39            p.add(file);
40        }
41    });
42    p.end();
43};
44const addFilesAsync = async (p, files) => {
45    for (let i = 0; i < files.length; i++) {
46        const file = String(files[i]);
47        if (file.charAt(0) === '@') {
48            await list({
49                file: path.resolve(String(p.cwd), file.slice(1)),
50                noResume: true,
51                onReadEntry: entry => {
52                    p.add(entry);
53                },
54            });
55        }
56        else {
57            p.add(file);
58        }
59    }
60    p.end();
61};
62const createSync = (opt, files) => {
63    const p = new PackSync(opt);
64    addFilesSync(p, files);
65    return p;
66};
67const createAsync = (opt, files) => {
68    const p = new Pack(opt);
69    addFilesAsync(p, files);
70    return p;
71};
72export const create = makeCommand(createFileSync, createFile, createSync, createAsync, (_opt, files) => {
73    if (!files?.length) {
74        throw new TypeError('no paths specified to add to archive');
75    }
76});
77//# sourceMappingURL=create.js.map
codekingpro/portable-devtools · Team Ai