@joystick.js/cli-canary 0.0.0-canary.8 → 0.0.0-canary.81
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/functions/start/index.js +4 -470
- package/dist/functions/start/onWarn.js +1 -1
- 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/build/removeDeletedDependenciesFromMap.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 +101 -27
- 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/functions/start/index.js +615 -612
- package/src/functions/start/onWarn.js +1 -1
- 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/build/removeDeletedDependenciesFromMap.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 +121 -35
- 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
|
@@ -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
|
|
|
6
6
|
const removeLocationDataFromStackTrace = (stackTrace = "") => {
|
|
7
7
|
return stackTrace.replace(OBJECT_REGEX, "");
|
|
@@ -8,6 +8,43 @@ import browserPathExclusions from "./browserPathExclusions.js";
|
|
|
8
8
|
import nodePaths from "./nodePaths.js";
|
|
9
9
|
import nodePathExclusions from "./nodePathExclusions.js";
|
|
10
10
|
import buildPlugins from "./buildPlugins.js";
|
|
11
|
+
import getCodeFrame from "./getCodeFrame.js";
|
|
12
|
+
import onWarn from "./onWarn.js";
|
|
13
|
+
|
|
14
|
+
const handleBuildException = (exception = {}, file = '') => {
|
|
15
|
+
try {
|
|
16
|
+
const error = exception?.errors && exception?.errors[0];
|
|
17
|
+
const snippet = fs.existsSync(file)
|
|
18
|
+
? getCodeFrame(file, {
|
|
19
|
+
line: error?.location?.line,
|
|
20
|
+
column: error?.location?.column,
|
|
21
|
+
})
|
|
22
|
+
: null;
|
|
23
|
+
|
|
24
|
+
onWarn({
|
|
25
|
+
file,
|
|
26
|
+
stack: exception?.stack,
|
|
27
|
+
line: error?.location?.line,
|
|
28
|
+
column: error?.location?.column,
|
|
29
|
+
snippet,
|
|
30
|
+
lineWithError: error?.location?.lineText?.trim(),
|
|
31
|
+
message: error?.text,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return snippet;
|
|
35
|
+
} catch (exception) {
|
|
36
|
+
throw new Error(`[actionName.handleBuildException] ${exception.message}`);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const handleParseFilePathFromException = (exception = {}) => {
|
|
41
|
+
try {
|
|
42
|
+
const rawErrorMessage = exception?.message?.split(':');
|
|
43
|
+
return rawErrorMessage[1] && rawErrorMessage[1]?.replace('\n', '') || '';
|
|
44
|
+
} catch (exception) {
|
|
45
|
+
throw new Error(`[actionName.handleParseFilePathFromException] ${exception.message}`);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
11
48
|
|
|
12
49
|
const handleBuildForNode = (nodePaths = [], options = {}) => {
|
|
13
50
|
try {
|
|
@@ -63,8 +100,10 @@ const handleCopyFiles = (files = [], outputPath = '') => {
|
|
|
63
100
|
for (let i = 0; i < files?.length; i += 1) {
|
|
64
101
|
const file = files[i];
|
|
65
102
|
const fileContents = fs.readFileSync(file.path);
|
|
66
|
-
|
|
67
|
-
fs.
|
|
103
|
+
|
|
104
|
+
// NOTE: Using fs.outputFileSync() from fs-extra to ensure parent path is created
|
|
105
|
+
// if it doesn't exist (avoids need for separate fs.mkdirSync()).
|
|
106
|
+
fs.outputFileSync(
|
|
68
107
|
`${outputPath || "./.joystick/build"}/${file.path}`,
|
|
69
108
|
fileContents
|
|
70
109
|
);
|
|
@@ -76,7 +115,7 @@ const handleCopyFiles = (files = [], outputPath = '') => {
|
|
|
76
115
|
|
|
77
116
|
const isNodePath = (path = '') => {
|
|
78
117
|
try {
|
|
79
|
-
return nodePaths.some((nodePath) => {
|
|
118
|
+
return !isNotJavaScript(path) && nodePaths.some((nodePath) => {
|
|
80
119
|
return path.includes(nodePath);
|
|
81
120
|
}) &&
|
|
82
121
|
!nodePathExclusions.some((nodeExclusionPath) => {
|
|
@@ -89,7 +128,7 @@ const isNodePath = (path = '') => {
|
|
|
89
128
|
|
|
90
129
|
const isBrowserPath = (path = '') => {
|
|
91
130
|
try {
|
|
92
|
-
return browserPaths.some((browserPath) => {
|
|
131
|
+
return !isNotJavaScript(path) && browserPaths.some((browserPath) => {
|
|
93
132
|
return path.includes(browserPath);
|
|
94
133
|
}) &&
|
|
95
134
|
!browserPathExclusions.some((browserExclusionPath) => {
|
|
@@ -181,9 +220,36 @@ const buildFiles = async (options, { resolve, reject }) => {
|
|
|
181
220
|
|
|
182
221
|
handleCopyFiles(copyFiles, options?.outputPath);
|
|
183
222
|
|
|
184
|
-
await Promise.all([
|
|
185
|
-
handleBuildForBrowser(browserFiles, options)
|
|
186
|
-
|
|
223
|
+
const fileResults = await Promise.all([
|
|
224
|
+
handleBuildForBrowser(browserFiles, options).then(() => {
|
|
225
|
+
return { success: true };
|
|
226
|
+
}).catch((exception) => {
|
|
227
|
+
const file = handleParseFilePathFromException(exception);
|
|
228
|
+
console.log(file, exception);
|
|
229
|
+
const snippet = handleBuildException(exception, file);
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
success: false,
|
|
233
|
+
path: file,
|
|
234
|
+
error: {
|
|
235
|
+
stack: exception?.stack,
|
|
236
|
+
snippet,
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}),
|
|
240
|
+
handleBuildForNode(nodeFiles, options).catch((exception) => {
|
|
241
|
+
const file = handleParseFilePathFromException(exception);
|
|
242
|
+
const snippet = handleBuildException(exception, file);
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
success: false,
|
|
246
|
+
path: file,
|
|
247
|
+
error: {
|
|
248
|
+
stack: exception?.stack,
|
|
249
|
+
snippet,
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}),
|
|
187
253
|
]);
|
|
188
254
|
|
|
189
255
|
if (options?.environment !== 'development') {
|
|
@@ -192,7 +258,7 @@ const buildFiles = async (options, { resolve, reject }) => {
|
|
|
192
258
|
}));
|
|
193
259
|
}
|
|
194
260
|
|
|
195
|
-
resolve();
|
|
261
|
+
resolve(fileResults);
|
|
196
262
|
} catch (exception) {
|
|
197
263
|
reject(`[buildFiles] ${exception.message}`);
|
|
198
264
|
}
|
|
@@ -25,22 +25,25 @@ export default {
|
|
|
25
25
|
(bootstrapTarget) => {
|
|
26
26
|
return args.path.includes(bootstrapTarget);
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
);
|
|
29
|
+
|
|
29
30
|
const isLayoutComponent = [getPlatformSafePath("ui/layouts")].some(
|
|
30
31
|
(bootstrapTarget) => {
|
|
31
32
|
return args.path.includes(bootstrapTarget);
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
);
|
|
35
|
+
|
|
34
36
|
const isPageComponent = [getPlatformSafePath("ui/pages")].some(
|
|
35
37
|
(bootstrapTarget) => {
|
|
36
38
|
return args.path.includes(bootstrapTarget);
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
);
|
|
41
|
+
|
|
39
42
|
const isEmailComponent = [getPlatformSafePath("email/")].some(
|
|
40
43
|
(bootstrapTarget) => {
|
|
41
44
|
return args.path.includes(bootstrapTarget);
|
|
42
45
|
}
|
|
43
|
-
|
|
46
|
+
);
|
|
44
47
|
|
|
45
48
|
if (
|
|
46
49
|
shouldSetSSRId ||
|
|
@@ -51,7 +54,7 @@ export default {
|
|
|
51
54
|
const code = fs.readFileSync(
|
|
52
55
|
getPlatformSafePath(args.path),
|
|
53
56
|
"utf-8"
|
|
54
|
-
|
|
57
|
+
);
|
|
55
58
|
|
|
56
59
|
// NOTE: Check to see if we have a valid component file.
|
|
57
60
|
const joystickUIMatches = code.match(JOYSTICK_UI_REGEX) || [];
|
|
@@ -65,8 +68,8 @@ export default {
|
|
|
65
68
|
console.warn(
|
|
66
69
|
chalk.yellowBright(
|
|
67
70
|
`All Joystick components in the ui directory must have an export default statement (e.g., export default MyComponent, export default MyLayout, or export default MyPage). Please check the file at ${args.path}.`
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
)
|
|
72
|
+
);
|
|
70
73
|
console.log(" ");
|
|
71
74
|
return;
|
|
72
75
|
}
|
|
@@ -110,7 +113,7 @@ export default {
|
|
|
110
113
|
|
|
111
114
|
export default ${componentName};
|
|
112
115
|
`
|
|
113
|
-
|
|
116
|
+
);
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
if (componentName && isPageComponent) {
|
|
@@ -128,7 +131,7 @@ export default {
|
|
|
128
131
|
|
|
129
132
|
export default ${componentName};
|
|
130
133
|
`
|
|
131
|
-
|
|
134
|
+
);
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
return {
|
|
@@ -143,25 +146,29 @@ export default {
|
|
|
143
146
|
|
|
144
147
|
build.onEnd(() => {
|
|
145
148
|
return new Promise((resolve) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
for (let i = 0; i < build?.initialOptions?.entryPoints?.length; i += 1) {
|
|
150
|
+
const entryPoint = build?.initialOptions?.entryPoints[i];
|
|
151
|
+
const shouldSetComponentId = [
|
|
152
|
+
getPlatformSafePath("ui/"),
|
|
153
|
+
getPlatformSafePath("email/"),
|
|
149
154
|
].some((bootstrapTarget) => {
|
|
150
|
-
return
|
|
155
|
+
return entryPoint.includes(bootstrapTarget);
|
|
151
156
|
});
|
|
152
157
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
158
|
+
if (shouldSetComponentId) {
|
|
159
|
+
const file = fs.readFileSync(`${build?.initialOptions?.outdir}/${entryPoint}`, "utf-8");
|
|
160
|
+
const joystickUIMatches =
|
|
156
161
|
file?.match(JOYSTICK_COMPONENT_REGEX) || [];
|
|
157
162
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
if (joystickUIMatches?.length > 0) {
|
|
164
|
+
let contents = setComponentId(file)?.replace(
|
|
165
|
+
/\.component\(\/\*\*\//g,
|
|
166
|
+
".component("
|
|
162
167
|
);
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
|
|
169
|
+
fs.writeFileSync(`${build?.initialOptions?.outdir}/${entryPoint}`, contents);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
165
172
|
}
|
|
166
173
|
|
|
167
174
|
resolve();
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { codeFrameColumns } from "@babel/code-frame";
|
|
3
3
|
|
|
4
|
-
export default (
|
|
5
|
-
const file = fs.readFileSync(
|
|
6
|
-
|
|
7
|
-
return frame;
|
|
4
|
+
export default (path = "", location = {}) => {
|
|
5
|
+
const file = fs.readFileSync(path, "utf-8");
|
|
6
|
+
return codeFrameColumns(file, { start: location });
|
|
8
7
|
};
|
package/src/lib/build/onWarn.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { OBJECT_REGEX } from "../regexes.js";
|
|
3
3
|
import rainbowRoad from '../rainbowRoad.js';
|
|
4
|
-
import getCodeFrame from "
|
|
4
|
+
import getCodeFrame from "./getCodeFrame.js";
|
|
5
5
|
|
|
6
6
|
const removeLocationDataFromStackTrace = (stackTrace = "") => {
|
|
7
7
|
return stackTrace.replace(OBJECT_REGEX, "");
|
package/src/lib/dev/cleanup.js
CHANGED
|
@@ -1,34 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
// NOTE: This module is intended to be run as a child_process as part of
|
|
2
|
+
// a SIGINT or SIGTERM event.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
try {
|
|
5
|
-
// Perform a single step in your action here.
|
|
6
|
-
} catch (exception) {
|
|
7
|
-
throw new Error(`[cleanup.actionMethod] ${exception.message}`);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
4
|
+
import ps from "ps-node";
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
if (!options) throw new Error('options object is required.');
|
|
14
|
-
if (!options.someOption) throw new Error('options.someOption is required.');
|
|
15
|
-
} catch (exception) {
|
|
16
|
-
throw new Error(`[cleanup.validateOptions] ${exception.message}`);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
6
|
+
process.title = "joystick_cleanup";
|
|
19
7
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
reject(`[cleanup] ${exception.message}`);
|
|
27
|
-
}
|
|
8
|
+
const killProcess = (pid = 0) => {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
ps.kill(pid, () => {
|
|
11
|
+
resolve();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
28
14
|
};
|
|
29
15
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
process.on('message', async (message) => {
|
|
17
|
+
const parsedMessage = JSON.parse(message);
|
|
18
|
+
const processIds = parsedMessage?.processIds;
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < processIds?.length; i += 1) {
|
|
21
|
+
const processId = processIds[i];
|
|
22
|
+
await killProcess(processId);
|
|
23
|
+
}
|
|
34
24
|
|
|
25
|
+
process.exit();
|
|
26
|
+
});
|
|
@@ -4,7 +4,7 @@ import child_process from "child_process";
|
|
|
4
4
|
import { kill as killPortProcess } from 'cross-port-killer';
|
|
5
5
|
import isWindows from "../../isWindows.js";
|
|
6
6
|
import CLILog from "../../../../lib/CLILog.js";
|
|
7
|
-
import getProcessIdFromPort from "
|
|
7
|
+
import getProcessIdFromPort from "../../../getProcessIdFromPort.js";
|
|
8
8
|
|
|
9
9
|
const getMongoProcessId = async (port = 2601) => {
|
|
10
10
|
const pids = await getProcessIdFromPort(port);
|
|
@@ -4,8 +4,8 @@ import util from "util";
|
|
|
4
4
|
import commandExists from "command-exists";
|
|
5
5
|
import child_process from "child_process";
|
|
6
6
|
import { kill as killPortProcess } from 'cross-port-killer';
|
|
7
|
-
import getProcessIdFromPort from "
|
|
8
|
-
import CLILog from "
|
|
7
|
+
import getProcessIdFromPort from "../../../getProcessIdFromPort.js";
|
|
8
|
+
import CLILog from "../../../CLILog.js";
|
|
9
9
|
|
|
10
10
|
const exec = util.promisify(child_process.exec);
|
|
11
11
|
|
package/src/lib/dev/index.js
CHANGED
|
@@ -10,7 +10,6 @@ import loadSettings from "./loadSettings.js";
|
|
|
10
10
|
import Loader from "../loader.js";
|
|
11
11
|
import startDatabases from "./startDatabases.js";
|
|
12
12
|
import runTests from "./runTests.js";
|
|
13
|
-
import cleanup from "./cleanup.js";
|
|
14
13
|
import startHMR from "./startHMR.js";
|
|
15
14
|
import startApp from "./startApp.js";
|
|
16
15
|
import requiredFiles from "./requiredFiles.js";
|
|
@@ -21,14 +20,7 @@ import filesToCopy from "../filesToCopy.js";
|
|
|
21
20
|
import { SETTINGS_FILE_NAME_REGEX } from "../regexes.js";
|
|
22
21
|
import getCodependenciesForFile from "./getCodependenciesForFile.js";
|
|
23
22
|
import removeDeletedDependenciesFromMap from "../build/removeDeletedDependenciesFromMap.js";
|
|
24
|
-
|
|
25
|
-
const nodeMajorVersion = parseInt(
|
|
26
|
-
process?.version?.split(".")[0]?.replace("v", ""),
|
|
27
|
-
10
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
31
|
-
const __dirname = dirname(__filename);
|
|
23
|
+
import chalk from "chalk";
|
|
32
24
|
|
|
33
25
|
const getDatabaseProcessIds = () => {
|
|
34
26
|
try {
|
|
@@ -61,7 +53,7 @@ const getDatabaseProcessIds = () => {
|
|
|
61
53
|
}
|
|
62
54
|
};
|
|
63
55
|
|
|
64
|
-
const handleSignalEvents = (processIds = []) => {
|
|
56
|
+
const handleSignalEvents = (processIds = [], nodeMajorVersion = 0, __dirname = '') => {
|
|
65
57
|
try {
|
|
66
58
|
const execArgv = ["--no-warnings"];
|
|
67
59
|
|
|
@@ -83,6 +75,8 @@ const handleSignalEvents = (processIds = []) => {
|
|
|
83
75
|
}
|
|
84
76
|
);
|
|
85
77
|
|
|
78
|
+
console.log(cleanupProcess);
|
|
79
|
+
|
|
86
80
|
process.on("SIGINT", async () => {
|
|
87
81
|
const databaseProcessIds = getDatabaseProcessIds();
|
|
88
82
|
cleanupProcess.send(JSON.stringify(({ processIds: [...processIds, ...databaseProcessIds] })));
|
|
@@ -99,6 +93,53 @@ const handleSignalEvents = (processIds = []) => {
|
|
|
99
93
|
}
|
|
100
94
|
};
|
|
101
95
|
|
|
96
|
+
const handleServerProcessMessages = () => {
|
|
97
|
+
try {
|
|
98
|
+
process.serverProcess.on("message", (message) => {
|
|
99
|
+
const processMessages = ["SERVER_CLOSED"];
|
|
100
|
+
|
|
101
|
+
if (!processMessages.includes(message)) {
|
|
102
|
+
process.loader.stable(message);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
} catch (exception) {
|
|
106
|
+
throw new Error(`[dev.handleServerProcessMessages] ${exception.message}`);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const handleServerProcessSTDIO = () => {
|
|
111
|
+
try {
|
|
112
|
+
if (process.serverProcess) {
|
|
113
|
+
process.serverProcess.on("error", (error) => {
|
|
114
|
+
console.log(error);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
process.serverProcess.stdout.on("data", (data) => {
|
|
118
|
+
const message = data.toString();
|
|
119
|
+
|
|
120
|
+
if (message && message.includes("App running at:")) {
|
|
121
|
+
process.loader.stable(message);
|
|
122
|
+
} else {
|
|
123
|
+
if (message && !message.includes("BUILD_ERROR")) {
|
|
124
|
+
console.log(message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
process.serverProcess.stderr.on("data", (data) => {
|
|
130
|
+
process.loader.stop();
|
|
131
|
+
|
|
132
|
+
CLILog(data.toString(), {
|
|
133
|
+
level: "danger",
|
|
134
|
+
docs: "https://cheatcode.co/docs/joystick",
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
} catch (exception) {
|
|
139
|
+
throw new Error(`[dev.handleServerProcessSTDIO] ${exception.message}`);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
102
143
|
const handleAddOrChangeFile = async (context = {}, path = '') => {
|
|
103
144
|
try {
|
|
104
145
|
if (context.isAddingOrChangingFile) {
|
|
@@ -228,7 +269,8 @@ const getWatchChangeContext = (event = '', path = '') => {
|
|
|
228
269
|
try {
|
|
229
270
|
const isHTMLUpdate = path === "index.html";
|
|
230
271
|
const isUIPath = path?.includes("ui/") || path === 'index.css' || isHTMLUpdate;
|
|
231
|
-
|
|
272
|
+
// TODO: Flimsy. May want to wait until HMR and server are up to do the builds/watching.
|
|
273
|
+
const isUIUpdate = (process.hmrProcess && process.hmrProcess.hasConnections && isUIPath) || false;
|
|
232
274
|
const isSettingsUpdate = path?.match(SETTINGS_FILE_NAME_REGEX)?.length > 0;
|
|
233
275
|
const isDirectory = fs.statSync(path).isDirectory();
|
|
234
276
|
const isFile = fs.statSync(path).isFile();
|
|
@@ -292,21 +334,26 @@ const startFileWatcher = (options = {}) => {
|
|
|
292
334
|
|
|
293
335
|
const runInitialBuild = async (buildSettings = {}) => {
|
|
294
336
|
try {
|
|
337
|
+
process.loader.text('Building app...');
|
|
338
|
+
|
|
295
339
|
const filesToBuild = getFilesToBuild(buildSettings?.excludedPaths, "start");
|
|
296
|
-
const fileResults = await buildFiles(
|
|
297
|
-
filesToBuild,
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
);
|
|
340
|
+
const fileResults = await buildFiles({
|
|
341
|
+
files: filesToBuild,
|
|
342
|
+
environment: process.env.NODE_ENV
|
|
343
|
+
});
|
|
301
344
|
|
|
302
345
|
const hasErrors = [...fileResults]
|
|
303
346
|
.filter((result) => !!result)
|
|
304
347
|
.map(({ success }) => success)
|
|
305
348
|
.includes(false);
|
|
306
349
|
|
|
307
|
-
//
|
|
308
|
-
|
|
350
|
+
// NOTE: If the initial build fails, exit the startup process.
|
|
351
|
+
if (hasErrors) {
|
|
352
|
+
console.log(chalk.redBright('Failed to start app. Correct the errors above and run joystick start again.\n'));
|
|
353
|
+
process.exit(1);
|
|
354
|
+
}
|
|
309
355
|
} catch (exception) {
|
|
356
|
+
console.warn(exception);
|
|
310
357
|
throw new Error(`[dev.runInitialBuild] ${exception.message}`);
|
|
311
358
|
}
|
|
312
359
|
};
|
|
@@ -352,18 +399,22 @@ const checkForRequiredFiles = () => {
|
|
|
352
399
|
|
|
353
400
|
let error = `The following paths are missing and required in a Joystick project:\n\n`;
|
|
354
401
|
|
|
355
|
-
|
|
402
|
+
if (files?.length > 0) {
|
|
403
|
+
error += ` > Required Files:\n\n`;
|
|
356
404
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
405
|
+
for (let i = 0; i < files?.length; i += 1) {
|
|
406
|
+
const file = files[i];
|
|
407
|
+
error += ` /${file.path}\n`;
|
|
408
|
+
}
|
|
360
409
|
}
|
|
361
410
|
|
|
362
|
-
|
|
411
|
+
if (directories?.length > 0) {
|
|
412
|
+
error += ` > Required Directories:\n\n`;
|
|
363
413
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
414
|
+
for (let i = 0; i < directories?.length; i += 1) {
|
|
415
|
+
const file = directories[i];
|
|
416
|
+
error += ` /${file.path}\n`;
|
|
417
|
+
}
|
|
367
418
|
}
|
|
368
419
|
|
|
369
420
|
CLILog(error, {
|
|
@@ -395,7 +446,7 @@ const warnInvalidJoystickEnvironment = () => {
|
|
|
395
446
|
process.exit(0);
|
|
396
447
|
}
|
|
397
448
|
|
|
398
|
-
if (process.env.NODE_ENV !== 'test' &&
|
|
449
|
+
if (process.env.NODE_ENV !== 'test' && !hasJoystickFolder) {
|
|
399
450
|
CLILog(
|
|
400
451
|
"joystick start must be run in a directory with a .joystick folder.",
|
|
401
452
|
{
|
|
@@ -425,28 +476,60 @@ const dev = async (options, { resolve, reject }) => {
|
|
|
425
476
|
validateOptions(options);
|
|
426
477
|
initProcess(options);
|
|
427
478
|
|
|
479
|
+
const nodeMajorVersion = parseInt(
|
|
480
|
+
process?.version?.split(".")[0]?.replace("v", ""),
|
|
481
|
+
10
|
|
482
|
+
);
|
|
483
|
+
|
|
484
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
485
|
+
const __dirname = dirname(__filename);
|
|
486
|
+
|
|
428
487
|
warnInvalidJoystickEnvironment();
|
|
429
488
|
checkForRequiredFiles();
|
|
430
489
|
|
|
431
490
|
const settings = await loadSettings({
|
|
432
491
|
environment: options.environment,
|
|
433
|
-
process: options.process,
|
|
434
492
|
});
|
|
435
493
|
|
|
436
|
-
await startDatabases(
|
|
494
|
+
await startDatabases({
|
|
495
|
+
environment: options.environment,
|
|
496
|
+
port: options.port,
|
|
497
|
+
settings: settings.parsed
|
|
498
|
+
});
|
|
437
499
|
|
|
438
500
|
await runInitialBuild(settings?.parsed?.config?.build);
|
|
439
501
|
await startFileWatcher(options);
|
|
440
502
|
|
|
441
|
-
|
|
503
|
+
const serverProcess = await startApp({
|
|
504
|
+
nodeMajorVersion,
|
|
505
|
+
port: options?.port,
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
if (serverProcess) {
|
|
509
|
+
process.serverProcess = serverProcess;
|
|
510
|
+
handleServerProcessSTDIO();
|
|
511
|
+
handleServerProcessMessages();
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// NOTE: Scope this out here so we can reference the processId below.
|
|
515
|
+
let hmrProcess;
|
|
516
|
+
|
|
517
|
+
if (options?.environment !== 'test') {
|
|
518
|
+
hmrProcess = await startHMR({
|
|
519
|
+
nodeMajorVersion,
|
|
520
|
+
__dirname,
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
handleSignalEvents(
|
|
525
|
+
[serverProcess.pid, hmrProcess.pid],
|
|
526
|
+
nodeMajorVersion,
|
|
527
|
+
__dirname
|
|
528
|
+
);
|
|
442
529
|
|
|
443
|
-
// if (options?.environment !== 'test') {
|
|
444
|
-
// await startHMR();
|
|
445
|
-
// }
|
|
446
530
|
//
|
|
447
531
|
// if (options?.environment === 'test') {
|
|
448
532
|
// await runTests(options);
|
|
449
|
-
// await cleanup();
|
|
450
533
|
// }
|
|
451
534
|
|
|
452
535
|
/*
|
|
@@ -456,7 +539,9 @@ const dev = async (options, { resolve, reject }) => {
|
|
|
456
539
|
- [x] If environment === 'test', check that both a .joystick fo lder exists AND a /tests folder
|
|
457
540
|
exists. If no /tests, log out docs on how to scaffold your tests.
|
|
458
541
|
- [x] Load settings.<environment>.json.
|
|
459
|
-
- [
|
|
542
|
+
- [x] Start databases relative to options.environment (development|test) from settings.<environment>.json.
|
|
543
|
+
- [x] Run the initial build
|
|
544
|
+
- [x] Start the file watcher
|
|
460
545
|
- [ ] Start the app as normal from the build directory.
|
|
461
546
|
- [ ] If environment === 'test', run the tests.
|
|
462
547
|
- [ ] If environment === 'test', after tests, run process.exit(0).
|
|
@@ -464,6 +549,7 @@ const dev = async (options, { resolve, reject }) => {
|
|
|
464
549
|
|
|
465
550
|
resolve();
|
|
466
551
|
} catch (exception) {
|
|
552
|
+
console.warn(exception);
|
|
467
553
|
reject(`[dev] ${exception.message}`);
|
|
468
554
|
}
|
|
469
555
|
};
|
|
@@ -73,9 +73,7 @@ const loadSettings = (options, { resolve, reject }) => {
|
|
|
73
73
|
const settings = getSettings(settingsPath);
|
|
74
74
|
warnIfInvalidJSONInSettings(settings);
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
options.process.env.JOYSTICK_SETTINGS = settings;
|
|
78
|
-
}
|
|
76
|
+
process.env.JOYSTICK_SETTINGS = settings;
|
|
79
77
|
|
|
80
78
|
resolve({
|
|
81
79
|
parsed: JSON.parse(settings),
|