@joystick.js/cli-canary 0.0.0-canary.1 → 0.0.0-canary.100
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/_package.json +2 -1
- package/dist/cli.js +7 -0
- package/dist/functions/index.js +21 -0
- package/dist/functions/start/buildFile.js +1 -1
- package/dist/functions/start/databases/mongodb/checkConnection.js +1 -4
- package/dist/functions/start/databases/mongodb/index.js +1 -1
- package/dist/functions/start/index.js +6 -511
- package/dist/functions/start/onWarn.js +1 -1
- package/dist/functions/start/setComponentId.js +1 -1
- package/dist/functions/test/index.js +11 -0
- package/dist/functions/use/index.js +4 -4
- package/dist/lib/build/browserPathExclusions.js +7 -0
- package/dist/lib/build/browserPaths.js +11 -0
- package/dist/lib/build/buildFile.js +84 -0
- package/dist/lib/build/buildFiles.js +239 -0
- package/dist/lib/build/buildPlugins.js +186 -0
- package/dist/lib/build/getCodeFrame.js +9 -0
- package/dist/lib/build/minifyFile.js +12 -0
- package/dist/lib/build/nodePathExclusions.js +7 -0
- package/dist/lib/build/nodePaths.js +11 -0
- package/dist/lib/build/onWarn.js +63 -0
- package/dist/lib/build/removeDeletedDependenciesFromMap.js +18 -0
- package/dist/lib/build/setComponentId.js +46 -0
- package/dist/lib/build/updateFileMap.js +67 -0
- package/dist/lib/constants.js +4 -0
- package/dist/lib/dev/cleanup.js +18 -0
- package/dist/lib/dev/databases/mongodb/availableQueryParameters.js +42 -0
- package/dist/lib/dev/databases/mongodb/buildConnectionString.js +22 -0
- package/dist/lib/dev/databases/mongodb/buildQueryParameters.js +14 -0
- package/dist/lib/dev/databases/mongodb/checkConnection.js +38 -0
- package/dist/lib/dev/databases/mongodb/connect.js +25 -0
- package/dist/lib/dev/databases/mongodb/index.js +93 -0
- package/dist/lib/dev/databases/postgresql/checkConnection.js +41 -0
- package/dist/lib/dev/databases/postgresql/connect.js +27 -0
- package/dist/lib/dev/databases/postgresql/index.js +106 -0
- package/dist/lib/dev/databases/providerMap.js +15 -0
- package/dist/lib/dev/getCodependenciesForFile.js +64 -0
- package/dist/lib/dev/getFilesToBuild.js +38 -0
- package/dist/lib/dev/index.js +531 -0
- package/dist/lib/dev/isWindows.js +5 -0
- package/dist/lib/dev/loadSettings.js +79 -0
- package/dist/lib/dev/readFileDependencyMap.js +16 -0
- package/dist/lib/dev/requiredFiles.js +18 -0
- package/dist/lib/dev/runBuild.js +30 -0
- package/dist/lib/dev/runTests.js +67 -0
- package/dist/lib/dev/startApp.js +70 -0
- package/dist/lib/dev/startDatabases.js +109 -0
- package/dist/lib/dev/startHMR.js +55 -0
- package/dist/lib/dev/tests.config.js +0 -0
- package/dist/lib/dev/updateFileMap.js +67 -0
- package/dist/lib/dev/validateProject.js +0 -0
- package/dist/lib/dev/watchlist.js +15 -0
- package/dist/lib/filesToCopy.js +18 -0
- package/dist/lib/generateId.js +74 -0
- package/dist/lib/getProcessIdFromPort.js +60 -0
- package/dist/lib/regexes.js +3 -1
- 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/buildFile.js +1 -1
- package/src/functions/start/databases/mongodb/checkConnection.js +1 -5
- package/src/functions/start/databases/mongodb/index.js +1 -1
- package/src/functions/start/index.js +637 -660
- package/src/functions/start/onWarn.js +1 -1
- package/src/functions/start/setComponentId.js +1 -1
- package/src/functions/test/index.js +9 -0
- package/src/functions/use/index.js +4 -4
- package/src/lib/build/browserPathExclusions.js +5 -0
- package/src/lib/build/browserPaths.js +9 -0
- package/src/lib/build/buildFile.js +91 -0
- package/src/lib/build/buildFiles.js +271 -0
- package/src/lib/build/buildPlugins.js +222 -0
- package/src/lib/build/getCodeFrame.js +7 -0
- package/src/lib/build/minifyFile.js +10 -0
- package/src/lib/build/nodePathExclusions.js +5 -0
- package/src/lib/build/nodePaths.js +9 -0
- package/src/lib/build/onWarn.js +68 -0
- package/src/lib/build/removeDeletedDependenciesFromMap.js +19 -0
- package/src/lib/build/setComponentId.js +58 -0
- package/src/lib/build/updateFileMap.js +100 -0
- package/src/lib/constants.js +1 -0
- package/src/lib/dev/cleanup.js +26 -0
- package/src/lib/dev/databases/mongodb/availableQueryParameters.js +39 -0
- package/src/lib/dev/databases/mongodb/buildConnectionString.js +28 -0
- package/src/lib/dev/databases/mongodb/buildQueryParameters.js +15 -0
- package/src/lib/dev/databases/mongodb/checkConnection.js +40 -0
- package/src/lib/dev/databases/mongodb/connect.js +25 -0
- package/src/lib/dev/databases/mongodb/index.js +108 -0
- package/src/lib/dev/databases/postgresql/checkConnection.js +43 -0
- package/src/lib/dev/databases/postgresql/connect.js +27 -0
- package/src/lib/dev/databases/postgresql/index.js +127 -0
- package/src/lib/dev/databases/providerMap.js +13 -0
- package/src/lib/dev/getCodependenciesForFile.js +84 -0
- package/src/lib/dev/getFilesToBuild.js +47 -0
- package/src/lib/dev/index.js +650 -0
- package/src/lib/dev/isWindows.js +3 -0
- package/src/lib/dev/loadSettings.js +90 -0
- package/src/lib/dev/readFileDependencyMap.js +19 -0
- package/src/lib/dev/requiredFiles.js +15 -0
- package/src/lib/dev/runBuild.js +33 -0
- package/src/lib/dev/runTests.js +75 -0
- package/src/lib/dev/startApp.js +79 -0
- package/src/lib/dev/startDatabases.js +131 -0
- package/src/lib/dev/startHMR.js +62 -0
- package/src/lib/dev/tests.config.js +0 -0
- package/src/lib/dev/updateFileMap.js +100 -0
- package/src/lib/dev/validateProject.js +0 -0
- package/src/lib/dev/watchlist.js +13 -0
- package/src/lib/filesToCopy.js +15 -0
- package/src/lib/generateId.js +73 -0
- package/src/lib/getProcessIdFromPort.js +92 -0
- package/src/lib/regexes.js +3 -1
- package/src/lib/types.js +3 -0
- package/dist/lib/getCodeFrame.js +0 -10
- package/src/lib/getCodeFrame.js +0 -8
package/_package.json
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@babel/code-frame": "^7.15.8",
|
|
27
27
|
"acorn": "^8.5.0",
|
|
28
28
|
"ascii-table": "^0.0.9",
|
|
29
|
+
"ava": "^5.3.1",
|
|
29
30
|
"chalk": "^4.1.2",
|
|
30
31
|
"chokidar": "^3.5.2",
|
|
31
32
|
"command-exists": "^1.2.9",
|
|
@@ -52,4 +53,4 @@
|
|
|
52
53
|
"ws": "^8.2.3",
|
|
53
54
|
"xmlhttprequest": "^1.8.0"
|
|
54
55
|
}
|
|
55
|
-
}
|
|
56
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -53,6 +53,13 @@ if (functionsCalled.includes("start")) {
|
|
|
53
53
|
functions.start.function(args, options);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
if (functionsCalled.includes("test")) {
|
|
57
|
+
const args = getArgs(functions.test.args);
|
|
58
|
+
const options = getOptions(functions.test.options);
|
|
59
|
+
if (functions.test.function && typeof functions.test.function === "function") {
|
|
60
|
+
functions.test.function(args, options);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
56
63
|
if (functionsCalled.includes("update")) {
|
|
57
64
|
const args = getArgs(functions.update.args);
|
|
58
65
|
const options = getOptions(functions.update.options);
|
package/dist/functions/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import logout from "./logout/index.js";
|
|
|
4
4
|
import start from "./start/index.js";
|
|
5
5
|
import update from "./update/index.js";
|
|
6
6
|
import use from "./use/index.js";
|
|
7
|
+
import test from "./test/index.js";
|
|
7
8
|
const [_node, _bin, ...rawArgs] = process.argv;
|
|
8
9
|
var functions_default = {
|
|
9
10
|
build: {
|
|
@@ -216,6 +217,26 @@ var functions_default = {
|
|
|
216
217
|
},
|
|
217
218
|
function: start
|
|
218
219
|
},
|
|
220
|
+
test: {
|
|
221
|
+
set: !!rawArgs.includes("test"),
|
|
222
|
+
description: "Start an existing Joystick app and run its tests.",
|
|
223
|
+
args: {
|
|
224
|
+
w: {
|
|
225
|
+
set: !!rawArgs.includes("w") && !!rawArgs[rawArgs.indexOf("w") + 1],
|
|
226
|
+
parent: "w",
|
|
227
|
+
value: !!rawArgs.includes("w") && rawArgs[rawArgs.indexOf("w") + 1],
|
|
228
|
+
description: "Run joystick test in watch mode."
|
|
229
|
+
},
|
|
230
|
+
watch: {
|
|
231
|
+
set: !!rawArgs.includes("watch") && !!rawArgs[rawArgs.indexOf("watch") + 1],
|
|
232
|
+
parent: "watch",
|
|
233
|
+
value: !!rawArgs.includes("watch") && rawArgs[rawArgs.indexOf("watch") + 1],
|
|
234
|
+
description: "Run joystick test in watch mode."
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
options: {},
|
|
238
|
+
function: test()
|
|
239
|
+
},
|
|
219
240
|
update: {
|
|
220
241
|
set: !!rawArgs.includes("update"),
|
|
221
242
|
description: "Update all Joystick packages to their latest version.",
|
|
@@ -3,7 +3,7 @@ import svg from "esbuild-plugin-svg";
|
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import plugins from "./buildPlugins.js";
|
|
5
5
|
import onWarn from "./onWarn.js";
|
|
6
|
-
import getCodeFrame from "../../lib/getCodeFrame.js";
|
|
6
|
+
import getCodeFrame from "../../lib/build/getCodeFrame.js";
|
|
7
7
|
const configs = {
|
|
8
8
|
node: (inputPath, outputPath = null, environment = "development") => ({
|
|
9
9
|
entryPoints: [inputPath],
|
|
@@ -3,11 +3,8 @@ import chalk from "chalk";
|
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import buildConnectionString from "./buildConnectionString.js";
|
|
5
5
|
var checkConnection_default = async (connection = {}, options = {}) => {
|
|
6
|
-
const connectionString = buildConnectionString(connection);
|
|
7
|
-
console.log({
|
|
8
|
-
connectionString
|
|
9
|
-
});
|
|
10
6
|
try {
|
|
7
|
+
const connectionString = buildConnectionString(connection2);
|
|
11
8
|
const connectionOptions = {
|
|
12
9
|
connectTimeoutMS: 3e3,
|
|
13
10
|
socketTimeoutMS: 3e3,
|
|
@@ -18,7 +18,7 @@ const warnMongoDBMissing = () => {
|
|
|
18
18
|
After you've installed MongoDB, run joystick start again, or, remove MongoDB from your config.databases array in your settings.development.json file to skip starting it up.`,
|
|
19
19
|
{
|
|
20
20
|
level: "danger",
|
|
21
|
-
docs: "https://
|
|
21
|
+
docs: "https://cheatcode.co/docs/joystick/cli/databases#mongodb"
|
|
22
22
|
}
|
|
23
23
|
);
|
|
24
24
|
};
|
|
@@ -1,216 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path, { dirname } from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
|
-
import ps from "ps-node";
|
|
5
|
-
import { killPortProcess } from "kill-port-process";
|
|
6
|
-
import fs from "fs";
|
|
7
|
-
import chokidar from "chokidar";
|
|
8
|
-
import Loader from "../../lib/loader.js";
|
|
9
|
-
import getFilesToBuild from "./getFilesToBuild.js";
|
|
10
|
-
import buildFiles from "./buildFiles.js";
|
|
11
|
-
import filesToCopy from "./filesToCopy.js";
|
|
12
|
-
import checkIfPortAvailable from "./checkIfPortAvailable.js";
|
|
13
|
-
import getCodependenciesForFile from "./getCodependenciesForFile.js";
|
|
14
|
-
import isValidJSONString from "../../lib/isValidJSONString.js";
|
|
15
|
-
import startDatabaseProvider from "./databases/startProvider.js";
|
|
16
|
-
import CLILog from "../../lib/CLILog.js";
|
|
17
|
-
import removeDeletedDependenciesFromMap from "./removeDeletedDependenciesFromMap.js";
|
|
18
|
-
import validateDatabasesFromSettings from "../../lib/validateDatabasesFromSettings.js";
|
|
19
|
-
import wait from "../../lib/wait.js";
|
|
20
|
-
const majorVersion = parseInt(
|
|
21
|
-
process?.version?.split(".")[0]?.replace("v", ""),
|
|
22
|
-
10
|
|
23
|
-
);
|
|
24
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
-
const __dirname = dirname(__filename);
|
|
26
|
-
const killProcess = (pid = 0) => {
|
|
27
|
-
return new Promise((resolve) => {
|
|
28
|
-
ps.kill(pid, () => {
|
|
29
|
-
resolve();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
const watchlist = [
|
|
34
|
-
{ path: "ui" },
|
|
35
|
-
{ path: "lib" },
|
|
36
|
-
{ path: "i18n" },
|
|
37
|
-
{ path: "api" },
|
|
38
|
-
{ path: "email" },
|
|
39
|
-
{ path: "fixtures" },
|
|
40
|
-
{ path: "routes" },
|
|
41
|
-
{ path: "index.client.js" },
|
|
42
|
-
{ path: "index.server.js" },
|
|
43
|
-
...filesToCopy
|
|
44
|
-
];
|
|
45
|
-
const requiredFileCheck = () => {
|
|
46
|
-
return new Promise((resolve) => {
|
|
47
|
-
const requiredFiles = [
|
|
48
|
-
{ path: "index.server.js", type: "file" },
|
|
49
|
-
{ path: "index.html", type: "file" },
|
|
50
|
-
{ path: "index.client.js", type: "file" },
|
|
51
|
-
{ path: "api", type: "directory" },
|
|
52
|
-
{ path: "i18n", type: "directory" },
|
|
53
|
-
{ path: "lib", type: "directory" },
|
|
54
|
-
{ path: "public", type: "directory" },
|
|
55
|
-
{ path: "ui", type: "directory" },
|
|
56
|
-
{ path: "ui/components", type: "directory" },
|
|
57
|
-
{ path: "ui/layouts", type: "directory" },
|
|
58
|
-
{ path: "ui/pages", type: "directory" }
|
|
59
|
-
];
|
|
60
|
-
requiredFiles.forEach((requiredFile) => {
|
|
61
|
-
const exists = fs.existsSync(`${process.cwd()}/${requiredFile.path}`);
|
|
62
|
-
const stats = exists && fs.statSync(`${process.cwd()}/${requiredFile.path}`);
|
|
63
|
-
const isFile = stats && stats.isFile();
|
|
64
|
-
const isDirectory = stats && stats.isDirectory();
|
|
65
|
-
if (requiredFile && requiredFile.type === "file") {
|
|
66
|
-
if (!exists || exists && !isFile) {
|
|
67
|
-
CLILog(
|
|
68
|
-
`The path ${requiredFile.path} must exist in your project and must be a file (not a directory).`,
|
|
69
|
-
{
|
|
70
|
-
level: "danger",
|
|
71
|
-
docs: "https://github.com/cheatcode/joystick#folder-and-file-structure"
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
process.exit(0);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (requiredFile && requiredFile.type === "directory") {
|
|
78
|
-
if (!exists || exists && !isDirectory) {
|
|
79
|
-
CLILog(
|
|
80
|
-
`The path ${requiredFile.path} must exist in your project and must be a directory (not a file).`,
|
|
81
|
-
{
|
|
82
|
-
level: "danger",
|
|
83
|
-
docs: "https://github.com/cheatcode/joystick#folder-and-file-structure"
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
process.exit(0);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
resolve();
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
const handleCleanup = async (processIds = [process?.serverProcess?.pid, process?.hmrProcess?.pid]) => {
|
|
94
|
-
for (let i = 0; i < processIds?.length; i += 1) {
|
|
95
|
-
const processId = processIds[i];
|
|
96
|
-
if (processId) {
|
|
97
|
-
await killProcess(processId);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const databases = Object.entries(process._databases || {});
|
|
101
|
-
for (let i = 0; i < databases?.length; i += 1) {
|
|
102
|
-
const [provider, providerConnection] = databases[i];
|
|
103
|
-
if (providerConnection?.pid) {
|
|
104
|
-
await killProcess(providerConnection.pid);
|
|
105
|
-
}
|
|
106
|
-
if (!providerConnection?.pid) {
|
|
107
|
-
const providerConnections = Object.entries(providerConnection);
|
|
108
|
-
for (let pc = 0; pc < providerConnections?.length; pc += 1) {
|
|
109
|
-
const [_connectionName, connection] = providerConnections[pc];
|
|
110
|
-
if (connection?.pid) {
|
|
111
|
-
await killProcess(connection?.pid);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
const getDatabaseProcessIds = () => {
|
|
118
|
-
const databaseProcessIds = [];
|
|
119
|
-
const databases = Object.entries(process._databases || {});
|
|
120
|
-
for (let i = 0; i < databases?.length; i += 1) {
|
|
121
|
-
const [_provider, providerConnection] = databases[i];
|
|
122
|
-
if (providerConnection?.pid) {
|
|
123
|
-
databaseProcessIds.push(providerConnection.pid);
|
|
124
|
-
}
|
|
125
|
-
if (!providerConnection?.pid) {
|
|
126
|
-
const providerConnections = Object.entries(providerConnection);
|
|
127
|
-
for (let pc = 0; pc < providerConnections?.length; pc += 1) {
|
|
128
|
-
const [_connectionName, connection] = providerConnections[pc];
|
|
129
|
-
if (connection?.pid) {
|
|
130
|
-
databaseProcessIds.push(connection.pid);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return databaseProcessIds;
|
|
136
|
-
};
|
|
137
|
-
const handleSignalEvents = (processIds = []) => {
|
|
138
|
-
const execArgv = ["--no-warnings"];
|
|
139
|
-
if (majorVersion < 19) {
|
|
140
|
-
execArgv.push("--experimental-specifier-resolution=node");
|
|
141
|
-
}
|
|
142
|
-
const cleanupProcess = child_process.fork(
|
|
143
|
-
path.resolve(`${__dirname}/cleanup/index.js`),
|
|
144
|
-
[],
|
|
145
|
-
{
|
|
146
|
-
// NOTE: Run in detached mode so when parent process dies, the child still runs
|
|
147
|
-
// and cleanup completes.
|
|
148
|
-
detached: true,
|
|
149
|
-
execArgv,
|
|
150
|
-
// NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
|
|
151
|
-
// communicate with the child_process.
|
|
152
|
-
silent: true
|
|
153
|
-
}
|
|
154
|
-
);
|
|
155
|
-
process.on("SIGINT", async () => {
|
|
156
|
-
const databaseProcessIds = getDatabaseProcessIds();
|
|
157
|
-
cleanupProcess.send(JSON.stringify({ processIds: [...processIds, ...databaseProcessIds] }));
|
|
158
|
-
process.exit();
|
|
159
|
-
});
|
|
160
|
-
process.on("SIGTERM", async () => {
|
|
161
|
-
const databaseProcessIds = getDatabaseProcessIds();
|
|
162
|
-
cleanupProcess.send(JSON.stringify({ processIds: [...processIds, ...databaseProcessIds] }));
|
|
163
|
-
process.exit();
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
const handleHMRProcessMessages = () => {
|
|
167
|
-
process.hmrProcess.on("message", (message) => {
|
|
168
|
-
const processMessages = [
|
|
169
|
-
"SERVER_CLOSED",
|
|
170
|
-
"HAS_HMR_CONNECTIONS",
|
|
171
|
-
"HAS_NO_HMR_CONNECTIONS",
|
|
172
|
-
"HMR_UPDATE_COMPLETED"
|
|
173
|
-
];
|
|
174
|
-
if (!processMessages.includes(message?.type)) {
|
|
175
|
-
process.loader.stable(message);
|
|
176
|
-
}
|
|
177
|
-
if (message?.type === "HAS_HMR_CONNECTIONS") {
|
|
178
|
-
process.hmrProcess.hasConnections = true;
|
|
179
|
-
}
|
|
180
|
-
if (message?.type === "HAS_NO_HMR_CONNECTIONS") {
|
|
181
|
-
process.hmrProcess.hasConnections = false;
|
|
182
|
-
}
|
|
183
|
-
if (message?.type === "HMR_UPDATE_COMPLETED") {
|
|
184
|
-
setTimeout(() => {
|
|
185
|
-
restartApplicationProcess(message?.sessions);
|
|
186
|
-
}, 500);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
const handleHMRProcessSTDIO = () => {
|
|
191
|
-
try {
|
|
192
|
-
if (process.hmrProcess) {
|
|
193
|
-
process.hmrProcess.on("error", (error) => {
|
|
194
|
-
CLILog(error.toString(), {
|
|
195
|
-
level: "danger",
|
|
196
|
-
docs: "https://github.com/cheatcode/joystick"
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
process.hmrProcess.stdout.on("data", (data) => {
|
|
200
|
-
console.log(data.toString());
|
|
201
|
-
});
|
|
202
|
-
process.hmrProcess.stderr.on("data", (data) => {
|
|
203
|
-
process.loader.stop();
|
|
204
|
-
CLILog(data.toString(), {
|
|
205
|
-
level: "danger",
|
|
206
|
-
docs: "https://github.com/cheatcode/joystick"
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
} catch (exception) {
|
|
211
|
-
throw new Error(`[dev.handleHMRProcessSTDIO] ${exception.message}`);
|
|
212
|
-
}
|
|
213
|
-
};
|
|
1
|
+
import dev from "../../lib/dev/index.js";
|
|
214
2
|
const startHMRProcess = () => {
|
|
215
3
|
const execArgv = ["--no-warnings"];
|
|
216
4
|
if (majorVersion < 19) {
|
|
@@ -230,305 +18,12 @@ const startHMRProcess = () => {
|
|
|
230
18
|
handleHMRProcessSTDIO();
|
|
231
19
|
handleHMRProcessMessages();
|
|
232
20
|
};
|
|
233
|
-
const notifyHMRClients = (indexHTMLChanged = false) => {
|
|
234
|
-
const settings = loadSettings(process.env.NODE_ENV);
|
|
235
|
-
process.hmrProcess.send(
|
|
236
|
-
JSON.stringify({
|
|
237
|
-
type: "RESTART_SERVER",
|
|
238
|
-
settings,
|
|
239
|
-
indexHTMLChanged
|
|
240
|
-
})
|
|
241
|
-
);
|
|
242
|
-
};
|
|
243
|
-
const handleServerProcessMessages = () => {
|
|
244
|
-
process.serverProcess.on("message", (message) => {
|
|
245
|
-
const processMessages = ["SERVER_CLOSED"];
|
|
246
|
-
if (!processMessages.includes(message)) {
|
|
247
|
-
process.loader.stable(message);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
const handleServerProcessSTDIO = () => {
|
|
252
|
-
try {
|
|
253
|
-
if (process.serverProcess) {
|
|
254
|
-
process.serverProcess.on("error", (error) => {
|
|
255
|
-
console.log(error);
|
|
256
|
-
});
|
|
257
|
-
process.serverProcess.stdout.on("data", (data) => {
|
|
258
|
-
const message = data.toString();
|
|
259
|
-
if (message && message.includes("App running at:")) {
|
|
260
|
-
process.loader.stable(message);
|
|
261
|
-
} else {
|
|
262
|
-
if (message && !message.includes("BUILD_ERROR")) {
|
|
263
|
-
console.log(message);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
process.serverProcess.stderr.on("data", (data) => {
|
|
268
|
-
process.loader.stop();
|
|
269
|
-
CLILog(data.toString(), {
|
|
270
|
-
level: "danger",
|
|
271
|
-
docs: "https://github.com/cheatcode/joystick"
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
} catch (exception) {
|
|
276
|
-
throw new Error(`[dev.handleServerProcessSTDIO] ${exception.message}`);
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
const startApplicationProcess = (sessionsBeforeHMRUpdate = null) => {
|
|
280
|
-
const execArgv = ["--no-warnings"];
|
|
281
|
-
if (majorVersion < 19) {
|
|
282
|
-
execArgv.push("--experimental-specifier-resolution=node");
|
|
283
|
-
}
|
|
284
|
-
if (process.env.NODE_ENV === "development" && process.env.IS_DEBUG_MODE === "true") {
|
|
285
|
-
execArgv.push("--inspect");
|
|
286
|
-
}
|
|
287
|
-
const serverProcess = child_process.fork(
|
|
288
|
-
path.resolve(".joystick/build/index.server.js"),
|
|
289
|
-
[],
|
|
290
|
-
{
|
|
291
|
-
execArgv,
|
|
292
|
-
// NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
|
|
293
|
-
// communicate with the child_process.
|
|
294
|
-
silent: true,
|
|
295
|
-
env: {
|
|
296
|
-
FORCE_COLOR: "1",
|
|
297
|
-
LOGS_PATH: process.env.LOGS_PATH,
|
|
298
|
-
NODE_ENV: process.env.NODE_ENV,
|
|
299
|
-
ROOT_URL: process.env.ROOT_URL,
|
|
300
|
-
PORT: process.env.PORT,
|
|
301
|
-
JOYSTICK_SETTINGS: process.env.JOYSTICK_SETTINGS,
|
|
302
|
-
HMR_SESSIONS: sessionsBeforeHMRUpdate
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
);
|
|
306
|
-
process.serverProcess = serverProcess;
|
|
307
|
-
handleServerProcessSTDIO();
|
|
308
|
-
handleServerProcessMessages();
|
|
309
|
-
return serverProcess;
|
|
310
|
-
};
|
|
311
|
-
const restartApplicationProcess = async (sessionsBeforeHMRUpdate = null) => {
|
|
312
|
-
if (process.serverProcess && process.serverProcess.pid) {
|
|
313
|
-
process.loader.text("Restarting app...");
|
|
314
|
-
process.serverProcess.kill();
|
|
315
|
-
startApplicationProcess(sessionsBeforeHMRUpdate);
|
|
316
|
-
return Promise.resolve();
|
|
317
|
-
}
|
|
318
|
-
process.loader.text("Starting app...");
|
|
319
|
-
startApplicationProcess();
|
|
320
|
-
if (!process.hmrProcess) {
|
|
321
|
-
startHMRProcess();
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
const initialBuild = async (buildSettings = {}) => {
|
|
325
|
-
const buildPath = `.joystick/build`;
|
|
326
|
-
const fileMapPath = `.joystick/build/fileMap.json`;
|
|
327
|
-
if (!fs.existsSync(buildPath)) {
|
|
328
|
-
fs.mkdirSync(".joystick/build");
|
|
329
|
-
}
|
|
330
|
-
if (fs.existsSync(fileMapPath)) {
|
|
331
|
-
fs.unlinkSync(fileMapPath);
|
|
332
|
-
}
|
|
333
|
-
process.loader.text("Building app...");
|
|
334
|
-
await requiredFileCheck();
|
|
335
|
-
const filesToBuild = getFilesToBuild(buildSettings?.excludedPaths, "start");
|
|
336
|
-
const fileResults = await buildFiles(
|
|
337
|
-
filesToBuild,
|
|
338
|
-
null,
|
|
339
|
-
process.env.NODE_ENV
|
|
340
|
-
);
|
|
341
|
-
const hasErrors = [...fileResults].filter((result) => !!result).map(({ success }) => success).includes(false);
|
|
342
|
-
if (!hasErrors) {
|
|
343
|
-
startApplicationProcess();
|
|
344
|
-
startHMRProcess();
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
const startWatcher = async (buildSettings = {}) => {
|
|
348
|
-
await initialBuild(buildSettings);
|
|
349
|
-
const watcher = chokidar.watch(
|
|
350
|
-
watchlist.map(({ path: path2 }) => path2),
|
|
351
|
-
{
|
|
352
|
-
ignoreInitial: true
|
|
353
|
-
}
|
|
354
|
-
);
|
|
355
|
-
watcher.on("all", async (event, path2) => {
|
|
356
|
-
await requiredFileCheck();
|
|
357
|
-
process.loader.text("Rebuilding app...");
|
|
358
|
-
const isHTMLUpdate = path2 === "index.html";
|
|
359
|
-
const isUIPath = path2?.includes("ui/") || path2 === "index.css" || isHTMLUpdate;
|
|
360
|
-
const isUIUpdate = process.hmrProcess.hasConnections && isUIPath || false;
|
|
361
|
-
if (["addDir"].includes(event) && fs.existsSync(path2) && fs.lstatSync(path2).isDirectory() && !fs.existsSync(`./.joystick/build/${path2}`)) {
|
|
362
|
-
fs.mkdirSync(`./.joystick/build/${path2}`);
|
|
363
|
-
if (isUIUpdate) {
|
|
364
|
-
notifyHMRClients(isHTMLUpdate);
|
|
365
|
-
} else {
|
|
366
|
-
restartApplicationProcess();
|
|
367
|
-
}
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
if (!!filesToCopy.find((fileToCopy) => fileToCopy.path === path2)) {
|
|
371
|
-
const isDirectory = fs.statSync(path2).isDirectory();
|
|
372
|
-
if (isDirectory && !fs.existsSync(`./.joystick/build/${path2}`)) {
|
|
373
|
-
fs.mkdirSync(`./.joystick/build/${path2}`);
|
|
374
|
-
}
|
|
375
|
-
if (!isDirectory) {
|
|
376
|
-
fs.writeFileSync(`./.joystick/build/${path2}`, fs.readFileSync(path2));
|
|
377
|
-
}
|
|
378
|
-
loadSettings(process.env.NODE_ENV);
|
|
379
|
-
if (isUIUpdate) {
|
|
380
|
-
notifyHMRClients(isHTMLUpdate);
|
|
381
|
-
} else {
|
|
382
|
-
restartApplicationProcess();
|
|
383
|
-
}
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
if (["add", "change"].includes(event) && fs.existsSync(path2)) {
|
|
387
|
-
const codependencies = getCodependenciesForFile(path2);
|
|
388
|
-
const fileResults = await buildFiles(
|
|
389
|
-
[path2, ...codependencies?.existing || []],
|
|
390
|
-
null,
|
|
391
|
-
process.env.NODE_ENV
|
|
392
|
-
);
|
|
393
|
-
const fileResultsHaveErrors = fileResults.filter((result) => !!result).map(({ success }) => success).includes(false);
|
|
394
|
-
removeDeletedDependenciesFromMap(codependencies.deleted);
|
|
395
|
-
const hasErrors = fileResultsHaveErrors;
|
|
396
|
-
if (process.serverProcess && hasErrors) {
|
|
397
|
-
process.serverProcess.send(
|
|
398
|
-
JSON.stringify({
|
|
399
|
-
error: "BUILD_ERROR",
|
|
400
|
-
paths: fileResults.filter(({ success }) => !success).map(({ path: pathWithError, error }) => ({
|
|
401
|
-
path: pathWithError,
|
|
402
|
-
error
|
|
403
|
-
}))
|
|
404
|
-
})
|
|
405
|
-
);
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
if (!hasErrors) {
|
|
409
|
-
process.initialBuildComplete = true;
|
|
410
|
-
if (isUIUpdate) {
|
|
411
|
-
notifyHMRClients(isHTMLUpdate);
|
|
412
|
-
} else {
|
|
413
|
-
restartApplicationProcess();
|
|
414
|
-
}
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
if (["unlink", "unlinkDir"].includes(event) && !fs.existsSync(`./.joystick/build/${path2}`)) {
|
|
419
|
-
if (isUIUpdate) {
|
|
420
|
-
notifyHMRClients(isHTMLUpdate);
|
|
421
|
-
} else {
|
|
422
|
-
restartApplicationProcess();
|
|
423
|
-
}
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
if (["unlink", "unlinkDir"].includes(event) && fs.existsSync(`./.joystick/build/${path2}`)) {
|
|
427
|
-
const pathToUnlink = `./.joystick/build/${path2}`;
|
|
428
|
-
const stats = fs.lstatSync(pathToUnlink);
|
|
429
|
-
if (stats.isDirectory()) {
|
|
430
|
-
fs.rmdirSync(pathToUnlink, { recursive: true });
|
|
431
|
-
}
|
|
432
|
-
if (stats.isFile()) {
|
|
433
|
-
fs.unlinkSync(pathToUnlink);
|
|
434
|
-
}
|
|
435
|
-
if (isUIUpdate) {
|
|
436
|
-
notifyHMRClients(isHTMLUpdate);
|
|
437
|
-
} else {
|
|
438
|
-
restartApplicationProcess();
|
|
439
|
-
}
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
};
|
|
444
|
-
const startDatabase = async (database = {}, databasePort = 2610, hasMultipleOfProvider = false) => {
|
|
445
|
-
process._databases = {
|
|
446
|
-
...process._databases || {},
|
|
447
|
-
[database.provider]: !hasMultipleOfProvider ? await startDatabaseProvider(database, databasePort) : {
|
|
448
|
-
...process._databases && process._databases[database.provider] || {},
|
|
449
|
-
[database?.name || `${database.provider}_${databasePort}`]: await startDatabaseProvider(database, databasePort)
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
return Promise.resolve(process._databases);
|
|
453
|
-
};
|
|
454
|
-
const startDatabases = async (databasePortStart = 2610) => {
|
|
455
|
-
try {
|
|
456
|
-
const hasSettings = !!process.env.JOYSTICK_SETTINGS;
|
|
457
|
-
const settings = hasSettings && JSON.parse(process.env.JOYSTICK_SETTINGS);
|
|
458
|
-
const databases = settings?.config?.databases || [];
|
|
459
|
-
if (databases && Array.isArray(databases) && databases.length > 0) {
|
|
460
|
-
validateDatabasesFromSettings(databases);
|
|
461
|
-
for (let i = 0; i < databases?.length; i += 1) {
|
|
462
|
-
const database = databases[i];
|
|
463
|
-
const hasMultipleOfProvider = databases?.filter((database2) => database2?.provider === database2?.provider)?.length > 1;
|
|
464
|
-
await startDatabase(database, databasePortStart + i, hasMultipleOfProvider);
|
|
465
|
-
}
|
|
466
|
-
return Promise.resolve();
|
|
467
|
-
}
|
|
468
|
-
return Promise.resolve();
|
|
469
|
-
} catch (exception) {
|
|
470
|
-
console.warn(exception);
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
const loadSettings = () => {
|
|
474
|
-
const environment = process.env.NODE_ENV;
|
|
475
|
-
const settingsFilePath = `${process.cwd()}/settings.${environment}.json`;
|
|
476
|
-
const hasSettingsFile = fs.existsSync(settingsFilePath);
|
|
477
|
-
if (!hasSettingsFile) {
|
|
478
|
-
CLILog(
|
|
479
|
-
`A settings file could not be found for this environment (${environment}). Create a settings.${environment}.json file at the root of your project and restart Joystick.`,
|
|
480
|
-
{
|
|
481
|
-
level: "danger",
|
|
482
|
-
docs: "https://github.com/cheatcode/joystick#settings"
|
|
483
|
-
}
|
|
484
|
-
);
|
|
485
|
-
process.exit(0);
|
|
486
|
-
}
|
|
487
|
-
const rawSettingsFile = fs.readFileSync(settingsFilePath, "utf-8");
|
|
488
|
-
const isValidJSON = isValidJSONString(rawSettingsFile);
|
|
489
|
-
if (!isValidJSON) {
|
|
490
|
-
CLILog(
|
|
491
|
-
`Failed to parse settings file. Double-check the syntax in your settings.${environment}.json file at the root of your project and restart Joystick.`,
|
|
492
|
-
{
|
|
493
|
-
level: "danger",
|
|
494
|
-
docs: "https://github.com/cheatcode/joystick#settings",
|
|
495
|
-
tools: [{ title: "JSON Linter", url: "https://jsonlint.com/" }]
|
|
496
|
-
}
|
|
497
|
-
);
|
|
498
|
-
process.exit(0);
|
|
499
|
-
}
|
|
500
|
-
const settingsFile = isValidJSON ? rawSettingsFile : "{}";
|
|
501
|
-
process.env.JOYSTICK_SETTINGS = settingsFile;
|
|
502
|
-
return JSON.parse(settingsFile);
|
|
503
|
-
};
|
|
504
|
-
const checkIfJoystickProject = () => {
|
|
505
|
-
return fs.existsSync(`${process.cwd()}/.joystick`);
|
|
506
|
-
};
|
|
507
21
|
var start_default = async (args = {}, options = {}) => {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
CLILog(
|
|
514
|
-
"This is not a Joystick project. A .joystick folder could not be found.",
|
|
515
|
-
{
|
|
516
|
-
level: "danger",
|
|
517
|
-
docs: "https://github.com/cheatcode/joystick"
|
|
518
|
-
}
|
|
519
|
-
);
|
|
520
|
-
process.exit(0);
|
|
521
|
-
}
|
|
522
|
-
await killPortProcess([port, port + 1]);
|
|
523
|
-
process.title = "joystick";
|
|
524
|
-
process.env.LOGS_PATH = options?.logs || null;
|
|
525
|
-
process.env.NODE_ENV = options?.environment || "development";
|
|
526
|
-
process.env.PORT = options?.port ? parseInt(options?.port) : 2600;
|
|
527
|
-
process.env.IS_DEBUG_MODE = options?.debug;
|
|
528
|
-
const settings = loadSettings(process.env.NODE_ENV);
|
|
529
|
-
await startDatabases(databasePortStart);
|
|
530
|
-
startWatcher(settings?.config?.build);
|
|
531
|
-
handleSignalEvents([]);
|
|
22
|
+
await dev({
|
|
23
|
+
environment: args?.environment || "development",
|
|
24
|
+
process,
|
|
25
|
+
port: options?.port ? parseInt(options?.port) : 2600
|
|
26
|
+
});
|
|
532
27
|
};
|
|
533
28
|
export {
|
|
534
29
|
start_default as default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { OBJECT_REGEX } from "../../lib/regexes.js";
|
|
3
3
|
import rainbowRoad from "../../lib/rainbowRoad.js";
|
|
4
|
-
import getCodeFrame from "../../lib/getCodeFrame.js";
|
|
4
|
+
import getCodeFrame from "../../lib/build/getCodeFrame.js";
|
|
5
5
|
const removeLocationDataFromStackTrace = (stackTrace = "") => {
|
|
6
6
|
return stackTrace.replace(OBJECT_REGEX, "");
|
|
7
7
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import generateId from "./generateId.js";
|
|
3
3
|
var setComponentId_default = (file = "") => {
|
|
4
|
-
const componentMapPath = process.env.NODE_ENV
|
|
4
|
+
const componentMapPath = ["development", "test"].includes(process.env.NODE_ENV) ? `./.joystick/build/componentMap.json` : `./.build/componentMap.json`;
|
|
5
5
|
const componentMapExists = fs.existsSync(componentMapPath);
|
|
6
6
|
const componentMap = componentMapExists ? JSON.parse(fs.readFileSync(componentMapPath, "utf-8")) : {};
|
|
7
7
|
const parts = [...file?.matchAll(/\/\/ ui+.*/gi)]?.map((match) => {
|