• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

coderaiser / cloudcmd / 21684180251

04 Feb 2026 06:51PM UTC coverage: 66.425%. Remained the same
21684180251

push

github

coderaiser
fix: cloudcmd: exports

724 of 788 branches covered (91.88%)

3 of 3 new or added lines in 1 file covered. (100.0%)

4 existing lines in 1 file now uncovered.

4665 of 7023 relevant lines covered (66.42%)

31.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.67
/server/cloudcmd.js
1
import path, {dirname, join} from 'node:path';
3✔
2
import {fileURLToPath} from 'node:url';
3✔
3
import process from 'node:process';
3✔
4
import fs from 'node:fs';
3✔
5
import {fullstore} from 'fullstore';
3✔
6
import currify from 'currify';
3✔
7
import apart from 'apart';
3✔
8
import ponse from 'ponse';
3✔
9
import {restafary} from 'restafary';
3✔
10
import restbox from 'restbox';
3✔
11
import konsole from 'console-io';
3✔
12
import {edward} from 'edward';
3✔
13
import dword from 'dword';
3✔
14
import deepword from 'deepword';
3✔
15
import nomine from 'nomine';
3✔
16
import fileop from '@cloudcmd/fileop';
3✔
17
import * as cloudfunc from '#common/cloudfunc';
3✔
18
import authentication from './auth.js';
3✔
19
import {createConfig, configPath} from './config.js';
3✔
20
import modulas from './modulas.js';
3✔
21
import {userMenu} from './user-menu.js';
3✔
22
import rest from './rest/index.js';
3✔
23
import route from './route.js';
3✔
24
import * as validate from './validate.js';
3✔
25
import prefixer from './prefixer.js';
3✔
26
import terminal from './terminal.js';
3✔
27
import {distributeExport} from './distribute/export.js';
3✔
28
import {createDepStore} from './depstore.js';
3✔
29

3✔
30
const __filename = fileURLToPath(import.meta.url);
3✔
31
const __dirname = dirname(__filename);
3✔
32
const {assign} = Object;
3✔
33
const DIR = `${__dirname}/`;
3✔
34
const DIR_ROOT = join(DIR, '..');
3✔
35
const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
3✔
36

3✔
37
const isDev = fullstore(process.env.NODE_ENV === 'development');
3✔
38

3✔
39
const getIndexPath = (isDev) => path.join(DIR, '..', `${getDist(isDev)}/index.html`);
3✔
40
const html = fs.readFileSync(getIndexPath(isDev()), 'utf8');
3✔
41

3✔
42
const initAuth = currify(_initAuth);
3✔
43
const notEmpty = (a) => a;
3✔
44
const clean = (a) => a.filter(notEmpty);
3✔
45

3✔
46
const isUndefined = (a) => typeof a === 'undefined';
3✔
47
const isFn = (a) => typeof a === 'function';
3✔
48

3✔
49
export default cloudcmd;
3✔
50

3✔
51
export function cloudcmd(params) {
3✔
52
    const p = params || {};
243!
53
    const options = p.config || {};
243✔
54
    const config = p.configManager || createConfig({
243✔
55
        configPath,
138✔
56
    });
243✔
57
    
243✔
58
    const {modules} = p;
243✔
59
    const keys = Object.keys(options);
243✔
60
    
243✔
61
    for (const name of keys) {
243✔
62
        let value = options[name];
690✔
63
        
690✔
64
        if (/root/.test(name))
690✔
65
            validate.root(value, config);
690✔
66
        
687✔
67
        if (/editor|packer|themes|menu/.test(name))
687✔
68
            validate[name](value);
690✔
69
        
687✔
70
        if (/prefix/.test(name))
687✔
71
            value = prefixer(value);
690✔
72
        
687✔
73
        config(name, value);
687✔
74
    }
687✔
75
    
240✔
76
    config('console', defaultValue(config, 'console', options));
240✔
77
    config('configDialog', defaultValue(config, 'configDialog', options));
240✔
78
    
240✔
79
    const prefixSocket = prefixer(options.prefixSocket);
240✔
80
    
240✔
81
    if (p.socket)
240✔
82
        listen({
243✔
83
            prefixSocket,
54✔
84
            config,
54✔
85
            socket: p.socket,
54✔
86
        });
54✔
87
    
240✔
88
    return cloudcmdMiddle({
240✔
89
        modules,
240✔
90
        config,
240✔
91
    });
240✔
92
}
243✔
93

3✔
94
const depStore = createDepStore();
3✔
95

3✔
96
export const createConfigManager = createConfig;
3✔
97
export {
3✔
98
    configPath,
3✔
99
};
3✔
100

3✔
101
export const _getIndexPath = getIndexPath;
3✔
102

3✔
103
function defaultValue(config, name, options) {
480✔
104
    const value = options[name];
480✔
105
    const previous = config(name);
480✔
106
    
480✔
107
    if (isUndefined(value))
480✔
108
        return previous;
480✔
109
    
24✔
110
    return value;
24✔
111
}
480✔
112

3✔
113
export const _getPrefix = getPrefix;
3✔
114

3✔
115
function getPrefix(prefix) {
63✔
116
    if (isFn(prefix))
63✔
117
        return prefix() || '';
63✔
118
    
57✔
119
    return prefix || '';
63✔
120
}
63✔
121

3✔
122
export function _initAuth(config, accept, reject, username, password) {
3✔
123
    if (!config('auth'))
12✔
124
        return accept();
12✔
125
    
6✔
126
    const isName = username === config('username');
6✔
127
    const isPass = password === config('password');
6✔
128
    
6✔
129
    if (isName && isPass)
12✔
130
        return accept();
12✔
131
    
3✔
132
    reject();
3✔
133
}
12✔
134

3✔
135
function listen({prefixSocket, socket, config}) {
54✔
136
    const root = apart(config, 'root');
54✔
137
    const auth = initAuth(config);
54✔
138
    
54✔
139
    prefixSocket = getPrefix(prefixSocket);
54✔
140
    config.listen(socket, auth);
54✔
141
    
54✔
142
    edward.listen(socket, {
54✔
143
        root,
54✔
144
        auth,
54✔
145
        prefixSocket: `${prefixSocket}/edward`,
54✔
146
    });
54✔
147
    
54✔
148
    dword.listen(socket, {
54✔
149
        root,
54✔
150
        auth,
54✔
151
        prefixSocket: `${prefixSocket}/dword`,
54✔
152
    });
54✔
153
    
54✔
154
    deepword.listen(socket, {
54✔
155
        root,
54✔
156
        auth,
54✔
157
        prefixSocket: `${prefixSocket}/deepword`,
54✔
158
    });
54✔
159
    
54✔
160
    config('console') && konsole.listen(socket, {
54✔
161
        auth,
51✔
162
        prefixSocket: `${prefixSocket}/console`,
51✔
163
    });
54✔
164
    
54✔
165
    fileop.listen(socket, {
54✔
166
        root,
54✔
167
        auth,
54✔
168
        prefix: `${prefixSocket}/fileop`,
54✔
169
    });
54✔
170
    
54✔
171
    config('terminal') && terminal(config).listen(socket, {
54!
UNCOV
172
        auth,
×
UNCOV
173
        prefix: `${prefixSocket}/gritty`,
×
174
        command: config('terminalCommand'),
×
175
        autoRestart: config('terminalAutoRestart'),
×
176
    });
54✔
177
    
54✔
178
    distributeExport(config, socket);
54✔
179
}
54✔
180

3✔
181
function cloudcmdMiddle({modules, config}) {
240✔
182
    const online = apart(config, 'online');
240✔
183
    const cache = false;
240✔
184
    const diff = apart(config, 'diff');
240✔
185
    const zip = apart(config, 'zip');
240✔
186
    const root = apart(config, 'root');
240✔
187
    
240✔
188
    const ponseStatic = ponse.static({
240✔
189
        cache,
240✔
190
        root: DIR_ROOT,
240✔
191
    });
240✔
192
    
240✔
193
    const dropbox = config('dropbox');
240✔
194
    const dropboxToken = config('dropboxToken');
240✔
195
    
240✔
196
    const funcs = clean([
240✔
197
        config('console') && konsole({
240✔
198
            online,
231✔
199
        }),
240✔
200
        config('terminal') && terminal(config, {}),
240✔
201
        edward({
240✔
202
            root,
240✔
203
            online,
240✔
204
            diff,
240✔
205
            zip,
240✔
206
            dropbox,
240✔
207
            dropboxToken,
240✔
208
        }),
240✔
209
        dword({
240✔
210
            root,
240✔
211
            online,
240✔
212
            diff,
240✔
213
            zip,
240✔
214
            dropbox,
240✔
215
            dropboxToken,
240✔
216
        }),
240✔
217
        deepword({
240✔
218
            root,
240✔
219
            online,
240✔
220
            diff,
240✔
221
            zip,
240✔
222
            dropbox,
240✔
223
            dropboxToken,
240✔
224
        }),
240✔
225
        fileop(),
240✔
226
        nomine(),
240✔
227
        setUrl,
240✔
228
        setSW,
240✔
229
        logout,
240✔
230
        authentication(config),
240✔
231
        config.middle,
240✔
232
        modules && modulas(modules),
240✔
233
        config('dropbox') && restbox({
240!
UNCOV
234
            prefix: cloudfunc.apiURL,
×
UNCOV
235
            root,
×
236
            token: dropboxToken,
×
237
        }),
240✔
238
        restafary({
240✔
239
            prefix: cloudfunc.apiURL + '/fs',
240✔
240
            root,
240✔
241
        }),
240✔
242
        userMenu({
240✔
243
            menuName: '.cloudcmd.menu.js',
240✔
244
        }),
240✔
245
        rest({
240✔
246
            config,
240✔
247
            fs: depStore('fs'),
240✔
248
            moveFiles: depStore('moveFiles'),
240✔
249
        }),
240✔
250
        route(config, {
240✔
251
            html,
240✔
252
            win32: depStore('win32'),
240✔
253
        }),
240✔
254
        ponseStatic,
240✔
255
    ]);
240✔
256
    
240✔
257
    return funcs;
240✔
258
}
240✔
259

3✔
260
function logout(req, res, next) {
180✔
261
    if (req.url !== '/logout')
180✔
262
        return next();
180✔
263
    
3✔
264
    res.sendStatus(401);
3✔
265
}
180✔
266

3✔
267
export const _isDev = isDev;
3✔
268
export const _replaceDist = replaceDist;
3✔
269

3✔
270
function replaceDist(url) {
189✔
271
    if (!isDev())
189✔
272
        return url;
189✔
273
    
3✔
274
    return url.replace(/^\/dist\//, '/dist-dev/');
3✔
275
}
189✔
276

3✔
277
function setUrl(req, res, next) {
180✔
278
    if (/^\/cloudcmd\.js(\.map)?$/.test(req.url))
180✔
279
        req.url = `/dist${req.url}`;
180✔
280
    
180✔
281
    req.url = replaceDist(req.url);
180✔
282
    
180✔
283
    next();
180✔
284
}
180✔
285

3✔
286
function setSW(req, res, next) {
180✔
287
    const {url} = req;
180✔
288
    const isSW = /^\/sw\.[mc]?js(\.map)?$/.test(url);
180✔
289
    
180✔
290
    if (isSW) {
180✔
291
        const url = req.url.replace(/[cm]js/, 'js');
3✔
292
        req.url = replaceDist(`/dist${url}`);
3✔
293
    }
3✔
294
    
180✔
295
    next();
180✔
296
}
180✔
297

3✔
298
assign(cloudcmd, {
3✔
299
    depStore,
3✔
300
    createConfigManager,
3✔
301
});
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc