From 3a63003b707815f091f8b35b19d1a5d936edfe30 Mon Sep 17 00:00:00 2001 From: SANTHOSH17-DOT Date: Sun, 15 Oct 2023 22:47:51 +0530 Subject: [PATCH] Update build --- dist/index.js | 2 +- dist/index.js.map | 2 +- dist/vc/commit.js | 40 ++++++++++-------- dist/vc/commit.js.map | 2 +- dist/vc/history.js | 30 ++++++++------ dist/vc/history.js.map | 2 +- dist/vc/init.js | 40 ++++++++++-------- dist/vc/init.js.map | 2 +- dist/vc/stage.js | 93 +++++++++++++++++++++++------------------- dist/vc/stage.js.map | 2 +- package-lock.json | 4 +- package.json | 2 +- src/index.ts | 2 +- 13 files changed, 126 insertions(+), 97 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1c85da4..52bd0ef 100755 --- a/dist/index.js +++ b/dist/index.js @@ -9,7 +9,7 @@ console.log(figlet.textSync("Statik")); const program = new Command(); program .name("statik") - .version("1.0.0") + .version("1.0.5-alpha") .description("An IPFS based version control system with static file hosting features"); program.command("init ").description("Initialize a new Statik repository"); program.command("add [file_path]").description("Add a file to the Statik repository"); diff --git a/dist/index.js.map b/dist/index.js.map index 68347a3..950b36f 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEvC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAC9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AG,EAAE,CAAC;AAC1B,QAAQ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;IACvB,KAAK,MAAM;QACT,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACrC,IAAI,CAAC,GAAG,EAAC,aAAa,CAAC,CAAC;QACxB,MAAM;IACR,KAAK,KAAK;QACR,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM;IACR,KAAK,QAAQ;QACX,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,MAAM;IACR,KAAK,KAAK;QACR,GAAG,CAAC,GAAG,CAAC,CAAC;QACT,MAAM;IACR;QACE,OAAO,CAAC,UAAU,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;CAClB"} \ No newline at end of file diff --git a/dist/vc/commit.js b/dist/vc/commit.js index 9e28a12..2d15c08 100644 --- a/dist/vc/commit.js +++ b/dist/vc/commit.js @@ -3,24 +3,30 @@ import { IsStatik } from "../utils/checkStatik.js"; import fs from 'fs'; import { FetchConfig } from "../utils/fetchConfig.js"; export async function Commit(cwd, message) { - IsStatik(cwd); - const snapshot = fs.readFileSync(cwd + "/.statik/SNAPSHOT").toString(); - if (!snapshot.length) { - console.error("No changes to commit"); + try { + IsStatik(cwd); + const snapshot = fs.readFileSync(cwd + "/.statik/SNAPSHOT").toString(); + if (!snapshot.length) { + console.error("No changes to commit"); + process.exit(1); + } + const client = create({ url: FetchConfig(cwd).ipfs_node_url }); + const prevCommit = fs.readFileSync(cwd + "/.statik/HEAD").toString(); + const commit = { + prevCommit: prevCommit, + snapshot: snapshot, + message: message, + timestamp: Date.now() + }; + const result = await client.add(JSON.stringify(commit)); + fs.writeFileSync(cwd + "/.statik/HEAD", result.path); + fs.writeFileSync(cwd + "/.statik/SNAPSHOT", ""); + console.log("Committed to IPFS with hash: " + result.path); + process.exit(0); + } + catch (e) { + console.error(e); process.exit(1); } - const client = create({ url: FetchConfig(cwd).ipfs_node_url }); - const prevCommit = fs.readFileSync(cwd + "/.statik/HEAD").toString(); - const commit = { - prevCommit: prevCommit, - snapshot: snapshot, - message: message, - timestamp: Date.now() - }; - const result = await client.add(JSON.stringify(commit)); - fs.writeFileSync(cwd + "/.statik/HEAD", result.path); - fs.writeFileSync(cwd + "/.statik/SNAPSHOT", ""); - console.log("Committed to IPFS with hash: " + result.path); - process.exit(0); } //# sourceMappingURL=commit.js.map \ No newline at end of file diff --git a/dist/vc/commit.js.map b/dist/vc/commit.js.map index 8ea3e6f..df8a93c 100644 --- a/dist/vc/commit.js.map +++ b/dist/vc/commit.js.map @@ -1 +1 @@ -{"version":3,"file":"commit.js","sourceRoot":"","sources":["../../src/vc/commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,GAAW,EAAC,OAAe;IACpD,QAAQ,CAAC,GAAG,CAAC,CAAA;IACb,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,GAAC,mBAAmB,CAAC,CAAC,QAAQ,EAAE,CAAA;IACpE,IAAG,CAAC,QAAQ,CAAC,MAAM,EAAC;QAChB,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAClB;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,EAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,aAAa,EAAC,CAAC,CAAA;IAC5D,MAAM,UAAU,GAAG,E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A;SAClB;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,EAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,aAAa,EAAC,CAAC,CAAA;QAC5D,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,GAAC,eAAe,CAAC,CAAC,QAAQ,EAAE,CAAA;QAClE,MAAM,MAAM,GAAG;YACX,UAAU,EAAE,UAAU;YACtB,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,OAAO;YAChB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACxB,CAAA;QACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;QACvD,EAAE,CAAC,aAAa,CAAC,GAAG,GAAC,eAAe,EAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACjD,EAAE,CAAC,aAAa,CAAC,GAAG,GAAC,mBAAmB,EAAC,EAAE,CAAC,CAAA;QAC5C,OAAO,CAAC,GAAG,CACP,+BAA+B,GAAC,MAAM,CAAC,IAAI,CAC9C,CAAA;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAClB;IAAA,OAAM,CAAC,EAAC;QACL,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAClB;AAEL,CAAC"} \ No newline at end of file diff --git a/dist/vc/history.js b/dist/vc/history.js index 9d1acd4..c6e6d07 100644 --- a/dist/vc/history.js +++ b/dist/vc/history.js @@ -3,19 +3,25 @@ import { IsStatik } from "../utils/checkStatik.js"; import fs from 'fs'; import { FetchConfig } from "../utils/fetchConfig.js"; export async function Log(cwd) { - IsStatik(cwd); - const client = create({ url: FetchConfig(cwd).ipfs_node_url }); - let head = fs.readFileSync(cwd + "/.statik/HEAD").toString(); - let asyncitr = client.cat(head); - console.log("Commit history: "); - while (head.length) { - for await (const itr of asyncitr) { - const data = Buffer.from(itr).toString(); - console.log("<" + head + ">" + " " + JSON.parse(data).message); - head = JSON.parse(data).prevCommit; - asyncitr = client.cat(head); + try { + IsStatik(cwd); + const client = create({ url: FetchConfig(cwd).ipfs_node_url }); + let head = fs.readFileSync(cwd + "/.statik/HEAD").toString(); + let asyncitr = client.cat(head); + console.log("Commit history: "); + while (head.length) { + for await (const itr of asyncitr) { + const data = Buffer.from(itr).toString(); + console.log("<" + head + ">" + " " + JSON.parse(data).message); + head = JSON.parse(data).prevCommit; + asyncitr = client.cat(head); + } } + process.exit(0); + } + catch (e) { + console.error(e); + process.exit(1); } - process.exit(0); } //# sourceMappingURL=history.js.map \ No newline at end of file diff --git a/dist/vc/history.js.map b/dist/vc/history.js.map index e714dc7..d6d1cdc 100644 --- a/dist/vc/history.js.map +++ b/dist/vc/history.js.map @@ -1 +1 @@ -{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/vc/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,GAAW;IACjC,QAAQ,CAAC,GAAG,CAAC,CAAA;IACb,MAAM,MAAM,GAAG,MAAM,CAAC,EAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,aAAa,EAAC,CAAC,CAAA;IAC5D,IAAI,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,GAAG,GAAC,eAAe,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC1D,IAAI,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC/B,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IAC/B,OAAM,IAAI,CAAC,M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AAK,EAAC,MAAM,GAAG,IAAI,QAAQ,EAAC;gBAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAA;gBACxC,OAAO,CAAC,GAAG,CAAC,GAAG,GAAC,IAAI,GAAC,GAAG,GAAC,GAAG,GAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAA;gBACtD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,CAAA;gBAClC,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;aAC9B;SACJ;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAClB;IAAA,OAAM,CAAC,EAAC;QACL,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAClB;AACL,CAAC"} \ No newline at end of file diff --git a/dist/vc/init.js b/dist/vc/init.js index 8b58cdd..d2cfd77 100644 --- a/dist/vc/init.js +++ b/dist/vc/init.js @@ -1,23 +1,29 @@ import fs from "fs"; export async function Init(cwd, ipfs_node_url) { - let reinitialize = false; - if (fs.existsSync(cwd + "/.statik")) { - reinitialize = true; - fs.rmSync(cwd + "/.statik", { recursive: true }); + try { + let reinitialize = false; + if (fs.existsSync(cwd + "/.statik")) { + reinitialize = true; + fs.rmSync(cwd + "/.statik", { recursive: true }); + } + fs.mkdirSync(cwd + "/.statik"); + fs.mkdirSync(cwd + "/.statik/refs/heads", { recursive: true }); + fs.writeFileSync(cwd + "/.statik/HEAD", ""); + fs.writeFileSync(cwd + "/.statik/SNAPSHOT", ""); + fs.writeFileSync(cwd + "/.statik/CONFIG", JSON.stringify({ + ipfs_node_url: ipfs_node_url + })); + if (reinitialize) { + console.error("Reinitialized Statik repository in " + cwd + "/.statik"); + } + else { + console.log("Initialized Statik repository in " + cwd + "/.statik"); + } + process.exit(0); } - fs.mkdirSync(cwd + "/.statik"); - fs.mkdirSync(cwd + "/.statik/refs/heads", { recursive: true }); - fs.writeFileSync(cwd + "/.statik/HEAD", ""); - fs.writeFileSync(cwd + "/.statik/SNAPSHOT", ""); - fs.writeFileSync(cwd + "/.statik/CONFIG", JSON.stringify({ - ipfs_node_url: ipfs_node_url - })); - if (reinitialize) { - console.error("Reinitialized Statik repository in " + cwd + "/.statik"); + catch (e) { + console.error(e); + process.exit(1); } - else { - console.log("Initialized Statik repository in " + cwd + "/.statik"); - } - process.exit(0); } //# sourceMappingURL=init.js.map \ No newline at end of file diff --git a/dist/vc/init.js.map b/dist/vc/init.js.map index c1044ef..14289c6 100644 --- a/dist/vc/init.js.map +++ b/dist/vc/init.js.map @@ -1 +1 @@ -{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/vc/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,GAAW,EAAC,aAAoB;IACvD,IAAI,YAAY,GAAG,KAAK,CAAC;IACzB,IAAG,EAAE,CAAC,UAAU,CAAC,GAAG,GAAC,UAAU,CAAC,EAAC;QAC7B,YAAY,GAAG,IAAI,CAAC;QACpB,EAAE,CAAC,MAAM,CAAC,GAAG,GAAC,UAAU,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAA;KAC/C;IACD,EAAE,CAAC,SAAS,CAAC,GAAG,GAAC,UAAU,CAAC,CAAA;IAC5B,EAAE,CAAC,SAAS,CAAC,GAAG,GAAC,qBAAqB,EAAC,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAA;IAEzD,EAAE,CAAC,aAAa,CAAC,GAAG,GAAC,eAAe,EAAE,EAAE,CAAC,CAAA;IACzC,EAAE,CAAC,aAAa,CAAC,GAAG,GAAC,mBAAmB,EAAE,EAAE,CAAC,CAAA;IAC7C,EAAE,CAAC,aAAa,CAAC,GAAG,GAA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,CAAC,KAAK,CAAC,qCAAqC,GAAC,GAAG,GAAC,UAAU,CAAC,CAAA;SACtE;aAAI;YACD,OAAO,CAAC,GAAG,CAAC,mCAAmC,GAAC,GAAG,GAAC,UAAU,CAAC,CAAA;SAClE;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAClB;IAAA,OAAM,CAAC,EAAC;QACL,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAClB;AACL,CAAC"} \ No newline at end of file diff --git a/dist/vc/stage.js b/dist/vc/stage.js index ba149d6..c22ac12 100644 --- a/dist/vc/stage.js +++ b/dist/vc/stage.js @@ -2,54 +2,65 @@ import { create, globSource } from "ipfs-http-client"; import { IsStatik } from "../utils/checkStatik.js"; import fs from 'fs'; import { FetchConfig } from "../utils/fetchConfig.js"; -// If order of elements changes, the hash changes -// Fix the logic (Sort maybe?) -// Accept file path '.' export async function Add(cwd, paths) { - IsStatik(cwd); - const client = create({ url: FetchConfig(cwd).ipfs_node_url }); - const prevCommit = fs.readFileSync(cwd + "/.statik/HEAD").toString(); - if (!prevCommit.length) { - let snapshot = []; - for (const path of paths) { - for await (const result of client.addAll(globSource(path, { recursive: true }))) { - snapshot.push(result); - } - } - // console.log(snapshot) - const result = await client.add(JSON.stringify(snapshot)); - fs.writeFileSync(cwd + "/.statik/SNAPSHOT", result.path); - console.log("Files staged to IPFS with cid: " + result.path); - } - else { - let asyncitr = client.cat(prevCommit); - let prevSnapshot = ""; - for await (const itr of asyncitr) { - const data = Buffer.from(itr).toString(); - prevSnapshot = JSON.parse(data).snapshot; + try { + IsStatik(cwd); + if (!paths.length) { + console.log("No file path specified!"); + console.log("Hint: statik help"); + return; } - let prevContent = []; - asyncitr = client.cat(prevSnapshot); - for await (const itr of asyncitr) { - const data = Buffer.from(itr).toString(); - prevContent = JSON.parse(data); + const client = create({ url: FetchConfig(cwd).ipfs_node_url }); + const prevCommit = fs.readFileSync(cwd + "/.statik/HEAD").toString(); + if (!prevCommit.length) { + let snapshot = []; + for (const path of paths) { + for await (const result of client.addAll(globSource(path, { recursive: true }))) { + snapshot.push(result); + } + } + // console.log(snapshot) + const result = await client.add(JSON.stringify(snapshot)); + fs.writeFileSync(cwd + "/.statik/SNAPSHOT", result.path); + console.log("Files staged to IPFS with cid: " + result.path); } - // Not optimized - for (const path of paths) { - for await (const result of client.addAll(globSource(path, { recursive: true }))) { - for (const prev of prevContent) { - if (prev.path == result.path) { - prevContent.splice(prevContent.indexOf(prev), 1); - break; + else { + let asyncitr = client.cat(prevCommit); + let prevSnapshot = ""; + for await (const itr of asyncitr) { + const data = Buffer.from(itr).toString(); + prevSnapshot = JSON.parse(data).snapshot; + } + let prevContent = []; + asyncitr = client.cat(prevSnapshot); + for await (const itr of asyncitr) { + const data = Buffer.from(itr).toString(); + prevContent = JSON.parse(data); + } + // Not optimized + for (const path of paths) { + for await (const result of client.addAll(globSource(path, { recursive: true }))) { + let flag = true; + for (const prev of prevContent) { + if (prev.path == result.path) { + prevContent.splice(prevContent.indexOf(prev), 1, result); + flag = false; + break; + } } + if (flag) + prevContent.push(result); } - prevContent.push(result); } + const result = await client.add(JSON.stringify(prevContent)); + fs.writeFileSync(cwd + "/.statik/SNAPSHOT", result.path); + console.log("Files staged to IPFS with cid: " + result.path); } - const result = await client.add(JSON.stringify(prevContent)); - fs.writeFileSync(cwd + "/.statik/SNAPSHOT", result.path); - console.log("Files staged to IPFS with cid: " + result.path); + process.exit(0); + } + catch (e) { + console.error(e); + process.exit(1); } - process.exit(0); } //# sourceMappingURL=stage.js.map \ No newline at end of file diff --git a/dist/vc/stage.js.map b/dist/vc/stage.js.map index de234b1..d567124 100644 --- a/dist/vc/stage.js.map +++ b/dist/vc/stage.js.map @@ -1 +1 @@ -{"version":3,"file":"stage.js","sourceRoot":"","sources":["../../src/vc/stage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAA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W,CAAC,OAAO,CAAC,IAAI,CAAC,EAAC,CAAC,EAAC,MAAM,CAAC,CAAA;4BACtD,IAAI,GAAG,KAAK,CAAA;4BACZ,MAAM;yBACT;qBACJ;oBACD,IAAG,IAAI;wBAAE,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;iBACpC;aACJ;YACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAA;YAC5D,EAAE,CAAC,aAAa,CAAC,GAAG,GAAC,mBAAmB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YACrD,OAAO,CAAC,GAAG,CACP,iCAAiC,GAAC,MAAM,CAAC,IAAI,CAChD,CAAA;SACJ;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAClB;IAAA,OAAM,CAAC,EAAC;QACL,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;KAClB;AACL,CAAC"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6f1268b..b16493a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "statikvc", - "version": "1.0.4-alpha", + "version": "1.0.5-alpha", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "statikvc", - "version": "1.0.4-alpha", + "version": "1.0.5-alpha", "license": "ISC", "dependencies": { "commander": "^11.0.0", diff --git a/package.json b/package.json index bb04411..9b99fdd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "statikvc", - "version": "1.0.4-alpha", + "version": "1.0.5-alpha", "description": "An IPFS based version control system with static file hosting features. Basic functions like repo initiation, staging, committing, and logging have been implemented. (Under active development)", "exports": "./dist/index.js", "scripts": { diff --git a/src/index.ts b/src/index.ts index 20f7b5d..4cc9c6c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,7 @@ console.log(figlet.textSync("Statik")); const program = new Command(); program .name("statik") - .version("1.0.4-alpha") + .version("1.0.5-alpha") .description("An IPFS based version control system with static file hosting features") program.command("init ").description("Initialize a new Statik repository") program.command("add [file_path]").description("Add a file to the Statik repository")