@bconnorwhite/bob

2.9.5 • Public • Published
Man Construction Worker on Apple iOS 13.3

@bconnorwhite/bob

npm typescript Coverage Status GitHub stars Twitter Follow

Bob is a toolkit for TypeScript projects.

Bob provides a set of tools for developing TypeScript projects for both Node and the browser (React) without having to think about tsc or babel.

Bob works with zero configuration, does not require babel.config.json, and will auto-generate the correct tsconfig.json file.

Installation

yarn add @bconnorwhite/bob
npm install @bconnorwhite/bob

Project Structure

build, watch, clean, list

Bob assumes your source files are in ./src. Build files (.js) and type declaration files (.d.ts) will be output to ./build.

Bob only builds .ts and .tsx files, but he will copy over any other file types.

start, dev

Bob will run main as defined in your package.json.

docker

For a single environment, use:

  • ./docker-compose.yml
  • ./Dockerfile

For multiple environments, use:

  • ./docker/${NODE_ENV}/docker-compose.yml
  • ./docker/${NODE_ENV}/Dockerfile

bob docker build will build the appropriate Dockerfile based on NODE_ENV. bob docker up will start docker-compose with the appropriate YAML file based on NODE_ENV.

NODE_ENV may be defined in .env or passed to bob on the command line.


CLI

bob

Usage: bob [options] [command]

Options:
  -v --version     output the version number
  -h, --help       display help for command

Commands:
  init             initialize source, package.json, .gitignore, tsconfig.json, README.md, .cz.json
  build [options]  build and output type declaration files
  watch            watch source files and build after changes
  start [options]  start the script defined in the main field of package.json
  dev [options]    start with NODE_ENV set to 'development' and watch for changes
  lint             lint package.json and source files
  test             run tests
  commit           create a conventional commit
  docker           run docker commands
  count            count lines across source files
  list             list files included in build
  help [command]   display help for command

bob init

Usage: bob init [options] [command]

initialize source, package.json, .gitignore, and tsconfig.json

Options:
  -h, --help    display help for command

Commands:
  source        initialize source directory
  package-json  initialize package.json
  gitignore     initialize git repo
  tsconfig      initialize tsconfig.json

bob build

Usage: bob build [options] [command]

build and output type declaration files

Options:
  -w --watch        watch files for changes
  -s --silent       silent output
  -h, --help        display help for command

Commands:
  source [options]  build source files
  types [options]   output type declaration files

bob watch

Usage: bob watch [options] [command]

watch source files and build after changes

Options:
  -h, --help  display help for command

Commands:
  source      build source files after changes
  types       output type declarations after changes

bob start

Usage: bob start [options]

start the script defined in the main field of package.json

Options:
  -d --dev                 set NODE_ENV to 'development' and watch for changes
  -i --ignore [ignore...]  files or directories to ignore for restart
  -h, --help               display help for command

bob dev

Usage: bob dev [options]

start with NODE_ENV set to 'development' and watch for changes

Options:
  -i --ignore [ignore...]  files or directories to ignore for restart
  -h, --help               display help for command

bob commit

Usage: bob commit [options]

create a conventional commit

Options:
  -h, --help  display help for command

bob lint

Usage: bob lint [options] [command]

lint package.json and source files

Options:
  -h, --help  display help for command

Commands:
  package     lint package.json
  source      lint source files with ESLint

bob test

Usage: bob test [options]

run tests

Options:
  -h, --help  display help for command

bob docker

Usage: bob docker [options] [command]

run docker commands

Options:
  -h, --help                 display help for command

Commands:
  build [options] <context>  run docker build on Dockerfile
  up [options]               run docker-compose up on docker-compose.yml
  help [command]             display help for command

bob count

Usage: bob count [options]

count lines across source files

Options:
  -h, --help  display help for command

bob list

Usage: bob list [options]

list files included in build

Options:
  -h, --help  display help for command

run-env

Bob also includes @bconnorwhite/run-env, which allows for running package.json scrips suffixed by the beginning characters of NODE_ENV.

For example, to run a script called build:dev or build:prod:

yarn run-env build

# If NODE_ENV=development:
# this will run scripts like 'build:dev' or 'build:development'
# If NODE_ENV=production:
# this will run scripts like 'build:prod' or 'build:production'

Suffixes must be at least 3 characters, as long as they match the first characters of NODE_ENV.

For full documentation visit https://www.npmjs.com/package/@bconnorwhite/run-env.


Build Configuration

The eqivalent of Bob's babel.config.json:

{
  "presets": [
    "@babel/preset-typescript",
    [
      "@babel/preset-env", {
        "loose": true,
        "exclude": [
          "@babel/plugin-transform-regenerator"
        ]
      }
    ],
    "@babel/preset-react"
  ]
}

The equivalent of Bob's tsconfig.json:

{
  "compilerOptions": {
    "declaration": true,
    "emitDeclarationOnly": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "preserve",
    "lib": [
      "dom",
      "esnext"
    ],
    "module": "commonjs",
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": true,
    "outDir": "build",
    "removeComments": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    "target": "esnext"
  },
  "include": [
    "source"
  ]
}

API

Bob includes an easily composable API for including its commands:

import { program } from "commander";
import {
  initCommand,
  buildCommand,
  watchCommand,
  startCommand,
  devCommand,
  dockerCommand,
  countCommand,
  listCommand
} from "@bconnorwhite/bob";

// These can easily be used as commander commands

program
  .addCommand(initCommand)
  .addCommand(buildCommand)
  .addCommand(watchCommand)
  .addCommand(startCommand)
  .addCommand(devCommand)
  .addCommand(dockerCommand)
  .addCommand(countCommand)
  .addCommand(listCommand)
  .parse();

You can also run the actions programmatically:

import {
  initAction,
  buildAction,
  watchAction,
  startAction,
  devAction,
  dockerizeAction,
  dockerBuildAction,
  countAction,
  listAction
} from "@bconnorwhite/bob";

// These can be used as commander commands

// equivalent of `bob init`
initAction();

// equivalent of `bob build`
buildAction({
  watch: false
});

// equivalent of `bob watch`
watchAction();

// equivalent of `bob clean`
cleanAction();

// equivalent of `bob start`
startAction({
  dev: false
});

// equivalent of `bob dev`
devAction();

// equivalent of `bob dockerize`
dockerizeAction();

// equivalent of `bob docker-build`
dockerBuildAction();

// equivalent of `bob count`
countAction();

// equivalent of `bob list`
listAction();

Dependenciesdependencies

  • @babel/cli: Babel command line.
  • @babel/core: Babel compiler core.
  • @babel/preset-env: A Babel preset for each environment.
  • @babel/preset-react: Babel preset for all React plugins.
  • @babel/preset-typescript: Babel preset for TypeScript.
  • @bconnorwhite/exec: Execute commands while keeping flags easily configurable as an object
  • @bconnorwhite/package: A utility for reading package.json of a project, and forming paths relative to it.
  • @bconnorwhite/run-env: Run package.json scripts suffixed with NODE_ENV.
  • chokidar: A neat wrapper around node.js fs.watch / fs.watchFile / fsevents.
  • commander-version: A wrapper for Commander that automatically sets the version based on your package.json
  • dotenv: Loads environment variables from .env file
  • find: Find files or directories by name
  • inquirer: A collection of common interactive command line user interfaces.
  • nodemon: Simple monitor script for use during development of a node.js app.
  • ora: Elegant terminal spinner
  • package-run: Programmatically run package.json scripts. Supports yarn, npm, and pnpm.
  • typescript: TypeScript is a language for application scale JavaScript development
  • wait-on: Wait-on is a cross platform command line utility and Node.js API which will wait for files, ports, sockets, and http(s) resources to become available
  • which-pm-lockfile: Check if a project uses yarn, npm, or pnpm. Supports yarn workspaces.


Dev DependenciesDavid


License license

MIT


Related Packages:

Package Sidebar

Install

npm i @bconnorwhite/bob

Weekly Downloads

21

Version

2.9.5

License

MIT

Unpacked Size

218 kB

Total Files

149

Last publish

Collaborators

  • bconnorwhite