Skip to content

Commit

Permalink
test: test latest feature and document in read me
Browse files Browse the repository at this point in the history
  • Loading branch information
teclone committed Mar 3, 2019
1 parent 8961767 commit bb0a431
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 60 deletions.
25 changes: 11 additions & 14 deletions .buildrc.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
{
"srcDir": "src",

"mainModuleFileName": "main.js",

"mainModuleName": "RollupAll",

"fileExtensions": [".js"],

"fileExtensions": [
".js"
],
"exclude": [],

"include": ["*"],

"externalModules": ["fs", "path"],

"include": [
"*"
],
"externalModules": [
"fs",
"path"
],
"copyAssets": true,

"sourcemap": false,

"sourcemap": true,
"distConfig": {
"disabled": true,
"format": "iife",
"outDir": "dist"
},

"libConfig": {
"disabled": false,
"format": "cjs",
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
node_modules
.nyc_output
dist
lib
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@

Rollup-all is a lightweight, extensive and configurable npm package for building all your ESNext source codes in one parse using [rollup.js](https://rollupjs.org/guide/en).

It enables you to generate separate project [lib and dist builds](https://stackoverflow.com/questions/39553079/difference-between-lib-and-dist-folders-when-packaging-library-using-webpack) using any of the supported [rollup.js build formats](https://rollupjs.org/guide/en#big-list-of-options) including support for minified build versions.
It enables you to generate separate project [lib and dist builds](https://stackoverflow.com/questions/39553079/difference-between-lib-and-dist-folders-when-packaging-library-using-webpack) using any of the supported [rollup.js build formats](https://rollupjs.org/guide/en#big-list-of-options) including support for minification.

It allows you to configure the build process, letting you define what should be included and excluded in the build, if sourcemap should be generated, if minified or only minified versions of the build should be generated, and lots more...
It allows you to configure the build process, letting you define what should be included and excluded in the build, if sourcemap should be generated, if minified versions of the build should be generated, and lots more...

## What's New

The latest version of this project now has support for `watch` and `globals` [options](https://rollupjs.org/guide/en#big-list-of-options), and can copy asset files to any deep length.

The latest version also checks for `process.env.NODE_ENV`, and will minify build if running in production environment, ignoring config settings.

**Minified files no longer has .min extension attached, that is to say, there is no separate file created for a minified build anymore. We decided to just generate one output file, to keep things consistent.**

## Getting Started

The api call is like shown below:
Expand All @@ -42,15 +46,15 @@ To start using the module, you have to modify your project's [rollup.js config f
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import uglifier from 'rollup-plugin-uglify';
import {uglify} from 'rollup-plugin-uglify';

import rollupAll from 'rollup-all';

/**
* run all plugins and store results in an array.
* do not include the uglifier plugin here.
*/
let plugins = [
const plugins = [
resolve(),
babel({
exclude: 'node_modules/**',
Expand All @@ -65,14 +69,14 @@ let plugins = [
* or placed in the root directory,
* then specify the relative path here
*/
let configPath = '';
const configPath = '';

/**
* call the api and export the result.
* if you are not using any uglifier
* pass in null as second paramter
*/
export default rollupAll.getExports(uglifier(), plugins, configPath);
export default rollupAll.getExports(uglify(), plugins, configPath);
```

> **Note**: if you are not using any [uglifier](https://github.com/rollup/rollup/wiki/Plugins#output--prettifying) plugin, pass in `null` as the first parameter. Note also that you must execute all plugins before passing it to the api call.
Expand Down Expand Up @@ -101,8 +105,6 @@ Rollup-all uses an internal `.buildrc.json` file that defines default build conf

"uglify": false,

"uglifyOnly": false,

"interop": false,

"sourcemap": true,
Expand Down Expand Up @@ -159,9 +161,7 @@ These makes it easy to similar build options in the global section and different

- **copyAssets***: defines if asset files should be copied over during the build process. Asset files are files whose extensions are not part of the **fileExtensions** entry options.

- **uglify***: defines if the build should produce minified versions too. minified versions has `.min` attached to their output file names. When set to true, you should also supply an uglifier plugin for it to work. It ignores the option if no uglifier plugin is supplied. Default value is `false`.

- **uglifyOnly***: defines if the build should produce only minified versions. minified versions has `.min` attached to their output file names. When set to true, you should also supply an uglifier plugin for it to work. It ignores the option if no uglifier plugin is supplied. Default value is `false`. **Note that no unminified build is produced if set to true**
- **uglify***: defines if the build should be minified. **when running in production environment, this value is automatically set to true**. When set to true, you should also supply an uglifier plugin for it to work. It ignores the option if no uglifier plugin is supplied. Default value is `false`.

- **interop***: defines if the `rollup.js` interop functionality should be enabled. Defuaults to `false`.

Expand Down Expand Up @@ -222,7 +222,7 @@ These makes it easy to similar build options in the global section and different

- **Generating minified builds**

We can also generate separate minified builds for all modules during the build process. Minified builds are named with `.min` format. We can even decide to generate only minified builds. You must pass in an [uglifier plugin](https://github.com/rollup/rollup/wiki/Plugins#output--prettifying) as first parameter to the API for this to work. Below, we uglify only the `dist` build.
We can also decide to minify the build output. You must pass in an [uglifier plugin](https://github.com/rollup/rollup/wiki/Plugins#output--prettifying) as first parameter to the API for this to work. Below, we uglify only the `dist` build.

```json
{
Expand All @@ -238,6 +238,7 @@ These makes it easy to similar build options in the global section and different
- **Using the Watch option**

To run build and watch for file changes, you can create two separate npm scripts as shown below:

```json
...,
"scripts": {
Expand Down
2 changes: 0 additions & 2 deletions test/configs/.buildrc1.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

"uglify": false,

"uglifyOnly": false,

"interop": true,

"sourcemap": true,
Expand Down
2 changes: 0 additions & 2 deletions test/configs/.buildrc2.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

"uglify": false,

"uglifyOnly": false,

"interop": true,

"sourcemap": true,
Expand Down
58 changes: 29 additions & 29 deletions test/modules/Bundler.spec.js
Original file line number Diff line number Diff line change
@@ -1,109 +1,109 @@
import Bundler from '../../src/modules/Bundler.js';
import {uglify} from 'rollup-plugin-uglify';
import { uglify } from 'rollup-plugin-uglify';
import path from 'path';
import rimraf from 'rimraf';

describe('Bundler', function() {
describe('Bundler', function () {
let bundler = null;

afterEach(function() {
afterEach(function () {
bundler = new Bundler();
rimraf.sync(path.resolve(__dirname, '../../dist'));
rimraf.sync(path.resolve(__dirname, '../../lib'));
});

describe('#constructor(uglifierPlugin?, otherPlugins?, configPath?)', function() {
it(`creates a bundler instance`, function() {
describe('#constructor(uglifierPlugin?, otherPlugins?, configPath?)', function () {
it(`creates a bundler instance`, function () {
expect(new Bundler()).to.be.a('Bundler');
});

it(`can take an optional rollup uglifier plugin object as first parameter`, function() {
it(`can take an optional rollup uglifier plugin object as first parameter`, function () {
expect(new Bundler(uglify())).to.be.a('Bundler');
});

it(`can take an optional array of other plugin options as a second parameter`, function() {
it(`can take an optional array of other plugin options as a second parameter`, function () {
expect(new Bundler(null, [])).to.be.a('Bundler');
});

it(`can take an optional string path denoting the relative location of the config file to
use as athird parameter`, function() {
use as athird parameter`, function () {
expect(new Bundler(null, null, 'somedirectory/.buildrc.json')).to.be.a('Bundler');
});
});

describe('#getEntryPath(mainFileName)', function() {
it (`should inspect the path given and return the project root directory just before the
first node_modules folder`, function() {
describe('#getEntryPath(mainFileName)', function () {
it(`should inspect the path given and return the project root directory just before the
first node_modules folder`, function () {
let dirAbsPath = path.join(__dirname, '../../node_modules');
expect(bundler.getEntryPath(dirAbsPath)).to.equals(path.resolve(__dirname, '../../'));
});

it (`should inspect the path given and return the project root directory by moving backward
in search of the first package.json`, function() {
it(`should inspect the path given and return the project root directory by moving backward
in search of the first package.json`, function () {
let dirAbsPath = path.resolve(__dirname);
expect(bundler.getEntryPath(dirAbsPath)).to.equals(path.join(dirAbsPath, '../../'));
});
});

describe('#resolveRegex(patterns, regexStore)', function() {
it (`should resolve the pattern and store it inside the regexStore array`, function() {
describe('#resolveRegex(patterns, regexStore)', function () {
it(`should resolve the pattern and store it inside the regexStore array`, function () {
let store = [];
bundler.resolveRegex('*', store);
expect(store).to.be.lengthOf(1).and.to.satisfy(store => {
return store.every(regex => regex instanceof RegExp);
});
});

it (`should simply queue in the pattern into the regexStore array if it is a regex
object`, function() {
it(`should simply queue in the pattern into the regexStore array if it is a regex
object`, function () {
let store = [], regex = /.*/;
bundler.resolveRegex(regex, store);
expect(store).to.be.lengthOf(1).and.to.satisfy(store => {
return store[0] === regex;
});
});

it (`should iterate through the array and resolve each pattern if argument given is an array
of patterns`, function() {
it(`should iterate through the array and resolve each pattern if argument given is an array
of patterns`, function () {
let store = [];
bundler.resolveRegex(['*', /.*/, 'src/**/*.js'], store);
expect(store).to.be.lengthOf(3).and.to.satisfy(store => {
return store.every(regex => regex instanceof RegExp);
});
});

it (`should do nothing if parameter is not an array, string or regex pattern`, function() {
it(`should do nothing if parameter is not an array, string or regex pattern`, function () {
let store = [];
bundler.resolveRegex(null, store);
expect(store).to.be.lengthOf(0);
});
});

describe(`#getModules(modules, resolvedPath, mainModuleFileName, mainModuleName, srcPaths,
fileExtensions)`, function() {
it (`should iteratively run throw the given folder and return all modules inside it
including asset files`, function() {
fileExtensions)`, function () {
it(`should iteratively run through the given folder and return all modules inside it
including asset files`, function () {
let modules = [];
bundler.getModules(modules, path.resolve(__dirname, '../../src'), 'main.js',
'Module', [], ['.js']);
'Module', '', ['.js']);

expect(modules).to.be.lengthOf(4);
});
});

describe(`#getExternalModules(modules)`, function() {
it (`should return a map of all modules abs path plus extension`, function() {
describe(`#getExternalModules(modules)`, function () {
it(`should return a map of all modules abs path`, function () {
let modules = [];
bundler.getModules(modules, path.resolve(__dirname, '../../src'), 'main.js',
'Module', [], ['.js']);
'Module', '', ['.js']);

let externalModules = bundler.getExternalModules(modules);
expect(externalModules).to.be.lengthOf(4);
});
});

describe('#process', function() {
it(`should return array of exports when called`, function() {
describe('#process', function () {
it(`should return array of exports when called`, function () {
//with uglify
let bundler = new Bundler(uglify(), []);
expect(bundler.process()).to.be.an('array');
Expand Down
24 changes: 24 additions & 0 deletions test/modules/Util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,28 @@ describe('Util module', function() {
expect(Util.mkDirSync('')).to.be.false;
});
});

describe('.isProdEnv()', function() {
it(`should return true if NODE_ENV starts with prod, case insensitive`, function() {
process.env.NODE_ENV = 'production';
expect(Util.isProdEnv()).to.be.true;
});

it(`should return false if NODE_ENV does not start with prod`, function() {
process.env.NODE_ENV = 'Droduction';
expect(Util.isProdEnv()).to.be.false;
});
});

describe('.isDevEnv()', function() {
it(`should return true if NODE_ENV does not start with prod, case insensitive`, function() {
process.env.NODE_ENV = 'Droduction';
expect(Util.isDevEnv()).to.be.true;
});

it(`should return false if NODE_ENV does start with prod, case insensitive`, function() {
process.env.NODE_ENV = 'Production';
expect(Util.isDevEnv()).to.be.false;
});
});
});

0 comments on commit bb0a431

Please sign in to comment.