mirror of
https://github.com/hectorm/otpauth.git
synced 2026-05-07 20:12:27 +00:00
Dynamically replace SJCL during build process
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
bower_components/
|
||||
node_modules/
|
||||
doc/
|
||||
src/.sjcl.custom.js
|
||||
npm-debug.log*
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
// Custom build of the Stanford Javascript Crypto Library (SJCL)
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const sjclTarget = path.join(__dirname, 'src/.sjcl.custom.js');
|
||||
const sjclPath = path.join(__dirname, 'node_modules/sjcl');
|
||||
const sjclSources = [
|
||||
'core/sjcl.js',
|
||||
'core/bitArray.js',
|
||||
'core/codecArrayBuffer.js',
|
||||
'core/sha1.js',
|
||||
'core/sha256.js',
|
||||
'core/sha512.js',
|
||||
'core/hmac.js',
|
||||
'core/exports.js'
|
||||
];
|
||||
|
||||
const sjclFile = sjclSources.reduce(function(sjcl, file) {
|
||||
let source = fs.readFileSync(path.join(sjclPath, file), {'encoding': 'utf8'});
|
||||
source = `\n/* === ${file} === */\n${source}`;
|
||||
|
||||
return sjcl + source;
|
||||
}, '');
|
||||
|
||||
fs.writeFileSync(sjclTarget, sjclFile, {'encoding': 'utf8'});
|
||||
|
||||
+27
-3
@@ -1,7 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const pkg = require('./package.json');
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const tmp = require('tmp');
|
||||
|
||||
const webpack = require('webpack');
|
||||
const ClosureCompilerPlugin = require('google-closure-compiler-js').webpack;
|
||||
|
||||
@@ -13,11 +17,31 @@ module.exports = {
|
||||
'filename': `${pkg.name}.js`,
|
||||
'path': path.join(__dirname, 'lib')
|
||||
},
|
||||
'node': {
|
||||
'Buffer': false
|
||||
},
|
||||
'devtool': 'source-map',
|
||||
'node': {'Buffer': false},
|
||||
'plugins': [
|
||||
// Custom build of the Stanford Javascript Crypto Library (SJCL)
|
||||
new webpack.NormalModuleReplacementPlugin(/^sjcl$/, function(result) {
|
||||
const request = tmp.fileSync().name;
|
||||
|
||||
const root = path.join(__dirname, 'node_modules/sjcl');
|
||||
const sources = [
|
||||
'core/sjcl.js',
|
||||
'core/bitArray.js',
|
||||
'core/codecArrayBuffer.js',
|
||||
'core/sha1.js',
|
||||
'core/sha256.js',
|
||||
'core/sha512.js',
|
||||
'core/hmac.js',
|
||||
'core/exports.js'
|
||||
];
|
||||
|
||||
fs.writeFileSync(request, sources.reduce(function(code, file) {
|
||||
return code + fs.readFileSync(path.join(root, file));
|
||||
}, ''));
|
||||
|
||||
result.request = request;
|
||||
}),
|
||||
new ClosureCompilerPlugin({
|
||||
'options': {
|
||||
'warningLevel': 'QUIET',
|
||||
|
||||
+3
-4
@@ -36,9 +36,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --config .eslintrc.js .",
|
||||
"build-otpauth": "webpack --display-reasons --config .webpack.js",
|
||||
"build-sjcl": "node .sjcl.js",
|
||||
"build": "run-s build-sjcl build-otpauth",
|
||||
"build": "webpack --display-reasons --config .webpack.js",
|
||||
"test-browser": "karma start .karma.js",
|
||||
"test-node": "mocha --reporter dot",
|
||||
"test": "run-s test-node test-browser",
|
||||
@@ -60,6 +58,7 @@
|
||||
"karma-phantomjs-launcher": "latest",
|
||||
"mocha": "latest",
|
||||
"npm-run-all": "latest",
|
||||
"rimraf": "latest"
|
||||
"rimraf": "latest",
|
||||
"tmp": "latest"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import sjcl from './.sjcl.custom.js';
|
||||
import sjcl from 'sjcl';
|
||||
|
||||
/**
|
||||
* An object containing some cryptography functions
|
||||
|
||||
Reference in New Issue
Block a user