Skip to content

Commit

Permalink
build library with rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
dpronin committed Dec 20, 2017
1 parent 47f02a5 commit 75d6238
Show file tree
Hide file tree
Showing 13 changed files with 15,533 additions and 15,273 deletions.
3,676 changes: 1 addition & 3,675 deletions bin/jsencrypt.js

Large diffs are not rendered by default.

73 changes: 0 additions & 73 deletions bin/jsencrypt.min.js

This file was deleted.

31 changes: 26 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var tslint = require('gulp-tslint');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var insert = require('gulp-insert');
var gulpCopy = require('gulp-copy');
var wrap = require('gulp-wrap');

var files = [
Expand All @@ -23,7 +24,8 @@ var files = [
];

var lintFiles = [
'src/jsencrypt.js'
'src/*.ts',
'lib/*/**.ts'
];

var licenses = [
Expand All @@ -33,11 +35,17 @@ var licenses = [
'lib/asn1js/LICENSE.txt'
];

var libs_for_test = [
"node_modules/mocha/mocha.css",
"node_modules/expect.js/index.js",
"node_modules/mocha/mocha.js"

]

gulp.task('lint', function () {
return gulp.src(lintFiles)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
.pipe(tslint({}))
.pipe(tslint.report({ summarizeFailureOutput: true }));
});

gulp.task('license', function() {
Expand All @@ -60,5 +68,18 @@ gulp.task('scripts', function() {
.pipe(gulp.dest('bin'));
});


gulp.task('assemble', function () {

});

gulp.task('prepare_test', function() {
return gulp
.src(libs_for_test)
.pipe(gulpCopy("test/libs/", { prefix: 2}));

});


gulp.task('build', ['lint', 'scripts', 'license']);
gulp.task('default', ['build']);
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
"expect.js": "^0.3.1",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.0",
"gulp-copy": "^1.0.1",
"gulp-eslint": "^2.0.0",
"gulp-insert": "^0.5.0",
"gulp-rename": "^1.2.2",
"gulp-tslint": "^8.1.2",
"gulp-uglify": "^1.5.3",
"gulp-watch": "^4.3.5",
"gulp-wrap": "^0.11.0",
Expand Down
81 changes: 41 additions & 40 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
"use strict";
const path = require('path');
const rollup = require('rollup');
const resolve = require('rollup-plugin-node-resolve');
const uglify = require('rollup-plugin-uglify');
const pkg = require('./package.json');

var plugins = [
resolve(),
uglify({
mangle: true,
warnings: true,
output: {
beautify: false,
},
compress: {
join_vars: true,
if_return: true,
properties: true,
conditionals: true,
warnings: true,
dead_code: true,
drop_console: true,
drop_debugger: true,
}
})
];


const entries = {
'src/JSEncrypt': {file: 'bin/jsencrypt.bundle', name: 'jsencrypt'},
'test/test.rsa': {file: 'test/test.rsa.bundle', name: 'rsaTest'}
};
for (let entry in entries) {
console.log(`processing ${entry}.js`);
rollup.rollup({
input: path.join(__dirname, `${entry}.js`),
plugins: [
resolve(),
uglify({
mangle: true,
warnings: true,
output: {
beautify: false,
},
compress: {
join_vars: true,
if_return: true,
properties: true,
conditionals: true,
warnings: true,
dead_code: true,
drop_console: true,
drop_debugger: true,
}
})
export default [
// {
// input: "./src/JSEncrypt.js",
// plugins: plugins,
// name: "JSEncrypt",
// output: [
// { file: pkg.browser, format: 'umd' },
// ]
//
// },
{
input: "./src/JSEncrypt.js",
plugins: plugins,
name: "JSEncrypt",
output: [
{ file: pkg.main, format: 'umd' },
// { file: pkg.module, format: 'es' }
]
}).then(function (bundle) {
console.log(`processing ${entry}.js finished`);
bundle.write({
format: 'umd',
name: entries[entry].name,
file: path.join(__dirname, `${entries[entry].file}.js`)
});
}).catch((e)=>{
console.log(e);
});
}

}
]
2 changes: 1 addition & 1 deletion src/JSEncrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface IJSEncryptOptions {
* - log {boolean} default: false whether log warn/error or not
* @constructor
*/
export class JSEncrypt {
export default class JSEncrypt {
constructor(options:IJSEncryptOptions) {
options = options || {};
this.default_key_size = parseInt(options.default_key_size, 10) || 1024;
Expand Down
Loading

0 comments on commit 75d6238

Please sign in to comment.