-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix save method added encryption support
- Loading branch information
1 parent
6b35f90
commit df78803
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const path = require('./path'); | ||
const format = require('./format'); | ||
const encode = require('../intermediate/encode'); | ||
const fs = require('fs'); | ||
|
||
function write(path, data){ | ||
fs.writeFileSync(path, data); | ||
}; | ||
|
||
function parseContent(processed_data){ | ||
var result = '{}'; | ||
try { result = JSON.stringify(processed_data, null, '\t'); } | ||
catch (err){ result = '{}' }; | ||
return result; | ||
}; | ||
|
||
function main(data, settings, cryptography){ | ||
var parents_path = settings.parents; | ||
var target_file = settings.name; | ||
var current_path = path.validate(parents_path, target_file); | ||
var formatted_content = format.compile(data); | ||
var parsed_content = parseContent(formatted_content); | ||
var encoded_content = encode(parsed_content, cryptography); | ||
write(current_path, encoded_content); | ||
}; | ||
|
||
module.exports = main; |