Skip to content

Commit

Permalink
List command added. (#4)
Browse files Browse the repository at this point in the history
* List command added.

* 'fs' not defined fixed and logo added.

* Installation should be global.

* Version updated.
  • Loading branch information
anikghosh256 authored Apr 23, 2023
1 parent 1f0314f commit 80b44ab
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CLI tool for creating kitty component.

## Installation
```bash
npm install @anikghosh256/kitty-cli
npm install @anikghosh256/kitty-cli -g
```

## Usage
Expand Down
33 changes: 33 additions & 0 deletions cmds/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');

const { logo } = require('../helpers/print');

exports.command = 'list'
exports.desc = 'List all kitty components.'

exports.handler = function () {
try {
const projectPath = process.cwd();

// check if kitty dir exists
if(!fs.existsSync(path.resolve(projectPath, './kitty'))) {
throw new Error('Kitty dir does not exist. Please run "kitty init" to initialize kitty dir.')
}

const kittyDir = fs.readdirSync(path.resolve(projectPath, './kitty'));
logo();
console.log(chalk.green('Kitty components:'));
console.log('');
for(let i = 0; i < kittyDir.length; i++) {
// check if dir
if(fs.lstatSync(path.resolve(projectPath, `./kitty/${kittyDir[i]}`)).isDirectory()) {
console.log(chalk.cyan(kittyDir[i]));
}
}

} catch (error) {
console.log(chalk.red(error.message));
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@anikghosh256/kitty-cli",
"description": "CLI tool for creating kitty component.",
"version": "0.1.2",
"version": "0.2.0",
"license": "MIT",
"bin": {
"kitty-cli": "kitty.js",
Expand Down

0 comments on commit 80b44ab

Please sign in to comment.