GithubHelp home page GithubHelp logo

jaywcjlove / tsbb Goto Github PK

View Code? Open in Web Editor NEW
100.0 6.0 7.0 2.05 MB

TSBB is a CLI tool for developing, testing and publishing modern TypeScript projects with zero configuration, and can also be used for module or react component development. @tsbbjs

Home Page: http://jaywcjlove.github.io/tsbb

License: MIT License

TypeScript 99.66% JavaScript 0.22% Shell 0.12%
typescript babel7 koa2 exress tsbb babel jest nodejs reactjs vue3

tsbb's Introduction

tsbb

Build & Deploy NPM Downloads Open in unpkg npm version

Quick Start · Example · Command Help · npm · License

TSBB is a CLI tool for developing, testing and publishing modern TypeScript projects with zero configuration, and can also be used for module or react component development.

TypeScript + Babel = TSBB

Migrate from tsbb 3.x to 4.x.

Features

  • 🔥 Single dependency zero-configuration
  • ⏱ Quick initialization of example projects and entering development mode
  • ♻️ Automatic recompilation of code when files are added, modified, or removed
  • 📚 Readable source code that encourages learning and contribution
  • 🚀 Faster compilation speeds
  • ⚛️ Support for React and Vue 3 component compilation
  • Jest test runner setup with defaults of tsbb test

Quick Start

You will need Node.js installed on your system.

$ yarn create tsbb [appName]
# or npm
$ npm create tsbb@latest my-app -- -e express
# --- Example name ------┴ˇˇˇˇˇ
# or npx
$ npx create-tsbb@latest my-app -e koa

# npm 7+, extra double-dash is needed:
$ npm init tsbb my-app -- --example typenexus
# npm 6.x
$ npm init tsbb my-app --example typenexus

$ cd my-project

$ npm run watch # Listen compile .ts files.
$ npm run build # compile .ts files.
$ npm start

1️⃣ Installation & Setup

$ npm i -D microbundle

2️⃣ Set up your package.json:

{
  "name": "@pkg/basic",
  "version": "1.0.0",
  "main": "./cjs/index.js",      // where to generate the CommonJS bundle
  "module": "./esm/index.js",    // where to generate the ESM bundle
  "exports": {
    "require": "./cjs/index.js", // used for require() in Node 12+
    "default": "./esm/index.js"  // where to generate the modern bundle (see below)
  },
  "scripts": {
    "watch": "tsbb watch",
    "build": "tsbb build --bail",
    "test": "tsbb test",
    "coverage": "tsbb test --coverage --bail"
  },
  "devDependencies": {
    "tsbb": "4.1.14"
  }
}

3️⃣ Try it out by running npm run build.

Example

create-tsbb initialize the project from one of the examples:

$ npx create-tsbb my-app -e <Example Name>
# --- E.g: ----------------┴ˇˇˇˇˇˇˇˇˇˇˇˇˇˇ
# npx create-tsbb my-app -e Basic

You can download the following examples directly. Download page.

TypeScript Project

To configure the tsconfig.json properly, you must first define either the include or files field(s) to specify which files need to be compiled. Once you've done that, you can then specify the outDir for the output directory in the configuration.

{
  "$schema": "http://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "module": "commonjs",
    "target": "esnext",
    "outDir": "./lib",
    "strict": true,
    "skipLibCheck": true
  },
  "include": ["src/**/*"],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

After completing tsconfig.jso configuration, you can configure scripts in package.json:

{
  "scripts": {
    "watch": "tsbb watch",
    "build": "tsbb build"
  },
  "devDependencies": {
    "tsbb": "*"
  }
}

Babel Project

Adding the parameter --use-babel to your project enables babel to compile and output cjs/esm files simultaneously, while ts is only needed for type output.

$ tsbb build "src/*ts" --use-babel

You can change the built-in settings of Babel by adding a .babelrc configuration file. Additionally, you can modify the Babel configurations for esm and cjs separately through environment variables. Please refer to the example below:

{
  "env": {
    "cjs": {
      "presets": ["@babel/preset-typescript"]
    },
    "esm": {
      "presets": ["@babel/preset-env", {
        "modules": false,
        "loose": true,
        "targets": {
          "esmodules": true,
        },
      }]
    }
  } 
}

At compile time, specify the environment variable --envName='xxx' to enable reading of relevant configurations from the settings. This environment variable can also be customized.

{
  "env": {
    "xxx": { ... }
  } 
}

Command Help

Below is a help of commands you might find useful.

tsbb

▶ tsbb --help

Usage: tsbb <command>

Commands:

  tsbb build [source…] [options]   Build your project once and exit.
  tsbb watch [source…] [options]   Recompile files on changes.
  tsbb test [options]              Run jest test runner in watch mode.
  tsbb copy|cpy <source …> [options]   Copy files.

Options:[build|watch]

  --bail                     Exit the compile as soon as the compile fails(default: true).
  --use-babel                Use Babel.(works in babel)
  --source-maps              Enables the generation of sourcemap files.(works in babel)
  --env-name                 The current active environment used during configuration loading.(works in babel)
  --esm                      Output "esm" directory.(works in babel)
  --cjs                      Output "cjs" directory.(works in babel)
  --use-vue                  Supports "Vue3", requires "--use-babel" to be used together.
Options:

  --version, -v              Show version number
  --help, -h                 Show help

Examples:

  $ tsbb build src/*.ts                    Build your project.
  $ tsbb build src/main.ts src/good.ts     Specify the entry directory.
  $ tsbb build src/*.ts --use-babel --no-source-maps   No ".js.map" file is generated. (works in babel)
  $ tsbb watch src/*.ts --use-babel --cjs ./cjs        Watch Output directory.
  $ tsbb build src/*.ts --use-babel --esm ./es         Output directory.
  $ tsbb build src/*.ts --use-babel --use-vue          To add Vue JSX support.
  $ tsbb test                              Run test suites related
  $ tsbb test --coverage --bail            Test coverage information should be collected
  $ tsbb copy  'src/*.png' '!src/goat.png' --output dist     Copy files.
  $ tsbb copy  'src/*.png' 'src/goat.{js,d.ts}' --output dist --watch

  Copyright 2023

tsbb create

Please use create-tsbb to create an example.

tsbb test

Runs the test watcher (Jest) in an interactive mode.

$ tsbb test                          Run test suites related
$ tsbb test --coverage --no-color    Test coverage information should be collected
export declare type Argv = Arguments<Partial<{
  all: boolean;
  automock: boolean;
  bail: boolean | number;
  cache: boolean;
  cacheDirectory: string;
  changedFilesWithAncestor: boolean;
  changedSince: string;
  ci: boolean;
  clearCache: boolean;
  clearMocks: boolean;
  collectCoverage: boolean;
  collectCoverageFrom: string;
  collectCoverageOnlyFrom: Array<string>;
  color: boolean;
  colors: boolean;
  config: string;
  coverage: boolean;
  coverageDirectory: string;
  coveragePathIgnorePatterns: Array<string>;
  coverageReporters: Array<string>;
  coverageThreshold: string;
  debug: boolean;
  env: string;
  expand: boolean;
  findRelatedTests: boolean;
  forceExit: boolean;
  globals: string;
  globalSetup: string | null | undefined;
  globalTeardown: string | null | undefined;
  haste: string;
  init: boolean;
  injectGlobals: boolean;
  json: boolean;
  lastCommit: boolean;
  logHeapUsage: boolean;
  maxWorkers: number | string;
  moduleDirectories: Array<string>;
  moduleFileExtensions: Array<string>;
  moduleNameMapper: string;
  modulePathIgnorePatterns: Array<string>;
  modulePaths: Array<string>;
  noStackTrace: boolean;
  notify: boolean;
  notifyMode: string;
  onlyChanged: boolean;
  onlyFailures: boolean;
  outputFile: string;
  preset: string | null | undefined;
  projects: Array<string>;
  prettierPath: string | null | undefined;
  resetMocks: boolean;
  resetModules: boolean;
  resolver: string | null | undefined;
  restoreMocks: boolean;
  rootDir: string;
  roots: Array<string>;
  runInBand: boolean;
  selectProjects: Array<string>;
  setupFiles: Array<string>;
  setupFilesAfterEnv: Array<string>;
  showConfig: boolean;
  silent: boolean;
  snapshotSerializers: Array<string>;
  testEnvironment: string;
  testFailureExitCode: string | null | undefined;
  testMatch: Array<string>;
  testNamePattern: string;
  testPathIgnorePatterns: Array<string>;
  testPathPattern: Array<string>;
  testRegex: string | Array<string>;
  testResultsProcessor: string;
  testRunner: string;
  testSequencer: string;
  testURL: string;
  testTimeout: number | null | undefined;
  timers: string;
  transform: string;
  transformIgnorePatterns: Array<string>;
  unmockedModulePathPatterns: Array<string> | null | undefined;
  updateSnapshot: boolean;
  useStderr: boolean;
  verbose: boolean;
  version: boolean;
  watch: boolean;
  watchAll: boolean;
  watchman: boolean;
  watchPathIgnorePatterns: Array<string>;
}>>;

Development

$ npm i
$ npm run build

Contributors

As always, thanks to our amazing contributors!

Made with contributors.

License

MIT © Kenny Wong

tsbb's People

Contributors

dependabot[bot] avatar jaywcjlove avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tsbb's Issues

The test files are not type checked

I noticed a few issues when creating a Basic app:

  • The tsconfig.json file excludes test files. This is good for the build but it means there is no type checking of the test code by default. This could be fixed by creating two tsconfig files: one for building and one for development. The development one would need noEmit: true.
  • The @types/jest dev dependency is missing. This adds types for jest globals like describe and it.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Migrate from tsbb 3.x to 4.x.

Updates in version v4

  1. Updated typescript v5 dependency
  2. Updated jest v29 dependency
  3. Refactored feature package management
  4. Refactored create-tsbb based on package internal examples generation
  5. Updated template examples
- tsbb build [options]
+ tsbb build [source…] [options]
- --entry, -e
- --emit-type
- --no-emit-type
- --disable-babel
- --no-babel-option
- --file-names, -f
+ --use-babel   Use Babel.(works in babel)
+ --bail        Exit the compile as soon as the compile fails(default: true).
 --source-maps  Enables the generation of sourcemap files.(works in babel)
 --env-name     The current active environment used during configuration loading.(works in babel)
 --esm          Output "esm" directory.(works in babel)
 --cjs          Output "cjs" directory.(works in babel)
- $ tsbb build --file-names src/main.ts --file-names src/good.ts
+ $ tsbb build src/main.ts src/good.ts
- $ tsbb build --entry src/main.ts
+ $ tsbb build src/main.ts
+ $ tsbb build src/*.ts                   # Build your project.
+ $ tsbb build src/main.ts src/good.ts    # Specify the entry directory.
$ tsbb build src/*.ts --use-babel --no-source-maps  # No ".js.map" file is generated. (works in babel)
$ tsbb watch src/*.ts --use-babel --cjs ./cjs       # Watch Output directory.
$ tsbb build src/*.ts --use-babel --esm ./es        # Output directory.
$ tsbb build src/*.ts --use-babel --use-vue         # To add Vue JSX support.
$ tsbb test                                         # Run test suites related
$ tsbb test --coverage --bail                       # Test coverage information should be collected
Usage: create-tsbb <app-name> [options] [--help|h]
Options:

  --version, -v Show version number
  --help, -h Displays help information.
-  --output, -o Output directory.
  --example, -e Example from: https://jaywcjlove.github.io/tsbb , default: "basic"
  --force, -f Overwrite target directory if it exists. default: false
-  --path, -p Specify the download target git address. default: "https://jaywcjlove.github.io/tsbb"

TypeScript Project

To configure the tsconfig.json properly, you must first define either the include or files field(s) to specify which files need to be compiled. Once you've done that, you can then specify the outDir for the output directory in the configuration.

{
  "$schema": "http://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "module": "commonjs",
    "target": "esnext",
    "outDir": "./lib",
    "strict": true,
    "skipLibCheck": true
  },
  "include": ["src/**/*"],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

After completing tsconfig.json configuration, you can configure scripts in package.json:

{
  "scripts": {
    "watch": "tsbb watch",
    "build": "tsbb build"
  },
  "devDependencies": {
    "tsbb": "*"
  }
}

Babel Project

Adding the parameter --use-babel to your project enables babel to compile and output cjs/esm files simultaneously, while ts is only needed for type output.

$ tsbb build "src/*ts" --use-babel

You can change the built-in settings of Babel by adding a .babelrc configuration file. Additionally, you can modify the Babel configurations for esm and cjs separately through environment variables. Please refer to the example below:

{
  "env": {
    "cjs": {
      "presets": ["@babel/preset-typescript"]
    },
    "esm": {
      "presets": ["@babel/preset-env", {
        "modules": false,
        "loose": true,
        "targets": {
          "esmodules": true,
        },
      }]
    }
  } 
}

At compile time, specify the environment variable --envName='xxx' to enable reading of relevant configurations from the settings. This environment variable can also be customized.

{
  "env": {
    "xxx": { ... }
  } 
}

jest dependency issue

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.dev.yml
  • actions/checkout v3
  • actions/setup-node v3
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/checkout v3
  • actions/setup-node v3
.github/workflows/main.yml
  • actions/checkout v3
  • actions/setup-node v3
  • peaceiris/actions-gh-pages v3
npm
package.json
  • husky ^8.0.3
  • lerna ^7.0.0
  • lint-staged ^14.0.0
  • prettier ^3.0.3
  • typescript ^5.1.3
  • jest ^29.5.0
  • jest-watch-typeahead ^2.2.2
  • jest-environment-jsdom ^29.5.0
  • jest-environment-node ^29.5.0
  • node >=16.0.0
  • typescript ^5.1.3
packages/babel/package.json
  • @babel/core ^7.22.5
  • @babel/plugin-proposal-class-properties ~7.18.6
  • @babel/plugin-proposal-decorators ^7.22.5
  • @babel/plugin-proposal-export-default-from ^7.22.0
  • @babel/plugin-syntax-dynamic-import ^7.8.3
  • @babel/plugin-transform-classes ^7.22.5
  • @babel/plugin-transform-modules-commonjs ^7.22.5
  • @babel/plugin-transform-runtime ^7.22.5
  • @babel/preset-env ^7.22.5
  • @babel/preset-react ^7.22.5
  • @babel/preset-typescript ^7.22.5
  • @types/babel__core ^7.20.0
  • @types/semver ~7.5.0
  • @vue/babel-plugin-jsx ~1.1.1
  • babel-plugin-add-module-exports ~1.0.4
  • babel-plugin-transform-import-meta ~2.2.0
  • babel-plugin-transform-remove-imports ~1.7.0
  • babel-plugin-transform-rename-import ~2.3.0
  • babel-plugin-transform-typescript-metadata ~0.3.2
  • semver ~7.5.0
  • node >=16.7.0
packages/core/package.json
  • @types/fs-extra ^11.0.1
  • chokidar ~3.5.3
  • fs-extra ^11.1.1
  • glob ^10.0.0
  • meow ^12.0.0
  • type-fest ~4.3.0
  • node >=16.7.0
packages/create-tsbb/package.json
  • @types/which ~3.0.0
  • execa ^8.0.0
  • fs-extra ^11.1.1
  • meow ^12.0.0
  • which ^4.0.0
  • cpy ^10.0.0
  • node >=16.7.0
packages/jest/package.json
  • @babel/plugin-proposal-decorators ^7.22.5
  • @babel/plugin-proposal-object-rest-spread ^7.20.7
  • @babel/plugin-proposal-private-property-in-object ^7.21.11
  • @babel/preset-env ^7.22.5
  • @babel/preset-react ^7.22.5
  • @babel/preset-typescript ^7.22.5
  • @types/jest ^29.5.0
  • babel-jest ^29.5.0
  • babel-plugin-parameter-decorator ^1.0.16
  • babel-preset-react-app ^10.0.1
  • camelcase ^6.3.0
  • identity-obj-proxy ^3.0.0
  • jest ^29.5.0
  • jest-environment-jsdom ^29.5.0
  • jest-environment-node ^29.5.0
  • jest-watch-typeahead ^2.2.2
  • ts-jest ^29.0.5
  • node >=16.7.0
packages/tsbb/package.json
  • node >=16.7.0
packages/typescript/package.json
  • typescript ^5.1.3
  • node >=16.7.0
  • typescript ^5.1.3

  • Check this box to trigger a request for Renovate to run again on this repository

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.