lowdefy 4.0.0-alpha.5 → 4.0.0-alpha.6

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.
@@ -12,7 +12,7 @@
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 spawnProcess from '../../utils/spawnProcess.js';
15
+ */ import { spawnProcess } from '@lowdefy/node-utils';
16
16
  const args = {
17
17
  npm: [
18
18
  'install',
@@ -26,7 +26,7 @@ async function installServer({ context }) {
26
26
  context.print.spin(`Running ${context.packageManager} install.`);
27
27
  try {
28
28
  await spawnProcess({
29
- context,
29
+ logger: context.print,
30
30
  command: context.packageManager,
31
31
  args: args[context.packageManager],
32
32
  processOptions: {
@@ -12,12 +12,12 @@
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 spawnProcess from '../../utils/spawnProcess.js';
15
+ */ import { spawnProcess } from '@lowdefy/node-utils';
16
16
  async function runLowdefyBuild({ context }) {
17
17
  context.print.log('Running Lowdefy build.');
18
18
  try {
19
19
  await spawnProcess({
20
- context,
20
+ logger: context.print,
21
21
  command: context.packageManager,
22
22
  args: [
23
23
  'run',
@@ -27,9 +27,9 @@ async function runLowdefyBuild({ context }) {
27
27
  cwd: context.directories.server,
28
28
  env: {
29
29
  ...process.env,
30
- LOWDEFY_BUILD_DIRECTORY: context.directories.build,
31
- LOWDEFY_CONFIG_DIRECTORY: context.directories.base,
32
- LOWDEFY_SERVER_DIRECTORY: context.directories.server
30
+ LOWDEFY_DIRECTORY_BUILD: context.directories.build,
31
+ LOWDEFY_DIRECTORY_CONFIG: context.directories.base,
32
+ LOWDEFY_DIRECTORY_SERVER: context.directories.server
33
33
  }
34
34
  },
35
35
  silent: false
@@ -12,12 +12,12 @@
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 spawnProcess from '../../utils/spawnProcess.js';
15
+ */ import { spawnProcess } from '@lowdefy/node-utils';
16
16
  async function runNextBuild({ context }) {
17
17
  context.print.log('Running Next build.');
18
18
  try {
19
19
  await spawnProcess({
20
- context,
20
+ logger: context.print,
21
21
  command: context.packageManager,
22
22
  args: [
23
23
  'run',
@@ -12,69 +12,20 @@
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 opener from 'opener';
16
- import buildWatcher from './buildWatcher.js';
17
- import envWatcher from './envWatcher.js';
18
- import getBuild from './getBuild.js';
19
- import getExpress from './getExpress.js';
20
- import getGraphQL from './getGraphQL.js';
21
- import prepare from './prepare.js';
22
- import versionWatcher from './versionWatcher.js';
23
- async function initialBuild({ context }) {
24
- const build = await getBuild({
25
- context
26
- });
27
- try {
28
- await build();
29
- // eslint-disable-next-line no-empty
30
- } catch (error) {
31
- }
32
- return build;
33
- }
34
- async function serverSetup({ context }) {
35
- const gqlServer = await getGraphQL({
36
- context
37
- });
38
- return getExpress({
39
- context,
40
- gqlServer
41
- });
42
- }
15
+ */ import getServer from './getServer.js';
16
+ import installServer from './installServer.js';
17
+ import runDevServer from './runDevServer.js';
43
18
  async function dev({ context }) {
44
- await prepare({
19
+ context.print.info('Starting development server.');
20
+ await getServer({
45
21
  context
46
22
  });
47
- const initialBuildPromise = initialBuild({
23
+ await installServer({
48
24
  context
49
25
  });
50
- const serverSetupPromise = serverSetup({
26
+ context.sendTelemetry();
27
+ await runDevServer({
51
28
  context
52
29
  });
53
- const [build, { expressApp , reloadFn }] = await Promise.all([
54
- initialBuildPromise,
55
- serverSetupPromise,
56
- ]);
57
- buildWatcher({
58
- build,
59
- context,
60
- reloadFn
61
- });
62
- envWatcher({
63
- context
64
- });
65
- versionWatcher({
66
- context
67
- });
68
- context.print.log('Starting Lowdefy development server.');
69
- const port = expressApp.get('port');
70
- expressApp.listen(port, function() {
71
- context.print.info(`Development server listening on port ${port}`);
72
- });
73
- opener(`http://localhost:${port}`);
74
- await context.sendTelemetry({
75
- data: {
76
- type: 'startup'
77
- }
78
- });
79
30
  }
80
31
  export default dev;
@@ -0,0 +1,42 @@
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 '../../utils/fetchNpmTarball.js';
19
+ async function getServer({ context }) {
20
+ let fetchServer = false;
21
+ const serverExists = fs.existsSync(path.join(context.directories.devServer, 'package.json'));
22
+ if (!serverExists) fetchServer = true;
23
+ if (serverExists) {
24
+ const serverPackageConfig = JSON.parse(await readFile(path.join(context.directories.devServer, 'package.json')));
25
+ if (serverPackageConfig.version !== context.lowdefyVersion) {
26
+ fetchServer = true;
27
+ context.print.warn(`Removing @lowdefy/server-dev with version ${serverPackageConfig.version}`);
28
+ await cleanDirectory(context.directories.devServer);
29
+ }
30
+ }
31
+ if (fetchServer) {
32
+ context.print.spin('Fetching @lowdefy/server-dev from npm.');
33
+ await fetchNpmTarball({
34
+ packageName: '@lowdefy/server-dev',
35
+ version: context.lowdefyVersion,
36
+ directory: context.directories.devServer
37
+ });
38
+ context.print.log('Fetched @lowdefy/server-dev from npm.');
39
+ return;
40
+ }
41
+ }
42
+ export default getServer;
@@ -0,0 +1,43 @@
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 { spawnProcess } from '@lowdefy/node-utils';
16
+ const args = {
17
+ npm: [
18
+ 'install',
19
+ '--legacy-peer-deps'
20
+ ],
21
+ yarn: [
22
+ 'install'
23
+ ]
24
+ };
25
+ async function installServer({ context }) {
26
+ context.print.spin(`Running ${context.packageManager} install.`);
27
+ try {
28
+ await spawnProcess({
29
+ logger: context.print,
30
+ command: context.packageManager,
31
+ args: args[context.packageManager],
32
+ processOptions: {
33
+ cwd: context.directories.devServer
34
+ },
35
+ silent: false
36
+ });
37
+ } catch (error) {
38
+ console.log(error);
39
+ throw new Error(`${context.packageManager} install failed.`);
40
+ }
41
+ context.print.log(`${context.packageManager} install successful.`);
42
+ }
43
+ export default installServer;
@@ -12,16 +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 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
15
+ */ import { spawnProcess } from '@lowdefy/node-utils';
16
+ async function runDevServer({ context }) {
17
+ await spawnProcess({
18
+ logger: context.print,
19
+ args: [
20
+ 'run',
21
+ 'start'
22
+ ],
23
+ command: context.packageManager,
24
+ processOptions: {
25
+ cwd: context.directories.devServer,
26
+ env: {
27
+ ...process.env,
28
+ LOWDEFY_DIRECTORY_CONFIG: context.directories.base
29
+ }
30
+ },
31
+ silent: false
21
32
  });
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
33
  }
27
- export default prepare;
34
+ export default runDevServer;
@@ -12,16 +12,16 @@
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 spawnProcess from '../../utils/spawnProcess.js';
15
+ */ import { spawnProcess } from '@lowdefy/node-utils';
16
16
  async function runStart({ context }) {
17
17
  context.print.spin(`Running "${context.packageManager} run start".`);
18
18
  await spawnProcess({
19
- context,
20
- command: context.packageManager,
19
+ logger: context.print,
21
20
  args: [
22
21
  'run',
23
22
  'start'
24
23
  ],
24
+ command: context.packageManager,
25
25
  processOptions: {
26
26
  cwd: context.directories.server
27
27
  },
@@ -13,6 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import runStart from './runStart.js';
16
+ // TODO: Handle "spawn yarn ENOENT" error if no built server exists.
16
17
  async function build({ context }) {
17
18
  context.print.info('Starting server.');
18
19
  context.sendTelemetry({
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@
16
16
  */ import { readFile } from '@lowdefy/node-utils';
17
17
  import program from 'commander';
18
18
  import build from './commands/build/build.js';
19
- // import dev from './commands/dev/dev.js';
19
+ import dev from './commands/dev/dev.js';
20
20
  import init from './commands/init/init.js';
21
21
  import start from './commands/start/start.js';
22
22
  import runCommand from './utils/runCommand.js';
@@ -26,33 +26,13 @@ program.name('lowdefy').description(description).version(version, '-v, --version
26
26
  program.command('build').description('Build a Lowdefy production app.').usage(`[options]`).option('--base-directory <base-directory>', 'Change base directory. Default is the current working directory.').option('--disable-telemetry', 'Disable telemetry.').option('--output-directory <output-directory>', 'Change the directory to which build artifacts are saved. Default is "<base-directory>/.lowdefy".').option('--package-manager <package-manager>', 'The package manager to use. Options are "npm" or "yarn".').option('--ref-resolver <ref-resolver-function-path>', 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.').action(runCommand({
27
27
  cliVersion: version
28
28
  })(build));
29
- // program
30
- // .command('dev')
31
- // .description('Start a Lowdefy development server.')
32
- // .usage(`[options]`)
33
- // .option(
34
- // '--base-directory <base-directory>',
35
- // 'Change base directory. Default is the current working directory.'
36
- // )
37
- // .option(
38
- // '--blocks-server-url <blocks-server-url>',
39
- // 'The URL from where Lowdefy blocks will be served.'
40
- // )
41
- // .option('--disable-telemetry', 'Disable telemetry.')
42
- // .option('--port <port>', 'Change the port the server is hosted at. Default is 3000.')
43
- // .option(
44
- // '--ref-resolver <ref-resolver-function-path>',
45
- // 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.'
46
- // )
47
- // .option(
48
- // '--watch <paths...>',
49
- // 'A list of paths to files or directories that should be watched for changes.'
50
- // )
51
- // .option(
52
- // '--watch-ignore <paths...>',
53
- // 'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported.'
54
- // )
55
- // .action(runCommand({ cliVersion: version })(dev));
29
+ program.command('dev').description('Start a Lowdefy development server.').usage(`[options]`).option('--base-directory <base-directory>', 'Change base directory. Default is the current working directory.').option('--disable-telemetry', 'Disable telemetry.').option('--package-manager <package-manager>', 'The package manager to use. Options are "npm" or "yarn".')// TODO:
30
+ .option('--port <port>', 'Change the port the server is hosted at. Default is 3000.')// TODO:
31
+ .option('--ref-resolver <ref-resolver-function-path>', 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.')// TODO:
32
+ .option('--watch <paths...>', 'A list of paths to files or directories that should be watched for changes.')// TODO:
33
+ .option('--watch-ignore <paths...>', 'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported.').action(runCommand({
34
+ cliVersion: version
35
+ })(dev));
56
36
  program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).action(runCommand({
57
37
  cliVersion: version
58
38
  })(init));
@@ -13,7 +13,8 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ let BatchChanges = class BatchChanges {
16
- newChange() {
16
+ newChange(...args) {
17
+ this.args.push(args);
17
18
  this.delay = this.minDelay;
18
19
  this._startTimer();
19
20
  }
@@ -21,28 +22,40 @@
21
22
  if (this.timer) {
22
23
  clearTimeout(this.timer);
23
24
  }
24
- this.timer = setTimeout(this._call, this.delay);
25
+ if (this.running) {
26
+ this.repeat = true;
27
+ } else {
28
+ this.timer = setTimeout(this._call, this.delay);
29
+ }
25
30
  }
26
31
  async _call() {
32
+ this.running = true;
27
33
  try {
28
- await this.fn();
34
+ const args = this.args;
35
+ this.args = [];
36
+ await this.fn(args);
37
+ this.running = false;
38
+ if (this.repeat) {
39
+ this.repeat = false;
40
+ this._call();
41
+ }
29
42
  } catch (error) {
30
- this.context.print.error(error.message, {
31
- timestamp: true
32
- });
43
+ this.running = false;
44
+ this.context.print.error(error.message);
33
45
  this.delay *= 2;
34
- this.context.print.warn(`Retrying in ${this.delay / 1000}s.`, {
35
- timestamp: true
36
- });
46
+ this.context.print.warn(`Retrying in ${this.delay / 1000}s.`);
37
47
  this._startTimer();
38
48
  }
39
49
  }
40
50
  constructor({ fn , context , minDelay }){
41
- this.fn = fn;
51
+ this._call = this._call.bind(this);
52
+ this.args = [];
42
53
  this.context = context;
43
54
  this.delay = minDelay || 500;
55
+ this.fn = fn;
44
56
  this.minDelay = minDelay || 500;
45
- this._call = this._call.bind(this);
57
+ this.repeat = false;
58
+ this.running = false;
46
59
  }
47
60
  };
48
61
  export default BatchChanges;
@@ -14,8 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import axios from 'axios';
16
16
  import createPrint from './print.js';
17
- async function logError({ error , context ={
18
- } }) {
17
+ async function logError({ error , context ={} }) {
19
18
  try {
20
19
  await axios.request({
21
20
  method: 'post',
@@ -24,7 +24,8 @@ function getDirectories({ baseDirectory , options }) {
24
24
  base: baseDirectory,
25
25
  build: path.join(dotLowdefy, 'server', 'build'),
26
26
  dotLowdefy,
27
- server: path.join(dotLowdefy, 'server')
27
+ server: path.join(dotLowdefy, 'server'),
28
+ devServer: path.join(dotLowdefy, 'dev')
28
29
  };
29
30
  }
30
31
  export default getDirectories;
@@ -28,8 +28,7 @@ async function getLowdefyYaml({ baseDirectory , command }) {
28
28
  throw new Error(`Could not find "lowdefy.yaml" file in specified base directory ${baseDirectory}.`);
29
29
  }
30
30
  return {
31
- cliConfig: {
32
- }
31
+ cliConfig: {}
33
32
  };
34
33
  }
35
34
  let lowdefy;
@@ -47,8 +46,7 @@ async function getLowdefyYaml({ baseDirectory , command }) {
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
  }
@@ -20,12 +20,9 @@ async function getTypes({ directories }) {
20
20
  }
21
21
  function getSendTelemetry({ appId , cliVersion , command , directories , lowdefyVersion , options }) {
22
22
  if (options.disableTelemetry) {
23
- return ()=>{
24
- };
23
+ return ()=>{};
25
24
  }
26
- async function sendTelemetry({ data ={
27
- } , sendTypes =false } = {
28
- }) {
25
+ async function sendTelemetry({ data ={} , sendTypes =false } = {}) {
29
26
  let types;
30
27
  if (sendTypes) {
31
28
  types = await getTypes({
@@ -22,8 +22,7 @@ import getOptions from './getOptions.js';
22
22
  import getPackageManager from './getPackageManager.js';
23
23
  import getSendTelemetry from './getSendTelemetry.js';
24
24
  import createPrint from './print.js';
25
- async function startUp({ context , options ={
26
- } , command }) {
25
+ async function startUp({ context , options ={} , command }) {
27
26
  context.command = command.name();
28
27
  context.commandLineOptions = options;
29
28
  context.print = createPrint();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lowdefy",
3
- "version": "4.0.0-alpha.5",
3
+ "version": "4.0.0-alpha.6",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy CLI",
6
6
  "homepage": "https://lowdefy.com",
@@ -40,29 +40,25 @@
40
40
  "test": "FORCE_COLOR=3 jest --coverage"
41
41
  },
42
42
  "dependencies": {
43
- "@lowdefy/helpers": "4.0.0-alpha.5",
44
- "@lowdefy/node-utils": "4.0.0-alpha.5",
43
+ "@lowdefy/helpers": "4.0.0-alpha.6",
44
+ "@lowdefy/node-utils": "4.0.0-alpha.6",
45
45
  "axios": "0.24.0",
46
46
  "chalk": "4.1.2",
47
- "chokidar": "3.5.2",
48
47
  "commander": "8.3.0",
49
48
  "decompress": "4.2.1",
50
49
  "decompress-targz": "4.1.1",
51
- "dotenv": "10.0.0",
52
50
  "js-yaml": "4.1.0",
53
- "opener": "1.5.2",
54
51
  "ora": "6.0.1",
55
- "reload": "3.2.0",
56
52
  "uuid": "8.3.2"
57
53
  },
58
54
  "devDependencies": {
59
- "@swc/cli": "0.1.52",
60
- "@swc/core": "1.2.112",
61
- "@swc/jest": "0.2.9",
55
+ "@swc/cli": "0.1.55",
56
+ "@swc/core": "1.2.130",
57
+ "@swc/jest": "0.2.17",
62
58
  "jest": "27.3.1"
63
59
  },
64
60
  "publishConfig": {
65
61
  "access": "public"
66
62
  },
67
- "gitHead": "995fcdb020927f3cdc626fc99c15a2e4137bd962"
63
+ "gitHead": "2530e31af795b6a3c75ac8f72c8dbe0ab5d1251b"
68
64
  }
@@ -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,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
- */ import chokidar from 'chokidar';
16
- import BatchChanges from '../../utils/BatchChanges';
17
- import getLowdefyYaml from '../../utils/getLowdefyYaml';
18
- function versionWatcher({ context }) {
19
- const changeLowdefyFileCallback = async ()=>{
20
- const { lowdefyVersion } = await getLowdefyYaml(context);
21
- if (lowdefyVersion !== context.lowdefyVersion) {
22
- context.print.warn('Lowdefy version changed. You should restart your development server.');
23
- process.exit();
24
- }
25
- };
26
- const changeLowdefyFileBatchChanges = new BatchChanges({
27
- fn: changeLowdefyFileCallback,
28
- context
29
- });
30
- const lowdefyFileWatcher = chokidar.watch('./lowdefy.yaml', {
31
- persistent: true
32
- });
33
- lowdefyFileWatcher.on('change', ()=>changeLowdefyFileBatchChanges.newChange()
34
- );
35
- }
36
- export default versionWatcher;
@@ -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 { spawn } from 'child_process';
16
- async function spawnProcess({ context , command , args , processOptions , silent }) {
17
- return new Promise((resolve, reject)=>{
18
- const process = spawn(command, args, processOptions);
19
- process.stdout.on('data', (data)=>{
20
- if (!silent) {
21
- data.toString('utf8').split('\n').forEach((line)=>{
22
- if (line) {
23
- context.print.log(line);
24
- }
25
- });
26
- }
27
- });
28
- process.stderr.on('data', (data)=>{
29
- if (!silent) {
30
- data.toString('utf8').split('\n').forEach((line)=>{
31
- if (line) {
32
- context.print.warn(line);
33
- }
34
- });
35
- }
36
- });
37
- process.on('error', (error)=>{
38
- reject(error);
39
- });
40
- process.on('exit', (code)=>{
41
- if (code !== 0) {
42
- reject(new Error(`${command} exited with code ${code}`));
43
- }
44
- resolve();
45
- });
46
- });
47
- }
48
- export default spawnProcess;