diff --git a/.idea/dictionaries/danang.xml b/.idea/dictionaries/danang.xml index 8e69b41..865cf9c 100644 --- a/.idea/dictionaries/danang.xml +++ b/.idea/dictionaries/danang.xml @@ -3,7 +3,9 @@ brix bundler + classnames delivr + fnames \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2b1f89f --- /dev/null +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 38a0600..b0db0ac 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 7a70706..9b23da3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "simple-crypto-js", - "version": "2.0.2", + "version": "2.1.4", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -135,6 +135,29 @@ "integrity": "sha512-NYrtPht0wGzhwe9+/idPaBB+TqkY9AhTvOLMkThm0IoEfLaiVQZwBwyJ5puCkO3AUCWrmcoePjp2mbFocKy4SQ==", "dev": true }, + "@types/node": { + "version": "12.6.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.6.9.tgz", + "integrity": "sha512-+YB9FtyxXGyD54p8rXwWaN1EWEyar5L58GlGWgtH2I9rGmLGBQcw63+0jw+ujqVavNuO47S1ByAjm9zdHMnskw==", + "dev": true + }, + "@types/uglify-js": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-3.0.4.tgz", + "integrity": "sha512-SudIN9TRJ+v8g5pTG8RRCqfqTMNqgWCKKd3vtynhGzkIIjxaicNAMuY5TRadJ6tzDu3Dotf3ngaMILtmOdmWEQ==", + "dev": true, + "requires": { + "source-map": "^0.6.1" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, "@webassemblyjs/ast": { "version": "1.8.5", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.8.5.tgz", @@ -5159,7 +5182,6 @@ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", "dev": true, - "optional": true, "requires": { "commander": "~2.20.0", "source-map": "~0.6.1" @@ -5169,15 +5191,38 @@ "version": "2.20.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", - "dev": true, - "optional": true + "dev": true }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, - "optional": true + "dev": true + } + } + }, + "uglifyjs-webpack-plugin": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-2.2.0.tgz", + "integrity": "sha512-mHSkufBmBuJ+KHQhv5H0MXijtsoA1lynJt1lXOaotja8/I0pR4L9oGaPIZw+bQBOFittXZg9OC1sXSGO9D9ZYg==", + "dev": true, + "requires": { + "cacache": "^12.0.2", + "find-cache-dir": "^2.1.0", + "is-wsl": "^1.1.0", + "schema-utils": "^1.0.0", + "serialize-javascript": "^1.7.0", + "source-map": "^0.6.1", + "uglify-js": "^3.6.0", + "webpack-sources": "^1.4.0", + "worker-farm": "^1.7.0" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true } } }, diff --git a/package.json b/package.json index 9dccf06..9c5b3ae 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" @@ -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", @@ -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" } diff --git a/scripts/minify.ts b/scripts/minify.ts new file mode 100644 index 0000000..ae3c7b7 --- /dev/null +++ b/scripts/minify.ts @@ -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); +} diff --git a/src/SimpleCrypto.ts b/src/SimpleCrypto.ts index 4ea326e..99ac3d2 100644 --- a/src/SimpleCrypto.ts +++ b/src/SimpleCrypto.ts @@ -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; @@ -89,3 +89,5 @@ export default class SimpleCrypto { } } + +export default SimpleCrypto; diff --git a/test/Cryptographic.test.ts b/test/Cryptographic.test.ts index f5e9607..8409776 100644 --- a/test/Cryptographic.test.ts +++ b/test/Cryptographic.test.ts @@ -1,4 +1,4 @@ -import * as chai from "chai"; +import chai from "chai"; import SimpleCrypto from "../src/SimpleCrypto"; diff --git a/test/RandomGenerator.test.ts b/test/RandomGenerator.test.ts index c3c0915..8e2851e 100644 --- a/test/RandomGenerator.test.ts +++ b/test/RandomGenerator.test.ts @@ -1,4 +1,4 @@ -import * as chai from "chai"; +import chai from "chai"; import SimpleCrypto from "../src/SimpleCrypto"; diff --git a/tsconfig.json b/tsconfig.json index de3947c..718f2dd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "noImplicitAny": true, "sourceMap": true, "declaration": true, - "outDir": "build" + "outDir": "build", + "esModuleInterop": true }, "include": [ "src/**/*.ts" diff --git a/webpack.config.js b/webpack.config.js index 9353cb6..01bd890 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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: [ { @@ -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', } };