Skip to content

linuxfandudeguy/cnsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cnsh

cnsh logo

npm version npm downloads License Coverage Status GitHub stars GitHub forks

cnsh is a lightweight package manager that provides a minimal alternative to Yarn. It fetches packages from the npm registry and installs them in a simplified directory structure.

Features

  • Add Packages: Install packages from the npm registry.
  • Remove Packages: Uninstall packages from your project.
  • Install Dependencies: Install all dependencies listed in package.json.
  • Global and Local Installation: Supports both global and local package management.
  • Simple and Efficient: Focuses on essential features for ease of use.

Installation

To install cnsh globally, follow these steps:

  1. Install via pnpm

    Run the following command in your terminal:

    pnpm install -g cnsh --verbose

    This will install cnsh globally, making it available from any directory on your system.

  2. Verify Installation

    To check if cnsh is installed correctly, run:

    cnsh

    If cnsh is installed, you should see the following output in red text along with the output from the --help command:

Unknown command.

This confirms that cnsh is properly installed and recognizing commands.

Usage

cnsh offers a simple set of commands for managing packages. Here’s how to use it:

Adding a Package

To add a package to your project, use:

cnsh add <package-name> --verbose
the verbose flag is optional, it is used to display more information

For example, to add lodash:

cnsh add lodash --verbose

This installs lodash into your project's cnsh_lib directory.

Updating

To update it, run this command in your terminal:

pnpm install -g cnsh@latest

Removing a Package

To remove a package, use:

cnsh remove <package-name>

For example, to remove lodash:

cnsh remove lodash

Installing Dependencies

To install all dependencies listed in your package.json, use:

cnsh install

This reads the package.json file and installs all listed dependencies into your cnsh_lib directory.

Global Installation

To install a package globally, use:

cnsh add -g <package-name>

Global packages will be installed in a global directory (typically ~/.cnsh-global/cnsh_lib).

Help

For a list of available commands and help, use:

cnsh --help

Example: Using axios with cnsh

Here’s a demonstration of how to use axios with cnsh:

  1. Install axios

    cnsh add axios
  2. Create a Simple Node.js Script

    Create a file named app.js with the following content:

    // Import axios from the local path where cnsh stores it
    import axios from './cnsh_lib/axios/package/dist/esm/axios.min.js';
    
    // Function to fetch data from a public API
    async function fetchData() {
        try {
            const response = await axios.get('https://jsonplaceholder.typicode.com/posts/1');
            console.log('Data fetched:', response.data);
        } catch (error) {
            console.error('Error fetching data:', error);
        }
    }
    
    // Call the fetchData function
    fetchData();

or if you like CommonJS better:

async function fetchData() {
    try {
        const axios = await import('./cnsh_lib/axios/package/dist/esm/axios.min.js');
        const response = await axios.default.get('https://jsonplaceholder.typicode.com/posts/1');
        console.log('Data fetched:', response.data);
    } catch (error) {
        console.error('Error fetching data:', error);
    }
}

fetchData();

UMD:

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD
        define(['axios'], factory);
    } else if (typeof module === 'object' && module.exports) {
        // Node.js or CommonJS
        module.exports = factory(require('./cnsh_lib/axios/package/dist/axios.js'));
    } else {
        // Browser global
        root.fetchData = factory(root.axios);
    }
}(typeof self !== 'undefined' ? self : this, function (axios) {
    'use strict';

    // Function to fetch data from a public API
    async function fetchData() {
        try {
            const response = await axios.get('https://jsonplaceholder.typicode.com/posts/1');
            console.log('Data fetched:', response.data);
        } catch (error) {
            console.error('Error fetching data:', error);
        }
    }

    // Return the function as part of the UMD module
    return fetchData;
}));

// To call fetchData in a browser environment:
fetchData();
  1. Run Your Script

    Execute your script using Node.js:

    node app.js

    You should see the data fetched from the public API printed to your console.

Contributing

Feel free to open issues or submit pull requests to help improve cnsh. If you have suggestions or feature requests, please let us know!

NEEDED FIXES FORK TO FIX

  • needs to install packages in node_modules/.cnsh and create a symlink
  • can only be used for packages without dependencies
  • Needs a run command
  • needs to make a exported path for global packages
  • needs a update Alert for The version specified in the package.json does not matchThe version according to the npm API

Once you Fork the package, publish it to npm with a name like @cnsh/{id} Thanks for contributing!

Licence

This project is licensed under the ISC License - see the LICENSE file for details.