An open API service indexing awesome lists of open source software.

https://github.com/messageflow/build

Quick build with Gulp
https://github.com/messageflow/build

babel build build-tool builder compile copy gulp lint minify tslint

Last synced: about 2 months ago
JSON representation

Quick build with Gulp

Awesome Lists containing this project

README

          


@messageflow/build

Quick build with Gulp



[![NPM][nodei-badge]][nodei-url]

[![Version][version-badge]][version-url]
[![Downloads][downloads-badge]][downloads-url]
[![MIT License][mit-license-badge]][mit-license-url]
[![Code of Conduct][coc-badge]][coc-url]

[![Build Status][travis-badge]][travis-url]
[![CircleCI][circleci-badge]][circleci-url]
[![Dependency Status][daviddm-badge]][daviddm-url]
[![NSP Status][nsp-badge]][nsp-url]
[![Codecov][codecov-badge]][codecov-url]
[![Coverage Status][coveralls-badge]][coveralls-url]

[![codebeat-badge]][codebeat-url]
[![codacy-badge]][codacy-url]

> Better build process with [Gulp][gulp-url] for general [Node.js][node-js-url] projects written in [TypeScript][typescript-url]. To embrace native ES modules in [Node.js][node-js-url], `@messageflow/build` allows you to build with compiling to any other module system such as `CommonJS` and also allows you to output files in the format of `.mjs`. See the [Using .mjs in Node.js][using-mjs-in-nodejs-url] section to learn how to use `.mjs` in Node.js.

## Table of contents

- [Pre-requisites](#pre-requisites)
- [Setup](#setup)
- [Install](#install)
- [Usage](#usage)
- [gulpfile.js](#gulpfilejs)
- [How to build for FOSS](#how-to-build-for-foss)
- [Using .mjs in Node.js](#using-mjs-in-nodejs)
- [API Reference](#api-reference)
- [DEFAULT_FOSS_CLEAN_GLOBS](#default_foss_clean_globs)
- [DEFAULT_IGNORE_GLOBS](#default_ignore_globs)
- [DEFAULT_BABEL_CONFIG](#default_babel_config)
- [Default FOSS configuration](#default-foss-configuration)
- [BuilderParams](#builderparams)
- [builder([options])](#builderoptions)
- [License](#license)

## Pre-requisites

- [Node.js][node-js-url] >= 8.9.0
- [NPM][npm-url] >= 5.5.1 ([NPM][npm-url] comes with [Node.js][node-js-url] so there is no need to install separately.)

## Setup

### Install

```sh
# Install via NPM as one of the `devDependencies`
$ npm install --save-dev @messageflow/build
```

### Usage

#### gulpfile.js

```js
const gulp = require('gulp');
const { builder } = require('@messageflow/build');

const build = builder();
/** `cleanGlobs` can be helpful when the destination directory is not the `dist` directory. */
// const build = builder({
// dist: '.',
// cleanGlobs: [
// './*.js',
// './*.d.ts',
// '!./gulpfile.js',
// '!./json.d.ts',
// ],
// });

gulp.task('clean', build.clean);
gulp.task('lint', build.lint);
gulp.task('copy', build.copy);
gulp.task('ts', build.ts);
gulp.task('watch', build.watch);
gulp.task('default', build.default); // or gulp.task('default', build.all);
```

#### How to build for FOSS

```js
// gulpfile.js

const gulp = require('gulp');
const builder = require('@messageflow/build').builder({ foss: true });
/** This is equivalent to */
// const builder = require('@messageflow/build').builder({
// dist: '.',
// cleanGlobs: [
// './*@(mj|j)s',
// './*.d.ts',
// '!./gulpfile.js',
// '!./json.d.ts',
// ],
// })

gulp.task('lint', builder.lint);
gulp.task('default', builder.all);
```

#### Using .mjs in Node.js

[Node.js][node-js-url] will import the correct dependencies based on the file extension you use. `.mjs` file will only import `.mjs` files.

```js
// main.mjs
import otherMod from './other-mod'; // This will import 'other-mod.mjs` but not 'other-mod.js'

// main.js
const otherMod = require('./other-mod'); // This will import 'other-mod.js' but not 'other-mod.mjs'
```

## API Reference

### DEFAULT_FOSS_CLEAN_GLOBS

```js
[
'./*.@(mj|j)s',
'./*.d.ts',
'!./gulpfile.js',
'!./json.d.ts',
]
```

### DEFAULT_IGNORE_GLOBS

```js
[
'!**/demo*/**/*.ts*',
'!**/test*/**/*.ts*',
]
```

### DEFAULT_BABEL_CONFIG

```js
{
presets: [
['@babel/preset-env', {
targets: { node: 'current' },
spec: true,
modules: false,
useBuiltIns: 'usage',
shippedProposals: true,
}],
['minify', {
replace: false,
mangle: { keepFnName: true },
removeConsole: false,
removeDebugger: true,
}],
],
}
```

### Default FOSS configuration

When `foss` is set to true, the following flags will be set to use its default values:

1. `dist` - `.`
2. `cleanGlobs` - [DEFAULT_FOSS_CLEAN_GLOBS][default-foss-clean-globs-url]

### BuilderParams

- `src` <[?string][string-mdn-url]> Optional source directory. Defaults to `src`.
- `dist` <[?string][string-mdn-url]> Optional destination directory. Defaults to `dist`.
- `cleanGlobs` <[?string][string-mdn-url]|[string][string-mdn-url][]> Optional glob patterns to clean files/ directories up before every build process initiates. **_This is required only when the destination directory is not the `dist` directory._** Defaults to the value of `dist` if unspecified.
- `copyGlobs` <[?string][string-mdn-url]|[string][string-mdn-url][]> Optional glob patterns to copy files/ directories to destination build directory. Defaults to `['/**/*.*', '!/**/*.ts*', '/**/*.d.ts']`.
- `ignoreGlobs` <[?string][string-mdn-url]|[string][string-mdn-url][]> Optional glob patterns to ignore files/ directories. Defaults to [DEFAULT_IGNORE_GLOBS][default-ignore-globs-url]. **_This only works when `isProd` is set to true._**
- `isProd` <[?boolean][boolean-mdn-url]> Optional production flage. Set to `true` if the build process is meant for production. Defaults to `process.env.NODE_ENV === 'production'`.
- `rootPath` <[?string][string-mdn-url]> Optional path to current working directory. Defaults to `.`.
- `babelConfig` <[?Object][object-mdn-url]> Optional configuration for [Babel][babel-url]. **_This is only needed when `isProd` is set to true._** Defaults to [DEFAULT_BABEL_CONFIG][default-babel-config-url].
- `tsConfig` <[?string][string-mdn-url]> Optional path to `tsconfig.json`. Defaults to `./tsconfig.json`.
- `tslintConfig` <[?string][string-mdn-url]> Optional path to `tslint.json`. Defaults to `./tslint.json`. **_This defaults to `./tslint.prod.json` when `isProd` is set to true._**
- `esModules` <[?boolean][boolean-mdn-url]> Optional ES modules flag to run compilation with native ES Modules. Defaults to `true`.
- `mjs` <[?boolean][boolean-mdn-url]> Optional flag to run compilation with native ES modules and output files in the format of `.mjs`. Defaults to `false`. **_Native ES modules will be used and will ignore any value set by `esModules` if this is set to true_**
- `foss` <[?boolean][boolean-mdn-url]> Optional flag to run compilation for [FOSS][foss-url]. Defaults to `false`. See [Default FOSS configuration][default-foss-configuration-url] to see what is being used under the hood.

___

### builder([options])

- `options` <[?BuilderParams][builderparams-url]> Optional configuration for the build process.
- returns: <[Object][object-mdn-url]> An object of build tasks to be assigned as [Gulp][gulp-url] task, e.g. `gulp.task('', )`. It comprises of a list of tasks fo a common build process with Gulp for most of the projects:

1. `clean` - Always remove old files from previous build.
2. `lint` - Always lint all `.ts` files with given `tslint.json`.
3. `ts` - Compile all `.ts` files with given `tsconfig.json`.
4. `copy` - Copy all asset files such as `images`, `json`, `md`, etc.
5. `watch` - Run the build process by watching for flle changes.
6. `default` - Default build process that comprises all the above.
7. `all` - Another default build process to compile and output in both `.js` and `.mjs`. See the [How to build for FOSS][how-to-build-for-foss-url] section to learn how to use `@messageflow/build` to build your open source [Node.js][node-js-url] package using the `{ foss: true }` shorthand.

## License

[MIT License](https://motss.mit-license.org/) © Rong Sen Ng

[typescript-url]: https://github.com/Microsoft/TypeScript
[node-js-url]: https://nodejs.org
[npm-url]: https://www.npmjs.com
[node-releases-url]: https://nodejs.org/en/download/releases
[gulp-url]: https://github.com/gulpjs/gulp
[babel-url]: https://github.com/babel/babel
[foss-url]: https://en.oxforddictionaries.com/definition/foss

[builderparams-url]: #builderparams
[default-ignore-globs-url]: #default_ignore_globs
[default-babel-config-url]: #default_babel_config
[default-foss-clean-globs-url]: #default_foss_clean_globs
[default-foss-configuration-url]: #default-foss-configuration
[using-mjs-in-nodejs-url]: #using-mjs-in-nodejs
[how-to-build-for-foss-url]: #how-to-build-for-foss

[array-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
[boolean-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[function-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
[map-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
[number-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
[object-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
[promise-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[regexp-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
[set-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
[string-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

[nodei-badge]: https://nodei.co/npm/@messageflow/build.png?downloads=true&downloadRank=true&stars=true

[version-badge]: https://img.shields.io/npm/v/@messageflow/build.svg?style=flat-square
[downloads-badge]: https://img.shields.io/npm/dm/@messageflow/build.svg?style=flat-square
[mit-license-badge]: https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square

[travis-badge]: https://img.shields.io/travis/Messageflow/build.svg?style=flat-square
[circleci-badge]: https://circleci.com/gh/Messageflow/build/tree/master.svg?style=svg
[daviddm-badge]: https://img.shields.io/david/Messageflow/build.svg?style=flat-square
[nsp-badge]: https://nodesecurity.io/orgs/messageflow/projects/4650ee88-a5b8-4474-bff4-7d55d8b2c51f/badge?style=flat-square
[codecov-badge]: https://codecov.io/gh/Messageflow/build/branch/master/graph/badge.svg?style=flat-square
[coveralls-badge]: https://coveralls.io/repos/github/Messageflow/build/badge.svg?branch=master&style=flat-square

[codebeat-badge]: https://codebeat.co/badges/ca230cdd-bdc5-4f9e-bd39-7b62d47f5fef?style=flat-square
[codacy-badge]: https://api.codacy.com/project/badge/Grade/ef8c3a98c9e649d19a67ae78f980748a

[nodei-url]: https://nodei.co/npm/@messageflow/build

[version-url]: https://www.npmjs.com/package/@messageflow/build
[downloads-url]: http://www.npmtrends.com/@messageflow/build
[mit-license-url]: https://github.com/Messageflow/build/blob/master/LICENSE
[coc-url]: https://github.com/Messageflow/build/blob/master/CODE_OF_CONDUCT.md

[travis-url]: https://travis-ci.org/Messageflow/build
[circleci-url]: https://circleci.com/gh/Messageflow/build/tree/master
[daviddm-url]: https://david-dm.org/Messageflow/build
[nsp-url]: https://nodesecurity.io/orgs/messageflow/projects/4650ee88-a5b8-4474-bff4-7d55d8b2c51f
[codecov-url]: https://codecov.io/gh/Messageflow/build
[coveralls-url]: https://coveralls.io/github/Messageflow/build?branch=master

[codebeat-url]: https://codebeat.co/projects/github-com-messageflow-build-master
[codacy-url]: https://www.codacy.com/app/Messageflow/build?utm_source=github.com&utm_medium=referral&utm_content=Messageflow/build&utm_campaign=Badge_Grade