@lowdefy/server-dev 0.0.0-alpha.7 → 0.0.0-experimental-20231123101256
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/.eslintrc.yaml +1 -0
- package/.npmrc +1 -0
- package/LICENSE +201 -0
- package/README.md +5 -0
- package/lib/client/App.js +68 -0
- package/lib/client/Page.js +51 -0
- package/lib/client/Reload.js +55 -0
- package/lib/client/RestartingPage.js +47 -0
- package/lib/client/auth/Auth.js +35 -0
- package/lib/client/auth/AuthConfigured.js +61 -0
- package/lib/client/auth/AuthNotConfigured.js +33 -0
- package/lib/client/setPageId.js +30 -0
- package/lib/client/utils/request.js +38 -0
- package/lib/client/utils/useMutateCache.js +25 -0
- package/lib/client/utils/usePageConfig.js +27 -0
- package/lib/client/utils/useRootConfig.js +26 -0
- package/lib/client/utils/waitForRestartedServer.js +38 -0
- package/lib/server/apiWrapper.js +68 -0
- package/lib/server/auth/getAuthOptions.js +35 -0
- package/lib/server/auth/getServerSession.js +28 -0
- package/lib/server/fileCache.js +20 -0
- package/lib/server/log/createLogger.js +29 -0
- package/lib/server/log/logError.js +40 -0
- package/lib/server/log/logRequest.js +33 -0
- package/manager/getContext.mjs +77 -0
- package/manager/processes/initialBuild.mjs +27 -0
- package/manager/processes/installPlugins.mjs +31 -0
- package/manager/processes/lowdefyBuild.mjs +35 -0
- package/manager/processes/nextBuild.mjs +31 -0
- package/manager/processes/readDotEnv.mjs +26 -0
- package/manager/processes/reloadClients.mjs +26 -0
- package/manager/processes/restartServer.mjs +28 -0
- package/manager/processes/shutdownServer.mjs +35 -0
- package/manager/processes/startServer.mjs +46 -0
- package/manager/processes/startWatchers.mjs +31 -0
- package/manager/run.mjs +109 -0
- package/manager/utils/BatchChanges.mjs +64 -0
- package/manager/utils/createCustomPluginTypesMap.mjs +80 -0
- package/manager/utils/createLogger.mjs +33 -0
- package/manager/utils/createStdOutLineHandler.mjs +33 -0
- package/manager/utils/getLowdefyVersion.mjs +51 -0
- package/manager/utils/getNextBin.mjs +36 -0
- package/manager/utils/setupWatcher.mjs +50 -0
- package/manager/watchers/envWatcher.mjs +35 -0
- package/manager/watchers/lowdefyBuildWatcher.mjs +55 -0
- package/manager/watchers/nextBuildWatcher.mjs +108 -0
- package/next.config.js +31 -0
- package/package.json +67 -38
- package/package.original.json +98 -0
- package/pages/404.js +19 -0
- package/pages/[pageId].js +19 -0
- package/pages/_app.js +42 -0
- package/pages/_document.js +54 -0
- package/pages/api/auth/[...nextauth].js +37 -0
- package/pages/api/page/[pageId].js +32 -0
- package/pages/api/ping.js +19 -0
- package/pages/api/reload.js +50 -0
- package/pages/api/request/[pageId]/[requestId].js +32 -0
- package/pages/api/root.js +25 -0
- package/pages/index.js +19 -0
- package/public_default/favicon.ico +0 -0
- package/CHANGELOG.md +0 -19
- package/dist/server.js +0 -55
- package/dist/shell/_yarn_cache_object-assign-npm-4_1_1-1004ad6dec-66cf021898_zip_node_modules_object-assign_index_js.js +0 -22
- package/dist/shell/index.html +0 -34
- package/dist/shell/main.js +0 -623
- package/dist/shell/public/icon-32.png +0 -0
- package/dist/shell/src_shell_bootstrap_js.js +0 -517
- package/dist/shell/vendors-_yarn_cache_object-assign-npm-4_1_1-1004ad6dec-66cf021898_zip_node_modules_object-ass-b18854.js +0 -66
- package/dist/shell/vendors-_yarn_cache_react-npm-17_0_1-98658812fc-a76d86ec97_zip_node_modules_react_index_js.js +0 -33
- package/dist/shell/vendors-_yarn_virtual_ajv-errors-virtual-6c363fa7a9_0_cache_ajv-errors-npm-1_0_1-32cd0b19f8-d-940326.js +0 -996
- package/dist/shell/vendors-_yarn_virtual_react-dom-virtual-2d0751dec5_0_cache_react-dom-npm-17_0_1-588d0088ca-6a-73f198.js +0 -33
- /package/{dist/shell/public → public_default}/apple-touch-icon.png +0 -0
- /package/{dist/shell/public → public_default}/icon-512.png +0 -0
- /package/{dist/shell/public → public_default}/icon.svg +0 -0
- /package/{dist/shell/public → public_default}/logo-dark-theme.png +0 -0
- /package/{dist/shell/public → public_default}/logo-light-theme.png +0 -0
- /package/{dist/shell/public → public_default}/logo-square-dark-theme.png +0 -0
- /package/{dist/shell/public → public_default}/logo-square-light-theme.png +0 -0
- /package/{dist/shell/public → public_default}/manifest.webmanifest +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
See the License for the specific language governing permissions and
|
|
11
|
+
limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import useSWR from 'swr';
|
|
15
|
+
|
|
16
|
+
import request from './request.js';
|
|
17
|
+
|
|
18
|
+
function fetchPageConfig(url) {
|
|
19
|
+
return request({ url });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function usePageConfig(pageId, basePath) {
|
|
23
|
+
const { data } = useSWR(`${basePath}/api/page/${pageId}`, fetchPageConfig, { suspense: true });
|
|
24
|
+
return { data };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default usePageConfig;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
See the License for the specific language governing permissions and
|
|
11
|
+
limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import useSWR from 'swr';
|
|
15
|
+
import request from './request.js';
|
|
16
|
+
|
|
17
|
+
function fetchRootConfig(url) {
|
|
18
|
+
return request({ url });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function useRootConfig(basePath) {
|
|
22
|
+
const { data } = useSWR(`${basePath}/api/root`, fetchRootConfig, { suspense: true });
|
|
23
|
+
return { data };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default useRootConfig;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import request from './request.js';
|
|
18
|
+
|
|
19
|
+
const MAX_COUNT = 1200; // 10 mins
|
|
20
|
+
|
|
21
|
+
function waitForRestartedServer(basePath) {
|
|
22
|
+
let count = 0;
|
|
23
|
+
setTimeout(async () => {
|
|
24
|
+
try {
|
|
25
|
+
await request({
|
|
26
|
+
url: `${basePath}/api/ping`,
|
|
27
|
+
});
|
|
28
|
+
window.location.reload();
|
|
29
|
+
} catch (error) {
|
|
30
|
+
count += 1;
|
|
31
|
+
if (count <= MAX_COUNT) {
|
|
32
|
+
waitForRestartedServer(basePath);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, 500); // TODO: this ping should be shorter than rerender delay until we can pass a rebuild flag to reload.
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default waitForRestartedServer;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import path from 'path';
|
|
17
|
+
import crypto from 'crypto';
|
|
18
|
+
import { createApiContext } from '@lowdefy/api';
|
|
19
|
+
import { getSecretsFromEnv } from '@lowdefy/node-utils';
|
|
20
|
+
|
|
21
|
+
import config from '../../build/config.json';
|
|
22
|
+
import connections from '../../build/plugins/connections.js';
|
|
23
|
+
import createLogger from './log/createLogger.js';
|
|
24
|
+
import fileCache from './fileCache.js';
|
|
25
|
+
import getServerSession from './auth/getServerSession.js';
|
|
26
|
+
import logError from './log/logError.js';
|
|
27
|
+
import logRequest from './log/logRequest.js';
|
|
28
|
+
import operators from '../../build/plugins/operators/server.js';
|
|
29
|
+
import getAuthOptions from './auth/getAuthOptions.js';
|
|
30
|
+
|
|
31
|
+
const secrets = getSecretsFromEnv();
|
|
32
|
+
|
|
33
|
+
function apiWrapper(handler) {
|
|
34
|
+
return async function wrappedHandler(req, res) {
|
|
35
|
+
const context = {
|
|
36
|
+
// Important to give absolute path so Next can trace build files
|
|
37
|
+
rid: crypto.randomUUID(),
|
|
38
|
+
buildDirectory: path.join(process.cwd(), 'build'),
|
|
39
|
+
config,
|
|
40
|
+
connections,
|
|
41
|
+
fileCache,
|
|
42
|
+
headers: req?.headers,
|
|
43
|
+
logger: console,
|
|
44
|
+
operators,
|
|
45
|
+
req,
|
|
46
|
+
res,
|
|
47
|
+
secrets,
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
context.logger = createLogger({ rid: context.rid });
|
|
51
|
+
context.authOptions = getAuthOptions(context);
|
|
52
|
+
if (!req.url.startsWith('/api/auth')) {
|
|
53
|
+
context.session = await getServerSession(context);
|
|
54
|
+
}
|
|
55
|
+
createApiContext(context);
|
|
56
|
+
logRequest({ context });
|
|
57
|
+
// Await here so that if handler throws it is caught.
|
|
58
|
+
const response = await handler({ context, req, res });
|
|
59
|
+
// TODO: Log response time?
|
|
60
|
+
return response;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
logError({ error, context });
|
|
63
|
+
res.status(500).json({ name: error.name, message: error.message });
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default apiWrapper;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { getNextAuthConfig } from '@lowdefy/api';
|
|
18
|
+
import { getSecretsFromEnv } from '@lowdefy/node-utils';
|
|
19
|
+
|
|
20
|
+
import adapters from '../../../build/plugins/auth/adapters.js';
|
|
21
|
+
import authJson from '../../../build/auth.json';
|
|
22
|
+
import callbacks from '../../../build/plugins/auth/callbacks.js';
|
|
23
|
+
import events from '../../../build/plugins/auth/events.js';
|
|
24
|
+
import providers from '../../../build/plugins/auth/providers.js';
|
|
25
|
+
|
|
26
|
+
function getAuthOptions({ logger }) {
|
|
27
|
+
return getNextAuthConfig({
|
|
28
|
+
authJson,
|
|
29
|
+
logger,
|
|
30
|
+
plugins: { adapters, callbacks, events, providers },
|
|
31
|
+
secrets: getSecretsFromEnv(),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default getAuthOptions;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { getServerSession as getNextAuthServerSession } from 'next-auth/next';
|
|
18
|
+
|
|
19
|
+
import authJson from '../../../build/auth.json';
|
|
20
|
+
|
|
21
|
+
function getServerSession({ authOptions, req, res }) {
|
|
22
|
+
if (authJson.configured === true) {
|
|
23
|
+
return getNextAuthServerSession(req, res, authOptions);
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default getServerSession;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
get: () => undefined,
|
|
19
|
+
set: () => undefined,
|
|
20
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import pino from 'pino';
|
|
18
|
+
|
|
19
|
+
const logger = pino({
|
|
20
|
+
name: 'lowdefy_server',
|
|
21
|
+
level: process.env.LOWDEFY_LOG_LEVEL ?? 'info',
|
|
22
|
+
base: { pid: undefined, hostname: undefined },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function createLogger(metadata = {}) {
|
|
26
|
+
return logger.child(metadata);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default createLogger;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function logError({ context, error }) {
|
|
18
|
+
try {
|
|
19
|
+
const { user = {} } = context;
|
|
20
|
+
|
|
21
|
+
context.logger.error({
|
|
22
|
+
err: error,
|
|
23
|
+
user: {
|
|
24
|
+
id: user.id,
|
|
25
|
+
roles: user.roles,
|
|
26
|
+
sub: user.sub,
|
|
27
|
+
session_id: user.session_id,
|
|
28
|
+
},
|
|
29
|
+
url: context.req.url,
|
|
30
|
+
method: context.req.method,
|
|
31
|
+
resolvedUrl: context.nextContext?.resolvedUrl,
|
|
32
|
+
});
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error(error);
|
|
35
|
+
console.error('An error occurred while logging the error.');
|
|
36
|
+
console.error(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default logError;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// TODO: Better name needed here maybe?
|
|
18
|
+
function logRequest({ context }) {
|
|
19
|
+
const { user = {} } = context;
|
|
20
|
+
context.logger.debug({
|
|
21
|
+
user: {
|
|
22
|
+
id: user.id,
|
|
23
|
+
roles: user.roles,
|
|
24
|
+
sub: user.sub,
|
|
25
|
+
session_id: user.session_id,
|
|
26
|
+
},
|
|
27
|
+
url: context.req.url,
|
|
28
|
+
method: context.req.method,
|
|
29
|
+
resolvedUrl: context.nextContext?.resolvedUrl,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default logRequest;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import path from 'path';
|
|
18
|
+
|
|
19
|
+
import yargs from 'yargs';
|
|
20
|
+
import { hideBin } from 'yargs/helpers';
|
|
21
|
+
|
|
22
|
+
import createLogger from './utils/createLogger.mjs';
|
|
23
|
+
import initialBuild from './processes/initialBuild.mjs';
|
|
24
|
+
import installPlugins from './processes/installPlugins.mjs';
|
|
25
|
+
import lowdefyBuild from './processes/lowdefyBuild.mjs';
|
|
26
|
+
import nextBuild from './processes/nextBuild.mjs';
|
|
27
|
+
import readDotEnv from './processes/readDotEnv.mjs';
|
|
28
|
+
import reloadClients from './processes/reloadClients.mjs';
|
|
29
|
+
import restartServer from './processes/restartServer.mjs';
|
|
30
|
+
import shutdownServer from './processes/shutdownServer.mjs';
|
|
31
|
+
import startWatchers from './processes/startWatchers.mjs';
|
|
32
|
+
|
|
33
|
+
import getNextBin from './utils/getNextBin.mjs';
|
|
34
|
+
|
|
35
|
+
const argv = yargs(hideBin(process.argv)).array('watch').array('watchIgnore').argv;
|
|
36
|
+
|
|
37
|
+
async function getContext() {
|
|
38
|
+
const env = process.env;
|
|
39
|
+
|
|
40
|
+
const context = {
|
|
41
|
+
bin: {
|
|
42
|
+
next: getNextBin(),
|
|
43
|
+
},
|
|
44
|
+
directories: {
|
|
45
|
+
build: path.resolve(process.cwd(), './build'),
|
|
46
|
+
config: path.resolve(argv.configDirectory || env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()),
|
|
47
|
+
server: process.cwd(),
|
|
48
|
+
},
|
|
49
|
+
logger: createLogger({ level: env.LOWDEFY_LOG_LEVEL }),
|
|
50
|
+
options: {
|
|
51
|
+
port: argv.port || env.PORT || 3000,
|
|
52
|
+
refResolver: argv.refResolver || env.LOWDEFY_BUILD_REF_RESOLVER,
|
|
53
|
+
watch:
|
|
54
|
+
argv.watch || env.LOWDEFY_SERVER_DEV_WATCH ? JSON.parse(env.LOWDEFY_SERVER_DEV_WATCH) : [],
|
|
55
|
+
watchIgnore:
|
|
56
|
+
argv.watchIgnore || env.LOWDEFY_SERVER_DEV_WATCH_IGNORE
|
|
57
|
+
? JSON.parse(env.LOWDEFY_SERVER_DEV_WATCH_IGNORE)
|
|
58
|
+
: [],
|
|
59
|
+
},
|
|
60
|
+
version: env.npm_package_version,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
context.packageManagerCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';
|
|
64
|
+
context.initialBuild = initialBuild(context);
|
|
65
|
+
context.installPlugins = installPlugins(context);
|
|
66
|
+
context.lowdefyBuild = lowdefyBuild(context);
|
|
67
|
+
context.nextBuild = nextBuild(context);
|
|
68
|
+
context.readDotEnv = readDotEnv(context);
|
|
69
|
+
context.reloadClients = reloadClients(context);
|
|
70
|
+
context.restartServer = restartServer(context);
|
|
71
|
+
context.shutdownServer = shutdownServer(context);
|
|
72
|
+
context.startWatchers = startWatchers(context);
|
|
73
|
+
|
|
74
|
+
return context;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default getContext;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
function initialBuild(context) {
|
|
19
|
+
return async () => {
|
|
20
|
+
context.readDotEnv();
|
|
21
|
+
await context.lowdefyBuild();
|
|
22
|
+
await context.installPlugins();
|
|
23
|
+
await context.nextBuild();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default initialBuild;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { spawnProcess } from '@lowdefy/node-utils';
|
|
18
|
+
|
|
19
|
+
function installPlugins({ logger, packageManagerCmd }) {
|
|
20
|
+
return async () => {
|
|
21
|
+
logger.info({ print: 'spin' }, 'Installing plugins...');
|
|
22
|
+
await spawnProcess({
|
|
23
|
+
command: packageManagerCmd,
|
|
24
|
+
args: ['install', '--no-frozen-lockfile'],
|
|
25
|
+
stdOutLineHandler: (line) => logger.debug(line),
|
|
26
|
+
});
|
|
27
|
+
logger.info({ print: 'log' }, 'Installed plugins.');
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default installPlugins;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import build from '@lowdefy/build';
|
|
18
|
+
import createCustomPluginTypesMap from '../utils/createCustomPluginTypesMap.mjs';
|
|
19
|
+
|
|
20
|
+
function lowdefyBuild({ directories, logger, options }) {
|
|
21
|
+
return async () => {
|
|
22
|
+
logger.info({ print: 'spin' }, 'Building config...');
|
|
23
|
+
const customTypesMap = await createCustomPluginTypesMap({ directories, logger });
|
|
24
|
+
await build({
|
|
25
|
+
customTypesMap,
|
|
26
|
+
directories,
|
|
27
|
+
logger,
|
|
28
|
+
refResolver: options.refResolver,
|
|
29
|
+
stage: 'dev',
|
|
30
|
+
});
|
|
31
|
+
logger.info({ print: 'log' }, 'Built config.');
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default lowdefyBuild;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { spawnProcess } from '@lowdefy/node-utils';
|
|
18
|
+
|
|
19
|
+
function nextBuild({ bin, logger }) {
|
|
20
|
+
return async () => {
|
|
21
|
+
logger.info({ print: 'spin' }, 'Building app...');
|
|
22
|
+
await spawnProcess({
|
|
23
|
+
command: 'node',
|
|
24
|
+
args: [bin.next, 'build'],
|
|
25
|
+
stdOutLineHandler: (line) => logger.debug(line),
|
|
26
|
+
});
|
|
27
|
+
logger.info({ print: 'log' }, 'Built app.');
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default nextBuild;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import dotenv from 'dotenv';
|
|
19
|
+
|
|
20
|
+
function readDotEnv(context) {
|
|
21
|
+
return () => {
|
|
22
|
+
dotenv.config({ path: path.join(context.directories.config, '.env'), silent: true });
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default readDotEnv;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import { writeFile } from '@lowdefy/node-utils';
|
|
19
|
+
|
|
20
|
+
function reloadClients({ directories }) {
|
|
21
|
+
return async () => {
|
|
22
|
+
await writeFile(path.join(directories.build, 'reload'), `${Date.now()}`);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default reloadClients;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import startServer from './startServer.mjs';
|
|
18
|
+
|
|
19
|
+
function restartServer(context) {
|
|
20
|
+
return () => {
|
|
21
|
+
context.shutdownServer();
|
|
22
|
+
context.logger.info({ print: 'spin' }, 'Restarting server...');
|
|
23
|
+
startServer(context);
|
|
24
|
+
context.logger.info({ print: 'succeed' }, 'Restarted server.');
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default restartServer;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function shutdownServer(context) {
|
|
18
|
+
return () => {
|
|
19
|
+
if (context.nextServer) {
|
|
20
|
+
context.logger.debug(
|
|
21
|
+
`Existing next server with pid ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
|
|
22
|
+
);
|
|
23
|
+
if (!context.nextServer.killed) {
|
|
24
|
+
context.logger.info({ print: 'spin' }, 'Shutting down server...');
|
|
25
|
+
context.nextServer.kill();
|
|
26
|
+
context.logger.debug(
|
|
27
|
+
`Killed next server with pid ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
context.nextServer = null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default shutdownServer;
|