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

coderaiser / cloudcmd / 25975031683

16 May 2026 10:48PM UTC coverage: 65.962% (+0.07%) from 65.895%
25975031683

push

github

coderaiser
chore: cloudcmd: v19.17.0

761 of 832 branches covered (91.47%)

4994 of 7571 relevant lines covered (65.96%)

33.15 hits per line

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

97.8
/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 * as 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 {qword} from 'qword';
3✔
16
import nomine from 'nomine';
3✔
17
import {fileop} from '@cloudcmd/fileop';
3✔
18
import * as cloudfunc from '#common/cloudfunc';
3✔
19
import authentication from './auth.js';
3✔
20
import {createConfig, configPath} from './config.js';
3✔
21
import modulas from './modulas.js';
3✔
22
import {userMenu} from './user-menu.js';
3✔
23
import rest from './rest/index.js';
3✔
24
import route from './route.js';
3✔
25
import * as validate from './validate.js';
3✔
26
import prefixer from './prefixer.js';
3✔
27
import terminal from './terminal.js';
3✔
28
import {distributeExport} from './distribute/export.js';
3✔
29
import {createDepStore} from './depstore.js';
3✔
30

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

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

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

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

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

3✔
50
export default cloudcmd;
3✔
51

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

3✔
96
const depStore = createDepStore();
3✔
97

3✔
98
export const createConfigManager = createConfig;
3✔
99
export {
3✔
100
    configPath,
3✔
101
};
3✔
102

3✔
103
export const _getIndexPath = getIndexPath;
3✔
104

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

3✔
115
export const _getPrefix = getPrefix;
3✔
116

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

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

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

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

3✔
277
function logout(req, res, next) {
180✔
278
    if (req.url !== '/logout')
180✔
279
        return next();
180✔
280
    
3✔
281
    res.sendStatus(401);
3✔
282
}
180✔
283

3✔
284
export const _isDev = isDev;
3✔
285
export const _replaceDist = replaceDist;
3✔
286

3✔
287
function replaceDist(url) {
189✔
288
    if (!isDev())
189✔
289
        return url;
189✔
290
    
3✔
291
    return url.replace(/^\/dist\//, '/dist-dev/');
3✔
292
}
189✔
293

3✔
294
function setUrl(req, res, next) {
180✔
295
    if (/^\/cloudcmd\.js(\.map)?$/.test(req.url))
180✔
296
        req.url = `/dist${req.url}`;
180✔
297
    
180✔
298
    req.url = replaceDist(req.url);
180✔
299
    
180✔
300
    next();
180✔
301
}
180✔
302

3✔
303
function setSW(req, res, next) {
180✔
304
    const {url} = req;
180✔
305
    const isSW = /^\/sw\.[mc]?js(\.map)?$/.test(url);
180✔
306
    
180✔
307
    if (isSW) {
180✔
308
        const url = req.url.replace(/[cm]js/, 'js');
3✔
309
        req.url = replaceDist(`/dist${url}`);
3✔
310
    }
3✔
311
    
180✔
312
    next();
180✔
313
}
180✔
314

3✔
315
assign(cloudcmd, {
3✔
316
    depStore,
3✔
317
    createConfigManager,
3✔
318
});
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