lowdefy 4.0.0-alpha.1 → 4.0.0-alpha.7

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 (33) hide show
  1. package/dist/commands/build/build.js +21 -19
  2. package/dist/commands/build/installServer.js +43 -0
  3. package/dist/commands/build/runLowdefyBuild.js +43 -0
  4. package/dist/commands/build/runNextBuild.js +36 -0
  5. package/dist/commands/dev/dev.js +9 -57
  6. package/dist/commands/dev/installServer.js +43 -0
  7. package/dist/commands/dev/runDevServer.js +39 -0
  8. package/dist/commands/init/init.js +5 -11
  9. package/dist/commands/init/lowdefyFile.js +1 -1
  10. package/dist/commands/start/runStart.js +36 -0
  11. package/dist/{utils/checkChildProcessError.js → commands/start/start.js} +11 -6
  12. package/dist/index.js +23 -56
  13. package/dist/utils/BatchChanges.js +24 -11
  14. package/dist/utils/checkForUpdatedVersions.js +11 -0
  15. package/dist/utils/{print.js → createPrint.js} +1 -0
  16. package/dist/utils/errorHandler.js +2 -3
  17. package/dist/utils/fetchNpmTarball.js +2 -1
  18. package/dist/utils/getCliJson.js +5 -8
  19. package/dist/utils/getDirectories.js +9 -5
  20. package/dist/utils/getLowdefyYaml.js +10 -12
  21. package/dist/utils/getPackageManager.js +54 -0
  22. package/dist/utils/getSendTelemetry.js +17 -8
  23. package/dist/utils/getServer.js +45 -0
  24. package/dist/utils/runCommand.js +22 -23
  25. package/dist/utils/startUp.js +6 -6
  26. package/package.json +15 -18
  27. package/dist/commands/dev/buildWatcher.js +0 -48
  28. package/dist/commands/dev/envWatcher.js +0 -32
  29. package/dist/commands/dev/getBuild.js +0 -37
  30. package/dist/commands/dev/getExpress.js +0 -71
  31. package/dist/commands/dev/getGraphQL.js +0 -39
  32. package/dist/commands/dev/prepare.js +0 -27
  33. package/dist/commands/dev/versionWatcher.js +0 -36
@@ -15,17 +15,14 @@
15
15
  */ import path from 'path';
16
16
  import { readFile, writeFile } from '@lowdefy/node-utils';
17
17
  import { v4 as uuid } from 'uuid';
18
- async function getCliJson({ baseDirectory }) {
19
- const filePath = path.resolve(baseDirectory, './.lowdefy/cli.json');
18
+ async function getCliJson({ configDirectory }) {
19
+ const filePath = path.resolve(configDirectory, './.lowdefy/cli.json');
20
20
  const cliJson = await readFile(filePath);
21
21
  if (!cliJson) {
22
22
  const appId = uuid();
23
- await writeFile({
24
- filePath,
25
- content: JSON.stringify({
26
- appId
27
- }, null, 2)
28
- });
23
+ await writeFile(filePath, JSON.stringify({
24
+ appId
25
+ }, null, 2));
29
26
  return {
30
27
  appId
31
28
  };
@@ -13,15 +13,19 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import path from 'path';
16
- function getDirectories({ baseDirectory , options }) {
17
- let buildDirectory;
16
+ function getDirectories({ configDirectory , options }) {
17
+ let dotLowdefy;
18
18
  if (options.outputDirectory) {
19
- buildDirectory = path.resolve(options.outputDirectory);
19
+ dotLowdefy = path.resolve(options.outputDirectory);
20
20
  } else {
21
- buildDirectory = path.resolve(baseDirectory, './.lowdefy/build');
21
+ dotLowdefy = path.resolve(configDirectory, '.lowdefy');
22
22
  }
23
23
  return {
24
- buildDirectory
24
+ config: configDirectory,
25
+ build: path.join(dotLowdefy, 'server', 'build'),
26
+ dotLowdefy,
27
+ server: options.serverDirectory ? path.resolve(options.serverDirectory) : path.join(dotLowdefy, 'server'),
28
+ dev: options.devDirectory ? path.resolve(options.devDirectory) : path.join(dotLowdefy, 'dev')
25
29
  };
26
30
  }
27
31
  export default getDirectories;
@@ -15,40 +15,38 @@
15
15
  */ import path from 'path';
16
16
  import { get, type } from '@lowdefy/helpers';
17
17
  import { readFile } from '@lowdefy/node-utils';
18
- import YAML from 'js-yaml';
19
- async function getLowdefyYaml({ baseDirectory , command }) {
20
- let lowdefyYaml = await readFile(path.resolve(baseDirectory, 'lowdefy.yaml'));
18
+ import YAML from 'yaml';
19
+ async function getLowdefyYaml({ configDirectory , command }) {
20
+ let lowdefyYaml = await readFile(path.resolve(configDirectory, 'lowdefy.yaml'));
21
21
  if (!lowdefyYaml) {
22
- lowdefyYaml = await readFile(path.resolve(baseDirectory, 'lowdefy.yml'));
22
+ lowdefyYaml = await readFile(path.resolve(configDirectory, 'lowdefy.yml'));
23
23
  }
24
24
  if (!lowdefyYaml) {
25
25
  if (![
26
26
  'init'
27
27
  ].includes(command)) {
28
- throw new Error(`Could not find "lowdefy.yaml" file in specified base directory ${baseDirectory}.`);
28
+ throw new Error(`Could not find "lowdefy.yaml" file in specified config directory ${configDirectory}.`);
29
29
  }
30
30
  return {
31
- cliConfig: {
32
- }
31
+ cliConfig: {}
33
32
  };
34
33
  }
35
34
  let lowdefy;
36
35
  try {
37
- lowdefy = YAML.load(lowdefyYaml);
36
+ lowdefy = YAML.parse(lowdefyYaml);
38
37
  } catch (error) {
39
38
  throw new Error(`Could not parse "lowdefy.yaml" file. Received error ${error.message}.`);
40
39
  }
41
40
  if (!lowdefy.lowdefy) {
42
41
  throw new Error(`No version specified in "lowdefy.yaml" file. Specify a version in the "lowdefy" field.`);
43
42
  }
44
- if (!type.isString(lowdefy.lowdefy) || !lowdefy.lowdefy.match(/\d+\.\d+\.\d+(-\w+\.\d+)?/)) {
45
- throw new Error(`Version number specified in "lowdefy.yaml" file is not valid. Received ${JSON.stringify(lowdefy.lowdefy)}.`);
43
+ if (!type.isString(lowdefy.lowdefy)) {
44
+ throw new Error(`Version number specified in "lowdefy.yaml" file should be a string. Received ${JSON.stringify(lowdefy.lowdefy)}.`);
46
45
  }
47
46
  return {
48
47
  lowdefyVersion: lowdefy.lowdefy,
49
48
  cliConfig: get(lowdefy, 'cli', {
50
- default: {
51
- }
49
+ default: {}
52
50
  })
53
51
  };
54
52
  }
@@ -0,0 +1,54 @@
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
+ */ // Source https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/should-use-yarn.ts
16
+ /*
17
+ The MIT License (MIT)
18
+
19
+ Copyright (c) 2021 Vercel, Inc.
20
+
21
+ Permission is hereby granted, free of charge, to any person obtaining a copy
22
+ of this software and associated documentation files (the "Software"), to deal
23
+ in the Software without restriction, including without limitation the rights
24
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
+ copies of the Software, and to permit persons to whom the Software is
26
+ furnished to do so, subject to the following conditions:
27
+
28
+ The above copyright notice and this permission notice shall be included in all
29
+ copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
+ SOFTWARE.
38
+ */ import { execSync } from 'child_process';
39
+ function getPackageManager({ options }) {
40
+ if (options.packageManager) return options.packageManager;
41
+ try {
42
+ const userAgent = process.env.npm_config_user_agent;
43
+ if (userAgent && userAgent.startsWith('yarn')) {
44
+ return 'yarn';
45
+ }
46
+ execSync('yarnpkg --version', {
47
+ stdio: 'ignore'
48
+ });
49
+ return 'yarn';
50
+ } catch (e) {
51
+ return 'npm';
52
+ }
53
+ }
54
+ export default getPackageManager;
@@ -12,15 +12,23 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import axios from 'axios';
16
- function getSendTelemetry({ appId , cliVersion , command , lowdefyVersion , options }) {
15
+ */ import path from 'path';
16
+ import axios from 'axios';
17
+ import { readFile } from '@lowdefy/node-utils';
18
+ async function getTypes({ directories }) {
19
+ return JSON.parse(await readFile(path.join(directories.build, 'types.json')));
20
+ }
21
+ function getSendTelemetry({ appId , cliVersion , command , directories , lowdefyVersion , options }) {
17
22
  if (options.disableTelemetry) {
18
- return ()=>{
19
- };
23
+ return ()=>{};
20
24
  }
21
- async function sendTelemetry({ data ={
22
- } } = {
23
- }) {
25
+ async function sendTelemetry({ data ={} , sendTypes =false } = {}) {
26
+ let types;
27
+ if (sendTypes) {
28
+ types = await getTypes({
29
+ directories
30
+ });
31
+ }
24
32
  try {
25
33
  await axios.request({
26
34
  method: 'post',
@@ -33,7 +41,8 @@ function getSendTelemetry({ appId , cliVersion , command , lowdefyVersion , opti
33
41
  app_id: appId,
34
42
  cli_version: cliVersion,
35
43
  command,
36
- lowdefy_version: lowdefyVersion
44
+ lowdefy_version: lowdefyVersion,
45
+ types
37
46
  }
38
47
  });
39
48
  } catch (error) {
@@ -0,0 +1,45 @@
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
+ */ import fs from 'fs';
16
+ import path from 'path';
17
+ import { cleanDirectory, readFile } from '@lowdefy/node-utils';
18
+ import fetchNpmTarball from './fetchNpmTarball.js';
19
+ async function getServer({ context , packageName }) {
20
+ if (context.lowdefyVersion === 'local') {
21
+ context.print.warn(`Running local ${packageName}.`);
22
+ return;
23
+ }
24
+ let fetchServer = false;
25
+ const serverExists = fs.existsSync(path.join(context.directories.server, 'package.json'));
26
+ if (!serverExists) fetchServer = true;
27
+ if (serverExists) {
28
+ const serverPackageConfig = JSON.parse(await readFile(path.join(context.directories.server, 'package.json')));
29
+ if (serverPackageConfig.version !== context.lowdefyVersion) {
30
+ fetchServer = true;
31
+ context.print.warn(`Removing @lowdefy/server with version ${serverPackageConfig.version}`);
32
+ await cleanDirectory(context.directories.server);
33
+ }
34
+ }
35
+ if (fetchServer) {
36
+ context.print.spin('Fetching @lowdefy/server from npm.');
37
+ await fetchNpmTarball({
38
+ packageName,
39
+ version: context.lowdefyVersion,
40
+ directory: context.directories.server
41
+ });
42
+ context.print.log('Fetched @lowdefy/server from npm.');
43
+ }
44
+ }
45
+ export default getServer;
@@ -14,29 +14,28 @@
14
14
  limitations under the License.
15
15
  */ import errorHandler from './errorHandler.js';
16
16
  import startUp from './startUp.js';
17
- const runCommand = ({ cliVersion })=>(fn)=>{
18
- async function run(options, command) {
19
- const context = {
20
- cliVersion
21
- };
22
- try {
23
- await startUp({
24
- context,
25
- options,
26
- command
27
- });
28
- const res = await fn({
29
- context
30
- });
31
- return res;
32
- } catch (error) {
33
- await errorHandler({
34
- context,
35
- error
36
- });
37
- }
17
+ const runCommand = ({ cliVersion , handler })=>{
18
+ async function run(options, command) {
19
+ const context = {
20
+ cliVersion
21
+ };
22
+ try {
23
+ await startUp({
24
+ context,
25
+ options,
26
+ command
27
+ });
28
+ const res = await handler({
29
+ context
30
+ });
31
+ return res;
32
+ } catch (error) {
33
+ await errorHandler({
34
+ context,
35
+ error
36
+ });
38
37
  }
39
- return run;
40
38
  }
41
- ;
39
+ return run;
40
+ };
42
41
  export default runCommand;
@@ -19,22 +19,22 @@ import getCliJson from './getCliJson.js';
19
19
  import getDirectories from './getDirectories.js';
20
20
  import getLowdefyYaml from './getLowdefyYaml.js';
21
21
  import getOptions from './getOptions.js';
22
+ import getPackageManager from './getPackageManager.js';
22
23
  import getSendTelemetry from './getSendTelemetry.js';
23
- import createPrint from './print.js';
24
- async function startUp({ context , options ={
25
- } , command }) {
24
+ import createPrint from './createPrint.js';
25
+ async function startUp({ context , options ={} , command }) {
26
26
  context.command = command.name();
27
27
  context.commandLineOptions = options;
28
28
  context.print = createPrint();
29
- context.baseDirectory = path.resolve(options.baseDirectory || process.cwd());
29
+ context.configDirectory = path.resolve(options.configDirectory || process.cwd());
30
30
  const { cliConfig , lowdefyVersion } = await getLowdefyYaml(context);
31
31
  context.cliConfig = cliConfig;
32
32
  context.lowdefyVersion = lowdefyVersion;
33
33
  const { appId } = await getCliJson(context);
34
34
  context.appId = appId;
35
35
  context.options = getOptions(context);
36
- const { buildDirectory } = getDirectories(context);
37
- context.buildDirectory = buildDirectory;
36
+ context.directories = getDirectories(context);
37
+ context.packageManager = getPackageManager(context);
38
38
  await checkForUpdatedVersions(context);
39
39
  context.sendTelemetry = getSendTelemetry(context);
40
40
  if (type.isNone(lowdefyVersion)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lowdefy",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.7",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy CLI",
6
6
  "homepage": "https://lowdefy.com",
@@ -37,32 +37,29 @@
37
37
  "start": "yarn node ./dist/index.js",
38
38
  "prepare": "yarn build",
39
39
  "swc": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
40
- "test": "FORCE_COLOR=3 jest --coverage"
40
+ "test": "FORCE_COLOR=3 yarn node --experimental-vm-modules $(yarn bin jest)"
41
41
  },
42
42
  "dependencies": {
43
- "@lowdefy/helpers": "4.0.0-alpha.1",
44
- "@lowdefy/node-utils": "4.0.0-alpha.1",
45
- "axios": "0.24.0",
43
+ "@lowdefy/helpers": "4.0.0-alpha.7",
44
+ "@lowdefy/node-utils": "4.0.0-alpha.7",
45
+ "axios": "0.25.0",
46
46
  "chalk": "4.1.2",
47
- "chokidar": "3.5.2",
48
- "commander": "8.3.0",
47
+ "commander": "9.0.0",
49
48
  "decompress": "4.2.1",
50
49
  "decompress-targz": "4.1.1",
51
- "dotenv": "10.0.0",
52
- "js-yaml": "4.1.0",
53
- "opener": "1.5.2",
54
- "ora": "6.0.1",
55
- "reload": "3.2.0",
56
- "uuid": "8.3.2"
50
+ "ora": "5.4.1",
51
+ "uuid": "8.3.2",
52
+ "yaml": "2.0.0-10"
57
53
  },
58
54
  "devDependencies": {
59
- "@swc/cli": "0.1.52",
60
- "@swc/core": "1.2.112",
61
- "@swc/jest": "0.2.9",
62
- "jest": "27.3.1"
55
+ "@jest/globals": "27.5.1",
56
+ "@swc/cli": "0.1.55",
57
+ "@swc/core": "1.2.135",
58
+ "@swc/jest": "0.2.17",
59
+ "jest": "27.5.1"
63
60
  },
64
61
  "publishConfig": {
65
62
  "access": "public"
66
63
  },
67
- "gitHead": "c97a8fa6b5a641e7d50df09f5601a9c586eeb65a"
64
+ "gitHead": "52ec14639d00de910cf9b8ab25bf933ca891cff5"
68
65
  }
@@ -1,48 +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
- */ import path from 'path';
16
- import chokidar from 'chokidar';
17
- import BatchChanges from '../../utils/BatchChanges.js';
18
- function buildWatcher({ build , context , reloadFn }) {
19
- const { watch =[] , watchIgnore =[] } = context.options;
20
- const resolvedWatchPaths = watch.map((pathName)=>path.resolve(pathName)
21
- );
22
- const buildCallback = async ()=>{
23
- await build();
24
- reloadFn();
25
- };
26
- const buildBatchChanges = new BatchChanges({
27
- fn: buildCallback,
28
- context
29
- });
30
- const configWatcher = chokidar.watch([
31
- '.',
32
- ...resolvedWatchPaths
33
- ], {
34
- ignored: [
35
- /(^|[/\\])\../,
36
- ...watchIgnore,
37
- ],
38
- persistent: true,
39
- ignoreInitial: true
40
- });
41
- configWatcher.on('add', ()=>buildBatchChanges.newChange()
42
- );
43
- configWatcher.on('change', ()=>buildBatchChanges.newChange()
44
- );
45
- configWatcher.on('unlink', ()=>buildBatchChanges.newChange()
46
- );
47
- }
48
- export default buildWatcher;
@@ -1,32 +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
- */ import chokidar from 'chokidar';
16
- import BatchChanges from '../../utils/BatchChanges.js';
17
- function envWatcher({ context }) {
18
- const changeEnvCallback = async ()=>{
19
- context.print.warn('.env file changed. You should restart your development server.');
20
- process.exit();
21
- };
22
- const changeEnvBatchChanges = new BatchChanges({
23
- fn: changeEnvCallback,
24
- context
25
- });
26
- const envFileWatcher = chokidar.watch('./.env', {
27
- persistent: true
28
- });
29
- envFileWatcher.on('change', ()=>changeEnvBatchChanges.newChange()
30
- );
31
- }
32
- export default envWatcher;
@@ -1,37 +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
- */ import getFederatedModule from '../../utils/getFederatedModule';
16
- async function getBuild({ context }) {
17
- const { default: buildScript } = await getFederatedModule({
18
- module: 'build',
19
- packageName: '@lowdefy/build',
20
- version: context.lowdefyVersion,
21
- context
22
- });
23
- async function build() {
24
- context.print.log('Building configuration.');
25
- await buildScript({
26
- blocksServerUrl: context.options.blocksServerUrl,
27
- buildDirectory: context.buildDirectory,
28
- cacheDirectory: context.cacheDirectory,
29
- configDirectory: context.baseDirectory,
30
- logger: context.print,
31
- refResolver: context.options.refResolver
32
- });
33
- context.print.succeed('Built successfully.');
34
- }
35
- return build;
36
- }
37
- export default getBuild;
@@ -1,71 +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
- */ import path from 'path';
16
- import express from 'express';
17
- import reload from 'reload';
18
- import { get } from '@lowdefy/helpers';
19
- import { readFile } from '@lowdefy/node-utils';
20
- import findOpenPort from '../../utils/findOpenPort';
21
- async function getExpress({ context , gqlServer }) {
22
- const serveIndex = async (req, res)=>{
23
- let indexHtml = await readFile(path.resolve(__dirname, 'shell/index.html'));
24
- let appConfig = await readFile(path.resolve(context.buildDirectory, 'app.json'));
25
- appConfig = JSON.parse(appConfig);
26
- indexHtml = indexHtml.replace('<!-- __LOWDEFY_APP_HEAD_HTML__ -->', get(appConfig, 'html.appendHead', {
27
- default: ''
28
- }));
29
- indexHtml = indexHtml.replace('<!-- __LOWDEFY_APP_BODY_HTML__ -->', get(appConfig, 'html.appendBody', {
30
- default: ''
31
- }));
32
- res.send(indexHtml);
33
- };
34
- const app = express();
35
- // port is initialized to 3000 in prepare function
36
- app.set('port', parseInt(context.options.port));
37
- gqlServer.applyMiddleware({
38
- app,
39
- path: '/api/graphql'
40
- });
41
- const reloadPort = await findOpenPort();
42
- const reloadReturned = await reload(app, {
43
- route: '/api/dev/reload.js',
44
- port: reloadPort
45
- });
46
- // serve index.html with appended html
47
- // else static server serves without appended html
48
- app.get('/', serveIndex);
49
- // serve public files
50
- app.use('/public', express.static(path.resolve(process.cwd(), 'public')));
51
- // serve webpack files
52
- app.use(express.static(path.resolve(__dirname, 'shell')));
53
- // Serve rendererRemoteEntryUrl for renderer module federation
54
- app.use('/api/dev/rendererRemoteEntryUrl', (req, res)=>{
55
- let rendererRemoteEntryUrl;
56
- if (context.options.blocksServerUrl) {
57
- rendererRemoteEntryUrl = `${context.options.blocksServerUrl}/renderer/remoteEntry.js`;
58
- } else {
59
- rendererRemoteEntryUrl = `https://blocks-cdn.lowdefy.com/v${context.lowdefyVersion}/renderer/remoteEntry.js`;
60
- }
61
- res.json(rendererRemoteEntryUrl);
62
- });
63
- // Redirect all 404 to index.html with status 200
64
- // This should always be the last route
65
- app.use(serveIndex);
66
- return {
67
- expressApp: app,
68
- reloadFn: reloadReturned.reload
69
- };
70
- }
71
- export default getExpress;
@@ -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
- */ import { createGetSecretsFromEnv } from '@lowdefy/node-utils';
16
- import { ApolloServer } from 'apollo-server-express';
17
- import getFederatedModule from '../../utils/getFederatedModule';
18
- async function getGraphQl({ context }) {
19
- const { typeDefs , resolvers , createContext: createGqlContext , } = await getFederatedModule({
20
- module: 'graphql',
21
- packageName: '@lowdefy/graphql-federated',
22
- version: context.lowdefyVersion,
23
- context
24
- });
25
- const config = {
26
- CONFIGURATION_BASE_PATH: context.buildDirectory,
27
- development: true,
28
- logger: console,
29
- getSecrets: createGetSecretsFromEnv()
30
- };
31
- const gqlContext = createGqlContext(config);
32
- const server = new ApolloServer({
33
- typeDefs,
34
- resolvers,
35
- context: gqlContext
36
- });
37
- return server;
38
- }
39
- export default getGraphQl;
@@ -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
- */ import path from 'path';
16
- import dotenv from 'dotenv';
17
- import { cleanDirectory } from '@lowdefy/node-utils';
18
- async function prepare({ context }) {
19
- dotenv.config({
20
- silent: true
21
- });
22
- // Setup
23
- if (!context.options.port) context.options.port = 3000;
24
- context.print.log(`Cleaning block meta cache at "${path.resolve(context.cacheDirectory, './meta')}".`);
25
- await cleanDirectory(path.resolve(context.cacheDirectory, './meta'));
26
- }
27
- export default prepare;