Skip to content

Commit 8490a39

Browse files
committed
Release 0.1.2
1 parent b57642d commit 8490a39

6 files changed

Lines changed: 154 additions & 99 deletions

File tree

.babelrc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
{
2-
"presets": ["es2015"],
3-
"plugins": ["syntax-async-functions", "transform-regenerator"]
2+
"presets": [
3+
"stage-0",
4+
"es2015"
5+
],
6+
"plugins": [
7+
["transform-runtime", {
8+
"polyfill": false,
9+
"regenerator": true
10+
}]
11+
]
412
}

package.json

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
{
22
"name": "discoid",
3-
"version": "0.0.0",
3+
"version": "0.1.2",
44
"description": "A simple utility to retrieve disk info",
5-
"main": "build/index.js",
5+
"main": "dist/index.js",
66
"directories": {
77
"test": "test"
88
},
99
"dependencies": {
10-
"lodash": "^4.0.0"
10+
"lodash": "^4.0.0",
11+
"windows-powershell": "^0.1.1"
1112
},
1213
"scripts": {
14+
"build": "babel src --out-dir dist --source-maps --copy-files",
15+
"release": "dotenv release-it",
16+
"example": "babel-node src/example/index.js",
1317
"prebuild": "rm -rf build && mkdir build",
14-
"build": "babel src -d build",
18+
"//build": "babel src -d dist",
1519
"postbuild": "",
16-
"commit:all": "git add . && git-cz",
17-
"commit": "git-cz",
18-
"check-coverage": "istanbul check-coverage --branches 50 --statements 80 --lines 80 --functions 70",
1920
"report-coverage": "codecov",
20-
"test": "mocha src/test/*.js --watch --colors --compilers js:babel-register",
21-
"test:single": "babel-node ./node_modules/.bin/babel-istanbul cover _mocha -- --recursive src/test --compilers js:babel-register",
22-
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
21+
"test": "exit 0 # mocha ./src/lib/*.test.js --compilers js:babel-core/register",
22+
"test:watch": "npm run test -- --watch"
2323
},
2424
"devDependencies": {
25-
"babel-cli": "^6.4.5",
26-
"babel-istanbul": "^0.6.0",
27-
"babel-plugin-syntax-async-functions": "^6.3.13",
28-
"babel-plugin-transform-regenerator": "^6.4.4",
29-
"babel-preset-es2015": "^6.3.13",
30-
"babel-register": "^6.4.3",
25+
"babel-cli": "^6.24.1",
26+
"babel-core": "^6.25.0",
27+
"babel-loader": "^7.0.0",
28+
"babel-plugin-transform-runtime": "^6.23.0",
29+
"babel-polyfill": "^6.23.0",
30+
"babel-preset-es2015": "^6.24.1",
31+
"babel-preset-stage-0": "^6.24.1",
3132
"chai": "^3.4.1",
3233
"chai-as-promised": "^5.2.0",
3334
"codecov": "^1.0.1",
3435
"commitizen": "^2.5.0",
3536
"cz-conventional-changelog": "^1.1.5",
37+
"dotenv-cli": "^1.4.0",
3638
"ghooks": "^1.0.3",
3739
"istanbul": "^0.4.2",
3840
"mocha": "^2.3.4",
41+
"release-it": "^2.7.3",
3942
"semantic-release": "^4.3.5"
4043
},
4144
"repository": {
@@ -52,13 +55,5 @@
5255
"bugs": {
5356
"url": "https://github.com/miniArray/discoid/issues"
5457
},
55-
"config": {
56-
"commitizen": {
57-
"path": "node_modules/cz-conventional-changelog"
58-
},
59-
"ghooks": {
60-
"pre-commit": "npm run test:single && npm run check-coverage"
61-
}
62-
},
6358
"homepage": "https://github.com/miniArray/discoid#readme"
6459
}

src/lib/discoid.js

Lines changed: 125 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,129 @@
1-
import mountvol from './mountvol';
1+
import mountvol from './mountvol'
2+
import ps from 'windows-powershell'
23

3-
let discoid = {
4-
list: function() {
5-
let isWin = /^win/.test(process.platform);
4+
// Network Mounts
5+
// Get-WmiObject Win32_LogicalDisk | where -property DriveType -eq 4 | convertto-json
66

7-
if (isWin) return mountvol();
8-
return Promise.resolve([]);
7+
// Local Volumes
8+
// get-volume | convertto-json
9+
10+
export async function list ({ local = true, network = true } = {}) {
11+
const isWin = /^win/.test(process.platform)
12+
let results = []
13+
14+
if (isWin) {
15+
if (local) {
16+
const obj = await getLocalMounts()
17+
const discsLocal = parseLocalResults(obj)
18+
19+
results = [
20+
...results,
21+
...discsLocal
22+
]
923
}
10-
};
1124

12-
module.exports = Object.create(discoid);
25+
if (network) {
26+
const obj = await getNetworkMounts()
27+
const discsNetwork = parseNetworkResults(obj)
28+
29+
results = [
30+
...results,
31+
...discsNetwork
32+
]
33+
}
34+
35+
return results
36+
}
37+
38+
return Promise.resolve([])
39+
}
40+
41+
export async function fromPath (path) {
42+
const isWin = /^win/.test(process.platform)
43+
44+
return Promise.resolve([])
45+
}
46+
47+
function getNetworkMounts () {
48+
const cmd = ps.pipe(
49+
'Get-WmiObject Win32_LogicalDisk',
50+
'where -property DriveType -eq 4'
51+
)
52+
53+
return ps.shell(ps.toJson(cmd))
54+
}
55+
56+
function getLocalMounts () {
57+
const cmd = ps.pipe(
58+
'get-volume',
59+
'where -property DriveType -ne 9999'
60+
)
61+
62+
return ps.shell(ps.toJson(cmd))
63+
}
64+
65+
function getUUIDFromQualifiers (qualifiers) {
66+
return trimTrailingSlash(
67+
qualifiers
68+
.filter(q => q.Name === 'UUID')[0]
69+
.Value
70+
)
71+
}
72+
73+
function getUUIDFromPath (path) {
74+
return path.split('\\')[3].slice(7, -2)
75+
}
76+
77+
function getHost (path) {
78+
return path.split('\\')[2]
79+
}
80+
81+
function parseNetworkResults (obj) {
82+
if (!('0' in obj.json))
83+
obj.json = { '0': obj.json }
84+
85+
return Object.entries(obj.json).map(([key, val]) => {
86+
return {
87+
host: getHost(val.providerName),
88+
size: val.size,
89+
unc: val.providerName,
90+
letter: val.name[0],
91+
free: val.freeSpace,
92+
fs: val.fileSystem,
93+
uuid: getUUIDFromQualifiers(val.qualifiers),
94+
type: 'network'
95+
}
96+
})
97+
}
98+
99+
function parseLocalResults (obj) {
100+
if (!('0' in obj.json))
101+
obj.json = { '0': obj.json }
102+
103+
const discs = Object.entries(obj.json)
104+
.map(([key, val]) => val)
105+
.filter(filterReserved)
106+
107+
return discs.map(val => {
108+
return {
109+
size: val.size,
110+
unc: val.uniqueId.slice(0, -1),
111+
letter: val.driveLetter,
112+
free: val.sizeRemaining,
113+
fs: val.fileSystem,
114+
host: val.cimSystemProperties.serverName.toLowerCase(),
115+
uuid: getUUIDFromPath(val.uniqueId),
116+
type: val.driveType.toLowerCase(val.uniqueId)
117+
}
118+
})
119+
}
120+
121+
function trimTrailingSlash (path) {
122+
return path
123+
.slice(0, -1)
124+
.slice(1)
125+
}
126+
127+
function filterReserved (disc) {
128+
return disc.fileSystemLabel !== 'System Reserved'
129+
}

src/test.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/test/discoid.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/test/mountvol.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)