Skip to content

Commit

Permalink
insert version into source
Browse files Browse the repository at this point in the history
  • Loading branch information
dpronin committed Dec 20, 2017
1 parent dd7ac81 commit 15c4c77
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 65 deletions.
2 changes: 1 addition & 1 deletion bin/jsencrypt.js

Large diffs are not rendered by default.

76 changes: 44 additions & 32 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
var gulp = require('gulp');
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 = [
'lib/jsbn/jsbn.js',
'lib/jsbn/jsbn2.js',
'lib/jsbn/prng4.js',
'lib/jsbn/rng.js',
'lib/jsbn/rsa.js',
'lib/jsbn/rsa2.js',
'lib/jsbn/rsa-async.js',
'lib/jsbn/base64.js',
'lib/jsrsasign/asn1-1.0.js',
'lib/asn1js/hex.js',
'lib/asn1js/base64.js',
'lib/asn1js/asn1.js',
'src/jsencrypt.js'
];
var ts = require('gulp-typescript');
var through = require('through2');
var rollup = require('rollup');


var lintFiles = [
'src/*.ts',
Expand All @@ -39,8 +24,7 @@ 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)
Expand All @@ -57,22 +41,50 @@ gulp.task('license', function() {
.pipe(gulp.dest(''));
});

var packageJson = require('./package.json');
gulp.task('scripts', function() {
return gulp.src(files)
.pipe(concat('jsencrypt.js'))
.pipe(wrap({src: 'src/template.txt'}, {version: packageJson.version}, {variable: 'data'}))
.pipe(gulp.dest('bin/'))
.pipe(rename('jsencrypt.min.js'))
.pipe(uglify({preserveComments: 'license'}))
.pipe(gulp.dest('bin'));
/**
* Build ts to js for rollup
*/
gulp.task('tsc', function() {
var tsProject = ts.createProject('./tsconfig.json');

var typescript_error_count = 0;

var tsResult = tsProject.src()
.pipe(tsProject({
reporter: ts.reporter.longReporter(),
error: function () {
typescript_error_count++;
this.reporter.error.apply(this.reporter, arguments);
},
finish: function () {
this.reporter.finish.apply(this.reporter, arguments);
}
}));

return tsResult.js.pipe(gulp.dest('./'))
.pipe(through.obj(function (chunk, enc, cb) {
if (typescript_error_count) {
this.emit("error", "TypeScript compile errors (count:" + typescript_error_count + ")");
}
cb(null, chunk)
}));
});

/**
* build library with rollup
*/
gulp.task('assemble', ['tsc'], function () {
var config = require('./rollup.config');

gulp.task('assemble', function () {
return rollup.rollup(config).then(function (bundle) {
return bundle.write(config.output);

});
});

/**
* copy mocha files from node modules to test directory (for gh-pages serving)
*/
gulp.task('prepare_test', function() {
return gulp
.src(libs_for_test)
Expand All @@ -81,5 +93,5 @@ gulp.task('prepare_test', function() {
});


gulp.task('build', ['lint', 'scripts', 'license']);
gulp.task('build', ['prepare_test', 'lint', 'assemble', '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 @@ -38,12 +38,14 @@
"gulp-insert": "^0.5.0",
"gulp-rename": "^1.2.2",
"gulp-tslint": "^8.1.2",
"gulp-typescript": "^3.2.3",
"gulp-uglify": "^1.5.3",
"gulp-watch": "^4.3.5",
"gulp-wrap": "^0.11.0",
"mocha": "^4.0.1",
"rollup": "^0.52.1",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^2.0.1",
"ts-loader": "^3.2.0",
"tslib": "^1.8.1",
Expand Down
29 changes: 13 additions & 16 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";
const resolve = require('rollup-plugin-node-resolve');
const uglify = require('rollup-plugin-uglify');
const replace = require('rollup-plugin-replace');
const pkg = require('./package.json');

var plugins = [
Expand All @@ -21,28 +22,24 @@ var plugins = [
drop_console: true,
drop_debugger: true,
}
}),
replace({
'JSENCRYPT_VERSION': JSON.stringify(pkg.version)
})

];


export default [
// {
// input: "./src/JSEncrypt.js",
// plugins: plugins,
// name: "JSEncrypt",
// output: [
// { file: pkg.browser, format: 'umd' },
// ]
//
// },
{
module.exports = {
input: "./src/JSEncrypt.js",
plugins: plugins,
name: "JSEncrypt",
output: [
{ file: pkg.main, format: 'umd' },
output: {
file: pkg.main,
format: 'umd',
name: "JSEncrypt"
},
// { file: pkg.module, format: 'es' }
]

}
]

};
4 changes: 4 additions & 0 deletions src/JSEncrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {b64tohex, hex2b64} from "../lib/jsbn/base64";
import {JSEncryptRSAKey} from "./JSEncryptRSAKey";


declare var JSENCRYPT_VERSION:string;

interface IJSEncryptOptions {
default_key_size?:string;
default_public_exponent?:string;
Expand Down Expand Up @@ -32,6 +34,8 @@ export default class JSEncrypt {
private log:boolean;
private key:JSEncryptRSAKey;

public static version:string = JSENCRYPT_VERSION;

/**
* Method to set the rsa key parameter (one method is enough to set both the public
* and the private key, since the private key contains the public key paramenters)
Expand Down
16 changes: 0 additions & 16 deletions src/template.txt

This file was deleted.

0 comments on commit 15c4c77

Please sign in to comment.