ihub-cli 1.0.0 → 1.0.2
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/dbconnection.js +0 -12
- package/index.js +21 -6
- package/package.json +1 -1
- package/recursive_file_extractor.js +23 -20
package/dbconnection.js
CHANGED
|
@@ -10,18 +10,6 @@ const client = new MongoClient(uri, {
|
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
async function runConnectionTest() {
|
|
14
|
-
try {
|
|
15
|
-
|
|
16
|
-
await client.connect();
|
|
17
|
-
await client.db("admin").command({ ping: 1 });
|
|
18
|
-
console.log("Pinged your deployment. You successfully connected to MongoDB!");
|
|
19
|
-
} catch (error) {
|
|
20
|
-
console.error("Connection error:", error);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
runConnectionTest();
|
|
25
13
|
|
|
26
14
|
|
|
27
15
|
function provideClient() {
|
package/index.js
CHANGED
|
@@ -11,8 +11,6 @@ import { PinataSDK } from "pinata";
|
|
|
11
11
|
import { provideClient } from "./dbconnection.js"
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
14
|
const IHUB_DIR = path.join(os.homedir(), ".ihub");
|
|
17
15
|
const FILE_TO_STORE_LOGIN = path.join(IHUB_DIR, "login.txt");
|
|
18
16
|
|
|
@@ -141,11 +139,18 @@ async function getFile(folder,cid,pinata) {
|
|
|
141
139
|
const arrayBuffer = await Data.arrayBuffer()
|
|
142
140
|
const buffer = Buffer.from(arrayBuffer);
|
|
143
141
|
console.log(buffer)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
//tester
|
|
146
|
+
deleteFilesWithExtension(".history.bundle",".")
|
|
147
|
+
|
|
148
|
+
|
|
144
149
|
let dynamicstring=crypto.randomUUID()
|
|
145
150
|
let shortID = dynamicstring.substring(0, 5)
|
|
146
151
|
let bpath=`${shortID}.history.bundle`
|
|
147
152
|
|
|
148
|
-
|
|
153
|
+
fs.writeFileSync(`${bpath}`,buffer);
|
|
149
154
|
|
|
150
155
|
|
|
151
156
|
if (fs.existsSync(folder)){
|
|
@@ -180,7 +185,10 @@ async function getFileNew(folder,obj,pinata) {
|
|
|
180
185
|
|
|
181
186
|
function deleteFilesWithExtension(extension, folder) {
|
|
182
187
|
try {
|
|
183
|
-
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
const absolutePath = path.resolve(folder);
|
|
191
|
+
const files = fs.readdirSync(absolutePath);
|
|
184
192
|
|
|
185
193
|
for (const file of files) {
|
|
186
194
|
if (file.endsWith(extension)) {
|
|
@@ -321,7 +329,8 @@ async function Push(FOLDER_TO_UPLOAD,pinata,client) {
|
|
|
321
329
|
const coll = db.collection("ihub_col");
|
|
322
330
|
|
|
323
331
|
let uploads=[]
|
|
324
|
-
|
|
332
|
+
const absolutePath = path.resolve(FOLDER_TO_UPLOAD);
|
|
333
|
+
let files=dirtoFileArray(absolutePath)
|
|
325
334
|
|
|
326
335
|
for (let file of files) {
|
|
327
336
|
|
|
@@ -332,7 +341,7 @@ async function Push(FOLDER_TO_UPLOAD,pinata,client) {
|
|
|
332
341
|
|
|
333
342
|
console.log(uploads)
|
|
334
343
|
const data = fs.readFileSync(FILE_TO_STORE_LOGIN, 'utf8');
|
|
335
|
-
const lastpath = path.basename(
|
|
344
|
+
const lastpath = path.basename(absolutePath);
|
|
336
345
|
|
|
337
346
|
let meta={"id":data,"folder":lastpath,"uploads":uploads,"is_latest":true}
|
|
338
347
|
|
|
@@ -453,6 +462,12 @@ yargs(hideBin(process.argv))
|
|
|
453
462
|
}
|
|
454
463
|
)
|
|
455
464
|
.demandCommand(1, 'You must provide a top-level command like "ihub".')
|
|
465
|
+
.usage('ihub <command> [options]')
|
|
466
|
+
.example('ihub op login 0xABC...', 'Login using wallet address')
|
|
467
|
+
.example('ihub op push ./repo', 'Push a local repository')
|
|
468
|
+
.example('ihub op clone <reponame> --new true', 'Clone a new repository | name will be the reponame in UI')
|
|
469
|
+
.example('ihub op clone <reponame>', 'Clone an existing repository | name will be the reponame in UI')
|
|
470
|
+
.epilog('ImmutableHub CLI • Built with ❤️')
|
|
456
471
|
.help()
|
|
457
472
|
.argv;
|
|
458
473
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import fs from "fs"
|
|
2
2
|
import path from "path";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @param {string} dir - Directory path
|
|
6
|
-
* @param {string[]} fileList - Accumulator for file paths
|
|
7
|
-
* @returns {string[]} Array of file paths
|
|
8
|
-
*/
|
|
3
|
+
|
|
4
|
+
|
|
9
5
|
function getAllFiles(dir, fileList = []) {
|
|
10
6
|
|
|
11
7
|
|
|
12
|
-
const skipDirs = [
|
|
8
|
+
const skipDirs = [
|
|
9
|
+
'node_modules',
|
|
10
|
+
'.git',
|
|
11
|
+
'dist',
|
|
12
|
+
'build',
|
|
13
|
+
'.next',
|
|
14
|
+
'coverage',
|
|
15
|
+
'__pycache__',
|
|
16
|
+
'.venv',
|
|
17
|
+
'venv',
|
|
18
|
+
'env',
|
|
19
|
+
'.env',
|
|
20
|
+
'.tox',
|
|
21
|
+
'.pytest_cache',
|
|
22
|
+
'.mypy_cache',
|
|
23
|
+
'.ruff_cache',
|
|
24
|
+
'.eggs',
|
|
25
|
+
'pip-wheel-metadata'];
|
|
13
26
|
const files = fs.readdirSync(dir);
|
|
14
27
|
|
|
15
28
|
files.forEach(file => {
|
|
@@ -27,11 +40,7 @@ function getAllFiles(dir, fileList = []) {
|
|
|
27
40
|
}
|
|
28
41
|
|
|
29
42
|
|
|
30
|
-
|
|
31
|
-
* Get MIME type from file extension
|
|
32
|
-
* @param {string} fileName - File name
|
|
33
|
-
* @returns {string} MIME type
|
|
34
|
-
*/
|
|
43
|
+
|
|
35
44
|
function getMimeType(fileName) {
|
|
36
45
|
const ext = path.extname(fileName).toLowerCase();
|
|
37
46
|
const types = {
|
|
@@ -54,17 +63,14 @@ function getMimeType(fileName) {
|
|
|
54
63
|
'.xml': 'application/xml',
|
|
55
64
|
'.csv': 'text/csv',
|
|
56
65
|
'.md': 'text/markdown',
|
|
66
|
+
'.py': 'text/x-python',
|
|
57
67
|
};
|
|
58
68
|
return types[ext] || 'application/octet-stream';
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
|
|
62
72
|
|
|
63
|
-
|
|
64
|
-
* Convert file paths to File objects for Pinata
|
|
65
|
-
* @param {string} dirPath - Directory path
|
|
66
|
-
* @returns {File[]} Array of File objects
|
|
67
|
-
*/
|
|
73
|
+
|
|
68
74
|
export default function dirToFileArray(dirPath) {
|
|
69
75
|
const filePaths = getAllFiles(dirPath);
|
|
70
76
|
|
|
@@ -75,6 +81,3 @@ export default function dirToFileArray(dirPath) {
|
|
|
75
81
|
return new File([buffer], fileName,{type:mimeType});
|
|
76
82
|
});
|
|
77
83
|
}
|
|
78
|
-
//const FOLDER_TO_UPLOAD = path.resolve('./demofolder');
|
|
79
|
-
//let f=dirToFileArray(FOLDER_TO_UPLOAD)
|
|
80
|
-
//console.log(f)
|