Skip to content

Commit

Permalink
build scripts cleanups and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojz committed Aug 27, 2017
1 parent 7805680 commit 058f4df
Show file tree
Hide file tree
Showing 38 changed files with 276 additions and 272 deletions.
11 changes: 2 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,10 @@ coverage
.npm
.node_repl_history

/dist
/docs
/site/public/**/otplib.*
!/site/public/otplib.png
/site/public/docs/*
/site/dist
/dist
/classes
/core
/impl
/utils
/site/public/docs/*

/authenticator.js
/core.js
Expand All @@ -49,5 +43,4 @@ coverage
/otplib.js
/totp.js
/utils.js
/v2.js
/lib-test.js
28 changes: 14 additions & 14 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
.DS_Store
src
coverage
tests
site
node_modules
node_modules-*

/docs
.nyc_output
.babelrc
.editorconfig
.eslintignore
.eslintrc.json
.nyc_output
.nycrc
.travis.yml
/build-page.sh
circle.yml
jsdoc.json
webpack.config.js
/webpack.config.js

/docs
/lib-test.js
/packages
/rollup.config.js
/scripts
/site
/webpack.config.js

circle.yml
coverage
jsdoc.json
node_modules
node_modules-*
src
tests
webpack.config.js
2 changes: 2 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ deployment:
commands:
- yarn run clean
- yarn run build
- cd dist
- echo -e "$NPM_USER\n$NPM_PASS\n$NPM_EMAIL" | npm login
- npm publish
- npm logout
- cd ..
- git config --global user.email $CI_DEPLOY_EMAIL
- git config --global user.name $CI_DEPLOY_NAME
- yarn deploy-gh-pages
2 changes: 1 addition & 1 deletion jsdoc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"include": ["src", "README.md", "package.json"],
"include": ["packages", "README.md", "package.json"],
"includePattern": ".+\\.js(doc|x)?$",
"excludePattern": "(node_modules/|docs)"
},
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
"description": "HMAC-based (HOTP) and Time-based (TOTP) One-Time Password library",
"main": "otplib.js",
"scripts": {
"build": "npm run build:module && npm run build:browser",
"build:module": "node ./scripts/build.js",
"build:browser": "webpack --config ./scripts/webpack.config.js",
"build": "npm run build:module && npm run build:browser && npm run build:pkg",
"build:browser": "webpack --config ./scripts/builds/webpack.config.js",
"build:docs": "jsdoc --configure jsdoc.json --verbose",
"build:site": "cross-env BUILD_FOLDER=./site/dist/lib npm run build:dist",
"clean": "rimraf core classes impl utils coverage .nyc_output docs",
"build:module": "node ./scripts/builds/node.js",
"build:pkg": "cp ./{README.md,package.json,yarn.lock,.npmignore} ./dist",
"clean": "npm run clean:folders && npm run clean:builds",
"clean:builds": "rimraf otplib.js otplib-browser.js browser.js core.js totp.js hotp.js utils.js authenticator.js",
"clean:folders": "rimraf coverage .nyc_output docs",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"deploy-gh-pages": "./scripts/build-page.sh",
"deploy-gh-pages": "./scripts/builds/page.sh",
"lint": "eslint --ext js src",
"test": "jest --coverage",
"test:watch": "jest --coverage --watch"
Expand Down
2 changes: 0 additions & 2 deletions packages/otplib-authenticator/Authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const TOTP = totp.TOTP;
* @module otplib-authenticator/Authenticator
* @extends {TOTP}
* @since 3.0.0
* @author Gerald Yeo
* @license MIT
*/
class Authenticator extends TOTP {

Expand Down
9 changes: 9 additions & 0 deletions packages/otplib-authenticator/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
import Authenticator from './Authenticator';

/**
* Instance of Authenticator
*
* Google Authenticator library
*
* @module otplib-authenticator
* @since 3.0.0
*/
export default new Authenticator();
5 changes: 5 additions & 0 deletions packages/otplib-browser/crypto.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import createHmac from 'create-hmac/browser';
import randomBytes from './randomBytes';

/**
* Crypto replacement for browser
*
* @module otplib-browser/crypto
*/
export default {
createHmac,
randomBytes
Expand Down
5 changes: 2 additions & 3 deletions packages/otplib-browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import crypto from './crypto';
*
* One-Time Password Library for browser
*
* @module otplib-browser
* @since 3.0.0
* @author Gerald Yeo
* @license MIT
*/
authenticator.options = {crypto}
hotp.options = {crypto}
totp.options = {crypto}

export default {
module.exports = {
Authenticator: authenticator.Authenticator,
HOTP: hotp.HOTP,
TOTP: totp.TOTP,
Expand Down
8 changes: 8 additions & 0 deletions packages/otplib-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import totpOptions from './totpOptions';
import totpSecret from './totpSecret';
import totpToken from './totpToken';

/**
* otplib-core
*
* One-Time Password Library Core Methods
*
* @module otplib-core
* @since 6.0.0
*/
export {
hotpCheck,
hotpCounter,
Expand Down
2 changes: 0 additions & 2 deletions packages/otplib-hotp/HOTP.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import {hotpCheck, hotpToken} from 'otplib-core';
* @class HOTP
* @module otplib-hotp/HOTP
* @since 3.0.0
* @author Gerald Yeo
* @license MIT
*/
class HOTP {

Expand Down
2 changes: 0 additions & 2 deletions packages/otplib-hotp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import HOTP from './HOTP';
*
* @module otplib-hotp
* @since 3.0.0
* @author Gerald Yeo
* @license MIT
*/
export default new HOTP();

2 changes: 0 additions & 2 deletions packages/otplib-totp/TOTP.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const HOTP = hotp.HOTP;
* @module otplib-totp/TOTP
* @extends {HOTP}
* @since 3.0.0
* @author Gerald Yeo
* @license MIT
*/
class TOTP extends HOTP {

Expand Down
2 changes: 0 additions & 2 deletions packages/otplib-totp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ import TOTP from './TOTP';
*
* @module otplib-totp
* @since 3.0.0
* @author Gerald Yeo
* @license MIT
*/
export default new TOTP();
8 changes: 8 additions & 0 deletions packages/otplib-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import secretKey from './secretKey';
import setsOf from './setsOf';
import stringToHex from './stringToHex';

/**
* otplib-utils
*
* One-Time Password Library Utilities
*
* @module otplib-utils
* @since 6.0.0
*/
export {
hexToInt,
intToHex,
Expand Down
2 changes: 0 additions & 2 deletions packages/otplib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import crypto from 'crypto';
*
* @module otplib
* @since 3.0.0
* @author Gerald Yeo
* @license MIT
*/
authenticator.options = {crypto}
hotp.options = {crypto}
Expand Down
12 changes: 12 additions & 0 deletions scripts/aliases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const path = require('path');
const directory = require('./directory');
const packages = require('./packages');

function aliases() {
return Object.keys(packages).reduce((accum, name) => {
accum[name] = path.join(directory.SOURCE, name, 'index.js');
return accum;
}, {});
}

module.exports = aliases();
31 changes: 0 additions & 31 deletions scripts/build.js

This file was deleted.

6 changes: 0 additions & 6 deletions scripts/buildPage.sh

This file was deleted.

17 changes: 17 additions & 0 deletions scripts/builds/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*eslint-disable no-console*/
const createModule = require('../createModule');
const pack = require('../pack');
const packages = require('../packages');

const PACKAGE_NAMES = Object.keys(packages);

// CommonJS Packages
PACKAGE_NAMES.forEach(name => {
const pkgConfig = packages[name];

// Default derive filename from the package folder
const filename = name.replace('otplib-', '') + '.js';

console.log('building...', filename);
pack(createModule(name, pkgConfig, filename));
});
12 changes: 12 additions & 0 deletions scripts/builds/page.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generate file dependants
yarn run build:browser;
yarn run build:docs;

# Build within site directory
cd site;
yarn install;
yarn run clean
yarn run build;
# yarn run deploy

cd ..
20 changes: 10 additions & 10 deletions scripts/webpack.config.js → scripts/builds/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
const path = require('path');
const webpack = require('webpack');
const directory = require('./directory');
const packages = require('./packages');

const ENV = process.env.NODE_ENV;
const aliases = require('../aliases');
const createBanner = require('../createBanner');
const directory = require('../directory');

const aliases = Object.keys(packages).reduce((accum, name) => {
accum[name] = path.join(directory.SOURCE, name, 'index.js');
return accum;
}, {});
const ENV = process.env.NODE_ENV;

module.exports = {
entry: {
Expand All @@ -17,8 +13,8 @@ module.exports = {
output: {
library: '[name]',
libraryTarget: 'umd',
path: directory.TARGET,
filename: 'browser.js'
path: directory.BUILD,
filename: 'otplib-browser.js'
},
module: {
rules: [{
Expand All @@ -40,6 +36,10 @@ module.exports = {
compress: {
warnings: false
}
}),
new webpack.BannerPlugin({
banner: createBanner('otplib-browser'),
raw: true
})
],
devtool: 'cheap-module-source-map',
Expand Down
13 changes: 13 additions & 0 deletions scripts/createBanner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const pkg = require('../package.json');

function createBanner(name) {
return `/**
* ${name}
*
* @author Gerald Yeo
* @version: ${pkg.version}
* @license: MIT
**/`
}

module.exports = createBanner;
Loading

0 comments on commit 058f4df

Please sign in to comment.