tfv 1.5.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,9 +29,12 @@ npm i -g tfv
29
29
  * [list](#list)
30
30
  <!--te-->
31
31
 
32
- ## Usag
32
+ ## Usage
33
+
34
+ https://user-images.githubusercontent.com/25563661/142188036-4f2a8b65-1a3e-4298-95e0-9ed533c66a18.mp4
33
35
 
34
36
  ### Modules
37
+
35
38
  #### *install*
36
39
  ```sh
37
40
  tfv install <version>
@@ -40,12 +43,12 @@ or
40
43
  ```sh
41
44
  tfv i <version>
42
45
  ```
43
- | Version | Description |
44
- | ---------------- | ----------------------------------------- |
45
- | x.x.x | Installs terraform version x.x.x |
46
- | x^ | Installs latest version of series x |
47
- | x.x.^ | Installs latest version of series x.x |
48
- | latest | Installs latest version of terraform |
46
+ | Version | Description |
47
+ | ---------------- | ------------------------------------------ |
48
+ | x.x.x | Installs terraform version x.x.x |
49
+ | x^ | Installs latest version of release x |
50
+ | x.x.^ | Installs latest version of release x.x |
51
+ | latest | Installs latest version of terraform |
49
52
 
50
53
  #### *use*
51
54
  ```sh
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const {join} = require('path');
3
3
  const {fetchAllVersions} = require('./remote');
4
- const {P_END, P_OK} = require('../utils/colors');
4
+ const {P_END, P_OK, P_ERROR} = require('../utils/colors');
5
5
 
6
6
  exports.list = async (local, remote) => {
7
7
  try {
@@ -20,6 +20,12 @@ exports.list = async (local, remote) => {
20
20
 
21
21
  if (local) {
22
22
  const store = join(__dirname, '../..', 'store');
23
+
24
+ if (!fs.existsSync(store)) {
25
+ console.log(`${P_ERROR}You're yet to install terraform with tfv${P_END}`);
26
+ return console.log(`For guidance, run ${P_OK}tfv -h${P_END}`);
27
+ }
28
+
23
29
  versions = fs.readdirSync(store).map(v => v.replace('.exe', ''));
24
30
 
25
31
  return result('Terraform versions installed by tfv', versions);
@@ -14,15 +14,19 @@ exports.use = async (tfVer) => {
14
14
  let aVer = a.replace(/(.exe)/g, '');
15
15
  let bVer = b.replace(/(.exe)/g, '');
16
16
 
17
- const [aMin] = aVer.match(/[^\.]*\s/g);
17
+ const major = /.*\./g;
18
+
19
+ const [aMajor] = aVer.match(major);
20
+ const aMin = aVer.replace(aMajor, '');
18
21
  const aMinUpdate = aMin.length === 1 ? `0${aMin}` : aMin;
19
- aVer = aVer.replace(/[^\.]*\s/g, aMinUpdate);
22
+ aVer = `${aMajor}${aMinUpdate}`.replace(/\.(?!.*\.)/g, '');
20
23
 
21
- const [bMin] = aVer.match(/[^\.]*\s/g);
22
- const bMinUpdate = aMin.length === 1 ? `0${bMin}` : bMin;
23
- bVer = bVer.replace(/[^\.]*\s/g, bMinUpdate);
24
+ const [bMajor] = bVer.match(major);
25
+ const bMin = bVer.replace(bMajor, '');
26
+ const bMinUpdate = bMin.length === 1 ? `0${bMin}` : bMin;
27
+ bVer = `${bMajor}${bMinUpdate}`.replace(/\.(?!.*\.)/g, '');
24
28
 
25
- return Number(bVer.replace(/\.(?!.*\.)/g, '')) - Number(aVer.replace(/\.(?!.*\.)/g, ''));
29
+ return Number(bVer) - Number(aVer);
26
30
  });
27
31
 
28
32
  console.log(`${P_INFO}Your latest installed version is ${version}${P_END}`);
@@ -43,7 +47,7 @@ exports.use = async (tfVer) => {
43
47
  const bin = os.platform() === 'darwin' ? '/usr/local/bin' : `${os.homedir()}/bin`;
44
48
 
45
49
  destination = `${bin}/terraform`;
46
- spawnSync('sudo', ['rm', `${destination}`], {stdio: 'inherit', shell: true});
50
+ // spawnSync('sudo', ['rm', `${destination}`], {stdio: 'inherit', shell: true});
47
51
  spawnSync('sudo', ['cp', `${source}`, `${destination}`], {stdio: 'inherit', shell: true});
48
52
  }
49
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tfv",
3
- "version": "1.5.0",
3
+ "version": "1.9.0",
4
4
  "description": "Terraform version manager",
5
5
  "main": "index.js",
6
6
  "directories": {