From 905523d373e660331497fd07dad55462d852abb4 Mon Sep 17 00:00:00 2001 From: Zishan Date: Thu, 28 Dec 2023 19:44:25 +0530 Subject: [PATCH] feat(CLI): update CLI logo and delete function --- .gitignore | 4 +++- dist/CLI/list-all.js | 31 +++++++++++++++++++++++++++++++ dist/CLI/list-all.js.map | 1 + dist/index.js | 25 ++++++++++++++++++------- dist/index.js.map | 2 +- dist/utils/generate-logo.js | 28 ++++++++++++++++++++++++++++ dist/utils/generate-logo.js.map | 1 + src/CLI/list-all.ts | 14 ++++++++++++++ src/index.ts | 30 +++++++++++++++++++++++------- src/utils/generate-logo.ts | 27 +++++++++++++++++++++++++++ 10 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 dist/CLI/list-all.js create mode 100644 dist/CLI/list-all.js.map create mode 100644 dist/utils/generate-logo.js create mode 100644 dist/utils/generate-logo.js.map create mode 100644 src/CLI/list-all.ts create mode 100644 src/utils/generate-logo.ts diff --git a/.gitignore b/.gitignore index cd89c25..318d180 100644 --- a/.gitignore +++ b/.gitignore @@ -127,4 +127,6 @@ out .yarn/unplugged .yarn/build-state.yml .yarn/install-state.gz -.pnp.* \ No newline at end of file +.pnp.* + + diff --git a/dist/CLI/list-all.js b/dist/CLI/list-all.js new file mode 100644 index 0000000..967fc4a --- /dev/null +++ b/dist/CLI/list-all.js @@ -0,0 +1,31 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const get_snippets_1 = __importDefault(require("../core/get-snippets")); +function listAll() { + return __awaiter(this, void 0, void 0, function* () { + const snippets = (0, get_snippets_1.default)(); + const detailedSnippetsPromises = snippets.map((snippet) => __awaiter(this, void 0, void 0, function* () { + return { + ID: snippet.id, + title: snippet.title, + language: snippet.language, + }; + })); + const detailedSnippets = yield Promise.all(detailedSnippetsPromises); + console.table(detailedSnippets); + }); +} +exports.default = listAll; +//# sourceMappingURL=list-all.js.map \ No newline at end of file diff --git a/dist/CLI/list-all.js.map b/dist/CLI/list-all.js.map new file mode 100644 index 0000000..19f00f7 --- /dev/null +++ b/dist/CLI/list-all.js.map @@ -0,0 +1 @@ +{"version":3,"file":"list-all.js","sourceRoot":"","sources":["../../src/CLI/list-all.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,wEAAgD;AAEhD,SAA8B,OAAO;;QACpC,MAAM,QAAQ,GAAG,IAAA,sBAAY,GAAE,CAAC;QAChC,MAAM,wBAAwB,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAO,OAAgB,EAAE,EAAE;YACxE,OAAO;gBACN,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;aAC1B,CAAC;QACH,CAAC,CAAA,CAAC,CAAC;QACH,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACrE,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACjC,CAAC;CAAA;AAXD,0BAWC"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 8ad09af..84e3767 100755 --- a/dist/index.js +++ b/dist/index.js @@ -29,21 +29,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const chalk_1 = __importDefault(require("chalk")); const commander_1 = require("commander"); -const figlet_1 = __importDefault(require("figlet")); const list_interface_1 = __importDefault(require("./core/list-interface")); const save_snippet_1 = require("./core/save-snippet"); const get_snippets_1 = __importDefault(require("./core/get-snippets")); const cli_highlight_1 = __importStar(require("cli-highlight")); +const generate_logo_1 = __importDefault(require("./utils/generate-logo")); +const list_all_1 = __importDefault(require("./CLI/list-all")); +const delete_snippet_1 = require("./core/delete-snippet"); const program = new commander_1.Command(); -// CSM logo in CLI -console.log(chalk_1.default.red(figlet_1.default.textSync('CSM', '3D Diagonal'))); +const version = require('../package.json').version; +(0, generate_logo_1.default)(); program - .version('1.3.0') + .version(version) .description(chalk_1.default.green('A CLI Code Snippet Manager tool for managing code snippets directly from your terminal')) .option('-s, --save ', 'Save a code snippet') .option('-ls, --list-all', 'List all snippets') .option('-o, --output ', 'Output a particular snippet') + .option('-d, --delete ', 'Delete snippet by ID') .option('-l, --list', 'Open TUI') + .addHelpText('after', ` +Example: + $ csm-kit -s hello.py + $ csm-kit -ls + $ csm-kit -o hello.py +`) .parse(process.argv); const options = program.opts(); if (!process.argv.slice(2).length) { @@ -60,9 +69,7 @@ if (options.list) { (0, list_interface_1.default)(); } if (options.listAll) { - const snippets = (0, get_snippets_1.default)(); - const titles = snippets.map((snippet) => snippet.title); - titles.forEach((title) => console.log(chalk_1.default.green(title))); + (0, list_all_1.default)(); } if (options.output) { const snippets = (0, get_snippets_1.default)(); @@ -89,4 +96,8 @@ if (options.output) { }); console.log(highlightedCode); } +if (options.delete) { + const snippetId = typeof options.delete === 'string' ? parseInt(options.delete) : 0; + console.log((0, delete_snippet_1.deleteSnippet)(snippetId)); +} //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map index ba1747c..ac30dbe 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kDAA0B;AAC1B,yCAAoC;AACpC,oDAA4B;AAC5B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IAAI,EAAE;QAClD,QAAQ,EAAE,cAAc;QACxB,cAAc,EAAE,IAAI;QACpB,KAAK,EAAE;YACN,OAAO,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;YAC7B,OAAO,EAAE,eAAK,CAAC,OAAO;YACtB,QAAQ,EAAE,eAAK,CAAC,UAAU;YAC1B,MAAM,EAAE,eAAK,CAAC,WAAW;YACzB,MAAM,EAAE,eAAK,CAAC,IAAI;YAClB,OAAO,EAAE,eAAK,CAAC,KAAK;YACpB,MAAM,EAAE,eAAK,CAAC,MAAM;SACpB;KACD,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC9B,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kDAA0B;AAC1B,yCAAoC;AAEpC,2EAAiD;AACjD,sDAAkD;AAClD,uEAA+C;AAC/C,+DAA4D;AAC5D,0EAAiD;AACjD,8DAAqC;AACrC,0DAAsD;AAEtD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,MAAM,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC;AACnD,IAAA,uBAAY,GAAE,CAAC;AACf,OAAO;KACL,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CACX,eAAK,CAAC,KAAK,CACV,wFAAwF,CACxF,CACD;KACA,MAAM,CAAC,uBAAuB,EAAE,qBAAqB,CAAC;KACtD,MAAM,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;KAC9C,MAAM,CAAC,8BAA8B,EAAE,6BAA6B,CAAC;KACrE,MAAM,CAAC,2BAA2B,EAAE,sBAAsB,CAAC;KAC3D,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC;KAChC,WAAW,CACX,OAAO,EACP;;;;;CAKD,CACC;KACA,KAAK,CAAC,OAAO,CAAC,IAAI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AgB,EAAE,EAAE,CACpB,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE,CAC3D,CAAC;IACF,MAAM,cAAc,GAAG,IAAA,gCAAgB,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QACzE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE;QACnC,CAAC,CAAC,KAAK,CAAC;IACT,MAAM,eAAe,GAAG,IAAA,uBAAS,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;QAClD,QAAQ,EAAE,cAAc;QACxB,cAAc,EAAE,IAAI;QACpB,KAAK,EAAE;YACN,OAAO,EAAE,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC;YAC7B,OAAO,EAAE,eAAK,CAAC,OAAO;YACtB,QAAQ,EAAE,eAAK,CAAC,UAAU;YAC1B,MAAM,EAAE,eAAK,CAAC,WAAW;YACzB,MAAM,EAAE,eAAK,CAAC,IAAI;YAClB,OAAO,EAAE,eAAK,CAAC,KAAK;YACpB,MAAM,EAAE,eAAK,CAAC,MAAM;SACpB;KACD,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC9B,CAAC;AAED,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IACpB,MAAM,SAAS,GACd,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,OAAO,CAAC,GAAG,CAAC,IAAA,8BAAa,EAAC,SAAS,CAAC,CAAC,CAAC;AACvC,CAAC"} \ No newline at end of file diff --git a/dist/utils/generate-logo.js b/dist/utils/generate-logo.js new file mode 100644 index 0000000..ad129ec --- /dev/null +++ b/dist/utils/generate-logo.js @@ -0,0 +1,28 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const chalk_1 = __importDefault(require("chalk")); +const figlet_1 = __importDefault(require("figlet")); +function generateLogo() { + // Generate figlet text for both symbols + const arrow = figlet_1.default.textSync('>', { font: '3D-ASCII' }); + const text = figlet_1.default.textSync('CSM', { font: '3D-ASCII' }); + // Split the generated text into lines + const arrowLines = arrow.split('\n'); + const textLines = text.split('\n'); + // To ensure both pieces have the same number of lines + const maxLength = Math.max(arrowLines.length, textLines.length); + // Create a combined text with colored lines + const combinedLines = []; + for (let i = 0; i < maxLength; i++) { + const arrowLine = arrowLines[i] || ''; + const textLine = textLines[i] || ''; + combinedLines.push(chalk_1.default.green(arrowLine) + chalk_1.default.red(textLine)); + } + // Print each combined line + combinedLines.forEach((line) => console.log(line)); +} +exports.default = generateLogo; +//# sourceMappingURL=generate-logo.js.map \ No newline at end of file diff --git a/dist/utils/generate-logo.js.map b/dist/utils/generate-logo.js.map new file mode 100644 index 0000000..bd4a7d1 --- /dev/null +++ b/dist/utils/generate-logo.js.map @@ -0,0 +1 @@ +{"version":3,"file":"generate-logo.js","sourceRoot":"","sources":["../../src/utils/generate-logo.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAC1B,oDAA4B;AAE5B,SAAwB,YAAY;IACnC,wCAAwC;IACxC,MAAM,KAAK,GAAG,gBAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IACzD,MAAM,IAAI,GAAG,gBAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IAE1D,sCAAsC;IACtC,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAEnC,sDAAsD;IACtD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IAEhE,4CAA4C;IAC5C,MAAM,aAAa,GAAG,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAEpC,aAAa,CAAC,IAAI,CAAC,eAAK,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,eAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClE,CAAC;IAED,2BAA2B;IAC3B,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACpD,CAAC;AAvBD,+BAuBC"} \ No newline at end of file diff --git a/src/CLI/list-all.ts b/src/CLI/list-all.ts new file mode 100644 index 0000000..976e0e2 --- /dev/null +++ b/src/CLI/list-all.ts @@ -0,0 +1,14 @@ +import loadSnippets from '../core/get-snippets'; + +export default async function listAll() { + const snippets = loadSnippets(); + const detailedSnippetsPromises = snippets.map(async (snippet: Snippet) => { + return { + ID: snippet.id, + title: snippet.title, + language: snippet.language, + }; + }); + const detailedSnippets = await Promise.all(detailedSnippetsPromises); + console.table(detailedSnippets); +} diff --git a/src/index.ts b/src/index.ts index 70c3411..7016ffa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,14 +7,16 @@ import listSnippets from './core/list-interface'; import { saveSnippet } from './core/save-snippet'; import loadSnippets from './core/get-snippets'; import highlight, { supportsLanguage } from 'cli-highlight'; +import generateLogo from './utils/generate-logo'; +import listAll from './CLI/list-all'; +import { deleteSnippet } from './core/delete-snippet'; const program = new Command(); -// CSM logo in CLI -console.log(chalk.red(figlet.textSync('CSM', '3D Diagonal'))); - +const version = require('../package.json').version; +generateLogo(); program - .version('1.3.0') + .version(version) .description( chalk.green( 'A CLI Code Snippet Manager tool for managing code snippets directly from your terminal', @@ -23,7 +25,17 @@ program .option('-s, --save ', 'Save a code snippet') .option('-ls, --list-all', 'List all snippets') .option('-o, --output ', 'Output a particular snippet') + .option('-d, --delete ', 'Delete snippet by ID') .option('-l, --list', 'Open TUI') + .addHelpText( + 'after', + ` +Example: + $ csm-kit -s hello.py + $ csm-kit -ls + $ csm-kit -o hello.py +`, + ) .parse(process.argv); const options = program.opts(); @@ -47,9 +59,7 @@ if (options.list) { } if (options.listAll) { - const snippets = loadSnippets(); - const titles = snippets.map((snippet: Snippet) => snippet.title); - titles.forEach((title: string) => console.log(chalk.green(title))); + listAll(); } if (options.output) { @@ -81,3 +91,9 @@ if (options.output) { }); console.log(highlightedCode); } + +if (options.delete) { + const snippetId = + typeof options.delete === 'string' ? parseInt(options.delete) : 0; + console.log(deleteSnippet(snippetId)); +} diff --git a/src/utils/generate-logo.ts b/src/utils/generate-logo.ts new file mode 100644 index 0000000..32fddfb --- /dev/null +++ b/src/utils/generate-logo.ts @@ -0,0 +1,27 @@ +import chalk from 'chalk'; +import figlet from 'figlet'; + +export default function generateLogo() { + // Generate figlet text for both symbols + const arrow = figlet.textSync('>', { font: '3D-ASCII' }); + const text = figlet.textSync('CSM', { font: '3D-ASCII' }); + + // Split the generated text into lines + const arrowLines = arrow.split('\n'); + const textLines = text.split('\n'); + + // To ensure both pieces have the same number of lines + const maxLength = Math.max(arrowLines.length, textLines.length); + + // Create a combined text with colored lines + const combinedLines = []; + for (let i = 0; i < maxLength; i++) { + const arrowLine = arrowLines[i] || ''; + const textLine = textLines[i] || ''; + + combinedLines.push(chalk.green(arrowLine) + chalk.red(textLine)); + } + + // Print each combined line + combinedLines.forEach((line) => console.log(line)); +}