Skip to content

Commit

Permalink
feat: implement arg parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
teclone committed Dec 10, 2019
1 parent c2e9f33 commit 1838afe
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/node_modules
/coverage
/lib
/esm
/build
/temp
17 changes: 13 additions & 4 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#!/usr/bin/env node
const args = require('args');

args.options([
{
name: 'dir',
description: 'defines the directory to locate the cjs build output',
defaultValue: '../build/cjs'
}
]);

const flags = args.parse(process.argv);
const getEntryPath = require('@forensic-js/node-utils').getEntryPath;
const loadFile = require('../lib/modules/utils').loadFile;
const Bundler = require('../lib/modules/Bundler').Bundler;
const loadFile = require(`${flags.dir}/modules/utils`).loadFile;
const Bundler = require(`${flags.dir}/modules/Bundler`).Bundler;

const entryPath = getEntryPath();

const options = loadFile(entryPath, 'rollup.config.js');

const bunder = new Bundler(options);

bunder.process();
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
"name": "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",
"main": "lib/index",
"typings": "lib/index",
"main": "build/cjs/index",
"module": "build/esm/index",
"typings": "build/cjs/index",
"bin": "./bin/index.js",
"scripts": {
"commit": "git-cz",
"test": "BABEL_ENV=test jest --runInBand",
"watch-test": "BABEL_ENV=test jest --watch --runInBand",
"prebuild": "rimraf lib esm",
"build": "tsc && BABEL_ENV=build babel src --out-dir lib --extensions .ts && node bin/index",
"lint": "eslint ./src --fix",
"prebuild": "rimraf build",
"postbuild": "rimraf temp",
"build-typings": "tsc",
"babel-build": "BABEL_ENV=build babel src --out-dir temp --extensions .ts",
"rollup-all": "node bin/index --dir ../temp",
"build": "yarn build-typings && yarn babel-build && yarn rollup-all",
"report-coverage": "jest --coverage --coverageReporters=text-lcov | coveralls",
"semantic-release": "semantic-release"
},
Expand Down Expand Up @@ -69,6 +74,8 @@
"@forensic-js/node-utils": "1.0.0",
"@forensic-js/utils": "2.9.0",
"@rollup/plugin-json": "4.0.0",
"args": "5.0.1",
"chalk": "3.0.0",
"rollup": "1.27.9",
"rollup-plugin-babel": "4.3.3",
"rollup-plugin-commonjs": "10.1.0",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const { config } = require('./lib');
module.exports = config();
module.exports = config({});
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const config: Config = {
/**
* defines output directory
*/
outDir: 'lib',
outDir: 'build/cjs',

format: 'cjs'
},
Expand All @@ -84,7 +84,7 @@ export const config: Config = {
/**
* defines output directory
*/
outDir: 'esm',
outDir: 'build/esm',

format: 'esm'
},
Expand All @@ -101,7 +101,7 @@ export const config: Config = {
/**
* defines output directory
*/
outDir: 'dist',
outDir: 'build/dist',

/**
* build format to use.
Expand Down
36 changes: 23 additions & 13 deletions src/modules/Bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import { COMMON_CONFIGS, REGEX_FIELDS } from '../constants';
import { mkDirSync, getEntryPath } from '@forensic-js/node-utils';
import { rollup } from 'rollup';
import { getRollupPlugins } from './utils';
import chalk from 'chalk';

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

const log = console.log;

class Bundler {
private entryPath: string = '';
Expand Down Expand Up @@ -255,6 +261,8 @@ class Bundler {
) {
const { assetFiles, typeDefinitionFiles, buildFiles } = moduleFiles;
if (config.enabled) {
log(chalk.yellow(`generating ${config.format} builds...\n`));

const plugins = getRollupPlugins(
this.config,
this.generalConfig,
Expand All @@ -263,24 +271,26 @@ class Bundler {
const external =
config.format === 'iife' || config.format === 'umd'
? config.externals
: () => true;
buildFiles.forEach(buildFile => {
: allExternal;
buildFiles.forEach(({ filePath, newRelativePath, oldRelativePath }) => {
promises.push(
rollup({
input: buildFile.filePath,
input: filePath,
plugins,
external
}).then(bundler =>
bundler.write({
file: path.resolve(
this.entryPath,
config.outDir,
buildFile.newRelativePath
),
format: config.format,
interop: config.interop,
sourcemap: config.sourcemap
})
bundler
.write({
file: path.resolve(
this.entryPath,
config.outDir,
newRelativePath
),
format: config.format,
interop: config.interop,
sourcemap: config.sourcemap
})
.then(returnNull)
)
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/modules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import path from 'path';
*/
export const loadFile = (entryPath: string, file: string) => {
try {
return require(path.resolve(entryPath, file)).default;
return require(path.resolve(entryPath, file));
} catch (ex) {
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"emitDeclarationOnly": true,
"noImplicitAny": false,
"downlevelIteration": true,
"outDir": "./lib",
"outDir": "./build/cjs",
"lib": ["dom", "es5", "es2015.collection", "es2015.iterable"]
},
"include": ["src"]
Expand Down
47 changes: 46 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ ansi-styles@^3.2.0, ansi-styles@^3.2.1:
dependencies:
color-convert "^1.9.0"

ansi-styles@^4.0.0:
ansi-styles@^4.0.0, ansi-styles@^4.1.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.0.tgz#5681f0dcf7ae5880a7841d8831c4724ed9cc0172"
integrity sha512-7kFQgnEaMdRtwf6uSfUnVr9gSGC7faurn+J/Mv90/W+iTtN0405/nLdopfMWwchyxhbGYl6TC4Sccn9TUkGAgg==
Expand Down Expand Up @@ -1537,6 +1537,16 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"

[email protected]:
version "5.0.1"
resolved "https://registry.yarnpkg.com/args/-/args-5.0.1.tgz#4bf298df90a4799a09521362c579278cc2fdd761"
integrity sha512-1kqmFCFsPffavQFGt8OxJdIcETti99kySRUPMpOhaGjL6mRJn8HFU1OxKY5bMqfZKUwTQc1mZkAjmGYaVOHFtQ==
dependencies:
camelcase "5.0.0"
chalk "2.4.2"
leven "2.1.0"
mri "1.1.4"

argv-formatter@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/argv-formatter/-/argv-formatter-1.0.0.tgz#a0ca0cbc29a5b73e836eebe1cbf6c5e0e4eb82f9"
Expand Down Expand Up @@ -2493,6 +2503,11 @@ camelcase-keys@^4.0.0:
map-obj "^2.0.0"
quick-lru "^1.0.0"

[email protected]:
version "5.0.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.0.0.tgz#03295527d58bd3cd4aa75363f35b2e8d97be2f42"
integrity sha512-faqwZqnWxbxn+F1d399ygeamQNy3lPp/H9H6rNrqYh4FSVCtcY+3cub1MxA8o9mDd55mM8Aghuu/kuyYA6VTsA==

camelcase@^4.0.0, camelcase@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd"
Expand Down Expand Up @@ -2542,6 +2557,14 @@ [email protected], chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

[email protected]:
version "3.0.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4"
integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
Expand Down Expand Up @@ -4195,6 +4218,11 @@ has-flag@^3.0.0:
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=

has-flag@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==

has-symbols@^1.0.0, has-symbols@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.1.tgz#9f5214758a44196c406d9bd76cebf81ec2dd31e8"
Expand Down Expand Up @@ -5493,6 +5521,11 @@ left-pad@^1.3.0:
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
integrity sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==

[email protected]:
version "2.1.0"
resolved "https://registry.yarnpkg.com/leven/-/leven-2.1.0.tgz#c2e7a9f772094dee9d34202ae8acce4687875580"
integrity sha1-wuep93IJTe6dNCAq6KzORoeHVYA=

leven@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2"
Expand Down Expand Up @@ -6149,6 +6182,11 @@ move-concurrently@^1.0.1:
rimraf "^2.5.4"
run-queue "^1.0.3"

[email protected]:
version "1.1.4"
resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.4.tgz#7cb1dd1b9b40905f1fac053abe25b6720f44744a"
integrity sha512-6y7IjGPm8AzlvoUrwAaw1tLnUBudaS3752vcd8JtrpGGQn+rXIe63LFVHm/YMwtqAuh+LJPCFdlLYPWM1nYn6w==

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
Expand Down Expand Up @@ -8515,6 +8553,13 @@ supports-color@^6.1.0:
dependencies:
has-flag "^3.0.0"

supports-color@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.1.0.tgz#68e32591df73e25ad1c4b49108a2ec507962bfd1"
integrity sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==
dependencies:
has-flag "^4.0.0"

supports-hyperlinks@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/supports-hyperlinks/-/supports-hyperlinks-1.0.1.tgz#71daedf36cc1060ac5100c351bb3da48c29c0ef7"
Expand Down

0 comments on commit 1838afe

Please sign in to comment.