ihub-cli 1.0.2 → 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 +112 -11
  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)
@@ -152,15 +222,16 @@ async function getFile(folder,cid,pinata) {
152
222
 
153
223
  fs.writeFileSync(`${bpath}`,buffer);
154
224
 
225
+ const absolutePath = path.resolve(folder);
155
226
 
156
- if (fs.existsSync(folder)){
157
- fs.rmSync(folder, { recursive: true, force: true });
227
+ if (fs.existsSync(absolutePath)){
228
+ fs.rmSync(absolutePath, { recursive: true, force: true });
158
229
  }
159
230
 
160
231
 
161
- fs.mkdirSync(folder, { recursive: true });
232
+ fs.mkdirSync(absolutePath, { recursive: true });
162
233
 
163
- execSync(`git clone ${bpath} ${folder}`, {
234
+ execSync(`git clone ${bpath} ${absolutePath}`, {
164
235
  cwd: ".",
165
236
  stdio: 'inherit'
166
237
  });
@@ -367,6 +438,10 @@ async function Push(FOLDER_TO_UPLOAD,pinata,client) {
367
438
  }
368
439
 
369
440
 
441
+
442
+
443
+
444
+
370
445
  yargs(hideBin(process.argv))
371
446
  .command(
372
447
  'op',
@@ -401,9 +476,7 @@ yargs(hideBin(process.argv))
401
476
  const { pinata, client } = await getRuntime();
402
477
  try{
403
478
 
404
-
405
479
  console.log(`\n⬆️ Starting PUSH operation on folder: ${argv.folderpath}`);
406
-
407
480
  gitBundler(argv.folderpath);
408
481
  await Push(argv.folderpath,pinata,client);
409
482
  console.log('Push operation finished.');
@@ -415,6 +488,33 @@ yargs(hideBin(process.argv))
415
488
  }
416
489
 
417
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
+
418
518
  }
419
519
  )
420
520
  .command(
@@ -467,6 +567,7 @@ yargs(hideBin(process.argv))
467
567
  .example('ihub op push ./repo', 'Push a local repository')
468
568
  .example('ihub op clone <reponame> --new true', 'Clone a new repository | name will be the reponame in UI')
469
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')
470
571
  .epilog('ImmutableHub CLI • Built with ❤️')
471
572
  .help()
472
573
  .argv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ihub-cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "immutablehub cli to push and clone repos",
5
5
  "main": "index.js",
6
6
  "type": "module",