@lowdefy/server-dev 4.0.0-alpha.7 → 4.0.0-alpha.8

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 (54) hide show
  1. package/package.json +27 -30
  2. package/src/components/App.js +0 -57
  3. package/src/components/Context.js +0 -62
  4. package/src/components/Head.js +0 -28
  5. package/src/components/LowdefyContext.js +0 -50
  6. package/src/components/Page.js +0 -54
  7. package/src/components/Reload.js +0 -43
  8. package/src/components/block/Block.js +0 -57
  9. package/src/components/block/CategorySwitch.js +0 -117
  10. package/src/components/block/Container.js +0 -86
  11. package/src/components/block/List.js +0 -93
  12. package/src/components/block/LoadingBlock.js +0 -22
  13. package/src/components/block/MountEvents.js +0 -46
  14. package/src/components/createComponents.js +0 -29
  15. package/src/components/createLinkComponent.js +0 -97
  16. package/src/manager/getContext.mjs +0 -79
  17. package/src/manager/processes/initialBuild.mjs +0 -27
  18. package/src/manager/processes/installPlugins.mjs +0 -36
  19. package/src/manager/processes/lowdefyBuild.mjs +0 -39
  20. package/src/manager/processes/nextBuild.mjs +0 -31
  21. package/src/manager/processes/readDotEnv.mjs +0 -28
  22. package/src/manager/processes/reloadClients.mjs +0 -26
  23. package/src/manager/processes/restartServer.mjs +0 -27
  24. package/src/manager/processes/shutdownServer.mjs +0 -35
  25. package/src/manager/processes/startNextServer.mjs +0 -45
  26. package/src/manager/processes/startServer.mjs +0 -31
  27. package/src/manager/processes/startWatchers.mjs +0 -31
  28. package/src/manager/run.mjs +0 -92
  29. package/src/manager/utils/BatchChanges.mjs +0 -67
  30. package/src/manager/utils/getLowdefyVersion.mjs +0 -51
  31. package/src/manager/utils/setupWatcher.mjs +0 -49
  32. package/src/manager/utils/spawnProcess.mjs +0 -55
  33. package/src/manager/watchers/envWatcher.mjs +0 -34
  34. package/src/manager/watchers/lowdefyBuildWatcher.mjs +0 -45
  35. package/src/manager/watchers/nextBuildWatcher.mjs +0 -93
  36. package/src/pages/404.js +0 -19
  37. package/src/pages/[pageId].js +0 -19
  38. package/src/pages/_app.js +0 -39
  39. package/src/pages/_document.js +0 -38
  40. package/src/pages/api/auth/[...nextauth].js +0 -28
  41. package/src/pages/api/page/[pageId].js +0 -29
  42. package/src/pages/api/ping.js +0 -19
  43. package/src/pages/api/reload.js +0 -50
  44. package/src/pages/api/request/[pageId]/[requestId].js +0 -45
  45. package/src/pages/api/root.js +0 -25
  46. package/src/pages/index.js +0 -19
  47. package/src/utils/callRequest.js +0 -27
  48. package/src/utils/request.js +0 -36
  49. package/src/utils/setPageId.js +0 -33
  50. package/src/utils/setupLink.js +0 -52
  51. package/src/utils/useMutateCache.js +0 -34
  52. package/src/utils/usePageConfig.js +0 -29
  53. package/src/utils/useRootConfig.js +0 -29
  54. package/src/utils/waitForRestartedServer.js +0 -32
@@ -1,93 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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 { Area, BlockLayout, layoutParamsToArea } from '@lowdefy/layout';
19
- import { makeCssClass } from '@lowdefy/block-utils';
20
-
21
- import Block from './Block.js';
22
-
23
- const List = ({ block, Blocks, Component, context, lowdefy }) => {
24
- const content = {};
25
- const contentList = [];
26
- Blocks.subBlocks[block.id].forEach((SBlock) => {
27
- Object.keys(SBlock.areas).forEach((areaKey) => {
28
- content[areaKey] = (areaStyle) => (
29
- <Area
30
- id={`ar-${block.blockId}-${SBlock.id}-${areaKey}`}
31
- key={`ar-${block.blockId}-${SBlock.id}-${areaKey}`}
32
- area={layoutParamsToArea({
33
- area: block.eval.areas[areaKey] || {},
34
- areaKey,
35
- layout: block.eval.layout || {},
36
- })}
37
- areaStyle={[areaStyle, block.eval.areas[areaKey] && block.eval.areas[areaKey].style]}
38
- highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
39
- makeCssClass={makeCssClass}
40
- >
41
- {SBlock.areas[areaKey].blocks.map((bl) => (
42
- <Block
43
- key={`ls-${bl.blockId}`}
44
- Blocks={SBlock}
45
- block={bl}
46
- context={context}
47
- lowdefy={lowdefy}
48
- />
49
- ))}
50
- </Area>
51
- );
52
- });
53
- contentList.push({ ...content });
54
- });
55
- return (
56
- <BlockLayout
57
- id={`bl-${block.blockId}`}
58
- blockStyle={block.eval.style}
59
- highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
60
- layout={block.eval.layout || {}}
61
- makeCssClass={makeCssClass}
62
- >
63
- <Component
64
- methods={Object.assign(block.methods, {
65
- makeCssClass,
66
- moveItemDown: block.moveItemDown,
67
- moveItemUp: block.moveItemUp,
68
- pushItem: block.pushItem,
69
- registerEvent: block.registerEvent,
70
- registerMethod: block.registerMethod,
71
- removeItem: block.removeItem,
72
- triggerEvent: block.triggerEvent,
73
- unshiftItem: block.unshiftItem,
74
- })}
75
- basePath={lowdefy.basePath}
76
- blockId={block.blockId}
77
- components={lowdefy._internal.components}
78
- events={block.eval.events}
79
- key={block.blockId}
80
- list={contentList}
81
- loading={block.loading}
82
- menus={lowdefy.menus}
83
- pageId={lowdefy.pageId}
84
- properties={block.eval.properties}
85
- required={block.eval.required}
86
- user={lowdefy.user}
87
- validation={block.eval.validation}
88
- />
89
- </BlockLayout>
90
- );
91
- };
92
-
93
- export default List;
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
- // import { Loading, makeCssClass } from '@lowdefy/block-utils';
3
- // import { get } from '@lowdefy/helpers';
4
- // import { BlockLayout } from '@lowdefy/layout';
5
-
6
- const LoadingBlock = ({ block, lowdefy }) => (
7
- <div>LoadingBlock</div>
8
- // <BlockLayout
9
- // id={`bl-loading-${block.blockId}`}
10
- // blockStyle={get(block, 'eval.style') || get(block, 'meta.loading.style', { default: {} })}
11
- // highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
12
- // layout={get(block, 'eval.layout') || get(block, 'meta.loading.layout', { default: {} })}
13
- // makeCssClass={makeCssClass}
14
- // >
15
- // <Loading
16
- // properties={get(block, 'meta.loading.properties')}
17
- // type={get(block, 'meta.loading.type')}
18
- // />
19
- // </BlockLayout>
20
- );
21
-
22
- export default LoadingBlock;
@@ -1,46 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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
- const MountEvents = ({ asyncEventName, context, eventName, triggerEvent, children }) => {
20
- const [loading, setLoading] = useState(true);
21
- const [error, setError] = useState(null);
22
- useEffect(() => {
23
- let mounted = true;
24
- const mount = async () => {
25
- try {
26
- await triggerEvent({ name: eventName, context });
27
- if (mounted) {
28
- triggerEvent({ name: asyncEventName, context });
29
- setLoading(false);
30
- }
31
- } catch (err) {
32
- setError(err);
33
- }
34
- };
35
- mount();
36
- return () => {
37
- mounted = false;
38
- };
39
- }, [context]);
40
-
41
- if (error) throw error;
42
-
43
- return <>{children(loading)}</>;
44
- };
45
-
46
- export default MountEvents;
@@ -1,29 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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 { createIcon } from '@lowdefy/block-utils';
18
-
19
- import createLinkComponent from './createLinkComponent.js';
20
- import icons from '../../build/plugins/icons.js';
21
-
22
- const createComponents = (lowdefy) => {
23
- return {
24
- Link: createLinkComponent(lowdefy),
25
- Icon: createIcon(icons),
26
- };
27
- };
28
-
29
- export default createComponents;
@@ -1,97 +0,0 @@
1
- import React from 'react';
2
- import NextLink from 'next/link';
3
- import { createLink } from '@lowdefy/engine';
4
- import { type } from '@lowdefy/helpers';
5
-
6
- const createLinkComponent = (lowdefy) => {
7
- const backLink = ({ ariaLabel, children, className, id, rel }) => (
8
- <a
9
- id={id}
10
- onClick={() => lowdefy._internal.router.back()}
11
- className={className}
12
- rel={rel}
13
- aria-label={ariaLabel || 'back'}
14
- >
15
- {type.isFunction(children) ? children(id) : children}
16
- </a>
17
- );
18
- const newOriginLink = ({
19
- ariaLabel,
20
- children,
21
- className,
22
- id,
23
- newTab,
24
- pageId,
25
- query,
26
- rel,
27
- url,
28
- }) => {
29
- return (
30
- <a
31
- id={id}
32
- aria-label={ariaLabel}
33
- className={className}
34
- href={`${url}${query ? `?${query}` : ''}`}
35
- rel={rel || (newTab && 'noopener noreferrer')}
36
- target={newTab && '_blank'}
37
- >
38
- {type.isFunction(children) ? children(pageId || url || id) : children}
39
- </a>
40
- );
41
- };
42
- const sameOriginLink = ({
43
- ariaLabel,
44
- children,
45
- className,
46
- id,
47
- newTab,
48
- pageId,
49
- pathname,
50
- query,
51
- rel,
52
- replace,
53
- scroll,
54
- setInput,
55
- url,
56
- }) => {
57
- if (newTab) {
58
- return (
59
- // eslint-disable-next-line react/jsx-no-target-blank
60
- <a
61
- id={id}
62
- aria-label={ariaLabel}
63
- className={className}
64
- href={`${window.location.origin}${lowdefy.basePath}${pathname}${
65
- query ? `?${query}` : ''
66
- }`}
67
- rel={rel || 'noopener noreferrer'}
68
- target="_blank"
69
- >
70
- {type.isFunction(children) ? children(pageId || url || id) : children}
71
- </a>
72
- );
73
- }
74
- return (
75
- <NextLink href={{ pathname, query }} replace={replace} scroll={scroll}>
76
- <a id={id} aria-label={ariaLabel} className={className} rel={rel} onClick={setInput}>
77
- {type.isFunction(children) ? children(pageId || url || id) : children}
78
- </a>
79
- </NextLink>
80
- );
81
- };
82
- const noLink = ({ className, children, id }) => (
83
- <span id={id} className={className}>
84
- {type.isFunction(children) ? children(id) : children}
85
- </span>
86
- );
87
- return createLink({
88
- backLink,
89
- lowdefy,
90
- newOriginLink,
91
- sameOriginLink,
92
- noLink,
93
- disabledLink: noLink,
94
- });
95
- };
96
-
97
- export default createLinkComponent;
@@ -1,79 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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 context = {
40
- bin: {
41
- // TODO: The string replace is a little hacky and will fail if the location of the bin changes,
42
- lowdefyBuild: require.resolve('@lowdefy/build').replace('index.js', 'scripts/run.js'),
43
- next: require.resolve('next').replace('server/next.js', 'bin/next'),
44
- },
45
- directories: {
46
- build: path.resolve(process.cwd(), './build'),
47
- config: path.resolve(argv.configDirectory || env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()),
48
- server: process.cwd(),
49
- },
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
- // TODO: read option from from env
60
- verbose: argv.verbose || false,
61
- },
62
- packageManager: argv.packageManager || env.LOWDEFY_PACKAGE_MANAGER || 'npm',
63
- version: env.npm_package_version,
64
- };
65
-
66
- context.initialBuild = initialBuild(context);
67
- context.installPlugins = installPlugins(context);
68
- context.lowdefyBuild = lowdefyBuild(context);
69
- context.nextBuild = nextBuild(context);
70
- context.readDotEnv = readDotEnv(context);
71
- context.reloadClients = reloadClients(context);
72
- context.restartServer = restartServer(context);
73
- context.shutdownServer = shutdownServer(context);
74
- context.startWatchers = startWatchers(context);
75
-
76
- return context;
77
- }
78
-
79
- export default getContext;
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env node
2
- /*
3
- Copyright 2020-2021 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;
@@ -1,36 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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;
@@ -1,39 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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 lowdefyBuild({ bin, directories, options }) {
20
- return async () => {
21
- await spawnProcess({
22
- command: 'node',
23
- args: [bin.lowdefyBuild],
24
- logger: console,
25
- processOptions: {
26
- env: {
27
- ...process.env,
28
- LOWDEFY_BUILD_REF_RESOLVER: options.refResolver,
29
- LOWDEFY_DIRECTORY_BUILD: directories.build,
30
- LOWDEFY_DIRECTORY_CONFIG: directories.config,
31
- LOWDEFY_DIRECTORY_SERVER: process.cwd(),
32
- },
33
- },
34
- silent: false,
35
- });
36
- };
37
- }
38
-
39
- export default lowdefyBuild;
@@ -1,31 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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;
@@ -1,28 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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
- import { readFile } from '@lowdefy/node-utils';
20
-
21
- function readDotEnv(context) {
22
- return async () => {
23
- const dotEnv = await readFile(path.join(context.directories.config, '.env'));
24
- context.serverEnv = dotenv.parse(dotEnv || '');
25
- };
26
- }
27
-
28
- export default readDotEnv;
@@ -1,26 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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;
@@ -1,27 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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 startNextServer from './startNextServer.mjs';
18
-
19
- function restartServer(context) {
20
- return () => {
21
- context.shutdownServer(); // Is this needed here?
22
- console.log('Restarting server...');
23
- startNextServer(context);
24
- };
25
- }
26
-
27
- export default restartServer;
@@ -1,35 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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
- // console.log(
21
- // `Existing server ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
22
- // );
23
- if (!context.nextServer.killed) {
24
- console.log('Shutting down server...');
25
- context.nextServer.kill();
26
- // console.log(
27
- // `Killed server ${context.nextServer.pid}, killed: ${context.nextServer.killed}`
28
- // );
29
- }
30
- context.nextServer = null;
31
- }
32
- };
33
- }
34
-
35
- export default shutdownServer;
@@ -1,45 +0,0 @@
1
- /*
2
- Copyright 2020-2021 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 '../utils/spawnProcess.mjs';
18
-
19
- function startServerProcess(context) {
20
- context.shutdownServer();
21
-
22
- const nextServer = spawnProcess({
23
- logger: console,
24
- command: 'node',
25
- args: [context.bin.next, 'start'],
26
- silent: false,
27
- processOptions: {
28
- env: {
29
- ...process.env,
30
- ...context.serverEnv,
31
- PORT: context.options.port,
32
- },
33
- },
34
- });
35
- // console.log(`Started server ${nextServer.pid}.`);
36
- // nextServer.on('exit', (code, signal) => {
37
- // console.log(`nextServer exit ${nextServer.pid}, signal: ${signal}, code: ${code}`);
38
- // });
39
- nextServer.on('error', (error) => {
40
- console.log(error);
41
- });
42
- context.nextServer = nextServer;
43
- }
44
-
45
- export default startServerProcess;