@joystick.js/cli-canary 0.0.0-canary.21 → 0.0.0-canary.210
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 +4 -4
- package/dist/cli.js +7 -0
- package/dist/functions/index.js +26 -0
- package/dist/functions/start/index.js +2 -1
- package/dist/functions/start/setComponentId.js +1 -1
- package/dist/functions/test/index.js +8 -26
- package/dist/lib/build/browserPathExclusions.js +2 -1
- package/dist/lib/build/buildFiles.js +66 -7
- package/dist/lib/build/buildPlugins.js +30 -19
- package/dist/lib/build/getCodeFrame.js +3 -4
- package/dist/lib/build/nodePaths.js +1 -0
- package/dist/lib/build/replaceExamples.js +13 -0
- package/dist/lib/build/setComponentId.js +1 -1
- package/dist/lib/dev/cleanup.js +15 -27
- package/dist/lib/dev/hmrServer.js +66 -0
- package/dist/lib/dev/index.js +220 -45
- package/dist/lib/dev/loadSettings.js +1 -3
- package/dist/lib/dev/runTests.js +73 -5
- package/dist/lib/dev/startApp.js +45 -3
- package/dist/lib/dev/startDatabases.js +12 -5
- package/dist/lib/dev/startHMR.js +30 -5
- package/dist/lib/dev/tests.config.js +12 -0
- package/dist/lib/regexes.js +2 -0
- package/dist/lib/types.js +6 -0
- package/package.json +2 -1
- package/src/cli.js +9 -0
- package/src/functions/index.js +26 -0
- package/src/functions/start/index.js +1 -690
- package/src/functions/start/setComponentId.js +1 -1
- package/src/functions/test/index.js +9 -33
- package/src/lib/build/browserPathExclusions.js +2 -1
- package/src/lib/build/buildFiles.js +77 -8
- package/src/lib/build/buildPlugins.js +47 -32
- package/src/lib/build/getCodeFrame.js +3 -4
- package/src/lib/build/nodePaths.js +1 -0
- package/src/lib/build/replaceExamples.js +11 -0
- package/src/lib/build/setComponentId.js +3 -3
- package/src/lib/dev/cleanup.js +20 -28
- package/src/lib/dev/hmrServer.js +78 -0
- package/src/lib/dev/index.js +265 -59
- package/src/lib/dev/loadSettings.js +1 -3
- package/src/lib/dev/runTests.js +97 -7
- package/src/lib/dev/startApp.js +54 -6
- package/src/lib/dev/startDatabases.js +12 -6
- package/src/lib/dev/startHMR.js +36 -7
- package/src/lib/dev/tests.config.js +9 -0
- package/src/lib/regexes.js +1 -0
- package/src/lib/types.js +3 -0
package/_package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "@joystick.js/cli",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
4
|
-
"developmentVersion": "1.0.0-beta.1695",
|
|
2
|
+
"name": "@joystick.js/cli-canary",
|
|
3
|
+
"version": "1.0.0-beta.74",
|
|
5
4
|
"type": "module",
|
|
6
5
|
"description": "CLI for the Joystick JavaScript framework.",
|
|
7
6
|
"main": "development.js",
|
|
@@ -26,6 +25,7 @@
|
|
|
26
25
|
"@babel/code-frame": "^7.15.8",
|
|
27
26
|
"acorn": "^8.5.0",
|
|
28
27
|
"ascii-table": "^0.0.9",
|
|
28
|
+
"ava": "^5.3.1",
|
|
29
29
|
"chalk": "^4.1.2",
|
|
30
30
|
"chokidar": "^3.5.2",
|
|
31
31
|
"command-exists": "^1.2.9",
|
|
@@ -52,4 +52,4 @@
|
|
|
52
52
|
"ws": "^8.2.3",
|
|
53
53
|
"xmlhttprequest": "^1.8.0"
|
|
54
54
|
}
|
|
55
|
-
}
|
|
55
|
+
}
|
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,31 @@ 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
|
+
watch: {
|
|
225
|
+
set: !!rawArgs.includes("watch"),
|
|
226
|
+
parent: "test",
|
|
227
|
+
value: !!rawArgs.includes("watch"),
|
|
228
|
+
description: "Run joystick test in watch mode."
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
options: {
|
|
232
|
+
watch: {
|
|
233
|
+
flags: {
|
|
234
|
+
"--watch": {
|
|
235
|
+
set: !!rawArgs.includes("--watch"),
|
|
236
|
+
value: !!rawArgs.includes("--watch"),
|
|
237
|
+
parent: "test"
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
description: "Environment to set for process.env.NODE_ENV."
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
function: test
|
|
244
|
+
},
|
|
219
245
|
update: {
|
|
220
246
|
set: !!rawArgs.includes("update"),
|
|
221
247
|
description: "Update all Joystick packages to their latest version.",
|
|
@@ -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) => {
|
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import dev from "../../lib/dev/index.js";
|
|
2
|
+
var test_default = async (args = {}, options = {}) => {
|
|
3
|
+
await dev({
|
|
4
|
+
environment: "test",
|
|
5
|
+
process,
|
|
6
|
+
port: 1977,
|
|
7
|
+
watch: options?.watch
|
|
8
|
+
});
|
|
6
9
|
};
|
|
7
|
-
const validateOptions = (options) => {
|
|
8
|
-
try {
|
|
9
|
-
if (!options)
|
|
10
|
-
throw new Error("options object is required.");
|
|
11
|
-
if (!options.someOption)
|
|
12
|
-
throw new Error("options.someOption is required.");
|
|
13
|
-
} catch (exception) {
|
|
14
|
-
throw new Error(`[test.validateOptions] ${exception.message}`);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
const test = (options, { resolve, reject }) => {
|
|
18
|
-
try {
|
|
19
|
-
validateOptions(options);
|
|
20
|
-
resolve();
|
|
21
|
-
} catch (exception) {
|
|
22
|
-
reject(`[test] ${exception.message}`);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
var test_default = (options) => new Promise((resolve, reject) => {
|
|
26
|
-
test(options, { resolve, reject });
|
|
27
|
-
});
|
|
28
10
|
export {
|
|
29
11
|
test_default as default
|
|
30
12
|
};
|
|
@@ -8,6 +8,37 @@ 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
|
+
const handleBuildException = (exception = {}, file = "") => {
|
|
14
|
+
try {
|
|
15
|
+
const error = exception?.errors && exception?.errors[0];
|
|
16
|
+
const snippet = fs.existsSync(file) ? getCodeFrame(file, {
|
|
17
|
+
line: error?.location?.line,
|
|
18
|
+
column: error?.location?.column
|
|
19
|
+
}) : null;
|
|
20
|
+
onWarn({
|
|
21
|
+
file,
|
|
22
|
+
stack: exception?.stack,
|
|
23
|
+
line: error?.location?.line,
|
|
24
|
+
column: error?.location?.column,
|
|
25
|
+
snippet,
|
|
26
|
+
lineWithError: error?.location?.lineText?.trim(),
|
|
27
|
+
message: error?.text
|
|
28
|
+
});
|
|
29
|
+
return snippet;
|
|
30
|
+
} catch (exception2) {
|
|
31
|
+
throw new Error(`[actionName.handleBuildException] ${exception2.message}`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const handleParseFilePathFromException = (exception = {}) => {
|
|
35
|
+
try {
|
|
36
|
+
const rawErrorMessage = exception?.message?.split(":");
|
|
37
|
+
return rawErrorMessage[1] && rawErrorMessage[1]?.replace("\n", "") || "";
|
|
38
|
+
} catch (exception2) {
|
|
39
|
+
throw new Error(`[actionName.handleParseFilePathFromException] ${exception2.message}`);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
11
42
|
const handleBuildForNode = (nodePaths2 = [], options = {}) => {
|
|
12
43
|
try {
|
|
13
44
|
return esbuild.build({
|
|
@@ -15,8 +46,10 @@ const handleBuildForNode = (nodePaths2 = [], options = {}) => {
|
|
|
15
46
|
format: "esm",
|
|
16
47
|
bundle: false,
|
|
17
48
|
entryPoints: nodePaths2?.map((file) => file.path),
|
|
49
|
+
entryNames: "[dir]/[name]",
|
|
18
50
|
// TODO: Make sure we don't need outbase here so the paths map correctly.
|
|
19
51
|
outdir: options?.outputPath || "./.joystick/build",
|
|
52
|
+
outbase: "./",
|
|
20
53
|
define: {
|
|
21
54
|
"process.env.NODE_ENV": `'${options?.environment}'`
|
|
22
55
|
},
|
|
@@ -38,6 +71,8 @@ const handleBuildForBrowser = (browserPaths2 = [], options = {}) => {
|
|
|
38
71
|
format: "esm",
|
|
39
72
|
bundle: true,
|
|
40
73
|
entryPoints: browserPaths2?.map((file) => file.path),
|
|
74
|
+
entryNames: "[dir]/[name]",
|
|
75
|
+
outbase: "./",
|
|
41
76
|
// TODO: Make sure we don't need outbase here so the paths map correctly.
|
|
42
77
|
outdir: options?.outputPath || "./.joystick/build",
|
|
43
78
|
define: {
|
|
@@ -60,7 +95,7 @@ const handleCopyFiles = (files = [], outputPath = "") => {
|
|
|
60
95
|
for (let i = 0; i < files?.length; i += 1) {
|
|
61
96
|
const file = files[i];
|
|
62
97
|
const fileContents = fs.readFileSync(file.path);
|
|
63
|
-
fs.
|
|
98
|
+
fs.outputFileSync(
|
|
64
99
|
`${outputPath || "./.joystick/build"}/${file.path}`,
|
|
65
100
|
fileContents
|
|
66
101
|
);
|
|
@@ -71,7 +106,7 @@ const handleCopyFiles = (files = [], outputPath = "") => {
|
|
|
71
106
|
};
|
|
72
107
|
const isNodePath = (path = "") => {
|
|
73
108
|
try {
|
|
74
|
-
return nodePaths.some((nodePath) => {
|
|
109
|
+
return !isNotJavaScript(path) && nodePaths.some((nodePath) => {
|
|
75
110
|
return path.includes(nodePath);
|
|
76
111
|
}) && !nodePathExclusions.some((nodeExclusionPath) => {
|
|
77
112
|
return path.includes(nodeExclusionPath);
|
|
@@ -82,7 +117,7 @@ const isNodePath = (path = "") => {
|
|
|
82
117
|
};
|
|
83
118
|
const isBrowserPath = (path = "") => {
|
|
84
119
|
try {
|
|
85
|
-
return browserPaths.some((browserPath) => {
|
|
120
|
+
return !isNotJavaScript(path) && browserPaths.some((browserPath) => {
|
|
86
121
|
return path.includes(browserPath);
|
|
87
122
|
}) && !browserPathExclusions.some((browserExclusionPath) => {
|
|
88
123
|
return path.includes(browserExclusionPath);
|
|
@@ -161,16 +196,40 @@ const buildFiles = async (options, { resolve, reject }) => {
|
|
|
161
196
|
const browserFiles = filesWithPlatform?.filter((file) => file?.platform === "browser");
|
|
162
197
|
const nodeFiles = filesWithPlatform?.filter((file) => file?.platform === "node");
|
|
163
198
|
handleCopyFiles(copyFiles, options?.outputPath);
|
|
164
|
-
await Promise.all([
|
|
165
|
-
handleBuildForBrowser(browserFiles, options)
|
|
166
|
-
|
|
199
|
+
const fileResults = await Promise.all([
|
|
200
|
+
handleBuildForBrowser(browserFiles, options).then(() => {
|
|
201
|
+
return { success: true };
|
|
202
|
+
}).catch((exception) => {
|
|
203
|
+
const file = handleParseFilePathFromException(exception);
|
|
204
|
+
const snippet = handleBuildException(exception, file);
|
|
205
|
+
return {
|
|
206
|
+
success: false,
|
|
207
|
+
path: file,
|
|
208
|
+
error: {
|
|
209
|
+
stack: exception?.stack,
|
|
210
|
+
snippet
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}),
|
|
214
|
+
handleBuildForNode(nodeFiles, options).catch((exception) => {
|
|
215
|
+
const file = handleParseFilePathFromException(exception);
|
|
216
|
+
const snippet = handleBuildException(exception, file);
|
|
217
|
+
return {
|
|
218
|
+
success: false,
|
|
219
|
+
path: file,
|
|
220
|
+
error: {
|
|
221
|
+
stack: exception?.stack,
|
|
222
|
+
snippet
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
})
|
|
167
226
|
]);
|
|
168
227
|
if (options?.environment !== "development") {
|
|
169
228
|
await Promise.all([browserFiles, nodeFiles].map((file) => {
|
|
170
229
|
return minifyFile(`${options?.outputPath || "./.joystick/build"}/${file.path}`);
|
|
171
230
|
}));
|
|
172
231
|
}
|
|
173
|
-
resolve();
|
|
232
|
+
resolve(fileResults);
|
|
174
233
|
} catch (exception) {
|
|
175
234
|
reject(`[buildFiles] ${exception.message}`);
|
|
176
235
|
}
|
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
JOYSTICK_UI_REGEX,
|
|
6
6
|
EXPORT_DEFAULT_REGEX,
|
|
7
7
|
JOYSTICK_COMPONENT_REGEX,
|
|
8
|
-
JOYSTICK_COMMENT_REGEX
|
|
8
|
+
JOYSTICK_COMMENT_REGEX,
|
|
9
|
+
EXAMPLE_CODE_REGEX
|
|
9
10
|
} from "../regexes.js";
|
|
10
11
|
import generateId from "../generateId.js";
|
|
11
12
|
import getPlatformSafePath from "../getPlatformSafePath.js";
|
|
12
13
|
import setComponentId from "./setComponentId.js";
|
|
14
|
+
import replaceExamples from "./replaceExamples.js";
|
|
13
15
|
var buildPlugins_default = {
|
|
14
16
|
bootstrapComponent: {
|
|
15
17
|
name: "bootstrapComponent",
|
|
@@ -17,7 +19,7 @@ var buildPlugins_default = {
|
|
|
17
19
|
const ssrId = generateId();
|
|
18
20
|
build.onLoad({ filter: /\.js$/ }, (args = {}) => {
|
|
19
21
|
try {
|
|
20
|
-
const
|
|
22
|
+
const shouldSetComponentId = [getPlatformSafePath("ui/")].some(
|
|
21
23
|
(bootstrapTarget) => {
|
|
22
24
|
return args.path.includes(bootstrapTarget);
|
|
23
25
|
}
|
|
@@ -37,7 +39,7 @@ var buildPlugins_default = {
|
|
|
37
39
|
return args.path.includes(bootstrapTarget);
|
|
38
40
|
}
|
|
39
41
|
);
|
|
40
|
-
if (
|
|
42
|
+
if (shouldSetComponentId || isLayoutComponent || isPageComponent || isEmailComponent) {
|
|
41
43
|
const code = fs.readFileSync(
|
|
42
44
|
getPlatformSafePath(args.path),
|
|
43
45
|
"utf-8"
|
|
@@ -56,7 +58,9 @@ var buildPlugins_default = {
|
|
|
56
58
|
console.log(" ");
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
|
-
|
|
61
|
+
const examples = code.match(EXAMPLE_CODE_REGEX) || [];
|
|
62
|
+
let contents = replaceExamples(code);
|
|
63
|
+
contents = setComponentId(contents)?.replace(
|
|
60
64
|
/\.component\(\/\*\*\//g,
|
|
61
65
|
".component("
|
|
62
66
|
);
|
|
@@ -103,6 +107,10 @@ var buildPlugins_default = {
|
|
|
103
107
|
`
|
|
104
108
|
);
|
|
105
109
|
}
|
|
110
|
+
for (let i = 0; i < examples?.length; i += 1) {
|
|
111
|
+
const exampleToRestore = examples[i];
|
|
112
|
+
contents = contents.replace(`%example:${i}%`, exampleToRestore);
|
|
113
|
+
}
|
|
106
114
|
return {
|
|
107
115
|
contents,
|
|
108
116
|
loader: "js"
|
|
@@ -114,21 +122,24 @@ var buildPlugins_default = {
|
|
|
114
122
|
});
|
|
115
123
|
build.onEnd(() => {
|
|
116
124
|
return new Promise((resolve) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
125
|
+
for (let i = 0; i < build?.initialOptions?.entryPoints?.length; i += 1) {
|
|
126
|
+
const entryPoint = build?.initialOptions?.entryPoints[i];
|
|
127
|
+
const shouldSetComponentId = [
|
|
128
|
+
getPlatformSafePath("ui/"),
|
|
129
|
+
getPlatformSafePath("email/")
|
|
130
|
+
].some((bootstrapTarget) => {
|
|
131
|
+
return entryPoint.includes(bootstrapTarget);
|
|
132
|
+
});
|
|
133
|
+
if (shouldSetComponentId) {
|
|
134
|
+
const file = fs.readFileSync(`${build?.initialOptions?.outdir}/${entryPoint}`, "utf-8");
|
|
135
|
+
const joystickUIMatches = file?.match(JOYSTICK_COMPONENT_REGEX) || [];
|
|
136
|
+
if (joystickUIMatches?.length > 0) {
|
|
137
|
+
let contents = setComponentId(file)?.replace(
|
|
138
|
+
/\.component\(\/\*\*\//g,
|
|
139
|
+
".component("
|
|
140
|
+
);
|
|
141
|
+
fs.writeFileSync(`${build?.initialOptions?.outdir}/${entryPoint}`, contents);
|
|
142
|
+
}
|
|
132
143
|
}
|
|
133
144
|
}
|
|
134
145
|
resolve();
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import { codeFrameColumns } from "@babel/code-frame";
|
|
3
|
-
var getCodeFrame_default = (
|
|
4
|
-
const file = fs.readFileSync(
|
|
5
|
-
|
|
6
|
-
return frame;
|
|
3
|
+
var getCodeFrame_default = (path = "", location = {}) => {
|
|
4
|
+
const file = fs.readFileSync(path, "utf-8");
|
|
5
|
+
return codeFrameColumns(file, { start: location });
|
|
7
6
|
};
|
|
8
7
|
export {
|
|
9
8
|
getCodeFrame_default as default
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EXAMPLE_CODE_REGEX } from "../regexes.js";
|
|
2
|
+
var replaceExamples_default = (code = "") => {
|
|
3
|
+
let exampleIndex = 0;
|
|
4
|
+
return code.replace(
|
|
5
|
+
EXAMPLE_CODE_REGEX,
|
|
6
|
+
() => {
|
|
7
|
+
return `%example:${exampleIndex++}%`;
|
|
8
|
+
}
|
|
9
|
+
);
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
replaceExamples_default as default
|
|
13
|
+
};
|
|
@@ -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) => {
|
package/dist/lib/dev/cleanup.js
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!options)
|
|
10
|
-
throw new Error("options object is required.");
|
|
11
|
-
if (!options.someOption)
|
|
12
|
-
throw new Error("options.someOption is required.");
|
|
13
|
-
} catch (exception) {
|
|
14
|
-
throw new Error(`[cleanup.validateOptions] ${exception.message}`);
|
|
15
|
-
}
|
|
1
|
+
import ps from "ps-node";
|
|
2
|
+
process.title = "joystick_cleanup";
|
|
3
|
+
const killProcess = (pid = 0) => {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
ps.kill(pid, () => {
|
|
6
|
+
resolve();
|
|
7
|
+
});
|
|
8
|
+
});
|
|
16
9
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
process.on("message", async (message) => {
|
|
11
|
+
const parsedMessage = JSON.parse(message);
|
|
12
|
+
const processIds = parsedMessage?.processIds;
|
|
13
|
+
for (let i = 0; i < processIds?.length; i += 1) {
|
|
14
|
+
const processId = processIds[i];
|
|
15
|
+
await killProcess(processId);
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
var cleanup_default = (options) => new Promise((resolve, reject) => {
|
|
26
|
-
cleanup(options, { resolve, reject });
|
|
17
|
+
process.exit();
|
|
27
18
|
});
|
|
28
|
-
export {
|
|
29
|
-
cleanup_default as default
|
|
30
|
-
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { WebSocketServer } from "ws";
|
|
3
|
+
import generateId from "../generateId.js";
|
|
4
|
+
var hmrServer_default = (() => {
|
|
5
|
+
const websocketServer = new WebSocketServer({
|
|
6
|
+
port: parseInt(process.env.PORT, 10) + 1,
|
|
7
|
+
path: "/_joystick/hmr"
|
|
8
|
+
});
|
|
9
|
+
process.on("message", (message) => {
|
|
10
|
+
if (typeof process.HMR_CONNECTIONS === "object") {
|
|
11
|
+
const parsedMessage = JSON.parse(message);
|
|
12
|
+
const connections = Object.values(process.HMR_CONNECTIONS);
|
|
13
|
+
for (let i = 0; i < connections?.length; i += 1) {
|
|
14
|
+
const connection = connections[i];
|
|
15
|
+
if (connection?.connection?.send) {
|
|
16
|
+
connection.connection.send(
|
|
17
|
+
JSON.stringify({
|
|
18
|
+
type: "FILE_CHANGE",
|
|
19
|
+
settings: {
|
|
20
|
+
global: parsedMessage?.settings?.global,
|
|
21
|
+
public: parsedMessage?.settings?.public
|
|
22
|
+
},
|
|
23
|
+
indexHTMLChanged: parsedMessage?.indexHTMLChanged
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
websocketServer.on("connection", function connection(websocketConnection) {
|
|
31
|
+
const connectionId = generateId();
|
|
32
|
+
process.HMR_CONNECTIONS = {
|
|
33
|
+
...process.HMR_CONNECTIONS || {},
|
|
34
|
+
[connectionId]: {
|
|
35
|
+
connection: websocketConnection,
|
|
36
|
+
watchlist: []
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
if (Object.keys(process.HMR_CONNECTIONS || {})?.length > 0) {
|
|
40
|
+
process.send({ type: "HAS_HMR_CONNECTIONS" });
|
|
41
|
+
}
|
|
42
|
+
websocketConnection.on("message", (message) => {
|
|
43
|
+
const parsedMessage = JSON.parse(message);
|
|
44
|
+
if (parsedMessage?.type === "HMR_UPDATE_COMPLETE") {
|
|
45
|
+
process.send({ type: "HMR_UPDATE_COMPLETED", sessions: parsedMessage?.sessions });
|
|
46
|
+
}
|
|
47
|
+
if (parsedMessage?.type === "HMR_WATCHLIST") {
|
|
48
|
+
process.HMR_CONNECTIONS[connectionId]?.watchlist?.push(
|
|
49
|
+
...parsedMessage?.tags || []
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
websocketConnection.on("close", () => {
|
|
54
|
+
if (process.HMR_CONNECTIONS[connectionId]) {
|
|
55
|
+
delete process.HMR_CONNECTIONS[connectionId];
|
|
56
|
+
if (Object.keys(process.HMR_CONNECTIONS || {})?.length === 0) {
|
|
57
|
+
process.send({ type: "HAS_NO_HMR_CONNECTIONS" });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return true;
|
|
63
|
+
})();
|
|
64
|
+
export {
|
|
65
|
+
hmrServer_default as default
|
|
66
|
+
};
|