Skip to content

Commit

Permalink
* Fix CDN release, setting webpack output as UMD with default library…
Browse files Browse the repository at this point in the history
… name of SimpleCrypto.

* CDN now have two file you may use, the distribution file and minified distribution one.
  • Loading branch information
Danang Galuh Tegar Prasetyo committed Aug 5, 2019
1 parent e02c6be commit dcf75e0
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/danang.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Changes Log (What's New)

**What's New in 2.2.0**

* Fix CDN release, setting webpack output as UMD with default library name of SimpleCrypto.
* CDN now have two file you may use, the distribution file and minified distribution one.

**What's New in 2.1.3**

* Fix jsDelivr link

**What's New in 2.1.2**

* Update missing file in NPM release.

**What's New in 2.1.0**

* Update dependency.
* Fix missing web bundler as distribution build tool for the Web (using webpack).
* Use of partial import instead of full import to minimise the size of distributed build file .

**What's New in 2.0.2**

* Bugs fixed.
* Remove gulp.

**What's New in 2.0.1**

* Add coverage service.

**What's New in 2.0.0**

* Using only these functions to encrypt or decrypt: `encrypt()` and `decrypt()` (accepts string, object, number, or boolean data type). Function `encryptObject()` and `decryptObject()` is in deprecation as these functions are enough.
* Securing instance's properties from public access. Access to instance properties, like `instance.secret`, is not allowed anymore.
* New TypeScript definition file of this library is now available.
* Fixed documentation (typos, diction, etc).
* For contributor: Using `mocha`, `chai` and `coveralls` to create full unit-testing of the library. You could see testing result on top of this README.
* For contributor: Using `gulp` to compile the TypeScript source code into JavaScript ES5.

**What's New in 1.0.0**

* Initial release
33 changes: 4 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,12 @@

## Changes Log (What's New)

**What's New in 2.1.3**
**What's New in 2.2.0**

* Fix jsDelivr link
* Fix CDN release, setting webpack output as UMD with default library name of SimpleCrypto.
* CDN now have two file you may use, the distribution file and minified distribution one.

**Included from 2.1.2**

* Update missing file in NPM release

**Included from 2.1.0**

* Update dependency
* Fix missing web bundler as distribution build tool for the Web (using webpack)
* Use of partial import instead of full import to minimise the size of distributed build file

**Included from 2.0.2**

* Bugs fixed
* Remove gulp

**Included from 2.0.1**

* Add coverage service

**Included from 2.0.0**

* Using only these functions to encrypt or decrypt: `encrypt()` and `decrypt()` (accepts string, object, number, or boolean data type). Function `encryptObject()` and `decryptObject()` is in deprecation as these functions are enough.
* Securing instance's properties from public access. Access to instance properties, like `instance.secret`, is not allowed anymore.
* New TypeScript definition file of this library is now available.
* Fixed documentation (typos, diction, etc).
* For contributor: Using `mocha`, `chai` and `coveralls` to create full unit-testing of the library. You could see testing result on top of this README.
* For contributor: Using `gulp` to compile the TypeScript source code into JavaScript ES5.
For full changelog, please refers to [CHANGELOG](CHANGELOG.md) file.

## Getting Started

Expand Down
57 changes: 51 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-crypto-js",
"version": "2.1.3",
"version": "2.2.0",
"description": "Simplify AES encryption and decryption of any JavaScript objects, implementing crypto-js library.",
"repository": "https://github.com/danang-id/simple-crypto-js.git",
"homepage": "https://github.com/danang-id/simple-crypto-js",
Expand All @@ -13,7 +13,7 @@
],
"scripts": {
"build": "tsc -p tsconfig.json",
"dist": "webpack --config webpack.config.js",
"dist": "webpack --config webpack.config.js && ts-node scripts/minify.ts",
"test": "cross-env NODE_ENV=test nyc mocha 'test/**/*.test.ts'",
"test:watch": "cross-env NODE_ENV=test nyc mocha --watch 'test/**/*.test.ts'",
"coverage": "cross-env NODE_ENV=test nyc report --reporter=text-lcov | coveralls"
Expand All @@ -26,6 +26,8 @@
"@types/chai": "^4.1.7",
"@types/crypto-js": "^3.1.43",
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"@types/uglify-js": "^3.0.4",
"chai": "^4.1.2",
"coveralls": "^3.0.5",
"cross-env": "^5.2.0",
Expand All @@ -34,6 +36,8 @@
"ts-loader": "^6.0.4",
"ts-node": "^6.2.0",
"typescript": "^2.9.2",
"uglify-js": "^3.6.0",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6"
}
Expand Down
42 changes: 42 additions & 0 deletions scripts/minify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fs from 'fs';
import path from 'path';
import UglifyJS from 'uglify-js';

const distFileLocation: fs.PathLike = path.join(__dirname, '..', 'dist', 'SimpleCrypto.js');
const minifiedDistFileLocation: fs.PathLike = path.join(__dirname, '..', 'dist', 'SimpleCrypto.min.js');

const options: UglifyJS.MinifyOptions = {
toplevel: true,
ie8: true,
output: {
beautify: false,
shebang: false,
preamble: `/**
* MIT License
*
* Copyright (c) 2017 Danang Galuh Tegar Prasetyo
* -------------------------------------
*/
`
}
};

try {
let distFileContent = fs.readFileSync(distFileLocation, 'utf-8');
const result: UglifyJS.MinifyOutput = UglifyJS.minify(distFileContent, options);
if (result.error) {
console.log(result.error);
process.exit(2);
}
distFileContent = distFileContent.concat(options.output.preamble);
const minifiedDistFileContent = result.code;
fs.writeFileSync(distFileLocation, distFileContent, {
encoding: 'utf-8'
});
fs.writeFileSync(minifiedDistFileLocation, minifiedDistFileContent, {
encoding: 'utf-8'
});
} catch (error) {
console.log(error);
process.exit(1);
}
4 changes: 3 additions & 1 deletion src/SimpleCrypto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { lib, PBKDF2, AES, pad, mode, enc } from 'crypto-js';
import { WordArray, Encoder } from 'crypto-js';

export default class SimpleCrypto {
export class SimpleCrypto {

private _secret: string;
private readonly _keySize: number;
Expand Down Expand Up @@ -89,3 +89,5 @@ export default class SimpleCrypto {
}

}

export default SimpleCrypto;
2 changes: 1 addition & 1 deletion test/Cryptographic.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chai from "chai";
import chai from "chai";

import SimpleCrypto from "../src/SimpleCrypto";

Expand Down
2 changes: 1 addition & 1 deletion test/RandomGenerator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chai from "chai";
import chai from "chai";

import SimpleCrypto from "../src/SimpleCrypto";

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"noImplicitAny": true,
"sourceMap": true,
"declaration": true,
"outDir": "build"
"outDir": "build",
"esModuleInterop": true
},
"include": [
"src/**/*.ts"
Expand Down
11 changes: 8 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ const path = require('path');

module.exports = {
entry: './src/SimpleCrypto.ts',
devtool: 'inline-source-map',
mode: 'production',
optimization: {
minimize: false
},
module: {
rules: [
{
Expand All @@ -17,7 +19,10 @@ module.exports = {
extensions: [ '.tsx', '.ts', '.js' ]
},
output: {
filename: 'SimpleCrypto.min.js',
path: path.resolve(__dirname, 'dist')
filename: 'SimpleCrypto.js',
path: path.resolve(__dirname, 'dist'),
library: 'SimpleCrypto',
libraryExport: 'SimpleCrypto',
libraryTarget: 'umd',
}
};

0 comments on commit dcf75e0

Please sign in to comment.