import * as path from 'path' import * as Promise from 'bluebird' import * as fs from 'fs-extra-promise' import {inc as incrementVersion} from 'semver' import { ReleaseType } from 'semver' interface Manifest { name: string, version: string } export default class PresentationVersion { private packagePath: string private bowerPath: string constructor(directory: string){ this.packagePath = path.resolve(directory, 'package.json') this.bowerPath = path.resolve(directory, 'bower.json') } get (): Promise { return fs.readJsonAsync(this.packagePath) .get('version') } set (version: string): Promise { return this.setVersion(version) } increment (release: string): Promise { return this.get() .then(version => incrementVersion(version, release)) .then(version => this.setVersion(version)) } private setVersion (version: string | null): Promise { return Promise.map([this.packagePath, this.bowerPath], (file: string) => { return fs.readJsonAsync(file) .then((data: Manifest) => { var updatedData = { ...data, version }; return fs.outputJsonAsync(file, updatedData) }) .catch((err) => { if(err.code !== 'ENOENT'){ throw err } }) }) } }