Skip to content

Commit

Permalink
helper.js and fs-extra fixes
Browse files Browse the repository at this point in the history
[Problem] helper.js name could be misleading. getTemplateContent
function in library.js works more predictable with sync version of
writeFile
[Solution] I've changed helper.js name to more descriptive. Also I've
change writeFile to writeFileSync in getTemplateContent.

Signed-off-by: Hubert Siwkin <h.siwkin@samsung.com>
  • Loading branch information
Hubert Siwkin authored and hsiwkin committed Jul 16, 2019
1 parent 54cbed5 commit d0a0a9f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion design-editor/src/pane/design-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ class Model {
// }

this._DOM.body.appendChild(scriptRunner);
this.addLibrary('helper.js');
this.addLibrary('back-button-support.js');
if (screen.shape == 'circle') {
this.addLibrary('tau.circle.css');
this.addLibrary('circle-helper.js');
Expand Down
2 changes: 1 addition & 1 deletion design-editor/src/system/libraries/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Library {
if (!exists) {
this.getTemplateContent()
.then((text) => {
return writeFile(this.getAbsolutePath(), text);
return fs.writeFileSync(this.getAbsolutePath(), text);
})
.then(callback)
.catch(err => {throw err;});
Expand Down
File renamed without changes.
22 changes: 20 additions & 2 deletions vsc-extension/design-editor/libs/fs-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ function makeDir(path, callback) {
* Writes data to file specified via name argument.
* Triggers callback afterwards.
*
* @param {String} path path starting from the project root
* @param {String} path Path starting from the project root
* @param {Object} data
* @param {Function} callback
* @param {Function} callback Callback function triggered after
* the writing to file is done
* @param {Object} [additionalOptions]
*/
function writeFile(path, data, callback, additionalOptions = {}) {
const options = {
Expand All @@ -102,6 +104,21 @@ function writeFile(path, data, callback, additionalOptions = {}) {
__fetchHelper(fileEndpoint, options, 'text', callback);
}

/**
* Synchronous version of writeFile
*
* @todo implement synchronous version of writeFile
* (for now it's here just for WATT compability pourposes)
* @param {String} path Path starting from the project root
* @param {Object} data
* @param {Function} callback Callback function triggered after
* the writing to file is done
* @param {Object} [additionalOptions]
*/
function writeFileSync(path, data, callback, additionalOptions = {}) {
writeFile(path, data, callback, additionalOptions);
}

/**
* Checks if file specified in name exists,
* triggers callback afterwards.
Expand Down Expand Up @@ -143,6 +160,7 @@ function readDir(URL, callback) {
module.exports = {
readFile,
writeFile,
writeFileSync,
makeDir,
existsDir,
exists,
Expand Down

0 comments on commit d0a0a9f

Please sign in to comment.