@lowdefy/server-dev 4.0.0-alpha.9 → 4.0.0-rc.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.
Files changed (60) hide show
  1. package/.npmrc +1 -0
  2. package/lib/App.js +67 -0
  3. package/lib/Page.js +50 -0
  4. package/lib/Reload.js +52 -0
  5. package/lib/RestartingPage.js +47 -0
  6. package/lib/auth/Auth.js +35 -0
  7. package/lib/auth/AuthConfigured.js +47 -0
  8. package/lib/auth/AuthNotConfigured.js +32 -0
  9. package/lib/auth/getServerSession.js +28 -0
  10. package/lib/fileCache.js +20 -0
  11. package/lib/setPageId.js +30 -0
  12. package/lib/utils/request.js +38 -0
  13. package/lib/utils/useMutateCache.js +25 -0
  14. package/lib/utils/usePageConfig.js +27 -0
  15. package/lib/utils/useRootConfig.js +26 -0
  16. package/lib/utils/waitForRestartedServer.js +38 -0
  17. package/manager/getContext.mjs +77 -0
  18. package/manager/processes/initialBuild.mjs +27 -0
  19. package/manager/processes/installPlugins.mjs +31 -0
  20. package/manager/processes/lowdefyBuild.mjs +34 -0
  21. package/manager/processes/nextBuild.mjs +31 -0
  22. package/manager/processes/readDotEnv.mjs +26 -0
  23. package/manager/processes/reloadClients.mjs +26 -0
  24. package/manager/processes/restartServer.mjs +28 -0
  25. package/manager/processes/shutdownServer.mjs +35 -0
  26. package/manager/processes/startServer.mjs +45 -0
  27. package/manager/processes/startWatchers.mjs +31 -0
  28. package/manager/run.mjs +109 -0
  29. package/manager/utils/BatchChanges.mjs +64 -0
  30. package/manager/utils/createCustomPluginTypesMap.mjs +79 -0
  31. package/manager/utils/createLogger.mjs +34 -0
  32. package/manager/utils/getLowdefyVersion.mjs +51 -0
  33. package/manager/utils/getNextBin.mjs +36 -0
  34. package/manager/utils/setupWatcher.mjs +50 -0
  35. package/manager/watchers/envWatcher.mjs +35 -0
  36. package/manager/watchers/lowdefyBuildWatcher.mjs +55 -0
  37. package/manager/watchers/nextBuildWatcher.mjs +99 -0
  38. package/next.config.js +2 -7
  39. package/package.json +50 -39
  40. package/package.original.json +94 -0
  41. package/pages/404.js +19 -0
  42. package/pages/[pageId].js +19 -0
  43. package/pages/_app.js +37 -0
  44. package/pages/_document.js +50 -0
  45. package/pages/api/auth/[...nextauth].js +45 -0
  46. package/pages/api/page/[pageId].js +40 -0
  47. package/pages/api/ping.js +19 -0
  48. package/pages/api/reload.js +50 -0
  49. package/pages/api/request/[pageId]/[requestId].js +50 -0
  50. package/pages/api/root.js +35 -0
  51. package/pages/index.js +19 -0
  52. package/public/apple-touch-icon.png +0 -0
  53. package/public/favicon.ico +0 -0
  54. package/public/icon-512.png +0 -0
  55. package/public/icon.svg +0 -17
  56. package/public/logo-dark-theme.png +0 -0
  57. package/public/logo-light-theme.png +0 -0
  58. package/public/logo-square-dark-theme.png +0 -0
  59. package/public/logo-square-light-theme.png +0 -0
  60. package/public/manifest.webmanifest +0 -16
package/.npmrc ADDED
@@ -0,0 +1 @@
1
+ strict-peer-dependencies=false
package/lib/App.js ADDED
@@ -0,0 +1,67 @@
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 React from 'react';
18
+
19
+ import { useRouter } from 'next/router';
20
+
21
+ import Head from 'next/head';
22
+ import Link from 'next/link';
23
+
24
+ import Reload from './Reload.js';
25
+ import Page from './Page.js';
26
+ import setPageId from './setPageId.js';
27
+ import useRootConfig from './utils/useRootConfig.js';
28
+
29
+ import actions from '../build/plugins/actions.js';
30
+ import blocks from '../build/plugins/blocks.js';
31
+ import icons from '../build/plugins/icons.js';
32
+ import operators from '../build/plugins/operators/client.js';
33
+
34
+ const App = ({ auth }) => {
35
+ const router = useRouter();
36
+ const { data: rootConfig } = useRootConfig(router.basePath);
37
+
38
+ const { redirect, pageId } = setPageId(router, rootConfig);
39
+ if (redirect) {
40
+ router.push(`/${pageId}`);
41
+ return '';
42
+ }
43
+ return (
44
+ <Reload basePath={router.basePath}>
45
+ {(resetContext) => (
46
+ <Page
47
+ auth={auth}
48
+ Components={{ Head, Link }}
49
+ config={{
50
+ rootConfig,
51
+ }}
52
+ pageId={pageId}
53
+ resetContext={resetContext}
54
+ router={router}
55
+ types={{
56
+ actions,
57
+ blocks,
58
+ icons,
59
+ operators,
60
+ }}
61
+ />
62
+ )}
63
+ </Reload>
64
+ );
65
+ };
66
+
67
+ export default App;
package/lib/Page.js ADDED
@@ -0,0 +1,50 @@
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 React from 'react';
18
+ import Client from '@lowdefy/client';
19
+
20
+ import RestartingPage from './RestartingPage.js';
21
+ import usePageConfig from './utils/usePageConfig.js';
22
+
23
+ const Page = ({ auth, Components, config, pageId, resetContext, router, types }) => {
24
+ const { data: pageConfig } = usePageConfig(pageId, router.basePath);
25
+
26
+ if (!pageConfig) {
27
+ router.replace(`/404`);
28
+ return '';
29
+ }
30
+ if (resetContext.restarting) {
31
+ return <RestartingPage />;
32
+ }
33
+ return (
34
+ <Client
35
+ auth={auth}
36
+ Components={Components}
37
+ config={{
38
+ ...config,
39
+ pageConfig,
40
+ }}
41
+ resetContext={resetContext}
42
+ router={router}
43
+ stage="dev"
44
+ types={types}
45
+ window={window}
46
+ />
47
+ );
48
+ };
49
+
50
+ export default Page;
package/lib/Reload.js ADDED
@@ -0,0 +1,52 @@
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 React, { useEffect, useState } from 'react';
18
+
19
+ import useMutateCache from './utils/useMutateCache.js';
20
+ import waitForRestartedServer from './utils/waitForRestartedServer.js';
21
+
22
+ const Reload = ({ children, basePath }) => {
23
+ const [reset, setReset] = useState(false);
24
+ const [restarting, setRestarting] = useState(false);
25
+ const mutateCache = useMutateCache(basePath);
26
+ useEffect(() => {
27
+ const sse = new EventSource(`${basePath}/api/reload`);
28
+
29
+ sse.addEventListener('reload', () => {
30
+ // add a update delay to prevent rerender before server is shut down for rebuild, ideally we don't want to do this.
31
+ // TODO: We need to pass a flag when a rebuild will happen so that client does not trigger render.
32
+ setTimeout(async () => {
33
+ await mutateCache();
34
+ setReset(true);
35
+ console.log('Reloaded config.');
36
+ }, 600);
37
+ });
38
+
39
+ sse.onerror = () => {
40
+ setRestarting(true);
41
+ console.log('Rebuilding Lowdefy App.');
42
+ sse.close();
43
+ waitForRestartedServer(basePath);
44
+ };
45
+ return () => {
46
+ sse.close();
47
+ };
48
+ }, []);
49
+ return <>{children({ reset, setReset, restarting })}</>;
50
+ };
51
+
52
+ export default Reload;
@@ -0,0 +1,47 @@
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 React from 'react';
18
+
19
+ const RestartingPage = () => {
20
+ return (
21
+ <div
22
+ style={{
23
+ height: '100vh',
24
+ textAlign: 'center',
25
+ display: 'flex',
26
+ flexDirection: 'column',
27
+ alignItems: 'center',
28
+ justifyContent: 'center',
29
+ }}
30
+ >
31
+ <div
32
+ style={{
33
+ verticalAlign: 'middle',
34
+ display: 'inline-block',
35
+ }}
36
+ >
37
+ <h3>Rebuilding Lowdefy App</h3>
38
+ <p>
39
+ The server is restarting because your configuration changed. The page will reload when
40
+ ready.
41
+ </p>
42
+ </div>
43
+ </div>
44
+ );
45
+ };
46
+
47
+ export default RestartingPage;
@@ -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
+ /* eslint-disable react/jsx-props-no-spreading */
17
+
18
+ import React from 'react';
19
+ import AuthConfigured from './AuthConfigured.js';
20
+ import AuthNotConfigured from './AuthNotConfigured.js';
21
+
22
+ import authConfig from '../../build/auth.json';
23
+
24
+ function Auth({ children, session }) {
25
+ if (authConfig.configured === true) {
26
+ return (
27
+ <AuthConfigured session={session} authConfig={authConfig}>
28
+ {(auth) => children(auth)}
29
+ </AuthConfigured>
30
+ );
31
+ }
32
+ return <AuthNotConfigured authConfig={authConfig}>{(auth) => children(auth)}</AuthNotConfigured>;
33
+ }
34
+
35
+ export default Auth;
@@ -0,0 +1,47 @@
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
+ /* eslint-disable react/jsx-props-no-spreading */
17
+
18
+ import React from 'react';
19
+ import { SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
20
+
21
+ function Session({ children }) {
22
+ const { data: session, status } = useSession();
23
+ // If session is passed to SessionProvider from getServerSideProps
24
+ // we won't have a loading state here.
25
+ // But 404 uses getStaticProps so we have this for 404.
26
+ if (status === 'loading') {
27
+ return '';
28
+ }
29
+ return children(session);
30
+ }
31
+
32
+ function AuthConfigured({ authConfig, children, serverSession }) {
33
+ const auth = { signIn, signOut, authConfig };
34
+
35
+ return (
36
+ <SessionProvider session={serverSession}>
37
+ <Session>
38
+ {(session) => {
39
+ auth.session = session;
40
+ return children(auth);
41
+ }}
42
+ </Session>
43
+ </SessionProvider>
44
+ );
45
+ }
46
+
47
+ export default AuthConfigured;
@@ -0,0 +1,32 @@
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
+ /* eslint-disable react/jsx-props-no-spreading */
17
+
18
+ function authNotConfigured() {
19
+ throw new Error('Auth not configured.');
20
+ }
21
+
22
+ function AuthNotConfigured({ authConfig, children }) {
23
+ const auth = {
24
+ authConfig,
25
+ signIn: authNotConfigured,
26
+ signOut: authNotConfigured,
27
+ };
28
+
29
+ return children(auth);
30
+ }
31
+
32
+ export default AuthNotConfigured;
@@ -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 { unstable_getServerSession } from 'next-auth/next';
18
+ import { authOptions } from '../../pages/api/auth/[...nextauth].js';
19
+ import authJson from '../../build/auth.json';
20
+
21
+ async function getServerSession({ req, res }) {
22
+ if (authJson.configured === true) {
23
+ return await unstable_getServerSession(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,30 @@
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 setPageId(router, rootConfig) {
18
+ if (router.pathname === `/404`) {
19
+ return { redirect: false, pageId: '404' };
20
+ }
21
+ if (!router.query.pageId) {
22
+ if (rootConfig.home.configured === false) {
23
+ return { redirect: true, pageId: rootConfig.home.pageId };
24
+ }
25
+ return { redirect: false, pageId: rootConfig.home.pageId };
26
+ }
27
+ return { redirect: false, pageId: router.query.pageId };
28
+ }
29
+
30
+ export default setPageId;
@@ -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
+ async function request({ url, method = 'GET', body }) {
18
+ const res = await fetch(url, {
19
+ method,
20
+ headers: {
21
+ 'Content-Type': 'application/json',
22
+ },
23
+ body: body && JSON.stringify(body),
24
+ });
25
+ if (res.status === 404) {
26
+ return null;
27
+ }
28
+ if (!res.ok) {
29
+ // TODO: check
30
+ const body = await res.json();
31
+ console.log(res);
32
+ console.log(body);
33
+ throw new Error(body.message || 'Request error');
34
+ }
35
+ return res.json();
36
+ }
37
+
38
+ export default request;
@@ -0,0 +1,25 @@
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 { useSWRConfig } from 'swr';
18
+
19
+ function useMutateCache(basePath) {
20
+ const { mutate } = useSWRConfig();
21
+ return () =>
22
+ mutate((key) => key.startsWith(`${basePath}/api/page`) || key === `${basePath}/api/root`);
23
+ }
24
+
25
+ export default useMutateCache;
@@ -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,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;