check-disk-space 1.5.0 → 3.0.1
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/LICENSE +1 -1
- package/README.md +24 -4
- package/dist/check-disk-space.cjs.js +157 -0
- package/dist/check-disk-space.d.ts +49 -0
- package/dist/check-disk-space.es.js +151 -0
- package/package.json +62 -17
- package/.editorconfig +0 -14
- package/.idea/check-disk-space.iml +0 -8
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -214
- package/.travis.yml +0 -6
- package/index.js +0 -151
- package/test.js +0 -205
- package/yarn.lock +0 -3680
package/.idea/workspace.xml
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ChangeListManager">
|
|
4
|
-
<list default="true" id="abd58cbf-ef3f-4064-9dbc-40549c986373" name="Default" comment="">
|
|
5
|
-
<change beforePath="$PROJECT_DIR$/package.json" afterPath="$PROJECT_DIR$/package.json" />
|
|
6
|
-
</list>
|
|
7
|
-
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
|
8
|
-
<option name="TRACKING_ENABLED" value="true" />
|
|
9
|
-
<option name="SHOW_DIALOG" value="false" />
|
|
10
|
-
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
11
|
-
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
12
|
-
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
13
|
-
</component>
|
|
14
|
-
<component name="FileColors">
|
|
15
|
-
<fileColor scope="Non-Project Files (Material Default)" color="2E3C43" />
|
|
16
|
-
<fileColor scope="Non-Project Files (Material Darker)" color="323232" />
|
|
17
|
-
<fileColor scope="Non-Project Files (Material Lighter)" color="eae8e8" />
|
|
18
|
-
<fileColor scope="Non-Project Files (Material Palenight)" color="2f2e43" />
|
|
19
|
-
</component>
|
|
20
|
-
<component name="FileEditorManager">
|
|
21
|
-
<leaf>
|
|
22
|
-
<file leaf-file-name="index.js" pinned="false" current-in-tab="false">
|
|
23
|
-
<entry file="file://$PROJECT_DIR$/index.js">
|
|
24
|
-
<provider selected="true" editor-type-id="text-editor">
|
|
25
|
-
<state relative-caret-position="552">
|
|
26
|
-
<caret line="120" column="17" lean-forward="false" selection-start-line="120" selection-start-column="17" selection-end-line="120" selection-end-column="17" />
|
|
27
|
-
<folding />
|
|
28
|
-
</state>
|
|
29
|
-
</provider>
|
|
30
|
-
</entry>
|
|
31
|
-
</file>
|
|
32
|
-
<file leaf-file-name="test.js" pinned="false" current-in-tab="false">
|
|
33
|
-
<entry file="file://$PROJECT_DIR$/test.js">
|
|
34
|
-
<provider selected="true" editor-type-id="text-editor">
|
|
35
|
-
<state relative-caret-position="391">
|
|
36
|
-
<caret line="119" column="24" lean-forward="false" selection-start-line="119" selection-start-column="24" selection-end-line="119" selection-end-column="24" />
|
|
37
|
-
<folding />
|
|
38
|
-
</state>
|
|
39
|
-
</provider>
|
|
40
|
-
</entry>
|
|
41
|
-
</file>
|
|
42
|
-
<file leaf-file-name="package.json" pinned="false" current-in-tab="true">
|
|
43
|
-
<entry file="file://$PROJECT_DIR$/package.json">
|
|
44
|
-
<provider selected="true" editor-type-id="text-editor">
|
|
45
|
-
<state relative-caret-position="46">
|
|
46
|
-
<caret line="2" column="17" lean-forward="false" selection-start-line="2" selection-start-column="17" selection-end-line="2" selection-end-column="17" />
|
|
47
|
-
<folding />
|
|
48
|
-
</state>
|
|
49
|
-
</provider>
|
|
50
|
-
</entry>
|
|
51
|
-
</file>
|
|
52
|
-
</leaf>
|
|
53
|
-
</component>
|
|
54
|
-
<component name="Git.Settings">
|
|
55
|
-
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
56
|
-
</component>
|
|
57
|
-
<component name="IdeDocumentHistory">
|
|
58
|
-
<option name="CHANGED_PATHS">
|
|
59
|
-
<list>
|
|
60
|
-
<option value="$PROJECT_DIR$/index.js" />
|
|
61
|
-
<option value="$PROJECT_DIR$/test.js" />
|
|
62
|
-
<option value="$PROJECT_DIR$/package.json" />
|
|
63
|
-
</list>
|
|
64
|
-
</option>
|
|
65
|
-
</component>
|
|
66
|
-
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
|
|
67
|
-
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER">
|
|
68
|
-
<package-json value="$PROJECT_DIR$/package.json" />
|
|
69
|
-
</component>
|
|
70
|
-
<component name="JsFlowSettings">
|
|
71
|
-
<service-enabled>true</service-enabled>
|
|
72
|
-
<exe-path />
|
|
73
|
-
<other-services-enabled>true</other-services-enabled>
|
|
74
|
-
<auto-save>true</auto-save>
|
|
75
|
-
</component>
|
|
76
|
-
<component name="JsGulpfileManager">
|
|
77
|
-
<detection-done>true</detection-done>
|
|
78
|
-
<sorting>DEFINITION_ORDER</sorting>
|
|
79
|
-
</component>
|
|
80
|
-
<component name="NodeModulesDirectoryManager">
|
|
81
|
-
<handled-path value="$PROJECT_DIR$/node_modules" />
|
|
82
|
-
</component>
|
|
83
|
-
<component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" />
|
|
84
|
-
<component name="ProjectFrameBounds" extendedState="6">
|
|
85
|
-
<option name="x" value="24" />
|
|
86
|
-
<option name="y" value="16" />
|
|
87
|
-
<option name="width" value="1920" />
|
|
88
|
-
<option name="height" value="1080" />
|
|
89
|
-
</component>
|
|
90
|
-
<component name="ProjectView">
|
|
91
|
-
<navigator currentView="ProjectPane" proportions="" version="1">
|
|
92
|
-
<flattenPackages />
|
|
93
|
-
<showMembers />
|
|
94
|
-
<showModules />
|
|
95
|
-
<showLibraryContents />
|
|
96
|
-
<hideEmptyPackages />
|
|
97
|
-
<abbreviatePackageNames />
|
|
98
|
-
<autoscrollToSource />
|
|
99
|
-
<autoscrollFromSource />
|
|
100
|
-
<sortByType />
|
|
101
|
-
<manualOrder />
|
|
102
|
-
<foldersAlwaysOnTop value="true" />
|
|
103
|
-
</navigator>
|
|
104
|
-
<panes>
|
|
105
|
-
<pane id="ProjectPane">
|
|
106
|
-
<subPane>
|
|
107
|
-
<expand>
|
|
108
|
-
<path>
|
|
109
|
-
<item name="check-disk-space" type="b2602c69:ProjectViewProjectNode" />
|
|
110
|
-
<item name="check-disk-space" type="2a2b976b:PhpTreeStructureProvider$1" />
|
|
111
|
-
</path>
|
|
112
|
-
</expand>
|
|
113
|
-
<select />
|
|
114
|
-
</subPane>
|
|
115
|
-
</pane>
|
|
116
|
-
<pane id="Scratches" />
|
|
117
|
-
<pane id="Scope" />
|
|
118
|
-
</panes>
|
|
119
|
-
</component>
|
|
120
|
-
<component name="PropertiesComponent">
|
|
121
|
-
<property name="settings.editor.selected.configurable" value="Settings.JavaScript" />
|
|
122
|
-
<property name="nodejs_interpreter_path" value="$USER_HOME$/.nvm/versions/node/v8.6.0/bin/node" />
|
|
123
|
-
<property name="javascript.nodejs.core.library.configured.version" value="8.6.0" />
|
|
124
|
-
<property name="JavaScriptWeakerCompletionTypeGuess" value="true" />
|
|
125
|
-
</component>
|
|
126
|
-
<component name="RunDashboard">
|
|
127
|
-
<option name="ruleStates">
|
|
128
|
-
<list>
|
|
129
|
-
<RuleState>
|
|
130
|
-
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
|
131
|
-
</RuleState>
|
|
132
|
-
<RuleState>
|
|
133
|
-
<option name="name" value="StatusDashboardGroupingRule" />
|
|
134
|
-
</RuleState>
|
|
135
|
-
</list>
|
|
136
|
-
</option>
|
|
137
|
-
</component>
|
|
138
|
-
<component name="ShelveChangesManager" show_recycled="false">
|
|
139
|
-
<option name="remove_strategy" value="false" />
|
|
140
|
-
</component>
|
|
141
|
-
<component name="SvnConfiguration">
|
|
142
|
-
<configuration />
|
|
143
|
-
</component>
|
|
144
|
-
<component name="TaskManager">
|
|
145
|
-
<task active="true" id="Default" summary="Default task">
|
|
146
|
-
<changelist id="abd58cbf-ef3f-4064-9dbc-40549c986373" name="Default" comment="" />
|
|
147
|
-
<created>1515666790254</created>
|
|
148
|
-
<option name="number" value="Default" />
|
|
149
|
-
<option name="presentableId" value="Default" />
|
|
150
|
-
<updated>1515666790254</updated>
|
|
151
|
-
</task>
|
|
152
|
-
<servers />
|
|
153
|
-
</component>
|
|
154
|
-
<component name="ToolWindowManager">
|
|
155
|
-
<frame x="-1" y="0" width="1922" height="1081" extended-state="6" />
|
|
156
|
-
<editor active="true" />
|
|
157
|
-
<layout>
|
|
158
|
-
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24973376" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
|
|
159
|
-
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
|
160
|
-
<window_info id="SvgViewer" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
|
161
|
-
<window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
|
162
|
-
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
|
|
163
|
-
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
|
164
|
-
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
|
165
|
-
<window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
|
|
166
|
-
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
|
167
|
-
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
|
168
|
-
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
|
|
169
|
-
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
|
|
170
|
-
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
|
|
171
|
-
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
|
|
172
|
-
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
|
|
173
|
-
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
|
174
|
-
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
|
|
175
|
-
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
|
176
|
-
</layout>
|
|
177
|
-
</component>
|
|
178
|
-
<component name="TypeScriptGeneratedFilesManager">
|
|
179
|
-
<option name="version" value="1" />
|
|
180
|
-
</component>
|
|
181
|
-
<component name="VcsContentAnnotationSettings">
|
|
182
|
-
<option name="myLimit" value="2678400000" />
|
|
183
|
-
</component>
|
|
184
|
-
<component name="XDebuggerManager">
|
|
185
|
-
<breakpoint-manager />
|
|
186
|
-
<watches-manager />
|
|
187
|
-
</component>
|
|
188
|
-
<component name="editorHistoryManager">
|
|
189
|
-
<entry file="file://$PROJECT_DIR$/index.js">
|
|
190
|
-
<provider selected="true" editor-type-id="text-editor">
|
|
191
|
-
<state relative-caret-position="552">
|
|
192
|
-
<caret line="120" column="17" lean-forward="false" selection-start-line="120" selection-start-column="17" selection-end-line="120" selection-end-column="17" />
|
|
193
|
-
<folding />
|
|
194
|
-
</state>
|
|
195
|
-
</provider>
|
|
196
|
-
</entry>
|
|
197
|
-
<entry file="file://$PROJECT_DIR$/test.js">
|
|
198
|
-
<provider selected="true" editor-type-id="text-editor">
|
|
199
|
-
<state relative-caret-position="391">
|
|
200
|
-
<caret line="119" column="24" lean-forward="false" selection-start-line="119" selection-start-column="24" selection-end-line="119" selection-end-column="24" />
|
|
201
|
-
<folding />
|
|
202
|
-
</state>
|
|
203
|
-
</provider>
|
|
204
|
-
</entry>
|
|
205
|
-
<entry file="file://$PROJECT_DIR$/package.json">
|
|
206
|
-
<provider selected="true" editor-type-id="text-editor">
|
|
207
|
-
<state relative-caret-position="46">
|
|
208
|
-
<caret line="2" column="17" lean-forward="false" selection-start-line="2" selection-start-column="17" selection-end-line="2" selection-end-column="17" />
|
|
209
|
-
<folding />
|
|
210
|
-
</state>
|
|
211
|
-
</provider>
|
|
212
|
-
</entry>
|
|
213
|
-
</component>
|
|
214
|
-
</project>
|
package/.travis.yml
DELETED
package/index.js
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const {exec} = require('child_process')
|
|
4
|
-
const fs = require('fs')
|
|
5
|
-
const path = require('path')
|
|
6
|
-
const util = require('util')
|
|
7
|
-
|
|
8
|
-
// Create some errors
|
|
9
|
-
const InvalidPathError = function (message) {
|
|
10
|
-
Error.captureStackTrace(this, this.constructor)
|
|
11
|
-
this.name = 'InvalidPathError'
|
|
12
|
-
this.message = message || ''
|
|
13
|
-
}
|
|
14
|
-
util.inherits(InvalidPathError, Error)
|
|
15
|
-
|
|
16
|
-
const NoMatchError = function (message) {
|
|
17
|
-
Error.captureStackTrace(this, this.constructor)
|
|
18
|
-
this.name = 'NoMatchError'
|
|
19
|
-
this.message = message || ''
|
|
20
|
-
}
|
|
21
|
-
util.inherits(NoMatchError, Error)
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Maps command output to a normalized object {free, size}
|
|
25
|
-
*
|
|
26
|
-
* @param {String} stdout - The command output
|
|
27
|
-
* @param {Function} filter - To filter drives (only used for win32)
|
|
28
|
-
* @param {Object} mapping - Map between column index and normalized column name
|
|
29
|
-
* @param {Number} coefficient - The size coefficient to get bytes instead of kB
|
|
30
|
-
* @return {Object} - {free, size} normalized object
|
|
31
|
-
*/
|
|
32
|
-
function mapOutput(stdout, filter, mapping, coefficient = 1) {
|
|
33
|
-
const parsed = stdout.trim().split('\n').slice(1).map(line => {
|
|
34
|
-
return line.trim().split(/\s+(?=[\d/])/)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
let filtered = parsed.filter(filter)
|
|
38
|
-
|
|
39
|
-
if (filtered.length === 0) {
|
|
40
|
-
throw new NoMatchError()
|
|
41
|
-
}
|
|
42
|
-
filtered = filtered[0]
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
diskPath: filtered[mapping.diskPath],
|
|
46
|
-
free: parseInt(filtered[mapping.free], 10) * coefficient,
|
|
47
|
-
size: parseInt(filtered[mapping.size], 10) * coefficient
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Run the command and do common things between win32 and unix
|
|
53
|
-
*
|
|
54
|
-
* @param {String} cmd - The command to execute
|
|
55
|
-
* @param {Function} filter - To filter drives (only used for win32)
|
|
56
|
-
* @param {Object} mapping - Map between column index and normalized column name
|
|
57
|
-
* @param {Number} coefficient - The size coefficient to get bytes instead of kB
|
|
58
|
-
* @return {Promise} -
|
|
59
|
-
*/
|
|
60
|
-
function check(cmd, filter, mapping, coefficient = 1) {
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
exec(cmd, (error, stdout) => {
|
|
63
|
-
if (error) {
|
|
64
|
-
reject(error)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
resolve(mapOutput(stdout, filter, mapping, coefficient))
|
|
69
|
-
} catch (err) {
|
|
70
|
-
reject(err)
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Build the check call for win32
|
|
78
|
-
*
|
|
79
|
-
* @param {String} directoryPath - The file/folder path from where we want to know disk space
|
|
80
|
-
* @return {Promise} -
|
|
81
|
-
*/
|
|
82
|
-
function checkWin32(directoryPath) {
|
|
83
|
-
if (directoryPath.charAt(1) !== ':') {
|
|
84
|
-
return new Promise((resolve, reject) => {
|
|
85
|
-
reject(new InvalidPathError(`The following path is invalid (should be X:\\...): ${directoryPath}`))
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return check(
|
|
90
|
-
`wmic logicaldisk get size,freespace,caption`,
|
|
91
|
-
driveData => {
|
|
92
|
-
// Only get the drive which match the path
|
|
93
|
-
const driveLetter = driveData[0]
|
|
94
|
-
return directoryPath.startsWith(driveLetter)
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
diskPath: 0,
|
|
98
|
-
free: 1,
|
|
99
|
-
size: 2
|
|
100
|
-
}
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Build the check call for unix
|
|
106
|
-
*
|
|
107
|
-
* @param {String} directoryPath - The file/folder path from where we want to know disk space
|
|
108
|
-
* @return {Promise} -
|
|
109
|
-
*/
|
|
110
|
-
function checkUnix(directoryPath) {
|
|
111
|
-
if (!path.normalize(directoryPath).startsWith(path.sep)) {
|
|
112
|
-
return new Promise((resolve, reject) => {
|
|
113
|
-
reject(new InvalidPathError(`The following path is invalid (should start by ${path.sep}): ${directoryPath}`))
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return check(
|
|
118
|
-
`df -Pk "${module.exports.getFirstExistingParentPath(directoryPath)}"`,
|
|
119
|
-
() => true, // We should only get one line, so we did not need to filter
|
|
120
|
-
{
|
|
121
|
-
diskPath: 5,
|
|
122
|
-
free: 3,
|
|
123
|
-
size: 1
|
|
124
|
-
},
|
|
125
|
-
1024 // We get sizes in kB, we need to convert that to bytes
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Inject the right check depending on the OS
|
|
130
|
-
module.exports = (process.platform === 'win32') ? checkWin32 : checkUnix
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Get the first existing parent path
|
|
134
|
-
*
|
|
135
|
-
* @param directoryPath
|
|
136
|
-
* @returns {*}
|
|
137
|
-
*/
|
|
138
|
-
module.exports.getFirstExistingParentPath = directoryPath => {
|
|
139
|
-
let parentDirectoryPath = directoryPath
|
|
140
|
-
let parentDirectoryFound = fs.existsSync(parentDirectoryPath)
|
|
141
|
-
|
|
142
|
-
while (!parentDirectoryFound) {
|
|
143
|
-
parentDirectoryPath = path.normalize(parentDirectoryPath + '/..')
|
|
144
|
-
parentDirectoryFound = fs.existsSync(parentDirectoryPath)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return parentDirectoryPath
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
module.exports.InvalidPathError = InvalidPathError
|
|
151
|
-
module.exports.NoMatchError = NoMatchError
|
package/test.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import test from 'ava'
|
|
4
|
-
|
|
5
|
-
const platformFixtures = {
|
|
6
|
-
win32: [
|
|
7
|
-
{
|
|
8
|
-
title: 'Windows XP',
|
|
9
|
-
path: 'D:/a/long/path',
|
|
10
|
-
execOutput: `
|
|
11
|
-
Caption FreeSpace Size
|
|
12
|
-
C: 627703808 10725732352
|
|
13
|
-
D: 0 699783168
|
|
14
|
-
E: 25851797504 107496861696
|
|
15
|
-
F: 834660716544 2000396742656
|
|
16
|
-
`,
|
|
17
|
-
result: {
|
|
18
|
-
diskPath: 'D:',
|
|
19
|
-
free: 0,
|
|
20
|
-
size: 699783168
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
title: 'Windows 7',
|
|
25
|
-
path: 'C:/blah',
|
|
26
|
-
execOutput: `
|
|
27
|
-
Caption FreeSpace Size
|
|
28
|
-
C: 1286164480 34359734272
|
|
29
|
-
D: 1864638464 50925137920
|
|
30
|
-
E:
|
|
31
|
-
F: 77553082368 990202818560
|
|
32
|
-
G:
|
|
33
|
-
L:
|
|
34
|
-
`,
|
|
35
|
-
result: {
|
|
36
|
-
diskPath: 'C:',
|
|
37
|
-
free: 1286164480,
|
|
38
|
-
size: 34359734272
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
title: 'Windows 8',
|
|
43
|
-
path: 'D:/MyGames',
|
|
44
|
-
execOutput: `
|
|
45
|
-
Caption FreeSpace Size
|
|
46
|
-
C: 498562174976 539028877312
|
|
47
|
-
D: 0 59494400
|
|
48
|
-
`,
|
|
49
|
-
result: {
|
|
50
|
-
diskPath: 'D:',
|
|
51
|
-
free: 0,
|
|
52
|
-
size: 59494400
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
title: 'Windows 10',
|
|
57
|
-
path: 'C:/User/toto',
|
|
58
|
-
execOutput: `
|
|
59
|
-
Caption FreeSpace Size
|
|
60
|
-
C: 159345410048 171204145152
|
|
61
|
-
D: 0 4001759232
|
|
62
|
-
`,
|
|
63
|
-
result: {
|
|
64
|
-
diskPath: 'C:',
|
|
65
|
-
free: 159345410048,
|
|
66
|
-
size: 171204145152
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
],
|
|
70
|
-
linux: [
|
|
71
|
-
{
|
|
72
|
-
title: 'bananian',
|
|
73
|
-
path: '/dev',
|
|
74
|
-
execOutput: `
|
|
75
|
-
Filesystem 1K-blocks Used Available Use% Mounted on
|
|
76
|
-
devtmpfs 447624 0 447624 0% /dev
|
|
77
|
-
`,
|
|
78
|
-
result: {
|
|
79
|
-
diskPath: '/dev',
|
|
80
|
-
free: 447624 * 1024,
|
|
81
|
-
size: 447624 * 1024
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
title: 'Ubuntu',
|
|
86
|
-
path: '/run/user/1000',
|
|
87
|
-
execOutput: `
|
|
88
|
-
Filesystem 1024-blocks Used Available Capacity Mounted on
|
|
89
|
-
tmpfs 89884 8 89876 1% /run/user/1000
|
|
90
|
-
`,
|
|
91
|
-
result: {
|
|
92
|
-
diskPath: '/run/user/1000',
|
|
93
|
-
free: 89876 * 1024,
|
|
94
|
-
size: 89884 * 1024
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
title: 'Ubuntu: russian locale',
|
|
99
|
-
path: '/media/Games',
|
|
100
|
-
execOutput: `
|
|
101
|
-
Файл.система 1024-блоков Использовано Доступно Вместимость Cмонтировано в
|
|
102
|
-
/dev/sdc 240234168 188729228 39278628 83% /media/Games
|
|
103
|
-
`,
|
|
104
|
-
result: {
|
|
105
|
-
diskPath: '/media/Games',
|
|
106
|
-
free: 39278628 * 1024,
|
|
107
|
-
size: 240234168 * 1024
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
],
|
|
111
|
-
darwin: [
|
|
112
|
-
{
|
|
113
|
-
title: 'macOS',
|
|
114
|
-
path: '/home/jacquie',
|
|
115
|
-
execOutput: `
|
|
116
|
-
Filesystem 1024-blocks Used Available Capacity Mounted on
|
|
117
|
-
/dev/disk0s2 145961032 20678788 125026244 15% /home
|
|
118
|
-
`,
|
|
119
|
-
result: {
|
|
120
|
-
diskPath: '/home',
|
|
121
|
-
free: 125026244 * 1024,
|
|
122
|
-
size: 145961032 * 1024
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
]
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function mockCheckDiskSpace(platform, fixture) {
|
|
129
|
-
// Clean some required paths
|
|
130
|
-
delete require.cache[require.resolve('./')]
|
|
131
|
-
|
|
132
|
-
// Forces the platform for test purposes
|
|
133
|
-
Object.defineProperty(process, 'platform', {value: platform})
|
|
134
|
-
|
|
135
|
-
// Mock child_process.exec
|
|
136
|
-
require('child_process').exec = (cmd, callback) => {
|
|
137
|
-
process.nextTick(() => {
|
|
138
|
-
callback(fixture.execError, fixture.execOutput)
|
|
139
|
-
})
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return require('./')
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function mockGetFirstExistingParentPath(existingDirectoryPath) {
|
|
146
|
-
// Clean some required paths
|
|
147
|
-
delete require.cache[require.resolve('./')]
|
|
148
|
-
|
|
149
|
-
// Forces the platform for test purposes
|
|
150
|
-
Object.defineProperty(process, 'platform', {value: 'linux'})
|
|
151
|
-
|
|
152
|
-
// Mock child_process.exec
|
|
153
|
-
require('fs').existsSync = directoryPath => directoryPath === existingDirectoryPath
|
|
154
|
-
|
|
155
|
-
return require('./').getFirstExistingParentPath
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
Object.keys(platformFixtures).forEach(platform => {
|
|
159
|
-
platformFixtures[platform].forEach(fixture => {
|
|
160
|
-
test(`${platform}: ${fixture.title}`, async t => {
|
|
161
|
-
const checkDiskSpace = mockCheckDiskSpace(platform, fixture)
|
|
162
|
-
|
|
163
|
-
t.deepEqual(await checkDiskSpace(fixture.path), fixture.result)
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
test(`win32: path did not match any disk`, async t => {
|
|
169
|
-
const checkDiskSpace = mockCheckDiskSpace('win32', platformFixtures.win32[0])
|
|
170
|
-
const error = await t.throws(checkDiskSpace('Z:/shouldfail'))
|
|
171
|
-
t.is(error.name, 'NoMatchError')
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
test(`win32: invalid path`, async t => {
|
|
175
|
-
const checkDiskSpace = mockCheckDiskSpace('win32', platformFixtures.win32[0])
|
|
176
|
-
const error = await t.throws(checkDiskSpace('an invalid path'))
|
|
177
|
-
t.is(error.name, 'InvalidPathError')
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
test(`unix: invalid path`, async t => {
|
|
181
|
-
const checkDiskSpace = mockCheckDiskSpace('linux', platformFixtures.linux[0])
|
|
182
|
-
const error = await t.throws(checkDiskSpace('an invalid path'))
|
|
183
|
-
t.is(error.name, 'InvalidPathError')
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
test(`exec has an error`, async t => {
|
|
187
|
-
const fixture = JSON.parse(JSON.stringify(platformFixtures.win32[0]))
|
|
188
|
-
fixture.execError = new Error('some error')
|
|
189
|
-
|
|
190
|
-
const checkDiskSpace = mockCheckDiskSpace('win32', fixture)
|
|
191
|
-
const error = await t.throws(checkDiskSpace('C:/something'))
|
|
192
|
-
t.is(error.message, 'some error')
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
test(`unix: get first existing parent path`, t => {
|
|
196
|
-
const parentPath = '/home/Lisa'
|
|
197
|
-
const getFirstExistingParentPath = mockGetFirstExistingParentPath(parentPath)
|
|
198
|
-
t.is(getFirstExistingParentPath('/home/Lisa/games/Ankama/Dofus'), parentPath)
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
test(`unix: get first parent can be the path itself`, t => {
|
|
202
|
-
const parentPath = '/home/Lisa'
|
|
203
|
-
const getFirstExistingParentPath = mockGetFirstExistingParentPath(parentPath)
|
|
204
|
-
t.is(getFirstExistingParentPath(parentPath), parentPath)
|
|
205
|
-
})
|