# @inward/build

> Build scripts and configuration files for LoopBack 4 modules

Latest version **5.5.0** (published 2020-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @inward/build
pnpm add @inward/build
yarn add @inward/build
bun add @inward/build
```

Provides the commands `ib-nyc`, `ib-tsc`, `ib-clean`, `ib-mocha`, `ib-eslint`, `ib-prettier`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.5.0 |
| Published | 2020-05-31 |
| First published | 2020-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 14 |
| Unpacked size | 70 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Inwio |
| Maintainers | towyuan |

## Links

- npm: https://www.npmjs.com/package/@inward/build
- Repository: https://github.com/inwio/inward
- Homepage: https://github.com/inwio/inward#readme
- Issues: https://github.com/inwio/inward/issues
- npm.io page: https://npm.io/package/@inward/build

## Dependencies (14)

- [nyc](https://npm.io/package/nyc.md) ^15.0.1
- [glob](https://npm.io/package/glob.md) ^7.1.6
- [debug](https://npm.io/package/debug.md) ^4.1.1
- [mocha](https://npm.io/package/mocha.md) ^7.2.0
- [eslint](https://npm.io/package/eslint.md) ^7.1.0
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^9.0.0
- [prettier](https://npm.io/package/prettier.md) ^2.0.5
- [typescript](https://npm.io/package/typescript.md) ^3.9.3
- [@types/node](https://npm.io/package/@types/node.md) ^14.0.6
- [cross-spawn](https://npm.io/package/cross-spawn.md) ^7.0.3
- [@types/mocha](https://npm.io/package/@types/mocha.md) ^7.0.2
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.19
- [@inward/eslint-config](https://npm.io/package/@inward/eslint-config.md) ^8.1.0

## Recent versions

- 5.5.0 (latest) — 2020-05-31

## README

# @inward/build

This module contains a set of common scripts and default configurations to build
LoopBack 4 or other TypeScript modules, including:

- ib-tsc: Use
  [`tsc`](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to
  compile typescript files
- ib-eslint: Run [`eslint`](https://typescript-eslint.io/)
- ib-prettier: Run [`prettier`](https://github.com/prettier/prettier)
- ib-mocha: Run [`mocha`](https://mochajs.org/) to execute test cases
- ib-nyc: Run [`nyc`](https://github.com/istanbuljs/nyc)

These scripts first try to locate the CLI from target project dependencies and
fall back to bundled ones in `@inward/build`.

## Basic use

To use `@inward/build` for your package:

1.  Run the following command to add `@inward/build` as a dev dependency.

`npm i @inward/build --save-dev`

2.  Configure your project package.json as follows:

```json
"scripts": {
    "build": "ib-tsc",
    "build:watch": "ib-tsc --watch",
    "clean": "ib-clean",
    "lint": "npm run prettier:check && npm run eslint",
    "lint:fix": "npm run prettier:fix && npm run eslint:fix",
    "prettier:cli": "ib-prettier \"**/*.ts\" \"**/*.js\"",
    "prettier:check": "npm run prettier:cli -- -l",
    "prettier:fix": "npm run prettier:cli -- --write",
    "eslint": "ib-eslint --report-unused-disable-directives .",
    "eslint:fix": "npm run eslint -- --fix",
    "pretest": "npm run clean && npm run build",
    "test": "ib-mocha \"dist/__tests__\"",
    "posttest": "npm run lint",
    "start": "npm run build && node .",
    "prepublishOnly": "npm run test"
  },
```

Please remember to replace `your-module-name` with the name of your module.

Now you run the scripts, such as:

- `npm run build` - Compile TypeScript files and copy resources (non `.ts`
  files) to outDir
- `npm test` - Run all mocha tests
- `npm run lint` - Run `eslint` and `prettier` on source files

3.  Override default configurations in your project

- ib-tsc

  By default, `ib-tsc` searches your project's root directory for
  `tsconfig.build.json` then `tsconfig.json`. If neither of them exists, a
  `tsconfig.json` will be created to extend from
  `@inward/build/config/tsconfig.common.json`.

  To customize the configuration:

  - Create `tsconfig.build.json` or `tsconfig.json` in your project's root
    directory

    ```json
    {
      "$schema": "http://json.schemastore.org/tsconfig",
      "extends": "@inward/build/config/tsconfig.common.json",
      "compilerOptions": {
        "outDir": "dist",
        "rootDir": "src"
      },
      "include": ["src"]
    }
    ```

  - Set options explicity for the script

    ```sh
    ib-tsc -p tsconfig.json --target es2017 --outDir dist
    ```

    For more information, see
    <https://www.typescriptlang.org/docs/handbook/compiler-options.html>.

  - The following un-official compiler options are available:

    | Option             | Description                                                                                       |
    | ------------------ | ------------------------------------------------------------------------------------------------- |
    | `--copy-resources` | Copy all non-typescript files from `src` and `test` to `outDir`, preserving their relative paths. |

4.  Run builds

```sh
npm run build
```

5.  Run code coverage reports

- `ib-nyc`

  `ib-nyc` is a simple wrapper for [`nyc`](https://github.com/istanbuljs/nyc).

  To customize the configuration:

  - Create `.nycrc` in your project's root directory

    ```json
    {
      "include": ["dist"],
      "exclude": ["dist/__tests__/"],
      "extension": [".js", ".ts"],
      "reporter": ["text", "html"],
      "exclude-after-remap": false
    }
    ```

  - Update your `package.json` scripts:

    ```json
    "precoverage": "npm test",
    "coverage": "open coverage/index.html",
    "coverage:ci": "ib-nyc report --reporter=text-lcov | coveralls",
    "test": "ib-nyc npm run mocha",
    "test:ci": "ib-nyc npm run mocha"
    ```

    `converage:ci` sets up integration with [Coveralls](https://coveralls.io/).

## A note on console logs printed by tests

We consider (console) logging from tests as a bad practice, because such logs
usually clutter the test output and make it difficult to distinguish legitimate
error messages from the noise.

By default, `ib-mocha` detects when the tests and/or the application tested have
printed console logs and fails the test run with the following message:

```
=== ATTENTION - INVALID USAGE OF CONSOLE LOGS DETECTED ===
```

If you need more information about behavior in the test, then the first choice
should be to use a better or more descriptive error assertion. If that's not
possible, then use debug statements to print additional information when
explicitly requested.

A typical situation is that a test is sending an HTTP request and the server
responds with an error code as expected. However, because the server is
configured to log failed requests, it will print a log also for requests where
the failure was expected and intentional. The solution is to configure your REST
server to suppress error messages for that specific error code only. Our
`@inward/testlab` module is providing a helper
[`createUnexpectedHttpErrorLogger`](https://github.com/inwio/inward/tree/master/packages/testlab#createUnexpectedHttpErrorLogger)
that makes this task super easy.

Alternatively, it's also possible to disable detection of console logs by
calling `ib-mocha` with `--allow-console-logs` argument.

## Contributions

- [Guidelines](https://github.com/inwio/inward/blob/master/docs/CONTRIBUTING.md)
- [Join the team](https://github.com/inwio/inward/issues/110)

## Tests

run `npm test` from the root folder.

## Contributors

See [all contributors](https://github.com/inwio/inward/graphs/contributors).

## License

MIT

---
_Source: https://npm.io/package/@inward/build · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
