Team Ai
Datasetpublic

codekingpro/portable-devtools

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