File size: 1,680 Bytes
e4bf523
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict'
/**

 * Copyright (c) 2017~2021, OBCon Inc.

 * All rights reserved.

 */

/**

 * @file

 * @copyright 2017~2021, OBCon Inc.

 * @author gye hyun james kim [pnuskgh@gmail.com]

 */

const fs = require('fs');
const path = require('path');

class Version {
    constructor() {
        this._filename = path.join(appl.root, 'version.json');

        this._version = null;
    }

    get version() {
        if (this._version == null) {
            this._version = this.read()
        }
        return this._version;
    }

    set version(newValue) {
        this._version = newValue;
    }

    read(filename=this._filename) {
        return require(filename);
    }

    write(version=this._version, filename=this._filename) {
        fs.writeFileSync(filename, JSON.stringify(version), 'utf8');
    }

    next() {
        let version = this.version;
        version.patch = version.patch + 1;
        version.minor = version.minor + parseInt(version.patch / 100);
        version.major = version.major + parseInt(version.minor / 10);

        version.minor = version.minor % 10;
        version.patch = version.patch % 100;
        // let international = Intl.NumberFormat('ko-KR', { minimumFractionDigits: 0, maximumFractionDigits: 0 });
        // let internationalFloat = Intl.NumberFormat('ko-KR', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
        version.version = `${version.major}.${String(version.minor).padStart(2, '0')}.${String(version.patch).padStart(3, '0')}`;
        // console.log(version);
        this._version = version
        return version;
    }
}

module.exports = Version;