Git Product home page Git Product logo

cli-boilerplate's Introduction

CLI Boilerplate

React and meowJS, CLI boilerplate comes configured to do quickly and easily cli apps with react and es6.

Install

$ git clone https://github.com/orionsoft/cli-boilerplate [app-name]

Getting Started

To start creating your own application you need to change the version, name and bin into package.json according to your application information.

// package.json
{
  "name": "[app-name]",
  "bin": {
    "[app-bin]": "lib/index.js"
  },
  "version": "[app-version]",
 }

Then run the following commands:

yarn build
yarn watch

And run in your terminal your app

[app-bin] --help

Congratz :) you can start to create and test your app's components

This boilerplate comes with some functionalities by default, since it's designed to start building CLI apps very faster. Each command its represented by a component, when you call a command from your terminal, your actually rendering a component.

Your flags are the equivalent to component's props, when you call command with any flags, you're actually calling a component with its props.

Boilerplate structure

|-- src
|   |-- components
|   |   |-- index.js
|   |   |-- sayHello.js
|   |   |-- sayHelloName.js
|   |-- utils
|-- flags.js
|-- index.js

Registering flags

When you create a flag you can assign an alias and a help text, the boilerplate will register it in the help text of your application automatically. And you will be able to call this flag as a props in any component

// flags.js
export default {
  flags: {
    name: {
      type: 'string',
      alias: 'n',
      help: 'Your name'
    },
    lastname: {
      type: 'string',
      alias: 'l',
      help: 'Your lastname'
    }
  }
}
// components/sayHello.js
export class SayHello extends Component {
  constructor(props, context) {
    super(props, context)

    this.state = {
      message: 'Ink is awesome'
    }
  }

  render(props, state) {
    const {name, lastname} = props
    return (
      <Text>
        Hello! {name} {lastname}
      </Text>
    )
  }
}

Creating component

Like any other React application you can create components, and use states and props to interact with them. When you want to create a component, make sure you have the following structure:

// components/sayHelloName.js
import {h, render, Component, Text} from 'ink'
import TextInput from 'ink-text-input'
import {SayHello} from './sayHello'
import PropTypes from 'prop-types'
export default class SayHelloName extends Component {
  static propTypes = {
    name: PropTypes.string
  }
  state = {
    name: ''
  }

  handleChange(value) {
    this.setState(value)
  }

  handleSubmit() {
    const unmount = render(<SayHello name={this.state.name} />)
    unmount()
  }

  render(props, state) {
    return (
      <div>
        Enter your name:
        <TextInput
          value={state.name}
          onChange={value => this.handleChange({name: value})}
          onSubmit={() => this.handleSubmit()}
        />
      </div>
    )
  }
}

And don't forget to register your component in the following file:

// components/index.js
import {h} from 'ink'
import {SayHello} from './sayHello'
import SayHelloName from './sayHelloName'

// This is where you put your inputs, each input call a Component
export default [
  {
    input: 'say-hello',
    render: <SayHello />,
    help: 'terminal greets you'
  },
  {
    input: 'say-hello-to-me',
    render: <SayHelloName />,
    help: 'terminal greets you by your name'
  }
]

Further Documentation

cli-boilerplate's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

prariehill

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.