@joystick.js/cli-canary 0.0.0-canary.1
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/.build/getFilesToBuild.js +38 -0
- package/.build/index.js +69 -0
- package/HMRNOTES.txt +23 -0
- package/README.md +7 -0
- package/_package.json +55 -0
- package/canary.js +12 -0
- package/dist/cli.js +69 -0
- package/dist/functions/build/getTarIgnoreList.js +25 -0
- package/dist/functions/build/index.js +54 -0
- package/dist/functions/create/buildPackageJSON.js +20 -0
- package/dist/functions/create/index.js +193 -0
- package/dist/functions/create/templates/api/index.js +4 -0
- package/dist/functions/create/templates/i18n/en-US.js +4 -0
- package/dist/functions/create/templates/index.client.js +7 -0
- package/dist/functions/create/templates/index.css +20 -0
- package/dist/functions/create/templates/index.html +23 -0
- package/dist/functions/create/templates/index.server.js +21 -0
- package/dist/functions/create/templates/public/apple-touch-icon-152x152.png +0 -0
- package/dist/functions/create/templates/public/favicon.ico +0 -0
- package/dist/functions/create/templates/public/manifest.json +25 -0
- package/dist/functions/create/templates/public/service-worker.js +32 -0
- package/dist/functions/create/templates/public/splash-screen-1024x1024.png +0 -0
- package/dist/functions/create/templates/settings.development.json +27 -0
- package/dist/functions/create/templates/ui/components/button/index.js +50 -0
- package/dist/functions/create/templates/ui/layouts/app/index.js +13 -0
- package/dist/functions/create/templates/ui/pages/error/index.js +31 -0
- package/dist/functions/create/templates/ui/pages/index/index.js +94 -0
- package/dist/functions/index.js +243 -0
- package/dist/functions/logout/index.js +20 -0
- package/dist/functions/push/checkIfProvisionAvailable.js +19 -0
- package/dist/functions/push/deploy/index.js +173 -0
- package/dist/functions/push/deploy/initial.js +100 -0
- package/dist/functions/push/deploy/version.js +100 -0
- package/dist/functions/push/domains.js +23 -0
- package/dist/functions/push/getAvailableCDN.js +23 -0
- package/dist/functions/push/getDeployment.js +41 -0
- package/dist/functions/push/getDeploymentSummary.js +38 -0
- package/dist/functions/push/getInstanceSizeRegions.js +37 -0
- package/dist/functions/push/getInstanceSizesForRegion.js +34 -0
- package/dist/functions/push/getProviderInstanceSizes.js +34 -0
- package/dist/functions/push/getProviderRegions.js +36 -0
- package/dist/functions/push/getProvidersWithConnectionStatus.js +20 -0
- package/dist/functions/push/getSessionToken.js +23 -0
- package/dist/functions/push/getUserFromSessionToken.js +37 -0
- package/dist/functions/push/index.js +210 -0
- package/dist/functions/push/loginToCheatCode.js +33 -0
- package/dist/functions/push/pingProvisionAPI.js +31 -0
- package/dist/functions/push/prompts.js +332 -0
- package/dist/functions/push/providerMap.js +11 -0
- package/dist/functions/push/providers.js +9 -0
- package/dist/functions/reset/index.js +0 -0
- package/dist/functions/reset/reset.js +127 -0
- package/dist/functions/start/bootstrapLayoutComponent.js +54 -0
- package/dist/functions/start/bootstrapPageComponent.js +51 -0
- package/dist/functions/start/buildFile.js +85 -0
- package/dist/functions/start/buildFiles.js +76 -0
- package/dist/functions/start/buildPlugins.js +183 -0
- package/dist/functions/start/checkIfPortAvailable.js +18 -0
- package/dist/functions/start/cleanup/index.js +18 -0
- package/dist/functions/start/databases/mongodb/availableQueryParameters.js +42 -0
- package/dist/functions/start/databases/mongodb/buildConnectionString.js +22 -0
- package/dist/functions/start/databases/mongodb/buildQueryParameters.js +14 -0
- package/dist/functions/start/databases/mongodb/checkConnection.js +38 -0
- package/dist/functions/start/databases/mongodb/connect.js +25 -0
- package/dist/functions/start/databases/mongodb/index.js +93 -0
- package/dist/functions/start/databases/postgresql/checkConnection.js +41 -0
- package/dist/functions/start/databases/postgresql/connect.js +27 -0
- package/dist/functions/start/databases/postgresql/index.js +106 -0
- package/dist/functions/start/databases/redis.js +0 -0
- package/dist/functions/start/databases/startProvider.js +16 -0
- package/dist/functions/start/fileDependencyMapper.js +22 -0
- package/dist/functions/start/filesToCopy.js +18 -0
- package/dist/functions/start/generateId.js +74 -0
- package/dist/functions/start/getCodependenciesForFile.js +64 -0
- package/dist/functions/start/getFilesToBuild.js +39 -0
- package/dist/functions/start/getProcessIdFromPort.js +60 -0
- package/dist/functions/start/hmrServer.js +66 -0
- package/dist/functions/start/index.js +535 -0
- package/dist/functions/start/isWindows.js +5 -0
- package/dist/functions/start/minifyFile.js +12 -0
- package/dist/functions/start/onWarn.js +63 -0
- package/dist/functions/start/readFileDependencyMap.js +16 -0
- package/dist/functions/start/removeDeletedDependenciesFromMap.js +18 -0
- package/dist/functions/start/setComponentId.js +46 -0
- package/dist/functions/start/updateFileMap.js +67 -0
- package/dist/functions/update/index.js +21 -0
- package/dist/functions/use/index.js +61 -0
- package/dist/index.js +8 -0
- package/dist/lib/CLILog.js +49 -0
- package/dist/lib/buildResolvePlugin.js +21 -0
- package/dist/lib/checkIfValidJSON.js +11 -0
- package/dist/lib/colorLog.js +7 -0
- package/dist/lib/getArgs.js +14 -0
- package/dist/lib/getCodeFrame.js +10 -0
- package/dist/lib/getOptions.js +15 -0
- package/dist/lib/getPlatformSafePath.js +7 -0
- package/dist/lib/getProvider.js +8 -0
- package/dist/lib/help.js +56 -0
- package/dist/lib/isObject.js +6 -0
- package/dist/lib/isValidJSONString.js +11 -0
- package/dist/lib/isWindows.js +5 -0
- package/dist/lib/killProcesses.js +0 -0
- package/dist/lib/loadSettings.js +33 -0
- package/dist/lib/loader.js +82 -0
- package/dist/lib/masterIgnoreList.js +16 -0
- package/dist/lib/nodeEnvironment.js +9 -0
- package/dist/lib/nodeEnvironments.js +8 -0
- package/dist/lib/parseCookiesFromLogin.js +18 -0
- package/dist/lib/rainbowRoad.js +7 -0
- package/dist/lib/readDirectorySync.js +14 -0
- package/dist/lib/regexes.js +12 -0
- package/dist/lib/replaceBackslashesWithForwardSlashes.js +8 -0
- package/dist/lib/replaceFileProtocol.js +8 -0
- package/dist/lib/serializeQueryParameters.js +8 -0
- package/dist/lib/settings.js +4 -0
- package/dist/lib/validateDatabasesFromSettings.js +34 -0
- package/dist/lib/wait.js +8 -0
- package/package.json +54 -0
- package/release.js +40 -0
- package/src/cli.js +88 -0
- package/src/functions/build/getTarIgnoreList.js +30 -0
- package/src/functions/build/index.js +63 -0
- package/src/functions/create/buildPackageJSON.js +18 -0
- package/src/functions/create/index.js +209 -0
- package/src/functions/create/templates/api/index.js +4 -0
- package/src/functions/create/templates/i18n/en-US.js +4 -0
- package/src/functions/create/templates/index.client.js +7 -0
- package/src/functions/create/templates/index.css +20 -0
- package/src/functions/create/templates/index.html +23 -0
- package/src/functions/create/templates/index.server.js +21 -0
- package/src/functions/create/templates/public/apple-touch-icon-152x152.png +0 -0
- package/src/functions/create/templates/public/favicon.ico +0 -0
- package/src/functions/create/templates/public/manifest.json +25 -0
- package/src/functions/create/templates/public/service-worker.js +32 -0
- package/src/functions/create/templates/public/splash-screen-1024x1024.png +0 -0
- package/src/functions/create/templates/settings.development.json +27 -0
- package/src/functions/create/templates/ui/components/button/index.js +50 -0
- package/src/functions/create/templates/ui/layouts/app/index.js +13 -0
- package/src/functions/create/templates/ui/pages/error/index.js +31 -0
- package/src/functions/create/templates/ui/pages/index/index.js +94 -0
- package/src/functions/index.js +243 -0
- package/src/functions/logout/index.js +20 -0
- package/src/functions/push/checkIfProvisionAvailable.js +20 -0
- package/src/functions/push/deploy/index.js +199 -0
- package/src/functions/push/deploy/initial.js +108 -0
- package/src/functions/push/deploy/version.js +108 -0
- package/src/functions/push/domains.js +23 -0
- package/src/functions/push/getAvailableCDN.js +27 -0
- package/src/functions/push/getDeployment.js +43 -0
- package/src/functions/push/getDeploymentSummary.js +39 -0
- package/src/functions/push/getInstanceSizeRegions.js +40 -0
- package/src/functions/push/getInstanceSizesForRegion.js +35 -0
- package/src/functions/push/getProviderInstanceSizes.js +35 -0
- package/src/functions/push/getProviderRegions.js +39 -0
- package/src/functions/push/getProvidersWithConnectionStatus.js +25 -0
- package/src/functions/push/getSessionToken.js +26 -0
- package/src/functions/push/getUserFromSessionToken.js +39 -0
- package/src/functions/push/index.js +245 -0
- package/src/functions/push/loginToCheatCode.js +34 -0
- package/src/functions/push/pingProvisionAPI.js +33 -0
- package/src/functions/push/prompts.js +276 -0
- package/src/functions/push/providerMap.js +8 -0
- package/src/functions/push/providers.js +6 -0
- package/src/functions/reset/index.js +0 -0
- package/src/functions/reset/reset.js +163 -0
- package/src/functions/start/bootstrapLayoutComponent.js +57 -0
- package/src/functions/start/bootstrapPageComponent.js +54 -0
- package/src/functions/start/buildFile.js +97 -0
- package/src/functions/start/buildFiles.js +101 -0
- package/src/functions/start/buildPlugins.js +215 -0
- package/src/functions/start/checkIfPortAvailable.js +21 -0
- package/src/functions/start/cleanup/index.js +23 -0
- package/src/functions/start/databases/mongodb/availableQueryParameters.js +39 -0
- package/src/functions/start/databases/mongodb/buildConnectionString.js +28 -0
- package/src/functions/start/databases/mongodb/buildQueryParameters.js +15 -0
- package/src/functions/start/databases/mongodb/checkConnection.js +40 -0
- package/src/functions/start/databases/mongodb/connect.js +25 -0
- package/src/functions/start/databases/mongodb/index.js +108 -0
- package/src/functions/start/databases/postgresql/checkConnection.js +43 -0
- package/src/functions/start/databases/postgresql/connect.js +27 -0
- package/src/functions/start/databases/postgresql/index.js +127 -0
- package/src/functions/start/databases/redis.js +0 -0
- package/src/functions/start/databases/startProvider.js +15 -0
- package/src/functions/start/fileDependencyMapper.js +24 -0
- package/src/functions/start/filesToCopy.js +15 -0
- package/src/functions/start/generateId.js +73 -0
- package/src/functions/start/getCodependenciesForFile.js +84 -0
- package/src/functions/start/getFilesToBuild.js +49 -0
- package/src/functions/start/getProcessIdFromPort.js +92 -0
- package/src/functions/start/hmrServer.js +78 -0
- package/src/functions/start/index.js +688 -0
- package/src/functions/start/isWindows.js +3 -0
- package/src/functions/start/minifyFile.js +10 -0
- package/src/functions/start/onWarn.js +68 -0
- package/src/functions/start/readFileDependencyMap.js +19 -0
- package/src/functions/start/removeDeletedDependenciesFromMap.js +19 -0
- package/src/functions/start/setComponentId.js +58 -0
- package/src/functions/start/updateFileMap.js +100 -0
- package/src/functions/update/index.js +20 -0
- package/src/functions/use/index.js +62 -0
- package/src/index.js +13 -0
- package/src/lib/CLILog.js +40 -0
- package/src/lib/buildResolvePlugin.js +32 -0
- package/src/lib/checkIfValidJSON.js +8 -0
- package/src/lib/colorLog.js +5 -0
- package/src/lib/getArgs.js +14 -0
- package/src/lib/getCodeFrame.js +8 -0
- package/src/lib/getOptions.js +12 -0
- package/src/lib/getPlatformSafePath.js +6 -0
- package/src/lib/getProvider.js +5 -0
- package/src/lib/help.js +56 -0
- package/src/lib/isObject.js +3 -0
- package/src/lib/isValidJSONString.js +8 -0
- package/src/lib/isWindows.js +3 -0
- package/src/lib/killProcesses.js +5 -0
- package/src/lib/loadSettings.js +40 -0
- package/src/lib/loader.js +94 -0
- package/src/lib/masterIgnoreList.js +13 -0
- package/src/lib/nodeEnvironment.js +6 -0
- package/src/lib/nodeEnvironments.js +8 -0
- package/src/lib/parseCookiesFromLogin.js +21 -0
- package/src/lib/rainbowRoad.js +5 -0
- package/src/lib/readDirectorySync.js +13 -0
- package/src/lib/regexes.js +5 -0
- package/src/lib/replaceBackslashesWithForwardSlashes.js +8 -0
- package/src/lib/replaceFileProtocol.js +8 -0
- package/src/lib/serializeQueryParameters.js +5 -0
- package/src/lib/settings.js +1 -0
- package/src/lib/validateDatabasesFromSettings.js +37 -0
- package/src/lib/wait.js +5 -0
- package/storage/.verdaccio-db.json +1 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { OBJECT_REGEX } from "../../lib/regexes.js";
|
|
3
|
+
import rainbowRoad from '../../lib/rainbowRoad.js';
|
|
4
|
+
import getCodeFrame from "../../lib/getCodeFrame.js";
|
|
5
|
+
|
|
6
|
+
const removeLocationDataFromStackTrace = (stackTrace = "") => {
|
|
7
|
+
return stackTrace.replace(OBJECT_REGEX, "");
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const logError = (warning = {}) => {
|
|
11
|
+
const snippetParts = warning?.snippet?.split(`\n`);
|
|
12
|
+
|
|
13
|
+
console.log('\n');
|
|
14
|
+
console.log(`${rainbowRoad()}\n`);
|
|
15
|
+
|
|
16
|
+
if (warning.file) {
|
|
17
|
+
console.log(chalk.yellowBright(`Build Error in ${warning?.file}:\n`));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (snippetParts && snippetParts.length > 0) {
|
|
21
|
+
snippetParts.forEach((line) => {
|
|
22
|
+
if (line.includes(`> ${warning.line} |`)) {
|
|
23
|
+
return console.log(` ${chalk.red(line)}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return console.log(` ${chalk.gray(line)}`);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (warning?.stack) {
|
|
31
|
+
console.log(chalk.magentaBright("\nStack Trace:\n"));
|
|
32
|
+
console.log(chalk.yellow(` ${removeLocationDataFromStackTrace(warning?.stack)}\n`));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
process.loader.error(
|
|
36
|
+
"Build error. Fix the error above to continue building your app."
|
|
37
|
+
);
|
|
38
|
+
console.log('\n');
|
|
39
|
+
console.log(`${rainbowRoad()}\n`);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const parseWarning = (warning = {}, type = "") => {
|
|
43
|
+
if (type && type === "BUILD_ERROR") {
|
|
44
|
+
return {
|
|
45
|
+
file: warning?.file,
|
|
46
|
+
snippet: warning?.snippet || getCodeFrame(warning.file, {
|
|
47
|
+
line: warning?.line,
|
|
48
|
+
column: warning?.column,
|
|
49
|
+
}),
|
|
50
|
+
stack: warning?.stack,
|
|
51
|
+
line: warning?.line,
|
|
52
|
+
character: warning?.column,
|
|
53
|
+
message: warning?.message,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return null;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default (warning) => {
|
|
61
|
+
const parsedWarning = parseWarning(warning, "BUILD_ERROR");
|
|
62
|
+
|
|
63
|
+
if (parsedWarning) {
|
|
64
|
+
logError(parsedWarning);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return parsedWarning;
|
|
68
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
|
|
3
|
+
export default () => {
|
|
4
|
+
const fileDependencyMapPath = `.joystick/build/fileMap.json`;
|
|
5
|
+
|
|
6
|
+
if (fs.existsSync(fileDependencyMapPath)) {
|
|
7
|
+
const fileDependencyMapAsJSON = fs.readFileSync(
|
|
8
|
+
fileDependencyMapPath,
|
|
9
|
+
"utf-8"
|
|
10
|
+
);
|
|
11
|
+
const fileMap = fileDependencyMapAsJSON
|
|
12
|
+
? JSON.parse(fileDependencyMapAsJSON)
|
|
13
|
+
: {};
|
|
14
|
+
|
|
15
|
+
return fileMap;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {};
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import readFileDependencyMap from "./readFileDependencyMap.js";
|
|
3
|
+
|
|
4
|
+
export default (deletedDependencies = []) => {
|
|
5
|
+
const fileDependencyMap = readFileDependencyMap();
|
|
6
|
+
|
|
7
|
+
deletedDependencies.forEach((dependency) => {
|
|
8
|
+
const match = Object.keys(fileDependencyMap).find((key) => key.includes(dependency));
|
|
9
|
+
|
|
10
|
+
if (match) {
|
|
11
|
+
delete fileDependencyMap[match];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
fs.writeFileSync(
|
|
16
|
+
`.joystick/build/fileMap.json`,
|
|
17
|
+
JSON.stringify(fileDependencyMap, null, 2)
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import generateId from "./generateId.js";
|
|
3
|
+
|
|
4
|
+
export default (file = "") => {
|
|
5
|
+
const componentMapPath =
|
|
6
|
+
process.env.NODE_ENV === "development"
|
|
7
|
+
? `./.joystick/build/componentMap.json`
|
|
8
|
+
: `./.build/componentMap.json`;
|
|
9
|
+
const componentMapExists = fs.existsSync(componentMapPath);
|
|
10
|
+
const componentMap = componentMapExists
|
|
11
|
+
? JSON.parse(fs.readFileSync(componentMapPath, "utf-8"))
|
|
12
|
+
: {};
|
|
13
|
+
|
|
14
|
+
const parts = [...file?.matchAll(/\/\/ ui+.*/gi)]?.map((match) => {
|
|
15
|
+
return {
|
|
16
|
+
path: match[0],
|
|
17
|
+
index: match.index,
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const components = (parts || [])?.map((part, partIndex) => {
|
|
22
|
+
const nextPart = parts[partIndex + 1];
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
path: part.path.replace("// ", ""),
|
|
26
|
+
index: part.index,
|
|
27
|
+
source: file.substring(
|
|
28
|
+
part.index,
|
|
29
|
+
nextPart ? nextPart.index : file.length
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i < components.length; i += 1) {
|
|
35
|
+
const component = components[i];
|
|
36
|
+
const componentId =
|
|
37
|
+
(componentMap && componentMap[component.path]) || generateId();
|
|
38
|
+
|
|
39
|
+
if (componentMap) {
|
|
40
|
+
componentMap[component.path] = componentId;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const tainted = component.source.replace(
|
|
44
|
+
/\.component\(\{+(?!\n + _componentId)/g,
|
|
45
|
+
() => {
|
|
46
|
+
return `.component({\n _componentId: '${componentId}',`;
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
file = file.replace(component.source, tainted);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (componentMap) {
|
|
54
|
+
fs.writeFileSync(componentMapPath, JSON.stringify(componentMap));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return file;
|
|
58
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import * as acorn from "acorn";
|
|
3
|
+
|
|
4
|
+
const getImportsAndRequires = (map = {}) => {
|
|
5
|
+
const { body } = map;
|
|
6
|
+
|
|
7
|
+
const imports =
|
|
8
|
+
body &&
|
|
9
|
+
body.filter(({ type }) => {
|
|
10
|
+
return type === "ImportDeclaration";
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const requires =
|
|
14
|
+
body &&
|
|
15
|
+
body.filter((statement) => {
|
|
16
|
+
const type = statement && statement.type;
|
|
17
|
+
const declarations = (statement && statement.declarations) || [];
|
|
18
|
+
|
|
19
|
+
const isVariableDeclaration = type === "VariableDeclaration";
|
|
20
|
+
|
|
21
|
+
const hasRequireStatement = declarations.some((declaration) => {
|
|
22
|
+
const isVariableDeclarator = declaration.type === "VariableDeclarator";
|
|
23
|
+
const calleeName =
|
|
24
|
+
declaration &&
|
|
25
|
+
declaration.init &&
|
|
26
|
+
declaration.init.callee &&
|
|
27
|
+
declaration.init.callee.name;
|
|
28
|
+
return isVariableDeclarator && calleeName === "require";
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return isVariableDeclaration && hasRequireStatement;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
imports: imports.map((importDeclaration) => {
|
|
36
|
+
return {
|
|
37
|
+
path:
|
|
38
|
+
importDeclaration &&
|
|
39
|
+
importDeclaration.source &&
|
|
40
|
+
importDeclaration.source.value,
|
|
41
|
+
};
|
|
42
|
+
}),
|
|
43
|
+
requires: requires.map((requireDeclaration) => {
|
|
44
|
+
const declarations = requireDeclaration.declarations;
|
|
45
|
+
const declaration = declarations && declarations[0];
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
path:
|
|
49
|
+
declaration &&
|
|
50
|
+
declaration.init &&
|
|
51
|
+
declaration.init.arguments &&
|
|
52
|
+
declaration.init.arguments[0] &&
|
|
53
|
+
declaration.init.arguments[0].value,
|
|
54
|
+
};
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const parseFileToAST = (source = "") => {
|
|
60
|
+
return acorn.parse(source, {
|
|
61
|
+
ecmaVersion: "latest",
|
|
62
|
+
sourceType: "module",
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const readFileDependencyMap = () => {
|
|
67
|
+
const fileDependencyMapPath = `.joystick/build/fileMap.json`;
|
|
68
|
+
|
|
69
|
+
if (fs.existsSync(fileDependencyMapPath)) {
|
|
70
|
+
const fileDependencyMapAsJSON = fs.readFileSync(
|
|
71
|
+
fileDependencyMapPath,
|
|
72
|
+
"utf-8"
|
|
73
|
+
);
|
|
74
|
+
const fileMap = fileDependencyMapAsJSON
|
|
75
|
+
? JSON.parse(fileDependencyMapAsJSON)
|
|
76
|
+
: {};
|
|
77
|
+
|
|
78
|
+
return fileMap;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default (path = "", source = "") => {
|
|
85
|
+
try {
|
|
86
|
+
const fileDependencyMap = readFileDependencyMap();
|
|
87
|
+
const fileAST = parseFileToAST(source);
|
|
88
|
+
const imports = fileAST ? getImportsAndRequires(fileAST) : [];
|
|
89
|
+
|
|
90
|
+
fileDependencyMap[path] = imports;
|
|
91
|
+
|
|
92
|
+
fs.writeFileSync(
|
|
93
|
+
`.joystick/build/fileMap.json`,
|
|
94
|
+
JSON.stringify(fileDependencyMap, null, 2)
|
|
95
|
+
);
|
|
96
|
+
} catch (exception) {
|
|
97
|
+
// Do nothing. This exists to handle acorn parsing errors that are also picked
|
|
98
|
+
// up by the esbuild parser (we want to defer to esbuild).
|
|
99
|
+
}
|
|
100
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import child_process from "child_process";
|
|
3
|
+
import Loader from "../../lib/loader.js";
|
|
4
|
+
|
|
5
|
+
process.loader = new Loader({ defaultMessage: "Updating Joystick dependencies..." });
|
|
6
|
+
|
|
7
|
+
export default () => {
|
|
8
|
+
process.loader.text('Updating @joystick.js/node...');
|
|
9
|
+
child_process.exec('npm i @joystick.js/node@latest', () => {
|
|
10
|
+
process.loader.text('Updating @joystick.js/ui...');
|
|
11
|
+
child_process.exec('npm i @joystick.js/ui@latest', () => {
|
|
12
|
+
process.loader.text('Updating @joystick.js/cli...');
|
|
13
|
+
child_process.exec('npm i -g @joystick.js/cli@latest', () => {
|
|
14
|
+
process.loader.stop();
|
|
15
|
+
console.log(chalk.green('Joystick updated!'));
|
|
16
|
+
process.exit(0);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import replaceInFiles from 'replace-in-files';
|
|
2
|
+
import child_process from "child_process";
|
|
3
|
+
|
|
4
|
+
export default async (args = {}) => {
|
|
5
|
+
if (args?.version === 'canary') {
|
|
6
|
+
await replaceInFiles({
|
|
7
|
+
files: ['./index.server.js', './api/**/*.js', 'lib/node/**/*.js'],
|
|
8
|
+
from: /(@joystick.js\/node)(?!-)/g,
|
|
9
|
+
to: '@joystick.js/node-canary',
|
|
10
|
+
optionsForFiles: { // default
|
|
11
|
+
"ignore": [
|
|
12
|
+
"**/node_modules/**"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
await replaceInFiles({
|
|
18
|
+
files: ['./index.client.js', './ui/**/*.js', 'lib/**/*.js'],
|
|
19
|
+
from: /(@joystick.js\/ui)(?!-)/g,
|
|
20
|
+
to: '@joystick.js/ui-canary',
|
|
21
|
+
optionsForFiles: { // default
|
|
22
|
+
"ignore": [
|
|
23
|
+
"**/node_modules/**"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
console.log('\nSwapping production packages for canary versions...\n');
|
|
29
|
+
|
|
30
|
+
child_process.execSync('npm uninstall @joystick.js/node && npm i @joystick.js/node-canary');
|
|
31
|
+
child_process.execSync('npm uninstall @joystick.js/ui && npm i @joystick.js/ui-canary');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (args?.version === 'production') {
|
|
35
|
+
await replaceInFiles({
|
|
36
|
+
files: ['./index.server.js', './api/**/*.js', 'lib/node/**/*.js'],
|
|
37
|
+
from: /(@joystick.js\/node-canary)/g,
|
|
38
|
+
to: '@joystick.js/node',
|
|
39
|
+
optionsForFiles: { // default
|
|
40
|
+
"ignore": [
|
|
41
|
+
"**/node_modules/**"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await replaceInFiles({
|
|
47
|
+
files: ['./index.client.js', './ui/**/*.js', 'lib/**/*.js'],
|
|
48
|
+
from: /(@joystick.js\/ui-canary)/g,
|
|
49
|
+
to: '@joystick.js/ui',
|
|
50
|
+
optionsForFiles: { // default
|
|
51
|
+
"ignore": [
|
|
52
|
+
"**/node_modules/**"
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
console.log('\nSwapping canary packages for production versions...\n');
|
|
58
|
+
|
|
59
|
+
child_process.execSync('npm uninstall @joystick.js/node-canary && npm i @joystick.js/node');
|
|
60
|
+
child_process.execSync('npm uninstall @joystick.js/ui-canary && npm i @joystick.js/ui');
|
|
61
|
+
}
|
|
62
|
+
};
|
package/src/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { dirname } from 'path';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = dirname(__filename);
|
|
9
|
+
|
|
10
|
+
// NOTE: Capture args passed to command line to forward to spawned script.
|
|
11
|
+
const args = process.argv.slice(2, process.argv.length);
|
|
12
|
+
|
|
13
|
+
spawn('node', ['--no-warnings', `${__dirname}/cli.js`, ...args], { stdio: 'inherit' });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import rainbowRoad from './rainbowRoad.js';
|
|
3
|
+
|
|
4
|
+
export default (message = '', options = {}) => {
|
|
5
|
+
const colors = {
|
|
6
|
+
info: 'blue',
|
|
7
|
+
success: 'green',
|
|
8
|
+
warning: 'yellowBright',
|
|
9
|
+
danger: 'red',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const titles = {
|
|
13
|
+
info: '❱ Info',
|
|
14
|
+
success: '❱ Ok',
|
|
15
|
+
warning: '❱ Warning',
|
|
16
|
+
danger: '❱ Error',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const color = options.level ? colors[options.level] : 'gray';
|
|
20
|
+
const title = options.level ? titles[options.level] : 'Log';
|
|
21
|
+
const docs = options.docs || 'https://github.com/cheatcode/joystick';
|
|
22
|
+
|
|
23
|
+
console.log(`\n${(options.padding || '')}${rainbowRoad()}\n`);
|
|
24
|
+
console.log(`${(options.padding || '')}${chalk[color](`${title}:`)}\n`)
|
|
25
|
+
console.log(`${(options.padding || '')}${chalk.white(message)}\n`);
|
|
26
|
+
console.log(`${(options.padding || '')}${chalk.grey('---')}\n`);
|
|
27
|
+
console.log(`${(options.padding || '')}${chalk.white('Relevant Documentation:')}\n`)
|
|
28
|
+
console.log(`${(options.padding || '')}${chalk.blue(docs)}\n`);
|
|
29
|
+
console.log(`${(options.padding || '')}${chalk.white('Stuck? Ask a Question:')}\n`)
|
|
30
|
+
console.log(`${(options.padding || '')}${chalk.blue('https://github.com/cheatcode/joystick/discussions')}\n`);
|
|
31
|
+
|
|
32
|
+
if (options.tools && Array.isArray(options.tools)) {
|
|
33
|
+
console.log(`${(options.padding || '')}${chalk.white('Helpful Tools:')}\n`);
|
|
34
|
+
options.tools.forEach((tool) => {
|
|
35
|
+
console.log(`${(options.padding || '')}${chalk.blue(`${tool.title} — ${tool.url}`)}\n`);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log(`${(options.padding || '')}${rainbowRoad()}\n`);
|
|
40
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// TODO: None of these plugin-level methods give us the info we need. They *should*
|
|
2
|
+
// but it's not defined (which means at best it's inconsistent).
|
|
3
|
+
//
|
|
4
|
+
// TODO: Just run a full build of the parent path where the file is located, or,
|
|
5
|
+
// build the entire app again. That has an n(0) problem that we'll have to solve
|
|
6
|
+
// but I think we can figure it out in time (or invent a custom a solution).
|
|
7
|
+
|
|
8
|
+
export default function myExample() {
|
|
9
|
+
return {
|
|
10
|
+
name: "joystick-build-resolve", // this name will show up in warnings and errors
|
|
11
|
+
buildEnd() {
|
|
12
|
+
const moduleIds = Array.from(this.getModuleIds());
|
|
13
|
+
const modules = moduleIds
|
|
14
|
+
.map((moduleId) => this.getModuleInfo(moduleId))
|
|
15
|
+
.filter(({ id }) => {
|
|
16
|
+
const ignorePaths = ["node_modules", "dist"];
|
|
17
|
+
const noResolvePaths = ["/ui", "/api"];
|
|
18
|
+
|
|
19
|
+
if (
|
|
20
|
+
!ignorePaths.some((path) => id.includes(path)) &&
|
|
21
|
+
noResolvePaths.some((path) => id.includes(path))
|
|
22
|
+
) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return null;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default (args = {}) => {
|
|
2
|
+
return Object.entries(args).reduce((values, [argName, argData]) => {
|
|
3
|
+
// NOTE: When creating, names can have hyphens.
|
|
4
|
+
if (argData && argData.value && argData.parent && argData.parent === 'create') {
|
|
5
|
+
values[argName] = argData.value;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (argData && argData.value && (!argData.parent || argData.parent !== 'create')) {
|
|
9
|
+
values[argName] = !argData.value.includes('-') ? argData.value : null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return values;
|
|
13
|
+
}, {});
|
|
14
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default (options = {}) => {
|
|
2
|
+
return Object.entries(options).reduce((values, [optionName, optionData]) => {
|
|
3
|
+
if (optionData && optionData.flags) {
|
|
4
|
+
Object.entries(optionData.flags).forEach(([_flagName, flag]) => {
|
|
5
|
+
if (flag && flag.value) {
|
|
6
|
+
values[optionName] = flag.value && ![`${flag.value}`.substring(0, 1)].includes('-')? flag.value : null;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
return values;
|
|
11
|
+
}, {});
|
|
12
|
+
};
|
package/src/lib/help.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import functions from '../functions/index.js';
|
|
5
|
+
import rainbowRoad from './rainbowRoad.js';
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const packageJSON = require('../../package.json');
|
|
9
|
+
|
|
10
|
+
const createSpacer = (target = 5, start = '') => {
|
|
11
|
+
const numberOfSpaces = target - start.length;
|
|
12
|
+
const spaces = [...(numberOfSpaces > 0 ? Array(target - start.length) : '')].map(() => ' ');
|
|
13
|
+
return spaces.join('');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getArgsForFunction = (functionArgs = {}) => {
|
|
17
|
+
return Object.keys(functionArgs).map((functionArg) => `<${functionArg}>`).join(' ');
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const buildOptionsForFunction = (functionOptions = {}) => {
|
|
21
|
+
return Object.entries(functionOptions).map(([optionName, optionSettings]) => {
|
|
22
|
+
return `
|
|
23
|
+
${chalk.green(optionName)}${createSpacer(15, optionName)}${optionSettings.flags && Object.keys(optionSettings.flags).map((flag) => chalk.magenta(flag)).join(', ')}${createSpacer(15, optionName)}${optionSettings.description}
|
|
24
|
+
`;
|
|
25
|
+
}).join('\r');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default () => {
|
|
29
|
+
console.log(`
|
|
30
|
+
|
|
31
|
+
${rainbowRoad()}
|
|
32
|
+
|
|
33
|
+
${chalk.yellowBright('@joystick.js/cli')} ${chalk.magenta(`(v${packageJSON.version})`)}
|
|
34
|
+
|
|
35
|
+
${chalk.blue('Create, start, build, and update your Joystick app.')}
|
|
36
|
+
|
|
37
|
+
${chalk.gray('https://github.com/cheatcode/joystick')}
|
|
38
|
+
|
|
39
|
+
${rainbowRoad()}\n
|
|
40
|
+
|
|
41
|
+
${chalk.magenta('Functions:')}
|
|
42
|
+
|
|
43
|
+
${Object.entries(functions).map(([functionName, functionSettings]) => {
|
|
44
|
+
return `
|
|
45
|
+
${chalk.green(functionName)}${createSpacer(8, functionName)}${chalk.gray(functionSettings.description)}\n
|
|
46
|
+
${chalk.yellow('Usage:')}
|
|
47
|
+
|
|
48
|
+
joystick ${functionName} ${chalk.yellow(getArgsForFunction(functionSettings.args))}\n
|
|
49
|
+
${functionSettings.options && Object.keys(functionSettings.options).length > 0 ? `
|
|
50
|
+
${chalk.yellow('Options:')}
|
|
51
|
+
${buildOptionsForFunction(functionSettings.options)}
|
|
52
|
+
`: ''}
|
|
53
|
+
`;
|
|
54
|
+
}).join('')}
|
|
55
|
+
`);
|
|
56
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import CLILog from './CLILog.js';
|
|
3
|
+
import isValidJSONString from './isValidJSONString.js';
|
|
4
|
+
|
|
5
|
+
export default async (env = null) => {
|
|
6
|
+
const environment = env;
|
|
7
|
+
const settingsFilePath = `${process.cwd()}/settings.${environment}.json`;
|
|
8
|
+
const hasSettingsFile = fs.existsSync(settingsFilePath);
|
|
9
|
+
|
|
10
|
+
if (!hasSettingsFile) {
|
|
11
|
+
CLILog(`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.`, {
|
|
12
|
+
level: 'danger',
|
|
13
|
+
docs: 'https://github.com/cheatcode/joystick#settings',
|
|
14
|
+
});
|
|
15
|
+
process.exit(0);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const rawSettingsFile = fs.readFileSync(settingsFilePath, "utf-8");
|
|
19
|
+
const isValidJSON = isValidJSONString(rawSettingsFile);
|
|
20
|
+
|
|
21
|
+
if (!isValidJSON) {
|
|
22
|
+
CLILog(`Failed to parse settings file. Double-check the syntax in your settings.${environment}.json file at the root of your project and restart Joystick.`, {
|
|
23
|
+
level: 'danger',
|
|
24
|
+
docs: 'https://github.com/cheatcode/joystick#settings',
|
|
25
|
+
tools: [
|
|
26
|
+
{ title: 'JSON Linter', url: 'https://jsonlint.com/' }
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const settingsFile = isValidJSON
|
|
33
|
+
? rawSettingsFile
|
|
34
|
+
: "{}";
|
|
35
|
+
|
|
36
|
+
// NOTE: Child process will inherit this env var from this parent process.
|
|
37
|
+
process.env.JOYSTICK_SETTINGS = settingsFile;
|
|
38
|
+
|
|
39
|
+
return JSON.parse(settingsFile);
|
|
40
|
+
};
|