UNPKG

file-manipulator

Version:

## Easy File operations library

31 lines (29 loc) 1.13 kB
import fileManipulator from './lib/index' const upVers = async () => { const {result, readed: isReadedJson} = await fileManipulator.read.file({name: 'package', ext: 'json', path: './'}) console.log({isReadedJson}) if (isReadedJson) { const obj = JSON.parse(result) const vers = obj.version || '' if (!vers) { return console.log('version not found', vers) } const lastNumRegExp = /(\d$)/ const versLastNum = vers.match(lastNumRegExp)[0] if (!Number.isFinite(Number(versLastNum))) { return console.log('version not corrent now', vers) } const newVersLastNum = Number(versLastNum || 0) + 1 const replacedNumber = vers.replace(lastNumRegExp, newVersLastNum) obj.version = replacedNumber const newObjString = JSON.stringify(obj, null, ' ') const isRewritedJson = await fileManipulator.update.file({ name: 'package', ext: 'json', path: './', stringTo: newObjString }) console.log({replacedNumber, isRewritedJson}) } } upVers()