@lowdefy/server-dev 3.23.1 → 4.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.yaml +1 -0
- package/README.md +0 -24
- package/lib/App.js +66 -0
- package/lib/Page.js +48 -0
- package/lib/Reload.js +52 -0
- package/lib/RestartingPage.js +47 -0
- package/lib/setPageId.js +30 -0
- package/lib/utils/request.js +38 -0
- package/lib/utils/useMutateCache.js +34 -0
- package/lib/utils/usePageConfig.js +29 -0
- package/lib/utils/useRootConfig.js +29 -0
- package/lib/utils/waitForRestartedServer.js +32 -0
- package/manager/getContext.mjs +81 -0
- package/manager/processes/initialBuild.mjs +27 -0
- package/manager/processes/installPlugins.mjs +36 -0
- package/manager/processes/lowdefyBuild.mjs +32 -0
- package/manager/processes/nextBuild.mjs +31 -0
- package/manager/processes/readDotEnv.mjs +28 -0
- package/manager/processes/reloadClients.mjs +26 -0
- package/manager/processes/restartServer.mjs +27 -0
- package/manager/processes/shutdownServer.mjs +35 -0
- package/manager/processes/startNextServer.mjs +45 -0
- package/manager/processes/startServer.mjs +31 -0
- package/manager/processes/startWatchers.mjs +31 -0
- package/manager/run.mjs +92 -0
- package/manager/utils/BatchChanges.mjs +67 -0
- package/manager/utils/createCustomPluginTypesMap.mjs +66 -0
- package/manager/utils/getLowdefyVersion.mjs +51 -0
- package/manager/utils/setupWatcher.mjs +49 -0
- package/manager/utils/spawnProcess.mjs +55 -0
- package/manager/watchers/envWatcher.mjs +34 -0
- package/manager/watchers/lowdefyBuildWatcher.mjs +45 -0
- package/manager/watchers/nextBuildWatcher.mjs +94 -0
- package/next.config.js +36 -0
- package/package.json +48 -34
- package/pages/404.js +19 -0
- package/pages/[pageId].js +19 -0
- package/pages/_app.js +35 -0
- package/pages/_document.js +38 -0
- package/pages/api/auth/[...nextauth].js +28 -0
- package/pages/api/page/[pageId].js +29 -0
- package/pages/api/ping.js +19 -0
- package/pages/api/reload.js +50 -0
- package/pages/api/request/[pageId]/[requestId].js +45 -0
- package/pages/api/root.js +25 -0
- package/pages/index.js +19 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/icon-512.png +0 -0
- package/public/icon.svg +17 -0
- package/public/logo-dark-theme.png +0 -0
- package/public/logo-light-theme.png +0 -0
- package/public/logo-square-dark-theme.png +0 -0
- package/public/logo-square-light-theme.png +0 -0
- package/public/manifest.webmanifest +16 -0
- package/dist/server.js +0 -47
package/.eslintrc.yaml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
extends: 'plugin:@next/next/core-web-vitals'
|
package/README.md
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
# @lowdefy/server-dev
|
|
2
2
|
|
|
3
|
-
A Lowdefy server for local development.
|
|
4
|
-
|
|
5
|
-
The server consists of a Lowdefy Graphql server, and a static file server to serve the web client shell. The web shell is a minimal react app, that loads a Lowdefy renderer using [webpack module federation](https://webpack.js.org/concepts/module-federation/).
|
|
6
|
-
|
|
7
|
-
> If you wish to develop a Lowdefy app, use the development server in the [CLI](https://docs.lowdefy.com/cli). The code for the CLI can be found [here](https://github.com/lowdefy/lowdefy/tree/main/packages/cli)
|
|
8
|
-
|
|
9
|
-
## Running a development server
|
|
10
|
-
|
|
11
|
-
- Build the repository in development mode by running `yarn build:dev` at the root of the repository.
|
|
12
|
-
- Create a `lowdefy.yaml` file in the root of the package directory, and build this configuration with the cli using `lowdefy build`.
|
|
13
|
-
- Build the dev server using `yarn build`.
|
|
14
|
-
- Run the dev server using `yarn start`.
|
|
15
|
-
- Run a [`@lowdefy/renderer`](https://github.com/lowdefy/lowdefy/tree/main/packages/renderer) server at port 3001 using `yarn start` or `yarn serve`.
|
|
16
|
-
|
|
17
|
-
To make changes to the server, you need to run `yarn build` in dependencies that have changed (like `@lowdefy/graphql`), and then run `yarn build`.
|
|
18
|
-
|
|
19
|
-
## More Lowdefy resources
|
|
20
|
-
|
|
21
|
-
- Getting started with Lowdefy - https://docs.lowdefy.com/tutorial-start
|
|
22
|
-
- Lowdefy docs - https://docs.lowdefy.com
|
|
23
|
-
- Lowdefy website - https://lowdefy.com
|
|
24
|
-
- Community forum - https://github.com/lowdefy/lowdefy/discussions
|
|
25
|
-
- Bug reports and feature requests - https://github.com/lowdefy/lowdefy/issues
|
|
26
|
-
|
|
27
3
|
## Licence
|
|
28
4
|
|
|
29
5
|
[Apache-2.0](https://github.com/lowdefy/lowdefy/blob/main/LICENSE)
|
package/lib/App.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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/operatorsClient.js';
|
|
33
|
+
|
|
34
|
+
const App = () => {
|
|
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
|
+
Components={{ Head, Link }}
|
|
48
|
+
config={{
|
|
49
|
+
rootConfig,
|
|
50
|
+
}}
|
|
51
|
+
pageId={pageId}
|
|
52
|
+
resetContext={resetContext}
|
|
53
|
+
router={router}
|
|
54
|
+
types={{
|
|
55
|
+
actions,
|
|
56
|
+
blocks,
|
|
57
|
+
icons,
|
|
58
|
+
operators,
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
)}
|
|
62
|
+
</Reload>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default App;
|
package/lib/Page.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 = ({ Components, config, pageId, resetContext, router, types }) => {
|
|
24
|
+
const { data: pageConfig } = usePageConfig(pageId, router.basePath);
|
|
25
|
+
if (!pageConfig) {
|
|
26
|
+
router.replace(`/404`);
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
if (resetContext.restarting) {
|
|
30
|
+
return <RestartingPage />;
|
|
31
|
+
}
|
|
32
|
+
return (
|
|
33
|
+
<Client
|
|
34
|
+
Components={Components}
|
|
35
|
+
config={{
|
|
36
|
+
...config,
|
|
37
|
+
pageConfig,
|
|
38
|
+
}}
|
|
39
|
+
resetContext={resetContext}
|
|
40
|
+
router={router}
|
|
41
|
+
stage="dev"
|
|
42
|
+
types={types}
|
|
43
|
+
window={window}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default Page;
|
package/lib/Reload.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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-2022 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;
|
package/lib/setPageId.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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-2022 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,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 { cache, mutate } = useSWRConfig();
|
|
21
|
+
return () => {
|
|
22
|
+
const keys = [`${basePath}/api/root`];
|
|
23
|
+
|
|
24
|
+
for (const key of cache.keys()) {
|
|
25
|
+
if (key.startsWith(`${basePath}/api/page`)) {
|
|
26
|
+
keys.push(key);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const mutations = keys.map((key) => mutate(key));
|
|
30
|
+
return Promise.all(mutations);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default useMutateCache;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
// TODO: Handle TokenExpiredError
|
|
19
|
+
|
|
20
|
+
function fetchPageConfig(url) {
|
|
21
|
+
return request({ url });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function usePageConfig(pageId, basePath) {
|
|
25
|
+
const { data } = useSWR(`${basePath}/api/page/${pageId}`, fetchPageConfig, { suspense: true });
|
|
26
|
+
return { data };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default usePageConfig;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
// TODO: Handle TokenExpiredError
|
|
19
|
+
|
|
20
|
+
function fetchRootConfig(url) {
|
|
21
|
+
return request({ url });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function useRootConfig(basePath) {
|
|
25
|
+
const { data } = useSWR(`${basePath}/api/root`, fetchRootConfig, { suspense: true });
|
|
26
|
+
return { data };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default useRootConfig;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
function waitForRestartedServer(basePath) {
|
|
20
|
+
setTimeout(async () => {
|
|
21
|
+
try {
|
|
22
|
+
await request({
|
|
23
|
+
url: `${basePath}/api/ping`,
|
|
24
|
+
});
|
|
25
|
+
window.location.reload();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
waitForRestartedServer(basePath);
|
|
28
|
+
}
|
|
29
|
+
}, 500); // TODO: this ping should be shorter than rerender delay until we can pass a rebuild flag to reload.
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default waitForRestartedServer;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 no-console */
|
|
17
|
+
|
|
18
|
+
import path from 'path';
|
|
19
|
+
import { createRequire } from 'module';
|
|
20
|
+
import yargs from 'yargs';
|
|
21
|
+
import { hideBin } from 'yargs/helpers';
|
|
22
|
+
|
|
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
|
+
const argv = yargs(hideBin(process.argv)).array('watch').array('watchIgnore').argv;
|
|
34
|
+
const require = createRequire(import.meta.url);
|
|
35
|
+
|
|
36
|
+
async function getContext() {
|
|
37
|
+
const env = process.env;
|
|
38
|
+
|
|
39
|
+
const nextPageJson = require('next/package.json');
|
|
40
|
+
const context = {
|
|
41
|
+
bin: {
|
|
42
|
+
next: path.join(
|
|
43
|
+
require.resolve('next').replace(nextPageJson.main.substring(1), ''),
|
|
44
|
+
nextPageJson.bin.next
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
directories: {
|
|
48
|
+
build: path.resolve(process.cwd(), './build'),
|
|
49
|
+
config: path.resolve(argv.configDirectory || env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()),
|
|
50
|
+
server: process.cwd(),
|
|
51
|
+
},
|
|
52
|
+
options: {
|
|
53
|
+
port: argv.port || env.PORT || 3000,
|
|
54
|
+
refResolver: argv.refResolver || env.LOWDEFY_BUILD_REF_RESOLVER,
|
|
55
|
+
watch:
|
|
56
|
+
argv.watch || env.LOWDEFY_SERVER_DEV_WATCH ? JSON.parse(env.LOWDEFY_SERVER_DEV_WATCH) : [],
|
|
57
|
+
watchIgnore:
|
|
58
|
+
argv.watchIgnore || env.LOWDEFY_SERVER_DEV_WATCH_IGNORE
|
|
59
|
+
? JSON.parse(env.LOWDEFY_SERVER_DEV_WATCH_IGNORE)
|
|
60
|
+
: [],
|
|
61
|
+
// TODO: read option from env
|
|
62
|
+
verbose: argv.verbose || false,
|
|
63
|
+
},
|
|
64
|
+
packageManager: argv.packageManager || env.LOWDEFY_PACKAGE_MANAGER || 'npm',
|
|
65
|
+
version: env.npm_package_version,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
context.initialBuild = initialBuild(context);
|
|
69
|
+
context.installPlugins = installPlugins(context);
|
|
70
|
+
context.lowdefyBuild = lowdefyBuild(context);
|
|
71
|
+
context.nextBuild = nextBuild(context);
|
|
72
|
+
context.readDotEnv = readDotEnv(context);
|
|
73
|
+
context.reloadClients = reloadClients(context);
|
|
74
|
+
context.restartServer = restartServer(context);
|
|
75
|
+
context.shutdownServer = shutdownServer(context);
|
|
76
|
+
context.startWatchers = startWatchers(context);
|
|
77
|
+
|
|
78
|
+
return context;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default getContext;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2020-2022 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
|
+
await context.lowdefyBuild();
|
|
21
|
+
await context.installPlugins();
|
|
22
|
+
await context.nextBuild();
|
|
23
|
+
await context.readDotEnv();
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default initialBuild;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
const args = {
|
|
20
|
+
npm: ['install', '--legacy-peer-deps'],
|
|
21
|
+
yarn: ['install'],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function installPlugins({ packageManager, options }) {
|
|
25
|
+
return async () => {
|
|
26
|
+
console.log('Installing plugins...');
|
|
27
|
+
await spawnProcess({
|
|
28
|
+
logger: console,
|
|
29
|
+
command: packageManager, // npm or yarn
|
|
30
|
+
args: args[packageManager],
|
|
31
|
+
silent: !options.verbose,
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default installPlugins;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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, options }) {
|
|
21
|
+
return async () => {
|
|
22
|
+
const customTypesMap = await createCustomPluginTypesMap({ directories });
|
|
23
|
+
await build({
|
|
24
|
+
customTypesMap,
|
|
25
|
+
directories,
|
|
26
|
+
logger: console,
|
|
27
|
+
refResolver: options.refResolver,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default lowdefyBuild;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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, options }) {
|
|
20
|
+
return async () => {
|
|
21
|
+
console.log('Building app...');
|
|
22
|
+
await spawnProcess({
|
|
23
|
+
logger: console,
|
|
24
|
+
command: 'node',
|
|
25
|
+
args: [bin.next, 'build'],
|
|
26
|
+
silent: !options.verbose,
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default nextBuild;
|