cloudcmd 17.1.4 → 17.1.6

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.
@@ -1,28 +1,12 @@
1
1
  'use strict';
2
2
 
3
+ const {join} = require('node:path');
3
4
  const fullstore = require('fullstore');
4
5
  const process = require('node:process');
5
- const DIR = `${__dirname}/`;
6
- const DIR_COMMON = `${DIR}../common/`;
7
6
  const path = require('node:path');
8
-
9
7
  const fs = require('node:fs');
10
- const cloudfunc = require(`${DIR_COMMON}cloudfunc`);
11
-
12
- const authentication = require(`${DIR}auth`);
13
- const {createConfig, configPath} = require(`${DIR}config`);
14
-
15
- const modulas = require(`${DIR}modulas`);
16
8
 
17
- const userMenu = require(`${DIR}user-menu`);
18
- const rest = require(`${DIR}rest`);
19
- const route = require(`${DIR}route`);
20
- const validate = require(`${DIR}validate`);
21
- const prefixer = require(`${DIR}prefixer`);
22
- const terminal = require(`${DIR}terminal`);
23
- const distribute = require(`${DIR}distribute`);
24
9
  const currify = require('currify');
25
-
26
10
  const apart = require('apart');
27
11
  const ponse = require('ponse');
28
12
  const restafary = require('restafary');
@@ -33,8 +17,25 @@ const dword = require('dword');
33
17
  const deepword = require('deepword');
34
18
  const nomine = require('nomine');
35
19
  const fileop = require('@cloudcmd/fileop');
36
- const DIR_ROOT = `${DIR}../`;
37
20
 
21
+ const cloudfunc = require('../common/cloudfunc');
22
+
23
+ const authentication = require('./auth');
24
+ const {createConfig, configPath} = require(`./config`);
25
+
26
+ const modulas = require(`./modulas`);
27
+
28
+ const userMenu = require(`./user-menu`);
29
+ const rest = require(`./rest`);
30
+ const route = require(`./route`);
31
+ const validate = require(`./validate`);
32
+ const prefixer = require(`./prefixer`);
33
+ const terminal = require(`./terminal`);
34
+ const distribute = require(`./distribute`);
35
+ const {createDepStore} = require('./depstore');
36
+ const {assign} = Object;
37
+ const DIR = `${__dirname}/`;
38
+ const DIR_ROOT = join(DIR, '..');
38
39
  const getDist = (isDev) => isDev ? 'dist-dev' : 'dist';
39
40
 
40
41
  const isDev = fullstore(process.env.NODE_ENV === 'development');
@@ -49,7 +50,9 @@ const clean = (a) => a.filter(notEmpty);
49
50
  const isUndefined = (a) => typeof a === 'undefined';
50
51
  const isFn = (a) => typeof a === 'function';
51
52
 
52
- module.exports = (params) => {
53
+ module.exports = cloudcmd;
54
+
55
+ function cloudcmd(params) {
53
56
  const p = params || {};
54
57
  const options = p.config || {};
55
58
  const config = p.configManager || createConfig({
@@ -57,7 +60,6 @@ module.exports = (params) => {
57
60
  });
58
61
 
59
62
  const {modules} = p;
60
-
61
63
  const keys = Object.keys(options);
62
64
 
63
65
  for (const name of keys) {
@@ -87,11 +89,17 @@ module.exports = (params) => {
87
89
  socket: p.socket,
88
90
  });
89
91
 
90
- return cloudcmd({
92
+ return cloudcmdMiddle({
91
93
  modules,
92
94
  config,
93
95
  });
94
- };
96
+ }
97
+
98
+ const depStore = createDepStore();
99
+
100
+ assign(cloudcmd, {
101
+ depStore,
102
+ });
95
103
 
96
104
  module.exports.createConfigManager = createConfig;
97
105
  module.exports.configPath = configPath;
@@ -176,7 +184,7 @@ function listen({prefixSocket, socket, config}) {
176
184
  distribute.export(config, socket);
177
185
  }
178
186
 
179
- function cloudcmd({modules, config}) {
187
+ function cloudcmdMiddle({modules, config}) {
180
188
  const online = apart(config, 'online');
181
189
  const cache = false;
182
190
  const diff = apart(config, 'diff');
@@ -243,6 +251,7 @@ function cloudcmd({modules, config}) {
243
251
  rest(config),
244
252
  route(config, {
245
253
  html,
254
+ win32: depStore('win32'),
246
255
  }),
247
256
  ponseStatic,
248
257
  ]);
package/server/config.js CHANGED
@@ -153,7 +153,7 @@ function listen(manage, sock, auth) {
153
153
  .on('connection', (socket) => {
154
154
  if (!manage('auth'))
155
155
  return connection(manage, socket);
156
-
156
+
157
157
  const reject = () => socket.emit('reject');
158
158
  socket.on('auth', auth(connectionWraped(manage, socket), reject));
159
159
  });
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ module.exports.createDepStore = () => {
4
+ let deps = {};
5
+
6
+ return (name, value) => {
7
+ if (!name)
8
+ return deps = {};
9
+
10
+ if (!value)
11
+ return deps[name];
12
+
13
+ deps[name] = value;
14
+ };
15
+ };
package/server/repl.js CHANGED
@@ -9,7 +9,7 @@ module.exports = net
9
9
  const {pid} = process;
10
10
  const addr = socket.remoteAddress;
11
11
  const port = socket.remotePort;
12
-
12
+
13
13
  const r = repl.start({
14
14
  prompt: `[${pid} ${addr}:${port}>`,
15
15
  input: socket,
@@ -17,11 +17,11 @@ module.exports = net
17
17
  terminal: true,
18
18
  useGlobal: false,
19
19
  });
20
-
20
+
21
21
  r.on('exit', () => {
22
22
  socket.end();
23
23
  });
24
-
24
+
25
25
  r.context.socket = socket;
26
26
  })
27
27
  .listen(1337);
package/server/root.js CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  const mellow = require('mellow');
4
4
 
5
- module.exports = (dir, root) => {
6
- return mellow.webToWin(dir, root || '/');
5
+ module.exports = (dir, root, {webToWin = mellow.webToWin} = {}) => {
6
+ return webToWin(dir, root || '/');
7
7
  };
package/server/route.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const {extname} = require('node:path');
4
4
 
5
- const {read} = require('win32');
5
+ const _win32 = require('win32');
6
6
  const ponse = require('ponse');
7
7
  const rendy = require('rendy');
8
8
  const format = require('format-io');
@@ -34,9 +34,9 @@ const sendIndex = (params, data) => {
34
34
  const onceRequire = once(require);
35
35
  const getPrefix = (config) => prefixer(config('prefix'));
36
36
 
37
- const getReadDir = (config) => {
37
+ const getReadDir = (config, {win32 = _win32} = {}) => {
38
38
  if (!config('dropbox'))
39
- return read;
39
+ return win32.read;
40
40
 
41
41
  const {readDir} = onceRequire('@cloudcmd/dropbox');
42
42
 
@@ -78,13 +78,15 @@ async function route({config, options, request, response}) {
78
78
  const rootName = name.replace(CloudFunc.FS, '') || '/';
79
79
  const fullPath = root(rootName, config('root'));
80
80
 
81
- const read = getReadDir(config);
81
+ const {html, win32} = options;
82
+ const read = getReadDir(config, {
83
+ win32,
84
+ });
85
+
82
86
  const [error, stream] = await tryToCatch(read, fullPath, {
83
87
  root: config('root'),
84
88
  });
85
89
 
86
- const {html} = options;
87
-
88
90
  if (error)
89
91
  return ponse.sendError(error, p);
90
92
 
@@ -84,9 +84,9 @@ function getError(error, source) {
84
84
  source,
85
85
  highlightCode: false,
86
86
  })}</pre>\`);
87
-
87
+
88
88
  e.code = 'frame';
89
-
89
+
90
90
  throw e;
91
91
  `;
92
92
  }
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ const {statSync: _statSync} = require('node:fs');
3
4
  const tryCatch = require('try-catch');
4
5
 
5
- const exit = require('./exit');
6
- const {getColumns} = require('./columns');
6
+ const _exit = require('./exit');
7
+ const {getColumns: _getColumns} = require('./columns');
7
8
  const isString = (a) => typeof a === 'string';
8
9
 
9
- module.exports.root = (dir, config) => {
10
+ module.exports.root = (dir, config, {exit = _exit, statSync = _statSync} = {}) => {
10
11
  if (!isString(dir))
11
12
  throw Error('dir should be a string');
12
13
 
@@ -16,28 +17,27 @@ module.exports.root = (dir, config) => {
16
17
  if (config('dropbox'))
17
18
  return;
18
19
 
19
- const {statSync} = require('node:fs');
20
20
  const [error] = tryCatch(statSync, dir);
21
21
 
22
22
  if (error)
23
23
  return exit('cloudcmd --root: %s', error.message);
24
24
  };
25
25
 
26
- module.exports.editor = (name) => {
26
+ module.exports.editor = (name, {exit = _exit} = {}) => {
27
27
  const reg = /^(dword|edward|deepword)$/;
28
28
 
29
29
  if (!reg.test(name))
30
30
  exit('cloudcmd --editor: could be "dword", "edward" or "deepword" only');
31
31
  };
32
32
 
33
- module.exports.packer = (name) => {
33
+ module.exports.packer = (name, {exit = _exit} = {}) => {
34
34
  const reg = /^(tar|zip)$/;
35
35
 
36
36
  if (!reg.test(name))
37
37
  exit('cloudcmd --packer: could be "tar" or "zip" only');
38
38
  };
39
39
 
40
- module.exports.columns = (type) => {
40
+ module.exports.columns = (type, {exit = _exit, getColumns = _getColumns} = {}) => {
41
41
  const addQuotes = (a) => `"${a}"`;
42
42
  const all = Object
43
43
  .keys(getColumns())