Skip to content

Commit

Permalink
Extract write file function
Browse files Browse the repository at this point in the history
  • Loading branch information
1v4n4 committed May 19, 2022
1 parent 1d9390e commit 8a4743b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
4 changes: 3 additions & 1 deletion 49.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"title": "Taxonomy",
"name": "taxonomy"
},
"layout": {},
"layout": {
"primaryColor": "#333373"
},
"component": {},
"portal": [],
"locales": {},
Expand Down
2 changes: 1 addition & 1 deletion modules/primaryColor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const isHexcolor = require('is-hexcolor')
const success = require('../messages/success');
const warning = require('../messages/warning');
const writeFile = require('../modules/writeFile');

module.exports = (args) => {
if (!isHexcolor(process.argv[3])) {
Expand Down
19 changes: 19 additions & 0 deletions modules/privacyPolicy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require('fs');
const validator = require('validator');
const success = require('../messages/success');
const warning = require('../messages/warning');


module.exports = (args) => {
if (!validator.isURL(process.argv[3])) {
warning('URL not valid.');
process.exit(1);
}
args.map(arg => {
if (!arg.fileContent.org) {
arg.fileContent.org = {privacyPolicy: process.argv[3]};
}
arg.fileContent.org.privacyPolicy = process.argv[3];
writeFile(arg.fileName, arg.fileContent);
});
}
1 change: 0 additions & 1 deletion modules/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = (args) => {
arg.fileContent.org = {url: process.argv[3]};
}
arg.fileContent.org.url = process.argv[3];
console.log('ii', arg.fileContent, arg.fileName, process.argv[3]);
fs.writeFile(arg.fileName, JSON.stringify(arg.fileContent, null, '\t'), function (err) {
if (err) throw err;
success('Organization URL changed', arg.fileName);
Expand Down
9 changes: 9 additions & 0 deletions modules/writeFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs');
const success = require('../messages/success');

module.exports = (fileName, fileContent) => {
fs.writeFile(fileName, JSON.stringify(fileContent, null, '\t'), function (err) {
if (err) throw err;
success('Privacy URL changed', fileName);
});
}

0 comments on commit 8a4743b

Please sign in to comment.