Skip to content

Commit

Permalink
fix: moved to teclone namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Harrison Ifeanyichukwu authored and Harrison Ifeanyichukwu committed Mar 1, 2020
1 parent a0abfd5 commit ee741b0
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 304 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Rollup-all
# @teclone/rollup-all

[![Build Status](https://travis-ci.org/harrison-ifeanyichukwu/rollup-all.svg?branch=master)](https://travis-ci.org/harrison-ifeanyichukwu/rollup-all)
[![Coverage Status](https://coveralls.io/repos/github/harrison-ifeanyichukwu/rollup-all/badge.svg?branch=master)](https://coveralls.io/github/harrison-ifeanyichukwu/rollup-all?branch=master)
[![Build Status](https://travis-ci.org/teclone/rollup-all.svg?branch=master)](https://travis-ci.org/teclone/rollup-all)
[![Coverage Status](https://coveralls.io/repos/github/teclone/rollup-all/badge.svg?branch=master)](https://coveralls.io/github/teclone/rollup-all?branch=master)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![npm version](https://badge.fury.io/js/rollup-all.svg)](https://badge.fury.io/js/rollup-all)
![npm](https://img.shields.io/npm/dt/rollup-all.svg)
[![npm version](https://badge.fury.io/js/%40teclone%2Frollup-all.svg)](https://badge.fury.io/js/%40teclone%2Frollup-all)
![npm](https://img.shields.io/npm/dt/%40teclone%2Frollup-all.svg)

## Overview

Rollup-all is an out of the box package for building all your shiny Javascript/Typescript library source codes in one parsing, allowing you to generate commonjs, es module, and browser builds at once. It is very configurable and runs asynchronously.
**@teclone/rollup-all** is an out of the box package for building all your shiny Javascript/Typescript library source codes in one parsing, allowing you to generate commonjs, es module, and browser builds at once. It is very configurable and runs asynchronously.

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, if **asset and type definition files** should be copied over, and lots more...

Expand All @@ -17,15 +17,15 @@ It comes with all needed configurations already done for you, including support
## Getting Started

```bash
npm install --save-dev rollup-all
npm install --save-dev @teclone/rollup-all
```

Next, add the build script to your package.json file

```json
{
"scripts": {
"build": "rollup-all"
"build": "@teclone/rollup-all"
}
}
```
Expand All @@ -36,7 +36,7 @@ In case you need to do some other configurations, such as passing extra babel pr
a `rollup.config.js` file at the root of your project. Like shown below:

```typescript
const { config } = require('rollup-all');
const { config } = require('@teclone/rollup-all');
module.exports = config(options);
```

Expand Down
10 changes: 5 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ args.options([
{
name: 'dir',
description: 'defines the directory to locate the cjs build output',
defaultValue: '../build'
defaultValue: '../build',
},
{
name: 'silent',
description: 'defines if build output logs should be sent to the console',
defaultValue: true
}
defaultValue: true,
},
]);

const flags = args.parse(process.argv);
const getEntryPath = require('@forensic-js/node-utils').getEntryPath;
const getEntryPath = require('@teclone/node-utils').getEntryPath;

const loadFile = require(`${flags.dir}/modules/utils`).loadFile;
const Bundler = require(`${flags.dir}/modules/Bundler`).Bundler;
Expand All @@ -25,6 +25,6 @@ const entryPath = getEntryPath();
const options = loadFile(entryPath, 'rollup.config.js');

const bunder = new Bundler(options, {
generateOutputLogs: flags.silent
generateOutputLogs: flags.silent,
});
bunder.process();
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "rollup-all",
"name": "@teclone/rollup-all",
"version": "0.0.0-development",
"description": "A lightweight, extensive and configurable npm package for building all your ES6 source codes in one parse using rollup",
"publishConfig": {
"access": "public"
},
"main": "build/index",
"module": "build/esm/index",
"typings": "build/index",
Expand All @@ -22,7 +25,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/harrison-ifeanyichukwu/rollup-all.git"
"url": "https://github.com/teclone/rollup-all.git"
},
"keywords": [
"rollup",
Expand All @@ -38,9 +41,9 @@
"author": "Harrison Ifeanyichukwu <Harrisonifeanyichukwu@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/harrison-ifeanyichukwu/rollup-all/issues"
"url": "https://github.com/teclone/rollup-all/issues"
},
"homepage": "https://github.com/harrison-ifeanyichukwu/rollup-all#readme",
"homepage": "https://github.com/teclone/rollup-all#readme",
"devDependencies": {
"@babel/cli": "7.7.5",
"@types/jest": "24.0.23",
Expand All @@ -52,7 +55,7 @@
"cz-conventional-changelog": "3.0.2",
"jest": "24.9.0",
"rimraf": "3.0.0",
"semantic-release": "^15.13.24",
"semantic-release": "^17.0.4",
"semantic-release-cli": "5.2.3",
"typescript": "3.7.3"
},
Expand All @@ -71,11 +74,11 @@
"@babel/preset-env": "7.7.6",
"@babel/preset-typescript": "7.7.4",
"@babel/runtime": "7.7.6",
"@forensic-js/node-utils": "1.0.2",
"@forensic-js/utils": "2.9.0",
"@rollup/plugin-commonjs": "11.0.1",
"@rollup/plugin-json": "4.0.0",
"@rollup/plugin-node-resolve": "7.0.0",
"@teclone/node-utils": "1.0.4",
"@teclone/utils": "2.14.3",
"args": "5.0.1",
"chalk": "3.0.0",
"rollup": "1.27.9",
Expand Down
71 changes: 26 additions & 45 deletions src/modules/Bundler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import * as fs from 'fs';
import { copy, isString, camelCase } from '@forensic-js/utils';
import { copy, isString, camelCase } from '@teclone/utils';
import {
Config,
UserConfig,
Expand All @@ -11,17 +11,16 @@ import {
ESMConfig,
ModuleFiles,
GeneralConfig,
BundlerOptions
BundlerOptions,
} from '../@types';
import { config as defualtConfig } from '../config';
import { COMMON_CONFIGS, REGEX_FIELDS } from '../constants';
import { mkDirSync, getEntryPath } from '@forensic-js/node-utils';
import { mkDirSync, getEntryPath } from '@teclone/node-utils';
import { rollup } from 'rollup';
import { getRollupPlugins } from './utils';
import chalk from 'chalk';

const allExternal = () => true;
const returnNull = () => null;

const log = console.log;

Expand All @@ -38,17 +37,11 @@ class Bundler {
* @param plugins array of extra plugins to be applied
* @param config path to user defined build config or the user defined config object
*/
constructor(
generalConfig: GeneralConfig = {},
bundlerOptions: BundlerOptions
) {
constructor(generalConfig: GeneralConfig = {}, bundlerOptions: BundlerOptions) {
this.entryPath = getEntryPath();
this.generalConfig = generalConfig;

this.config = this.resolveConfig(
this.entryPath,
generalConfig.config ?? {}
);
this.config = this.resolveConfig(this.entryPath, generalConfig.config ?? {});

this.bundlerOptions = bundlerOptions;
}
Expand Down Expand Up @@ -88,7 +81,7 @@ class Bundler {
private mergeConfig(
prop: keyof CommonConfig,
config: Config,
target: CJSConfig | ESMConfig | DistConfig
target: CJSConfig | ESMConfig | DistConfig,
) {
const configValue = config[prop];
const targetValue = target[prop];
Expand Down Expand Up @@ -171,7 +164,7 @@ class Bundler {
entryFile: string,
moduleName: string,
currentRelativeDir: string,
extensions: string[]
extensions: string[],
): Promise<Module[]> {
return new Promise((resolve, reject) => {
fs.readdir(resolvedPath, (err, files) => {
Expand All @@ -190,21 +183,17 @@ class Bundler {
entryFile,
moduleName,
path.join(currentRelativeDir, file),
extensions
)
extensions,
),
);
} else {
const firstDotPos =
file.charAt(0) === '.' ? file.indexOf('.', 1) : file.indexOf('.');
const baseName =
firstDotPos > -1 ? file.substring(0, firstDotPos) : file;
const baseName = firstDotPos > -1 ? file.substring(0, firstDotPos) : file;
const extname = firstDotPos > -1 ? file.substring(firstDotPos) : '';

const oldRelativePath = path.join(currentRelativeDir, file);
const newRelativePath = path.join(
currentRelativeDir,
baseName + '.js'
);
const newRelativePath = path.join(currentRelativeDir, baseName + '.js');

modules.push({
id: modules.length + 1,
Expand All @@ -213,7 +202,7 @@ class Bundler {
newRelativePath,
filePath,
name: oldRelativePath === entryFile ? moduleName : baseName,
isBuildFile: extensions.includes(extname)
isBuildFile: extensions.includes(extname),
});
}
}
Expand All @@ -232,13 +221,13 @@ class Bundler {
config.entryFile,
config.moduleName,
'',
config.extensions
config.extensions,
);

const result: ModuleFiles = {
assetFiles: [],
buildFiles: [],
typeDefinitionFiles: []
typeDefinitionFiles: [],
};

let src = '';
Expand Down Expand Up @@ -276,7 +265,7 @@ class Bundler {
async runBuild(
promises: Promise<any>[],
moduleFiles: ModuleFiles,
config: DistConfig | CJSConfig | ESMConfig
config: DistConfig | CJSConfig | ESMConfig,
) {
const { assetFiles, typeDefinitionFiles, buildFiles } = moduleFiles;
if (config.enabled) {
Expand All @@ -285,7 +274,7 @@ class Bundler {
const plugins = getRollupPlugins(
this.config,
this.generalConfig,
config.format === 'esm'
config.format === 'esm',
);
const external =
config.format === 'iife' || config.format === 'umd'
Expand All @@ -297,28 +286,24 @@ class Bundler {
const bundler = await rollup({
input: filePath,
plugins,
external
external,
});

const out = path.resolve(
this.entryPath,
config.outDir,
newRelativePath
);
const out = path.resolve(this.entryPath, config.outDir, newRelativePath);
promises.push(
bundler
.write({
file: out,
format: config.format,
interop: config.interop,
sourcemap: config.sourcemap
sourcemap: config.sourcemap,
})
.then(() => {
if (this.bundlerOptions.generateOutputLogs) {
log(chalk.green(`${oldRelativePath} ... ${out} \n`));
}
})
.catch(this.handleErrors)
.catch(this.handleErrors),
);
} catch (ex) {
console.log(ex.message);
Expand All @@ -329,12 +314,8 @@ class Bundler {
promises.push(
this.copyFile(
assetFile.filePath,
path.resolve(
this.entryPath,
config.outDir,
assetFile.oldRelativePath
)
)
path.resolve(this.entryPath, config.outDir, assetFile.oldRelativePath),
),
);
});

Expand All @@ -345,9 +326,9 @@ class Bundler {
path.resolve(
this.entryPath,
config.outDir,
typeDefinitionFile.oldRelativePath
)
)
typeDefinitionFile.oldRelativePath,
),
),
);
});
}
Expand All @@ -360,7 +341,7 @@ class Bundler {
*/
async processModule(
moduleFiles: ModuleFiles,
config: CJSConfig | ESMConfig | DistConfig
config: CJSConfig | ESMConfig | DistConfig,
) {
let promises: Promise<any>[] = [];
await this.runBuild(promises, moduleFiles, config);
Expand Down
Loading

0 comments on commit ee741b0

Please sign in to comment.