From b1d244e34c3e05b40e231e0ed8193fa1ef424880 Mon Sep 17 00:00:00 2001 From: joe fleming Date: Thu, 13 Sep 2018 16:12:23 -0700 Subject: [PATCH] chore: add version sync script --- scripts/version-sync.mjs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 scripts/version-sync.mjs diff --git a/scripts/version-sync.mjs b/scripts/version-sync.mjs new file mode 100644 index 0000000..67d337b --- /dev/null +++ b/scripts/version-sync.mjs @@ -0,0 +1,26 @@ +import fs from 'fs'; +import { promisify } from 'util'; +import { join } from 'path'; +import pkg from '../package.json'; + +const readDir = promisify(fs.readdir); +const readFile = promisify(fs.readFile); +const writeFile = promisify(fs.writeFile); + +async function syncPackageVersions() { + const packagesPath = 'packages'; // path for all packages + const { version } = pkg; + + const packages = await readDir(packagesPath); + + packages.forEach(async pack => { + const packagePath = join(packagesPath, pack, 'package.json'); + const p = JSON.parse(await readFile(packagePath, 'utf-8')); + p.version = version; + await writeFile(packagePath, `${JSON.stringify(p, null, 2)}\n`); + }); + + console.log(`Versions with root: ${version}`); +} + +syncPackageVersions();