-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
belozer
committed
Jan 24, 2017
1 parent
ad91d23
commit 1cc7144
Showing
3 changed files
with
35 additions
and
1 deletion.
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
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,32 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const stringify = require('javascript-stringify'); | ||
const converter = require('./convert'); | ||
|
||
/** | ||
* Save normalized declaration to target format | ||
* | ||
* @param {String} filename Filename for save declaration | ||
* @param {Object} decl Normalized declaraions | ||
* @param {Object} opts Addtional options | ||
* @param {String} opts.format Format for save declaration | ||
* @return {Promise} Success or Error | ||
*/ | ||
module.exports = (filename, decl, opts) => { | ||
opts = Object.assign({ format: 'v2' }, opts); | ||
decl = converter(decl, opts); | ||
|
||
let data = [ | ||
'exports.format = ' + stringify(opts.format), | ||
'exports.decl = ' + stringify(decl, null, ' '), | ||
'' | ||
].join(';\n'); | ||
|
||
return new Promise((resolve, reject) => { | ||
fs.writeFile(filename, data, (err) => { | ||
if (err) { reject(err); } | ||
resolve() | ||
}); | ||
}); | ||
} |
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