|
1 |
| -const {SHELL, CURRENT_DIRECTORY, COLORS, NAME, VERSION, NOTIFY} = require('../config/superman.config'); |
2 |
| -const {PACKAGE_CONTENT, PACKAGE_VERSION} = require('../actions/helpers.action'); |
| 1 | +const {SPLIT_VERSION, WRITE_PACKAGE_FILE} = require('../actions/helpers.action'); |
3 | 2 | /**
|
4 | 3 | * Update Package
|
5 | 4 | *
|
6 | 5 | * @param options
|
7 | 6 | */
|
8 | 7 | const initVersion = (options) => {
|
9 | 8 | if (options.major) {
|
10 |
| - initMajor(PACKAGE_CONTENT, PACKAGE_VERSION); |
| 9 | + initMajor(); |
11 | 10 | } else if (options.minor) {
|
12 |
| - initMinor(PACKAGE_CONTENT, PACKAGE_VERSION); |
| 11 | + initMinor(); |
13 | 12 | } else if (options.patch) {
|
14 |
| - initPatch(PACKAGE_CONTENT, PACKAGE_VERSION) |
| 13 | + initPatch() |
15 | 14 | } else {
|
16 |
| - initFileVersion(PACKAGE_CONTENT, PACKAGE_VERSION); |
| 15 | + initFileVersion(); |
17 | 16 | }
|
18 | 17 | };
|
| 18 | + |
19 | 19 | /**
|
20 | 20 | * Set MAJOR
|
21 | 21 | *
|
22 |
| - * @param packageContent |
23 |
| - * @param packageVersion |
24 | 22 | */
|
25 |
| -const initMajor = (packageContent, packageVersion) => { |
26 |
| - /** |
27 |
| - * Variables |
28 |
| - * @type {*|string[]} |
29 |
| - */ |
30 |
| - let version = packageVersion.split('.'), |
31 |
| - minor = parseInt(version[1]), |
32 |
| - patch = parseInt(version[2]), |
33 |
| - newVersion = `${0}.${minor}.${patch}`; |
34 |
| - |
35 |
| - /** |
36 |
| - * Output console |
37 |
| - */ |
38 |
| - outputConsole(); |
39 |
| - |
40 |
| - /** |
41 |
| - * Set Package value |
42 |
| - */ |
43 |
| - SHELL.sed('-i', `"version": "${packageVersion}"`, `"version": "${newVersion}"`, `${CURRENT_DIRECTORY}/package.json`) |
44 |
| - |
| 23 | +const initMajor = () => { |
| 24 | + let version = SPLIT_VERSION(); |
45 | 25 | /**
|
46 |
| - * output notification |
| 26 | + * Write package file |
47 | 27 | */
|
48 |
| - outputFinish(newVersion); |
| 28 | + WRITE_PACKAGE_FILE(`${0}.${version.minor}.${version.patch}`); |
49 | 29 | };
|
| 30 | + |
50 | 31 | /**
|
51 | 32 | * Set MINOR
|
52 | 33 | *
|
53 |
| - * @param packageContent |
54 |
| - * @param packageVersion |
55 | 34 | */
|
56 |
| -const initMinor = (packageContent, packageVersion) => { |
| 35 | +const initMinor = () => { |
| 36 | + let version = SPLIT_VERSION(); |
57 | 37 | /**
|
58 |
| - * Variables |
59 |
| - * @type {*|string[]} |
| 38 | + /** |
| 39 | + * Write package file |
60 | 40 | */
|
61 |
| - let version = packageVersion.split('.'), |
62 |
| - major = parseInt(version[0]), |
63 |
| - patch = parseInt(version[2]), |
64 |
| - newVersion = `${major}.${0}.${patch}`; |
65 |
| - |
66 |
| - /** |
67 |
| - * Output console |
68 |
| - */ |
69 |
| - outputConsole(); |
70 |
| - |
71 |
| - /** |
72 |
| - * Set Package value |
73 |
| - */ |
74 |
| - SHELL.sed('-i', `"version": "${packageVersion}"`, `"version": "${newVersion}"`, `${CURRENT_DIRECTORY}/package.json`) |
75 |
| - |
76 |
| - /** |
77 |
| - * output notification |
78 |
| - */ |
79 |
| - outputFinish(newVersion); |
| 41 | + WRITE_PACKAGE_FILE(`${version.major}.${0}.${version.patch}`); |
80 | 42 | };
|
| 43 | + |
81 | 44 | /**
|
82 | 45 | * Set PATCH
|
83 | 46 | *
|
84 |
| - * @param packageContent |
85 |
| - * @param packageVersion |
86 | 47 | */
|
87 |
| -const initPatch = (packageContent, packageVersion) => { |
| 48 | +const initPatch = () => { |
| 49 | + let version = SPLIT_VERSION(); |
88 | 50 | /**
|
89 |
| - * Variables |
90 |
| - * @type {*|string[]} |
| 51 | + * Write package file |
91 | 52 | */
|
92 |
| - let version = packageVersion.split('.'), |
93 |
| - major = parseInt(version[0]), |
94 |
| - minor = parseInt(version[1]), |
95 |
| - newVersion = `${major}.${minor}.${0}`; |
96 |
| - |
97 |
| - /** |
98 |
| - * Output console |
99 |
| - */ |
100 |
| - outputConsole(); |
101 |
| - |
102 |
| - /** |
103 |
| - * Set Package value |
104 |
| - */ |
105 |
| - SHELL.sed('-i', `"version": "${packageVersion}"`, `"version": "${newVersion}"`, `${CURRENT_DIRECTORY}/package.json`) |
106 |
| - |
107 |
| - /** |
108 |
| - * output notification |
109 |
| - */ |
110 |
| - outputFinish(newVersion); |
| 53 | + WRITE_PACKAGE_FILE(`${version.major}.${version.minor}.${0}`); |
111 | 54 | };
|
| 55 | + |
112 | 56 | /**
|
113 | 57 | * Set version
|
114 |
| - * |
115 |
| - * @param packageContent |
116 |
| - * @param packageVersion |
117 | 58 | */
|
118 |
| -const initFileVersion = (packageContent, packageVersion) => { |
119 |
| - /** |
120 |
| - * Output console |
121 |
| - */ |
122 |
| - outputConsole(); |
123 |
| - |
124 |
| - /** |
125 |
| - * Set Package value |
126 |
| - */ |
127 |
| - SHELL.sed('-i', `"version": "${packageVersion}"`, `"version": "0.0.0"`, `${CURRENT_DIRECTORY}/package.json`) |
128 |
| - |
| 59 | +const initFileVersion = () => { |
129 | 60 | /**
|
130 |
| - * output notification |
| 61 | + * Write package file |
131 | 62 | */
|
132 |
| - outputFinish('0.0.0'); |
133 |
| -}; |
134 |
| -/** |
135 |
| - * Output Console |
136 |
| - */ |
137 |
| -const outputConsole = () => { |
138 |
| - console.log('\n', COLORS.white.bold(NAME), COLORS.cyan.bold(VERSION)); |
139 |
| - console.log('\n', COLORS.grey(' Pleas wait tasks is running...'), '\n'); |
140 |
| -}; |
141 |
| -/** |
142 |
| - * Output notify |
143 |
| - * @param version |
144 |
| - */ |
145 |
| -const outputFinish = (version) => { |
146 |
| - NOTIFY.notify({ |
147 |
| - title: 'Superman', |
148 |
| - message: `Oh yes!, your application version is now update to ${version}.` |
149 |
| - }); |
150 |
| - console.log(COLORS.green(` Oh yes!, your application version is now update to ${COLORS.yellow(version)}.`)); |
| 63 | + WRITE_PACKAGE_FILE('0.0.0'); |
151 | 64 | };
|
| 65 | + |
152 | 66 | /**
|
153 | 67 | * Export module
|
154 | 68 | * @type {{updatePackage: initVersion}}
|
|
0 commit comments