Skip to content

Commit

Permalink
chore(scripts): check for package.json before updating
Browse files Browse the repository at this point in the history
  • Loading branch information
chaance committed Nov 19, 2021
1 parent 422dff9 commit 89aee5b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ async function updateChangesVersion(version, date) {
*/
async function updateExamplesPackageConfig(example, transform) {
let file = packageJson(example, "examples");
if (!(await fileExists(file))) return;

let json = await jsonfile.readFile(file);
transform(json);
await jsonfile.writeFile(file, json, { spaces: 2 });
Expand Down Expand Up @@ -224,3 +226,16 @@ run(process.argv.slice(2)).then(
process.exit(1);
}
);

/**
* @param {string} filePath
* @returns {Promise<boolean>}
*/
async function fileExists(filePath) {
try {
let stat = await fsp.stat(filePath);
return stat.code !== "ENOENT";
} catch (_) {
return false;
}
}

0 comments on commit 89aee5b

Please sign in to comment.