Skip to content

Commit

Permalink
readFile instead of require
Browse files Browse the repository at this point in the history
  • Loading branch information
caoyangs committed Nov 16, 2016
1 parent f1823f8 commit 57fd73a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
30 changes: 15 additions & 15 deletions server/component-api/check-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ const writeDeps = (moduleName, moduleDeps) => {
return;
}

// Fetch the repo data file if it already exists
let repoFile = {};
try {
repoFile = require(`../../data/${moduleName}.json`);
} catch (err) {}

repoFile.deps = moduleDeps;

const writePath = Path.join(__dirname, `../../data/${moduleName}.json`);

return new Promise((resolve) => {
Fs.writeFile(writePath, JSON.stringify(repoFile), (err) => {
if (err) {
console.error("Error writing file with dependencies", err);
}
resolve({});
Fs.readFile(Path.join(__dirname, `../../data/${moduleName}.json`), (err, repoFile) => {
let data = {};
try {
data = JSON.parse(repoFile);
} catch (e) {}

data.deps = moduleDeps;

const writePath = Path.join(__dirname, `../../data/${moduleName}.json`);
Fs.writeFile(writePath, JSON.stringify(data), (err) => {
if (err) {
console.error("Error writing file with dependencies", err);
}
resolve({});
});
});
});
};
Expand Down
1 change: 0 additions & 1 deletion server/component-api/update-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ const UpdateHandler = function (request, reply) {
}).catch((e) => {
console.log("e", e);
return reply(`Error encountered: ${e.message}`);

});

};
Expand Down

0 comments on commit 57fd73a

Please sign in to comment.