@joystick.js/cli-canary 0.0.0-canary.9 → 0.0.0-canary.90
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/dist/cli.js +7 -0
- package/dist/functions/index.js +21 -0
- package/dist/functions/start/index.js +3 -489
- package/dist/functions/start/onWarn.js +1 -1
- package/dist/functions/start/setComponentId.js +1 -1
- package/dist/functions/test/index.js +7 -26
- package/dist/lib/build/buildFiles.js +63 -7
- package/dist/lib/build/buildPlugins.js +18 -15
- package/dist/lib/build/getCodeFrame.js +3 -4
- package/dist/lib/build/onWarn.js +1 -1
- package/dist/lib/dev/cleanup.js +15 -27
- package/dist/lib/dev/databases/mongodb/index.js +1 -1
- package/dist/lib/dev/databases/postgresql/index.js +2 -2
- package/dist/lib/dev/databases/providerMap.js +1 -1
- package/dist/lib/dev/index.js +104 -28
- package/dist/lib/dev/isWindows.js +5 -0
- package/dist/lib/dev/loadSettings.js +1 -3
- package/dist/lib/dev/startApp.js +43 -3
- package/dist/lib/dev/startDatabases.js +12 -5
- package/dist/lib/dev/startHMR.js +30 -5
- package/dist/lib/getProcessIdFromPort.js +60 -0
- package/dist/lib/types.js +6 -0
- package/package.json +1 -1
- package/src/cli.js +9 -0
- package/src/functions/index.js +21 -0
- package/src/functions/start/index.js +2 -691
- package/src/functions/start/onWarn.js +1 -1
- package/src/functions/start/setComponentId.js +1 -1
- package/src/functions/test/index.js +7 -32
- package/src/lib/build/buildFiles.js +74 -8
- package/src/lib/build/buildPlugins.js +29 -22
- package/src/lib/build/getCodeFrame.js +3 -4
- package/src/lib/build/onWarn.js +1 -1
- package/src/lib/dev/cleanup.js +20 -28
- package/src/lib/dev/databases/mongodb/index.js +1 -1
- package/src/lib/dev/databases/postgresql/index.js +2 -2
- package/src/lib/dev/databases/providerMap.js +1 -1
- package/src/lib/dev/index.js +124 -41
- package/src/lib/dev/isWindows.js +3 -0
- package/src/lib/dev/loadSettings.js +1 -3
- package/src/lib/dev/startApp.js +52 -6
- package/src/lib/dev/startDatabases.js +12 -6
- package/src/lib/dev/startHMR.js +36 -7
- package/src/lib/getProcessIdFromPort.js +92 -0
- package/src/lib/types.js +3 -0
package/src/lib/dev/startApp.js
CHANGED
|
@@ -1,16 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
import child_process from "child_process";
|
|
2
|
+
import path from "path";
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
+
const handleStartServerProcess = (execArgv = {}, sessionsBeforeHMRUpdate = {}) => {
|
|
4
5
|
try {
|
|
5
|
-
|
|
6
|
+
process.loader.text('Starting app...');
|
|
7
|
+
|
|
8
|
+
return child_process.fork(
|
|
9
|
+
path.resolve(".joystick/build/index.server.js"),
|
|
10
|
+
[],
|
|
11
|
+
{
|
|
12
|
+
execArgv,
|
|
13
|
+
// NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
|
|
14
|
+
// communicate with the child_process.
|
|
15
|
+
silent: true,
|
|
16
|
+
env: {
|
|
17
|
+
FORCE_COLOR: "1",
|
|
18
|
+
LOGS_PATH: process.env.LOGS_PATH,
|
|
19
|
+
NODE_ENV: process.env.NODE_ENV,
|
|
20
|
+
ROOT_URL: process.env.ROOT_URL,
|
|
21
|
+
PORT: process.env.PORT,
|
|
22
|
+
JOYSTICK_SETTINGS: process.env.JOYSTICK_SETTINGS,
|
|
23
|
+
HMR_SESSIONS: JSON.stringify(sessionsBeforeHMRUpdate),
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
);
|
|
6
27
|
} catch (exception) {
|
|
7
|
-
throw new Error(`[startApp.
|
|
28
|
+
throw new Error(`[startApp.handleStartServerProcess] ${exception.message}`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const getExecArgs = (nodeMajorVersion = 0) => {
|
|
33
|
+
try {
|
|
34
|
+
const execArgv = ["--no-warnings"];
|
|
35
|
+
|
|
36
|
+
if (nodeMajorVersion < 19) {
|
|
37
|
+
execArgv.push("--experimental-specifier-resolution=node");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (
|
|
41
|
+
process.env.NODE_ENV === "development" &&
|
|
42
|
+
process.env.IS_DEBUG_MODE === "true"
|
|
43
|
+
) {
|
|
44
|
+
execArgv.push("--inspect");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return execArgv;
|
|
48
|
+
} catch (exception) {
|
|
49
|
+
throw new Error(`[startApp.getExecArgs] ${exception.message}`);
|
|
8
50
|
}
|
|
9
51
|
};
|
|
10
52
|
|
|
11
53
|
const validateOptions = (options) => {
|
|
12
54
|
try {
|
|
13
55
|
if (!options) throw new Error('options object is required.');
|
|
56
|
+
if (!options.nodeMajorVersion) throw new Error('options.nodeMajorVersion is required.');
|
|
14
57
|
if (!options.port) throw new Error('options.port is required.');
|
|
15
58
|
} catch (exception) {
|
|
16
59
|
throw new Error(`[startApp.validateOptions] ${exception.message}`);
|
|
@@ -20,8 +63,11 @@ const validateOptions = (options) => {
|
|
|
20
63
|
const startApp = (options, { resolve, reject }) => {
|
|
21
64
|
try {
|
|
22
65
|
validateOptions(options);
|
|
23
|
-
|
|
24
|
-
|
|
66
|
+
|
|
67
|
+
const execArgv = getExecArgs(options?.nodeMajorVersion);
|
|
68
|
+
const serverProcess = handleStartServerProcess(execArgv);
|
|
69
|
+
|
|
70
|
+
return resolve(serverProcess);
|
|
25
71
|
} catch (exception) {
|
|
26
72
|
reject(`[startApp] ${exception.message}`);
|
|
27
73
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable consistent-return */
|
|
2
2
|
|
|
3
|
-
import util from "util";
|
|
4
3
|
import CLILog from "../CLILog.js";
|
|
5
4
|
import providerMap from "./databases/providerMap.js";
|
|
5
|
+
import { isObject } from '../types.js';
|
|
6
6
|
|
|
7
7
|
const startDatabaseProvider = async (
|
|
8
8
|
environment = 'development',
|
|
@@ -31,13 +31,14 @@ const startDatabaseProvider = async (
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
const startDatabaseProviders = async (databases = [], databasePortStart = 2610) => {
|
|
34
|
+
const startDatabaseProviders = async (databases = [], databasePortStart = 2610, environment = '') => {
|
|
35
35
|
try {
|
|
36
36
|
for (let i = 0; i < databases?.length; i += 1) {
|
|
37
37
|
const database = databases[i];
|
|
38
38
|
const hasMultipleOfProvider = (databases?.filter((database) => database?.provider === database?.provider))?.length > 1;
|
|
39
39
|
|
|
40
40
|
await startDatabaseProvider(
|
|
41
|
+
environment,
|
|
41
42
|
database,
|
|
42
43
|
// NOTE: Increment each database port using index in the databases array from settings if no port
|
|
43
44
|
// is assigned in the settings.
|
|
@@ -53,8 +54,8 @@ const startDatabaseProviders = async (databases = [], databasePortStart = 2610)
|
|
|
53
54
|
const validateDatabasesFromSettings = (databases = []) => {
|
|
54
55
|
try {
|
|
55
56
|
const databasesNotAsObjects = databases.filter(
|
|
56
|
-
(database) => !
|
|
57
|
-
|
|
57
|
+
(database) => !isObject(database)
|
|
58
|
+
);
|
|
58
59
|
|
|
59
60
|
const userDatabases = databases.filter((database) => !!database.users);
|
|
60
61
|
const queueDatabases = databases.filter((database) => !!database.queues);
|
|
@@ -95,6 +96,7 @@ const validateDatabasesFromSettings = (databases = []) => {
|
|
|
95
96
|
const validateOptions = (options) => {
|
|
96
97
|
try {
|
|
97
98
|
if (!options) throw new Error('options object is required.');
|
|
99
|
+
if (!options.environment) throw new Error('options.environment is required.');
|
|
98
100
|
if (!options.port) throw new Error('options.port is required.');
|
|
99
101
|
if (!options.settings) throw new Error('options.settings is required.');
|
|
100
102
|
} catch (exception) {
|
|
@@ -106,11 +108,15 @@ const startDatabases = async (options, { resolve, reject }) => {
|
|
|
106
108
|
try {
|
|
107
109
|
validateOptions(options);
|
|
108
110
|
|
|
109
|
-
const databases = options?.settings?.databases || [];
|
|
111
|
+
const databases = options?.settings?.config?.databases || [];
|
|
110
112
|
|
|
111
113
|
if (databases?.length > 0) {
|
|
112
114
|
validateDatabasesFromSettings(databases);
|
|
113
|
-
await startDatabaseProviders(
|
|
115
|
+
await startDatabaseProviders(
|
|
116
|
+
databases,
|
|
117
|
+
options?.port + 10,
|
|
118
|
+
options?.environment,
|
|
119
|
+
);
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
resolve();
|
package/src/lib/dev/startHMR.js
CHANGED
|
@@ -1,17 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
import child_process from "child_process";
|
|
2
|
+
import path from "path";
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
+
const handleStartHMRProcess = (execArgv = {}, __dirname = '') => {
|
|
4
5
|
try {
|
|
5
|
-
//
|
|
6
|
+
// NOTE: Port is automatically pulled via process.env.PORT
|
|
7
|
+
// in the hmrServer.js script.
|
|
8
|
+
return child_process.fork(
|
|
9
|
+
path.resolve(`${__dirname}/hmrServer.js`),
|
|
10
|
+
[],
|
|
11
|
+
{
|
|
12
|
+
execArgv,
|
|
13
|
+
// NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
|
|
14
|
+
// communicate with the child_process.
|
|
15
|
+
silent: true,
|
|
16
|
+
}
|
|
17
|
+
);
|
|
6
18
|
} catch (exception) {
|
|
7
|
-
throw new Error(`[startHMR.
|
|
19
|
+
throw new Error(`[startHMR.handleStartHMRProcess] ${exception.message}`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const getExecArgs = (nodeMajorVersion = 0) => {
|
|
24
|
+
try {
|
|
25
|
+
const execArgv = ["--no-warnings"];
|
|
26
|
+
|
|
27
|
+
if (nodeMajorVersion < 19) {
|
|
28
|
+
execArgv.push("--experimental-specifier-resolution=node");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return execArgv;
|
|
32
|
+
} catch (exception) {
|
|
33
|
+
throw new Error(`[startHMR.getExecArgs] ${exception.message}`);
|
|
8
34
|
}
|
|
9
35
|
};
|
|
10
36
|
|
|
11
37
|
const validateOptions = (options) => {
|
|
12
38
|
try {
|
|
13
39
|
if (!options) throw new Error('options object is required.');
|
|
14
|
-
if (!options.
|
|
40
|
+
if (!options.nodeMajorVersion) throw new Error('options.nodeMajorVersion is required.');
|
|
15
41
|
} catch (exception) {
|
|
16
42
|
throw new Error(`[startHMR.validateOptions] ${exception.message}`);
|
|
17
43
|
}
|
|
@@ -20,8 +46,11 @@ const validateOptions = (options) => {
|
|
|
20
46
|
const startHMR = (options, { resolve, reject }) => {
|
|
21
47
|
try {
|
|
22
48
|
validateOptions(options);
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
|
|
50
|
+
const execArgv = getExecArgs(options?.nodeMajorVersion);
|
|
51
|
+
const hmrProcess = handleStartHMRProcess(execArgv, options?.__dirname);
|
|
52
|
+
|
|
53
|
+
return resolve(hmrProcess);
|
|
25
54
|
} catch (exception) {
|
|
26
55
|
reject(`[startHMR] ${exception.message}`);
|
|
27
56
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import condense from 'selective-whitespace';
|
|
2
|
+
import netstats from 'netstats';
|
|
3
|
+
|
|
4
|
+
const platform = process.platform;
|
|
5
|
+
|
|
6
|
+
function pushTo(target, item) {
|
|
7
|
+
if (item !== '' && typeof item === 'number' && item !== 0 && target.indexOf(item) === -1) {
|
|
8
|
+
target.push(item);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Example output to parse (macOS):
|
|
13
|
+
// $ lsof -i :8017
|
|
14
|
+
/*
|
|
15
|
+
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
|
|
16
|
+
nc 20661 michael 3u IPv4 0x3b190d9d07c2c3db 0t0 TCP *:8017 (LISTEN)
|
|
17
|
+
nc 21145 michael 3u IPv4 0x3b190d9d054773db 0t0 TCP *:8017 (LISTEN)
|
|
18
|
+
Python 21221 michael 3u IPv4 0x3b190d9ceb8dfd7b 0t0 UDP localhost:8017
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// [WIN] $ netstat.exe -a -n -o | findstr :9000
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
TCP 0.0.0.0:9000 0.0.0.0:0 LISTENING 5220
|
|
25
|
+
TCP 127.0.0.1:9000 127.0.0.1:62376 ESTABLISHED 5220
|
|
26
|
+
TCP 127.0.0.1:9000 127.0.0.1:62379 ESTABLISHED 5220
|
|
27
|
+
TCP 127.0.0.1:62288 127.0.0.1:9000 TIME_WAIT 0
|
|
28
|
+
TCP 127.0.0.1:62299 127.0.0.1:9000 TIME_WAIT 0
|
|
29
|
+
TCP 127.0.0.1:62376 127.0.0.1:9000 ESTABLISHED 7604
|
|
30
|
+
TCP 127.0.0.1:62378 127.0.0.1:9000 ESTABLISHED 7604
|
|
31
|
+
UDP 127.0.0.1:9000 *:* 1240
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
async function processNetStats(arr) {
|
|
35
|
+
const pidindex = 1;
|
|
36
|
+
let items = arr.slice(1);
|
|
37
|
+
|
|
38
|
+
if (platform === 'win32') {
|
|
39
|
+
items = arr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const pids = {
|
|
43
|
+
all: [],
|
|
44
|
+
tcp: [],
|
|
45
|
+
udp: [],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
await Promise.all(items.map((item) => {
|
|
49
|
+
const values = condense(item).split(' ');
|
|
50
|
+
let pid = parseInt(values[pidindex], 10);
|
|
51
|
+
|
|
52
|
+
if (platform === 'win32') {
|
|
53
|
+
pid = parseInt(values.pop(), 10);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (values.length > 1) {
|
|
57
|
+
if (values.indexOf('TCP') !== -1) {
|
|
58
|
+
pushTo(pids.tcp, pid);
|
|
59
|
+
pushTo(pids.all, pid);
|
|
60
|
+
} else if (values.indexOf('UDP') !== -1) {
|
|
61
|
+
pushTo(pids.udp, pid);
|
|
62
|
+
pushTo(pids.all, pid);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
return pids;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getProcessIdFromPort(port) {
|
|
73
|
+
if (typeof port !== 'number') {
|
|
74
|
+
throw new TypeError('Expected a port number');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return new Promise(((resolve) => {
|
|
78
|
+
netstats(port).then((stats) => {
|
|
79
|
+
processNetStats(stats).then((ps) => {
|
|
80
|
+
resolve(ps);
|
|
81
|
+
});
|
|
82
|
+
}).catch(() => {
|
|
83
|
+
resolve({
|
|
84
|
+
all: [],
|
|
85
|
+
tcp: [],
|
|
86
|
+
udp: [],
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default getProcessIdFromPort;
|
package/src/lib/types.js
ADDED