Package detail

@bconnorwhite/bob

bconnorwhite179MIT2.9.5

Bob is a toolkit for TypeScript projects

bob, build, typescript, watch

readme

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:

changelog

2.9.5 (2021-08-14)

2.9.4 (2021-03-30)

Bug Fixes

2.9.3 (2021-03-30)

Bug Fixes

  • bumped eslint-config-bob version (5874cd2)
  • dependency bumps (23aad50)

2.9.2 (2020-10-03)

Bug Fixes

2.9.1 (2020-10-03)

Bug Fixes

2.9.0 (2020-10-02)

Bug Fixes

  • add DS_Store to gitignore (55c9ae2)
  • add replace ts export plugin (cc47c49)
  • fix issue pushing with set upstream (49de628)
  • fix relative typeRoots issue (d8c6063)
  • make spinner output more consistent (bc1f8b8)
  • use sh instead of bash in README (7564993)

Features

  • add shebang to bin files on build (662c135)

2.8.1 (2020-10-01)

Bug Fixes

  • avoid error when lint has unmatched pattern (5c785d1)
  • fixed issue causing init of empty tsconfig (ded14c2)
  • read fresh package.json on README init (69b0e4d)
  • save coveralls token after prompt in release command (9a4eaee)
  • silence commit sha output (8c5ad53)

2.8.0 (2020-10-01)

Bug Fixes

  • also check git tags before bumping version (7d79c62)
  • clean up prerelease output (a631c55)
  • default release script to publish (139ac65)
  • fix init readme command naming issue (967b865)
  • fix issue setting coveralls token in release (60700a4)
  • fix warning message in release output (046eaa7)
  • reorder imports in test init (6425152)
  • set upstream during push if necessary (e72612c)
  • use actions in prerelease for better output (9a9de15)

Features

2.7.0 (2020-09-30)

Bug Fixes

  • add quotes to lint source output (80013c7)
  • add support for publishing from yarn and pnpm (5c89a80)
  • added spinner for test command (ab89d40)
  • adjust build spinner output text (abebb71)
  • allow lint commit without husky env being set (c553c1e)
  • fix husky commit-msg command (a838a87)
  • fix issue with sending coverage to Coveralls (29c6ff6)
  • fix package json lint rules (1db8c5e)
  • fix to pushing tags (626fc8c)

Features

2.6.3 (2020-09-27)

Bug Fixes

  • catch error from version exists (60026b6)
  • fix version error on release (4b3e796)
  • remove extra newline when initializing gitignore (a7f674d)

2.6.2 (2020-09-27)

Bug Fixes

  • check if version exists before bumping (2be985e)

2.6.1 (2020-09-27)

Bug Fixes

  • fix missing newlines in readme init (7a9c42f)
  • init github after git init (23750a4)
  • log errors from coveralls release (1691155)

2.6.0 (2020-09-27)

Bug Fixes

  • add test as a typescript rootDir (fd3b071)
  • fix coveralls init issue (7047396)
  • readme init update (b83cf8f)
  • tsconfig rootDir issue (f31aa60)

Features

2.5.2 (2020-09-26)

Bug Fixes

  • issue with init in repo without org (04ac552)

2.5.1 (2020-09-26)

Bug Fixes

2.5.0 (2020-09-26)

Bug Fixes

Features

  • add lint commit command (0c27cd4)
  • allow types as type root directory (4926983)
  • commit command (c122430)
  • github init (80bd57c)
  • lint commit messages with husky (4bc2b05)
  • save package.json init to configstore (2dd62ee)
  • test command (00cf7fc)
  • use github top languages in README init (7f95b5a)

2.4.2 (2020-09-23)

Bug Fixes

2.4.1 (2020-09-23)

Bug Fixes

2.4.0 (2020-09-22)

Features

2.3.1 (2020-09-20)

Bug Fixes

2.3.0 (2020-09-20)

Features

2.2.1 (2020-09-20)

2.2.0 (2020-09-20)

2.1.3 (2020-09-20)

Bug Fixes

2.1.2 (2020-09-20)

Bug Fixes

Features

  • init gitignore with .DS_Store (0959c51)

2.1.0 (2020-09-20)

Bug Fixes

  • package json init fixes (1c51a38)
  • switch to live tsconfig.json file (1d6a1cb)
  • update init description (abbaf94)

Features

  • git init (9f157f5)
  • init README, init tsconfig, git init only if not already a git repo (092ede2)

2.0.1 (2020-09-20)

2.0.0 (2020-09-20)

Features

1.9.7 (2020-09-02)

1.9.6 (2020-09-02)

1.9.5 (2020-08-24)

1.9.4 (2020-08-22)

1.9.3 (2020-08-18)

1.9.2 (2020-08-18)

1.9.1 (2020-08-18)

1.9.0 (2020-08-18)

1.8.0 (2020-08-13)

1.7.7 (2020-08-12)

1.7.6 (2020-08-10)

1.7.5 (2020-08-10)

1.7.4 (2020-08-10)

1.7.3 (2020-08-10)

1.7.2 (2020-08-10)

1.7.1 (2020-08-10)

1.7.0 (2020-08-10)

1.6.0 (2020-08-09)

1.5.2 (2020-08-08)

1.5.1 (2020-08-08)

1.5.0 (2020-08-07)

1.4.3 (2020-07-26)