ihub-cli 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/index.js +107 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -16,6 +16,81 @@ const FILE_TO_STORE_LOGIN = path.join(IHUB_DIR, "login.txt");
16
16
 
17
17
 
18
18
 
19
+ async function UpdateRepo(folder,cid,pinata) {
20
+
21
+
22
+ const result = await pinata.gateways.public.get(cid)
23
+ const Data = result.data;
24
+ console.log(Data)
25
+ const arrayBuffer = await Data.arrayBuffer()
26
+ const buffer = Buffer.from(arrayBuffer);
27
+ console.log(buffer)
28
+ deleteFilesWithExtension(".history.bundle",".")
29
+ let dynamicstring=crypto.randomUUID()
30
+ let shortID = dynamicstring.substring(0, 5)
31
+ let bpath=`${shortID}.history.bundle`
32
+
33
+ fs.writeFileSync(`${bpath}`,buffer);
34
+
35
+ const absolutePath = path.resolve(folder);
36
+
37
+ execSync(`git pull ${bpath} ${absolutePath}`, {
38
+ cwd: ".",
39
+ stdio: 'inherit'
40
+ });
41
+ console.log("pulled successfully")
42
+
43
+ }
44
+
45
+
46
+
47
+ async function Pull(folder,pinata,client){
48
+
49
+
50
+ const db = client.db("ihub_db");
51
+ const coll = db.collection("ihub_col");
52
+ const targetManifestId= fs.readFileSync(FILE_TO_STORE_LOGIN,'utf8');
53
+ const doc = await coll.findOne({
54
+ "owner": "system",
55
+ "manifests.id": targetManifestId
56
+ });
57
+ if(doc) {
58
+
59
+ let uploads=null
60
+ let bundle=null
61
+ let manifests=doc.manifests
62
+
63
+
64
+ for(let obj of manifests){
65
+
66
+ let dbfolder=String(obj.folder)
67
+
68
+ if(obj.id==targetManifestId && dbfolder==folder){
69
+ console.log(obj.folder)
70
+ uploads=obj.uploads
71
+ }
72
+
73
+
74
+
75
+ }
76
+ console.log(uploads)
77
+
78
+ for(let obj of uploads){
79
+
80
+ let name=obj.name
81
+ const isIncluded = name.includes(".history.bundle");
82
+ if(isIncluded) {
83
+
84
+ bundle=obj.cid
85
+
86
+ }}
87
+
88
+ await UpdateRepo(folder,bundle,pinata)
89
+
90
+ }}
91
+
92
+
93
+
19
94
  async function getcreds() {
20
95
 
21
96
  let request=await fetch("https://immutablehub-creds.hf.space/creds",{
@@ -44,7 +119,6 @@ async function getRuntime() {
44
119
  function setUp(wallet) {
45
120
 
46
121
 
47
-
48
122
  if (!fs.existsSync(IHUB_DIR)) {
49
123
  fs.mkdirSync(IHUB_DIR, { recursive: true });
50
124
 
@@ -127,10 +201,6 @@ async function manifestExists(targetManifestId, foldername,client) {
127
201
 
128
202
 
129
203
 
130
-
131
-
132
-
133
-
134
204
  async function getFile(folder,cid,pinata) {
135
205
 
136
206
  const result = await pinata.gateways.public.get(cid)
@@ -368,6 +438,10 @@ async function Push(FOLDER_TO_UPLOAD,pinata,client) {
368
438
  }
369
439
 
370
440
 
441
+
442
+
443
+
444
+
371
445
  yargs(hideBin(process.argv))
372
446
  .command(
373
447
  'op',
@@ -402,9 +476,7 @@ yargs(hideBin(process.argv))
402
476
  const { pinata, client } = await getRuntime();
403
477
  try{
404
478
 
405
-
406
479
  console.log(`\n⬆️ Starting PUSH operation on folder: ${argv.folderpath}`);
407
-
408
480
  gitBundler(argv.folderpath);
409
481
  await Push(argv.folderpath,pinata,client);
410
482
  console.log('Push operation finished.');
@@ -416,6 +488,33 @@ yargs(hideBin(process.argv))
416
488
  }
417
489
 
418
490
 
491
+ }
492
+ )
493
+ .command(
494
+ 'pull <foldername>',
495
+ 'Pulls the uploaded history into an existing project',
496
+ (yargs) => {
497
+ return yargs.positional('foldername', {
498
+ describe: 'the repo/folder to pull',
499
+ type: 'string'
500
+ });
501
+ },
502
+ async (argv) => {
503
+
504
+ const { pinata, client } = await getRuntime();
505
+ try{
506
+
507
+ console.log(`\n⬆️ Starting Pull operation`);
508
+ await Pull(argv.foldername,pinata,client)
509
+
510
+
511
+ }catch(e){
512
+ console.log(str(e))
513
+ }finally{
514
+ await client.close()
515
+ }
516
+
517
+
419
518
  }
420
519
  )
421
520
  .command(
@@ -468,6 +567,7 @@ yargs(hideBin(process.argv))
468
567
  .example('ihub op push ./repo', 'Push a local repository')
469
568
  .example('ihub op clone <reponame> --new true', 'Clone a new repository | name will be the reponame in UI')
470
569
  .example('ihub op clone <reponame>', 'Clone an existing repository | name will be the reponame in UI')
570
+ .example('ihub op clone <reponame>', 'Pull updates in an existing repository | name will be the reponame in UI')
471
571
  .epilog('ImmutableHub CLI • Built with ❤️')
472
572
  .help()
473
573
  .argv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ihub-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "immutablehub cli to push and clone repos",
5
5
  "main": "index.js",
6
6
  "type": "module",