@joystick.js/cli-canary 0.0.0-canary.1 → 0.0.0-canary.10
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/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 +5 -43
- package/dist/functions/start/onWarn.js +1 -1
- package/dist/functions/test/index.js +30 -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 +183 -0
- package/dist/lib/build/buildPlugins.js +183 -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 +30 -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 +378 -0
- package/dist/lib/dev/loadSettings.js +81 -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 +30 -0
- package/dist/lib/dev/startApp.js +30 -0
- package/dist/lib/dev/startDatabases.js +102 -0
- package/dist/lib/dev/startHMR.js +30 -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/regexes.js +3 -1
- package/package.json +1 -1
- 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 +63 -53
- package/src/functions/start/onWarn.js +1 -1
- package/src/functions/test/index.js +34 -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 +205 -0
- package/src/lib/build/buildPlugins.js +215 -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 +34 -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 +475 -0
- package/src/lib/dev/loadSettings.js +92 -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 +33 -0
- package/src/lib/dev/startApp.js +33 -0
- package/src/lib/dev/startDatabases.js +125 -0
- package/src/lib/dev/startHMR.js +33 -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/regexes.js +3 -1
- /package/dist/lib/{getCodeFrame.js → build/getCodeFrame.js} +0 -0
- /package/src/lib/{getCodeFrame.js → build/getCodeFrame.js} +0 -0
|
@@ -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,22 +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";
|
|
1
|
+
import dev from "../../lib/dev/index.js";
|
|
20
2
|
const majorVersion = parseInt(
|
|
21
3
|
process?.version?.split(".")[0]?.replace("v", ""),
|
|
22
4
|
10
|
|
@@ -505,30 +487,10 @@ const checkIfJoystickProject = () => {
|
|
|
505
487
|
return fs.existsSync(`${process.cwd()}/.joystick`);
|
|
506
488
|
};
|
|
507
489
|
var start_default = async (args = {}, options = {}) => {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
if (!isJoystickProject) {
|
|
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([]);
|
|
490
|
+
await dev({
|
|
491
|
+
environment: options?.environment,
|
|
492
|
+
process
|
|
493
|
+
});
|
|
532
494
|
};
|
|
533
495
|
export {
|
|
534
496
|
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
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const actionMethod = () => {
|
|
2
|
+
try {
|
|
3
|
+
} catch (exception) {
|
|
4
|
+
throw new Error(`[test.actionMethod] ${exception.message}`);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
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
|
+
export {
|
|
29
|
+
test_default as default
|
|
30
|
+
};
|
|
@@ -3,7 +3,7 @@ import child_process from "child_process";
|
|
|
3
3
|
var use_default = async (args = {}) => {
|
|
4
4
|
if (args?.version === "canary") {
|
|
5
5
|
await replaceInFiles({
|
|
6
|
-
files: ["
|
|
6
|
+
files: ["**/*.js"],
|
|
7
7
|
from: /(@joystick.js\/node)(?!-)/g,
|
|
8
8
|
to: "@joystick.js/node-canary",
|
|
9
9
|
optionsForFiles: {
|
|
@@ -14,7 +14,7 @@ var use_default = async (args = {}) => {
|
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
await replaceInFiles({
|
|
17
|
-
files: ["
|
|
17
|
+
files: ["**/*.js"],
|
|
18
18
|
from: /(@joystick.js\/ui)(?!-)/g,
|
|
19
19
|
to: "@joystick.js/ui-canary",
|
|
20
20
|
optionsForFiles: {
|
|
@@ -30,7 +30,7 @@ var use_default = async (args = {}) => {
|
|
|
30
30
|
}
|
|
31
31
|
if (args?.version === "production") {
|
|
32
32
|
await replaceInFiles({
|
|
33
|
-
files: ["
|
|
33
|
+
files: ["**/*.js"],
|
|
34
34
|
from: /(@joystick.js\/node-canary)/g,
|
|
35
35
|
to: "@joystick.js/node",
|
|
36
36
|
optionsForFiles: {
|
|
@@ -41,7 +41,7 @@ var use_default = async (args = {}) => {
|
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
43
|
await replaceInFiles({
|
|
44
|
-
files: ["
|
|
44
|
+
files: ["**/*.js"],
|
|
45
45
|
from: /(@joystick.js\/ui-canary)/g,
|
|
46
46
|
to: "@joystick.js/ui",
|
|
47
47
|
optionsForFiles: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import getPlatformSafePath from "../getPlatformSafePath.js";
|
|
2
|
+
var browserPaths_default = [
|
|
3
|
+
getPlatformSafePath("email/"),
|
|
4
|
+
getPlatformSafePath("lib/"),
|
|
5
|
+
getPlatformSafePath("lib/browser"),
|
|
6
|
+
getPlatformSafePath("ui/"),
|
|
7
|
+
"index.client.js"
|
|
8
|
+
];
|
|
9
|
+
export {
|
|
10
|
+
browserPaths_default as default
|
|
11
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import esbuild from "esbuild";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import onWarn from "./onWarn.js";
|
|
4
|
+
import getCodeFrame from "./getCodeFrame.js";
|
|
5
|
+
import buildConfigs from "./buildConfigs.js";
|
|
6
|
+
const handleBuildException = (exception = {}, file = "") => {
|
|
7
|
+
try {
|
|
8
|
+
console.warn(exception);
|
|
9
|
+
const error = exception?.errors && exception?.errors[0];
|
|
10
|
+
const snippet = fs.existsSync(file) ? getCodeFrame(file, {
|
|
11
|
+
line: error?.location?.line,
|
|
12
|
+
column: error?.location?.column
|
|
13
|
+
}) : null;
|
|
14
|
+
onWarn({
|
|
15
|
+
file,
|
|
16
|
+
stack: exception?.stack,
|
|
17
|
+
line: error?.location?.line,
|
|
18
|
+
column: error?.location?.column,
|
|
19
|
+
snippet,
|
|
20
|
+
lineWithError: error?.location?.lineText?.trim(),
|
|
21
|
+
message: error?.text
|
|
22
|
+
});
|
|
23
|
+
return snippet;
|
|
24
|
+
} catch (exception2) {
|
|
25
|
+
throw new Error(`[buildFile.handleBuildException] ${exception2.message}`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const getConfig = (platform = "", file = "", outputPath = "", environment = "development") => {
|
|
29
|
+
try {
|
|
30
|
+
return buildConfigs[platform] && buildConfigs[platform](file, outputPath, environment);
|
|
31
|
+
} catch (exception) {
|
|
32
|
+
throw new Error(`[buildFile.getConfig] ${exception.message}`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const validateOptions = (options) => {
|
|
36
|
+
try {
|
|
37
|
+
if (!options)
|
|
38
|
+
throw new Error("options object is required.");
|
|
39
|
+
if (!options.platform)
|
|
40
|
+
throw new Error("options.platform is required.");
|
|
41
|
+
if (!options.file)
|
|
42
|
+
throw new Error("options.file is required.");
|
|
43
|
+
if (!options.outputPath)
|
|
44
|
+
throw new Error("options.outputPath is required.");
|
|
45
|
+
if (!options.environment)
|
|
46
|
+
throw new Error("options.environment is required.");
|
|
47
|
+
} catch (exception) {
|
|
48
|
+
throw new Error(`[buildFile.validateOptions] ${exception.message}`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const buildFile = async (options, { resolve, reject }) => {
|
|
52
|
+
try {
|
|
53
|
+
validateOptions(options);
|
|
54
|
+
const config = getConfig(
|
|
55
|
+
options?.platform,
|
|
56
|
+
options?.file,
|
|
57
|
+
options?.outputPath,
|
|
58
|
+
options?.environment
|
|
59
|
+
);
|
|
60
|
+
if (config) {
|
|
61
|
+
esbuild.build(config).then(() => {
|
|
62
|
+
return resolve({ success: true });
|
|
63
|
+
}).catch((exception) => {
|
|
64
|
+
const snippet = handleBuildException(exception, options?.file);
|
|
65
|
+
return resolve({
|
|
66
|
+
success: false,
|
|
67
|
+
path: options?.file,
|
|
68
|
+
error: {
|
|
69
|
+
stack: exception?.stack,
|
|
70
|
+
snippet
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
} catch (exception) {
|
|
76
|
+
reject(`[buildFile] ${exception.message}`);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var buildFile_default = (options) => new Promise((resolve, reject) => {
|
|
80
|
+
buildFile(options, { resolve, reject });
|
|
81
|
+
});
|
|
82
|
+
export {
|
|
83
|
+
buildFile_default as default
|
|
84
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import esbuild from "esbuild";
|
|
3
|
+
import svg from "esbuild-plugin-svg";
|
|
4
|
+
import filesToCopy from "../filesToCopy.js";
|
|
5
|
+
import minifyFile from "../build/minifyFile.js";
|
|
6
|
+
import browserPaths from "./browserPaths.js";
|
|
7
|
+
import browserPathExclusions from "./browserPathExclusions.js";
|
|
8
|
+
import nodePaths from "./nodePaths.js";
|
|
9
|
+
import nodePathExclusions from "./nodePathExclusions.js";
|
|
10
|
+
import buildPlugins from "./buildPlugins.js";
|
|
11
|
+
const handleBuildForNode = (nodePaths2 = [], options = {}) => {
|
|
12
|
+
try {
|
|
13
|
+
return esbuild.build({
|
|
14
|
+
platform: "node",
|
|
15
|
+
format: "esm",
|
|
16
|
+
bundle: false,
|
|
17
|
+
entryPoints: nodePaths2?.map((file) => file.path),
|
|
18
|
+
// TODO: Make sure we don't need outbase here so the paths map correctly.
|
|
19
|
+
outdir: options?.outputPath || "./.joystick/build",
|
|
20
|
+
define: {
|
|
21
|
+
"process.env.NODE_ENV": `'${options?.environment}'`
|
|
22
|
+
},
|
|
23
|
+
logLevel: "silent",
|
|
24
|
+
plugins: [
|
|
25
|
+
buildPlugins.warnNodeEnvironment,
|
|
26
|
+
buildPlugins.generateFileDependencyMap
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
} catch (exception) {
|
|
30
|
+
throw new Error(`[buildFiles.handleBuildForNode] ${exception.message}`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const handleBuildForBrowser = (browserPaths2 = [], options = {}) => {
|
|
34
|
+
try {
|
|
35
|
+
return esbuild.build({
|
|
36
|
+
target: "es2020",
|
|
37
|
+
platform: "browser",
|
|
38
|
+
format: "esm",
|
|
39
|
+
bundle: true,
|
|
40
|
+
entryPoints: browserPaths2?.map((file) => file.path),
|
|
41
|
+
// TODO: Make sure we don't need outbase here so the paths map correctly.
|
|
42
|
+
outdir: options?.outputPath || "./.joystick/build",
|
|
43
|
+
define: {
|
|
44
|
+
"process.env.NODE_ENV": `'${options?.environment}'`
|
|
45
|
+
},
|
|
46
|
+
logLevel: "silent",
|
|
47
|
+
plugins: [
|
|
48
|
+
buildPlugins.warnNodeEnvironment,
|
|
49
|
+
buildPlugins.generateFileDependencyMap,
|
|
50
|
+
buildPlugins.bootstrapComponent,
|
|
51
|
+
svg()
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
} catch (exception) {
|
|
55
|
+
throw new Error(`[buildFiles.handleBuildForBrowser] ${exception.message}`);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const handleCopyFiles = (files = [], outputPath = "") => {
|
|
59
|
+
try {
|
|
60
|
+
for (let i = 0; i < files?.length; i += 1) {
|
|
61
|
+
const file = files[i];
|
|
62
|
+
const fileContents = fs.readFileSync(file.path);
|
|
63
|
+
fs.writeFileSync(
|
|
64
|
+
`${outputPath || "./.joystick/build"}/${file.path}`,
|
|
65
|
+
fileContents
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
} catch (exception) {
|
|
69
|
+
throw new Error(`[buildFiles.handleCopyFiles] ${exception.message}`);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const isNodePath = (path = "") => {
|
|
73
|
+
try {
|
|
74
|
+
return nodePaths.some((nodePath) => {
|
|
75
|
+
return path.includes(nodePath);
|
|
76
|
+
}) && !nodePathExclusions.some((nodeExclusionPath) => {
|
|
77
|
+
return path.includes(nodeExclusionPath);
|
|
78
|
+
});
|
|
79
|
+
} catch (exception) {
|
|
80
|
+
throw new Error(`[buildFiles.isNodePath] ${exception.message}`);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const isBrowserPath = (path = "") => {
|
|
84
|
+
try {
|
|
85
|
+
return browserPaths.some((browserPath) => {
|
|
86
|
+
return path.includes(browserPath);
|
|
87
|
+
}) && !browserPathExclusions.some((browserExclusionPath) => {
|
|
88
|
+
return path.includes(browserExclusionPath);
|
|
89
|
+
});
|
|
90
|
+
} catch (exception) {
|
|
91
|
+
throw new Error(`[buildFiles.isBrowserPath] ${exception.message}`);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const isNotJavaScript = (path = "") => {
|
|
95
|
+
try {
|
|
96
|
+
const extension = path.split(".").pop();
|
|
97
|
+
return extension && !extension.match(/js$/);
|
|
98
|
+
} catch (exception) {
|
|
99
|
+
throw new Error(`[buildFiles.isNotJavaScript] ${exception.message}`);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const isCopyPath = (path = "") => {
|
|
103
|
+
try {
|
|
104
|
+
const hasCopyRegexMatch = filesToCopy.some((fileToCopy) => {
|
|
105
|
+
return fileToCopy.regex.test(path);
|
|
106
|
+
});
|
|
107
|
+
return isNotJavaScript(path) || hasCopyRegexMatch;
|
|
108
|
+
} catch (exception) {
|
|
109
|
+
throw new Error(`[buildFiles.isCopyPath] ${exception.message}`);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const getFilePlatform = (path = "") => {
|
|
113
|
+
try {
|
|
114
|
+
let platform = "";
|
|
115
|
+
const isCopy = isCopyPath(path);
|
|
116
|
+
const isBrowser = isBrowserPath(path);
|
|
117
|
+
const isNode = isNodePath(path);
|
|
118
|
+
if (isCopy) {
|
|
119
|
+
platform = "copy";
|
|
120
|
+
}
|
|
121
|
+
if (isBrowser) {
|
|
122
|
+
platform = "browser";
|
|
123
|
+
}
|
|
124
|
+
if (isNode) {
|
|
125
|
+
platform = "node";
|
|
126
|
+
}
|
|
127
|
+
return platform;
|
|
128
|
+
} catch (exception) {
|
|
129
|
+
throw new Error(`[buildFiles.getFilePlatform] ${exception.message}`);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const getFilesWithPlatform = (files = []) => {
|
|
133
|
+
try {
|
|
134
|
+
return files?.map((file = "") => {
|
|
135
|
+
return {
|
|
136
|
+
path: file,
|
|
137
|
+
platform: getFilePlatform(file)
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
} catch (exception) {
|
|
141
|
+
throw new Error(`[buildFiles.getFilesWithPlatform] ${exception.message}`);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const validateOptions = (options) => {
|
|
145
|
+
try {
|
|
146
|
+
if (!options)
|
|
147
|
+
throw new Error("options object is required.");
|
|
148
|
+
if (!options.files)
|
|
149
|
+
throw new Error("options.files is required.");
|
|
150
|
+
if (!options.environment)
|
|
151
|
+
throw new Error("options.environment is required.");
|
|
152
|
+
} catch (exception) {
|
|
153
|
+
throw new Error(`[buildFiles.validateOptions] ${exception.message}`);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const buildFiles = async (options, { resolve, reject }) => {
|
|
157
|
+
try {
|
|
158
|
+
validateOptions(options);
|
|
159
|
+
const filesWithPlatform = getFilesWithPlatform(options?.files);
|
|
160
|
+
const copyFiles = filesWithPlatform?.filter((file) => file?.platform === "copy");
|
|
161
|
+
const browserFiles = filesWithPlatform?.filter((file) => file?.platform === "browser");
|
|
162
|
+
const nodeFiles = filesWithPlatform?.filter((file) => file?.platform === "node");
|
|
163
|
+
handleCopyFiles(copyFiles, options?.outputPath);
|
|
164
|
+
await Promise.all([
|
|
165
|
+
handleBuildForBrowser(browserFiles, options),
|
|
166
|
+
handleBuildForNode(nodeFiles, options)
|
|
167
|
+
]);
|
|
168
|
+
if (options?.environment !== "development") {
|
|
169
|
+
await Promise.all([browserFiles, nodeFiles].map((file) => {
|
|
170
|
+
return minifyFile(`${options?.outputPath || "./.joystick/build"}/${file.path}`);
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
resolve();
|
|
174
|
+
} catch (exception) {
|
|
175
|
+
reject(`[buildFiles] ${exception.message}`);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var buildFiles_default = (options) => new Promise((resolve, reject) => {
|
|
179
|
+
buildFiles(options, { resolve, reject });
|
|
180
|
+
});
|
|
181
|
+
export {
|
|
182
|
+
buildFiles_default as default
|
|
183
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import updateFileMap from "./updateFileMap.js";
|
|
4
|
+
import {
|
|
5
|
+
JOYSTICK_UI_REGEX,
|
|
6
|
+
EXPORT_DEFAULT_REGEX,
|
|
7
|
+
JOYSTICK_COMPONENT_REGEX,
|
|
8
|
+
JOYSTICK_COMMENT_REGEX
|
|
9
|
+
} from "../regexes.js";
|
|
10
|
+
import generateId from "../generateId.js";
|
|
11
|
+
import getPlatformSafePath from "../getPlatformSafePath.js";
|
|
12
|
+
import setComponentId from "./setComponentId.js";
|
|
13
|
+
var buildPlugins_default = {
|
|
14
|
+
bootstrapComponent: {
|
|
15
|
+
name: "bootstrapComponent",
|
|
16
|
+
setup(build) {
|
|
17
|
+
const ssrId = generateId();
|
|
18
|
+
build.onLoad({ filter: /\.js$/ }, (args = {}) => {
|
|
19
|
+
try {
|
|
20
|
+
const shouldSetSSRId = [getPlatformSafePath("ui/")].some(
|
|
21
|
+
(bootstrapTarget) => {
|
|
22
|
+
return args.path.includes(bootstrapTarget);
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
const isLayoutComponent = [getPlatformSafePath("ui/layouts")].some(
|
|
26
|
+
(bootstrapTarget) => {
|
|
27
|
+
return args.path.includes(bootstrapTarget);
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
const isPageComponent = [getPlatformSafePath("ui/pages")].some(
|
|
31
|
+
(bootstrapTarget) => {
|
|
32
|
+
return args.path.includes(bootstrapTarget);
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
const isEmailComponent = [getPlatformSafePath("email/")].some(
|
|
36
|
+
(bootstrapTarget) => {
|
|
37
|
+
return args.path.includes(bootstrapTarget);
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
if (shouldSetSSRId || isLayoutComponent || isPageComponent || isEmailComponent) {
|
|
41
|
+
const code = fs.readFileSync(
|
|
42
|
+
getPlatformSafePath(args.path),
|
|
43
|
+
"utf-8"
|
|
44
|
+
);
|
|
45
|
+
const joystickUIMatches = code.match(JOYSTICK_UI_REGEX) || [];
|
|
46
|
+
const joystickUIMatch = joystickUIMatches && joystickUIMatches[0];
|
|
47
|
+
const exportDefaultMatches = code.match(EXPORT_DEFAULT_REGEX) || [];
|
|
48
|
+
const exportDefaultMatch = exportDefaultMatches && exportDefaultMatches[0];
|
|
49
|
+
if (joystickUIMatch && !exportDefaultMatch) {
|
|
50
|
+
console.log(" ");
|
|
51
|
+
console.warn(
|
|
52
|
+
chalk.yellowBright(
|
|
53
|
+
`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}.`
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
console.log(" ");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
let contents = setComponentId(code)?.replace(
|
|
60
|
+
/\.component\(\/\*\*\//g,
|
|
61
|
+
".component("
|
|
62
|
+
);
|
|
63
|
+
contents = contents.replace(JOYSTICK_COMMENT_REGEX, "");
|
|
64
|
+
const exportDefaultMatchParts = exportDefaultMatch && exportDefaultMatch.split(" ") || [];
|
|
65
|
+
const componentName = exportDefaultMatchParts.pop();
|
|
66
|
+
if (componentName && isLayoutComponent) {
|
|
67
|
+
contents = contents.replace(
|
|
68
|
+
`${exportDefaultMatch};`,
|
|
69
|
+
`if (
|
|
70
|
+
typeof window !== 'undefined' &&
|
|
71
|
+
window.__joystick_ssr__ === true &&
|
|
72
|
+
window.__joystick_layout_page__ &&
|
|
73
|
+
ui &&
|
|
74
|
+
ui.mount
|
|
75
|
+
) {
|
|
76
|
+
(async () => {
|
|
77
|
+
const layoutComponentFile = await import(window.__joystick_layout__);
|
|
78
|
+
const pageComponentFile = await import(window.window.__joystick_layout_page_url__);
|
|
79
|
+
const layout = layoutComponentFile.default;
|
|
80
|
+
const page = pageComponentFile.default;
|
|
81
|
+
ui.mount(layout, Object.assign({ ...window.__joystick_ssr_props__ }, { page }), document.getElementById('app'));
|
|
82
|
+
})();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default ${componentName};
|
|
86
|
+
`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
if (componentName && isPageComponent) {
|
|
90
|
+
contents = contents.replace(
|
|
91
|
+
`${exportDefaultMatch};`,
|
|
92
|
+
`if (
|
|
93
|
+
typeof window !== 'undefined' &&
|
|
94
|
+
window.__joystick_ssr__ === true &&
|
|
95
|
+
!window.__joystick_layout_page__ &&
|
|
96
|
+
ui &&
|
|
97
|
+
ui.mount
|
|
98
|
+
) {
|
|
99
|
+
ui.mount(${componentName}, window.__joystick_ssr_props__ || {}, document.getElementById('app'));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export default ${componentName};
|
|
103
|
+
`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
contents,
|
|
108
|
+
loader: "js"
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
} catch (exception) {
|
|
112
|
+
console.warn(exception);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
build.onEnd(() => {
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
const shouldSetComponentId = [
|
|
118
|
+
getPlatformSafePath("ui/"),
|
|
119
|
+
getPlatformSafePath("email/")
|
|
120
|
+
].some((bootstrapTarget) => {
|
|
121
|
+
return build.initialOptions.outfile.includes(bootstrapTarget);
|
|
122
|
+
});
|
|
123
|
+
if (shouldSetComponentId) {
|
|
124
|
+
const file = fs.readFileSync(build.initialOptions.outfile, "utf-8");
|
|
125
|
+
const joystickUIMatches = file?.match(JOYSTICK_COMPONENT_REGEX) || [];
|
|
126
|
+
if (joystickUIMatches?.length > 0) {
|
|
127
|
+
let contents = setComponentId(file)?.replace(
|
|
128
|
+
/\.component\(\/\*\*\//g,
|
|
129
|
+
".component("
|
|
130
|
+
);
|
|
131
|
+
fs.writeFileSync(build.initialOptions.outfile, contents);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
resolve();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
generateFileDependencyMap: {
|
|
140
|
+
name: "generateFileDependencyMap",
|
|
141
|
+
setup(build) {
|
|
142
|
+
build.onLoad({ filter: /\.js$/ }, (args) => {
|
|
143
|
+
try {
|
|
144
|
+
const canAddToMap = ![
|
|
145
|
+
"node_modules",
|
|
146
|
+
".joystick",
|
|
147
|
+
"?",
|
|
148
|
+
"commonjsHelpers.js"
|
|
149
|
+
].some((excludedPath) => {
|
|
150
|
+
return getPlatformSafePath(args.path).includes(excludedPath);
|
|
151
|
+
});
|
|
152
|
+
if (canAddToMap) {
|
|
153
|
+
const code = fs.readFileSync(
|
|
154
|
+
getPlatformSafePath(args.path),
|
|
155
|
+
"utf-8"
|
|
156
|
+
);
|
|
157
|
+
updateFileMap(getPlatformSafePath(args.path), code);
|
|
158
|
+
}
|
|
159
|
+
} catch (exception) {
|
|
160
|
+
console.warn(exception);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
warnNodeEnvironment: {
|
|
166
|
+
name: "warnNodeEnvironment",
|
|
167
|
+
setup(build) {
|
|
168
|
+
build.onLoad({ filter: /\.js$/ }, (args = {}) => {
|
|
169
|
+
const code = fs.readFileSync(args.path, "utf-8");
|
|
170
|
+
if (code?.match(/process.env.NODE_ENV\s+=\s/gi)?.length) {
|
|
171
|
+
console.warn(
|
|
172
|
+
chalk.yellowBright(
|
|
173
|
+
"\n[WARNING] process.env.NODE_ENV should only be set via a CLI flag in development or via external environment variables in production.\n"
|
|
174
|
+
)
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
export {
|
|
182
|
+
buildPlugins_default as default
|
|
183
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import esbuild from "esbuild";
|
|
3
|
+
var minifyFile_default = async (path = "") => {
|
|
4
|
+
if (fs.existsSync(path)) {
|
|
5
|
+
const file = fs.readFileSync(path, "utf-8");
|
|
6
|
+
const minified = await esbuild.transform(file, { minify: true });
|
|
7
|
+
fs.writeFileSync(path, minified.code);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
minifyFile_default as default
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import getPlatformSafePath from "../getPlatformSafePath.js";
|
|
2
|
+
var nodePaths_default = [
|
|
3
|
+
getPlatformSafePath("api/"),
|
|
4
|
+
getPlatformSafePath("routes/"),
|
|
5
|
+
getPlatformSafePath("fixtures/"),
|
|
6
|
+
getPlatformSafePath("lib/node"),
|
|
7
|
+
"index.server.js"
|
|
8
|
+
];
|
|
9
|
+
export {
|
|
10
|
+
nodePaths_default as default
|
|
11
|
+
};
|