Permalink
Browse files

refactoring

  • Loading branch information...
1 parent 6902c71 commit 68b8d51c8b00893a4918df0f5e7115e06c71acd4 @openhoat committed Feb 11, 2013
Showing with 17 additions and 19 deletions.
  1. +2 −2 README.md
  2. +0 −1 demo/.gitignore
  3. +0 −1 demo/encrypted/hello.js
  4. +1 −0 demo/hello.js
  5. +2 −2 grunt.js
  6. +12 −13 tasks/crypt.js
View
@@ -19,9 +19,9 @@ Put this in your grunt config :
crypt:{
files:[ // files to process
{
- dir:'demo/src', // root dir of files to encrypt, or dest dir of files to decrypt
+ dir:'demo', // root dir of files to encrypt / decrypt
include:'**/*.js', // pattern to include files
- encryptedDir:'demo/encrypted' // dest dir of files to encrypt, or root dir of files to decrypt
+ encryptedExtension:'.encrypted' // extension used for encrypted files
}
],
options:{
View
@@ -1 +0,0 @@
-src
@@ -1 +0,0 @@
-335f29f79d9dea937e6a58712a60b3e364763ce769053f002f188b0efe30fb5f
View
@@ -0,0 +1 @@
+console.log('hello!');
View
@@ -16,9 +16,9 @@ module.exports = function (grunt) {
crypt:{
files:[
{
- dir:'demo/src',
+ dir:'demo',
include:'**/*.js',
- encryptedDir:'demo/encrypted'
+ encryptedExtension:'.encrypted'
}
],
options:{
View
@@ -9,17 +9,17 @@ module.exports = function (grunt) {
, cryptKey = options.key;
files.forEach(function (file) {
var srcDir = file.dir || 'src'
- , destDir = file.encryptedDir || path.join('encrypted', srcDir)
+ , encryptedExtension = file.encryptedExtension || '.encrypted'
, include = file.include || '*.js'
, filePaths = grunt.file.expand({ cwd:srcDir }, include);
filePaths.forEach(function (filePath) {
var srcFilePath = path.join(srcDir, filePath)
- , destFilePath = path.join(destDir, filePath)
- , content, encryptedContent;
+ , destFilePath = srcFilePath + encryptedExtension
+ , decryptedContent, encryptedContent;
try {
grunt.log.write('Encrypting "' + srcFilePath + '" to "' + destFilePath + '"...');
- content = grunt.file.read(srcFilePath);
- encryptedContent = kruptosUtilCrypt.encryptText(content, cryptKey);
+ decryptedContent = grunt.file.read(srcFilePath);
+ encryptedContent = kruptosUtilCrypt.encryptText(decryptedContent, cryptKey);
grunt.file.write(destFilePath, encryptedContent);
grunt.log.ok();
} catch (e) {
@@ -35,19 +35,18 @@ module.exports = function (grunt) {
, options = grunt.config('crypt').options
, cryptKey = options.key;
files.forEach(function (file) {
- var destDir = file.dir || 'src'
- , srcDir = file.encryptedDir || path.join('encrypted', destDir)
- , include = file.include || '*.js'
- , filePaths = grunt.file.expand({ cwd:srcDir }, include);
+ var srcDir = file.dir || 'src'
+ , encryptedExtension = file.encryptedExtension || '.encrypted'
+ , filePaths = grunt.file.expand({ cwd:srcDir }, '*' + encryptedExtension);
filePaths.forEach(function (filePath) {
var srcFilePath = path.join(srcDir, filePath)
- , destFilePath = path.join(destDir, filePath)
- , content, encryptedContent;
+ , destFilePath = srcFilePath.substring(0, srcFilePath.length - encryptedExtension.length)
+ , decryptedContent, encryptedContent;
try {
grunt.log.write('Decrypting "' + srcFilePath + '" to "' + destFilePath + '"...');
encryptedContent = grunt.file.read(srcFilePath);
- content = kruptosUtilCrypt.decryptText(encryptedContent, cryptKey);
- grunt.file.write(destFilePath, content);
+ decryptedContent = kruptosUtilCrypt.decryptText(encryptedContent, cryptKey);
+ grunt.file.write(destFilePath, decryptedContent);
grunt.log.ok();
} catch (e) {
grunt.log.error();

0 comments on commit 68b8d51

Please sign in to comment.