lowdefy 4.0.0-alpha.5 → 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.
- package/dist/commands/build/build.js +26 -9
- package/dist/commands/dev/dev.js +23 -57
- package/dist/commands/dev/runDevServer.js +39 -0
- package/dist/commands/init/init.js +5 -11
- package/dist/commands/init/lowdefyFile.js +1 -1
- package/dist/commands/start/runStart.js +10 -5
- package/dist/commands/start/start.js +3 -1
- package/dist/index.js +20 -39
- package/dist/utils/BatchChanges.js +24 -11
- package/dist/utils/addCustomPluginsAsDeps.js +32 -0
- package/dist/{commands/dev/prepare.js → utils/copyPluginsFolder.js} +7 -11
- package/dist/utils/{print.js → createPrint.js} +0 -0
- package/dist/utils/errorHandler.js +2 -3
- package/dist/utils/getCliJson.js +5 -8
- package/dist/utils/getDirectories.js +5 -4
- package/dist/utils/getLowdefyYaml.js +12 -10
- package/dist/utils/getSendTelemetry.js +2 -5
- package/dist/{commands/build → utils}/getServer.js +14 -11
- package/dist/{commands/build → utils}/installServer.js +4 -4
- package/dist/utils/runCommand.js +22 -23
- package/dist/{commands/build → utils}/runLowdefyBuild.js +8 -7
- package/dist/{commands/build → utils}/runNextBuild.js +4 -4
- package/dist/utils/startUp.js +5 -5
- package/package.json +15 -18
- package/dist/commands/dev/buildWatcher.js +0 -48
- package/dist/commands/dev/envWatcher.js +0 -32
- package/dist/commands/dev/getBuild.js +0 -37
- package/dist/commands/dev/getExpress.js +0 -71
- package/dist/commands/dev/getGraphQL.js +0 -39
- package/dist/commands/dev/versionWatcher.js +0 -36
- package/dist/utils/spawnProcess.js +0 -48
|
@@ -12,26 +12,43 @@
|
|
|
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
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
15
|
+
*/ import addCustomPluginsAsDeps from '../../utils/addCustomPluginsAsDeps.js';
|
|
16
|
+
import copyPluginsFolder from '../../utils/copyPluginsFolder.js';
|
|
17
|
+
import getServer from '../../utils/getServer.js';
|
|
18
|
+
import installServer from '../../utils/installServer.js';
|
|
19
|
+
import runLowdefyBuild from '../../utils/runLowdefyBuild.js';
|
|
20
|
+
import runNextBuild from '../../utils/runNextBuild.js';
|
|
19
21
|
async function build({ context }) {
|
|
20
22
|
context.print.info('Starting build.');
|
|
23
|
+
const directory = context.directories.server;
|
|
21
24
|
await getServer({
|
|
22
|
-
context
|
|
25
|
+
context,
|
|
26
|
+
packageName: '@lowdefy/server',
|
|
27
|
+
directory
|
|
28
|
+
});
|
|
29
|
+
await copyPluginsFolder({
|
|
30
|
+
context,
|
|
31
|
+
directory
|
|
32
|
+
});
|
|
33
|
+
await addCustomPluginsAsDeps({
|
|
34
|
+
context,
|
|
35
|
+
directory
|
|
23
36
|
});
|
|
24
37
|
await installServer({
|
|
25
|
-
context
|
|
38
|
+
context,
|
|
39
|
+
directory
|
|
26
40
|
});
|
|
27
41
|
await runLowdefyBuild({
|
|
28
|
-
context
|
|
42
|
+
context,
|
|
43
|
+
directory
|
|
29
44
|
});
|
|
30
45
|
await installServer({
|
|
31
|
-
context
|
|
46
|
+
context,
|
|
47
|
+
directory
|
|
32
48
|
});
|
|
33
49
|
await runNextBuild({
|
|
34
|
-
context
|
|
50
|
+
context,
|
|
51
|
+
directory
|
|
35
52
|
});
|
|
36
53
|
await context.sendTelemetry({
|
|
37
54
|
sendTypes: true
|
package/dist/commands/dev/dev.js
CHANGED
|
@@ -12,69 +12,35 @@
|
|
|
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
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
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 addCustomPluginsAsDeps from '../../utils/addCustomPluginsAsDeps.js';
|
|
16
|
+
import copyPluginsFolder from '../../utils/copyPluginsFolder.js';
|
|
17
|
+
import installServer from '../../utils/installServer.js';
|
|
18
|
+
import runDevServer from './runDevServer.js';
|
|
19
|
+
import getServer from '../../utils/getServer.js';
|
|
43
20
|
async function dev({ context }) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const initialBuildPromise = initialBuild({
|
|
48
|
-
context
|
|
49
|
-
});
|
|
50
|
-
const serverSetupPromise = serverSetup({
|
|
51
|
-
context
|
|
52
|
-
});
|
|
53
|
-
const [build, { expressApp , reloadFn }] = await Promise.all([
|
|
54
|
-
initialBuildPromise,
|
|
55
|
-
serverSetupPromise,
|
|
56
|
-
]);
|
|
57
|
-
buildWatcher({
|
|
58
|
-
build,
|
|
21
|
+
const directory = context.directories.dev;
|
|
22
|
+
context.print.info('Starting development server.');
|
|
23
|
+
await getServer({
|
|
59
24
|
context,
|
|
60
|
-
|
|
25
|
+
packageName: '@lowdefy/server-dev',
|
|
26
|
+
directory
|
|
61
27
|
});
|
|
62
|
-
|
|
63
|
-
context
|
|
28
|
+
await copyPluginsFolder({
|
|
29
|
+
context,
|
|
30
|
+
directory
|
|
64
31
|
});
|
|
65
|
-
|
|
66
|
-
context
|
|
32
|
+
await addCustomPluginsAsDeps({
|
|
33
|
+
context,
|
|
34
|
+
directory
|
|
67
35
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
context.print.info(`Development server listening on port ${port}`);
|
|
36
|
+
await installServer({
|
|
37
|
+
context,
|
|
38
|
+
directory
|
|
72
39
|
});
|
|
73
|
-
|
|
74
|
-
await
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
40
|
+
context.sendTelemetry();
|
|
41
|
+
await runDevServer({
|
|
42
|
+
context,
|
|
43
|
+
directory
|
|
78
44
|
});
|
|
79
45
|
}
|
|
80
46
|
export default dev;
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
async function runDevServer({ context , directory }) {
|
|
17
|
+
await spawnProcess({
|
|
18
|
+
logger: context.print,
|
|
19
|
+
args: [
|
|
20
|
+
'run',
|
|
21
|
+
'start'
|
|
22
|
+
],
|
|
23
|
+
command: context.packageManager,
|
|
24
|
+
processOptions: {
|
|
25
|
+
cwd: directory,
|
|
26
|
+
env: {
|
|
27
|
+
...process.env,
|
|
28
|
+
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
|
29
|
+
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
30
|
+
LOWDEFY_PACKAGE_MANAGER: context.packageManager,
|
|
31
|
+
LOWDEFY_SERVER_DEV_WATCH: JSON.stringify(context.options.watch),
|
|
32
|
+
LOWDEFY_SERVER_DEV_WATCH_IGNORE: JSON.stringify(context.options.watchIgnore),
|
|
33
|
+
PORT: context.options.port
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
silent: false
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export default runDevServer;
|
|
@@ -23,18 +23,12 @@ async function init({ context }) {
|
|
|
23
23
|
throw new Error('Cannot initialize a Lowdefy project, a "lowdefy.yaml" file already exists');
|
|
24
24
|
}
|
|
25
25
|
context.print.log(`Initializing Lowdefy project`);
|
|
26
|
-
await writeFile({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
version: context.cliVersion
|
|
30
|
-
})
|
|
31
|
-
});
|
|
26
|
+
await writeFile(lowdefyFilePath, lowdefyFile({
|
|
27
|
+
version: context.cliVersion
|
|
28
|
+
}));
|
|
32
29
|
context.print.log(`Created 'lowdefy.yaml'.`);
|
|
33
|
-
await writeFile(
|
|
34
|
-
|
|
35
|
-
content: `.lowdefy/**
|
|
36
|
-
.env`
|
|
37
|
-
});
|
|
30
|
+
await writeFile(path.resolve('./.gitignore'), `.lowdefy/**
|
|
31
|
+
.env`);
|
|
38
32
|
context.print.log(`Created '.gitignore'.`);
|
|
39
33
|
await context.sendTelemetry();
|
|
40
34
|
context.print.succeed(`Project initialized.`);
|
|
@@ -12,18 +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 spawnProcess from '
|
|
16
|
-
async function runStart({ context }) {
|
|
15
|
+
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
async function runStart({ context , directory }) {
|
|
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
|
-
cwd:
|
|
26
|
+
cwd: directory,
|
|
27
|
+
env: {
|
|
28
|
+
...process.env,
|
|
29
|
+
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
30
|
+
PORT: context.options.port
|
|
31
|
+
}
|
|
27
32
|
},
|
|
28
33
|
silent: false
|
|
29
34
|
});
|
|
@@ -13,13 +13,15 @@
|
|
|
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({
|
|
19
20
|
sendTypes: true
|
|
20
21
|
});
|
|
21
22
|
await runStart({
|
|
22
|
-
context
|
|
23
|
+
context,
|
|
24
|
+
directory: context.directories.server
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
export default build;
|
package/dist/index.js
CHANGED
|
@@ -14,49 +14,30 @@
|
|
|
14
14
|
See the License for the specific language governing permissions and
|
|
15
15
|
limitations under the License.
|
|
16
16
|
*/ import { readFile } from '@lowdefy/node-utils';
|
|
17
|
-
import
|
|
17
|
+
import { Command } from 'commander';
|
|
18
18
|
import build from './commands/build/build.js';
|
|
19
|
-
|
|
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';
|
|
23
23
|
const packageJson = JSON.parse(await readFile(new URL('../package.json', import.meta.url).pathname));
|
|
24
|
-
const { description , version } = packageJson;
|
|
25
|
-
program
|
|
26
|
-
program.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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));
|
|
24
|
+
const { description , version: cliVersion } = packageJson;
|
|
25
|
+
const program = new Command();
|
|
26
|
+
program.name('lowdefy').description(description).version(cliVersion, '-v, --version');
|
|
27
|
+
program.command('build').description('Build a Lowdefy production app.').usage(`[options]`).option('--config-directory <config-directory>', 'Change config 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 "<config-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.').option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').action(runCommand({
|
|
28
|
+
cliVersion,
|
|
29
|
+
handler: build
|
|
30
|
+
}));
|
|
31
|
+
program.command('dev').description('Start a Lowdefy development server.').usage(`[options]`).option('--config-directory <config-directory>', 'Change config 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".').option('--port <port>', 'Change the port the development server is hosted at. Default is 3000.').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.').option('--watch <paths...>', 'A list of paths to files or directories that should be watched for changes. Globs are supported. Specify each path to watch separated by spaces.').option('--watch-ignore <paths...>', 'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported. Specify each path to watch separated by spaces.').option('--dev-directory <dev-directory>', 'Change the development server directory. Default is "<config-directory>/.lowdefy/dev".').action(runCommand({
|
|
32
|
+
cliVersion,
|
|
33
|
+
handler: dev
|
|
34
|
+
}));
|
|
56
35
|
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).action(runCommand({
|
|
57
|
-
cliVersion
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
36
|
+
cliVersion,
|
|
37
|
+
handler: init
|
|
38
|
+
}));
|
|
39
|
+
program.command('start').description('Start a Lowdefy production app.').usage(`[options]`).option('--config-directory <config-directory>', 'Change config 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 "<config-directory>/.lowdefy".').option('--package-manager <package-manager>', 'The package manager to use. Options are "npm" or "yarn".').option('--port <port>', 'Change the port the server is hosted at. Default is 3000.').option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').action(runCommand({
|
|
40
|
+
cliVersion,
|
|
41
|
+
handler: start
|
|
42
|
+
}));
|
|
62
43
|
program.parse(process.argv);
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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.
|
|
31
|
-
|
|
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.
|
|
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.
|
|
57
|
+
this.repeat = false;
|
|
58
|
+
this.running = false;
|
|
46
59
|
}
|
|
47
60
|
};
|
|
48
61
|
export default BatchChanges;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { readFile, writeFile } from '@lowdefy/node-utils';
|
|
17
|
+
async function addCustomPluginsAsDeps({ context , directory }) {
|
|
18
|
+
const packageJsonPath = path.join(directory, 'package.json');
|
|
19
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath));
|
|
20
|
+
const devDependencies = packageJson.devDependencies;
|
|
21
|
+
Object.values(context.plugins).forEach((plugin)=>{
|
|
22
|
+
devDependencies[plugin.name] = plugin.version;
|
|
23
|
+
});
|
|
24
|
+
// Sort dependencies
|
|
25
|
+
packageJson.devDependencies = {};
|
|
26
|
+
Object.keys(devDependencies).sort().forEach((name)=>{
|
|
27
|
+
packageJson.devDependencies[name] = devDependencies[name];
|
|
28
|
+
});
|
|
29
|
+
const newPackageJsonContent = JSON.stringify(packageJson, null, 2).concat('\n');
|
|
30
|
+
await writeFile(packageJsonPath, newPackageJsonContent);
|
|
31
|
+
}
|
|
32
|
+
export default addCustomPluginsAsDeps;
|
|
@@ -13,15 +13,11 @@
|
|
|
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
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
async function
|
|
19
|
-
|
|
20
|
-
|
|
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'));
|
|
16
|
+
import fs from 'fs';
|
|
17
|
+
import { copyDirectory } from '@lowdefy/node-utils';
|
|
18
|
+
async function copyPluginsFolder({ context , directory }) {
|
|
19
|
+
if (context.directories.config === directory) return;
|
|
20
|
+
if (!fs.existsSync(path.resolve(context.directories.config, 'plugins'))) return;
|
|
21
|
+
await copyDirectory(path.resolve(context.directories.config, 'plugins'), path.resolve(directory, 'plugins'));
|
|
26
22
|
}
|
|
27
|
-
export default
|
|
23
|
+
export default copyPluginsFolder;
|
|
File without changes
|
|
@@ -13,9 +13,8 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import axios from 'axios';
|
|
16
|
-
import createPrint from './
|
|
17
|
-
async function logError({ error , context ={
|
|
18
|
-
} }) {
|
|
16
|
+
import createPrint from './createPrint.js';
|
|
17
|
+
async function logError({ error , context ={} }) {
|
|
19
18
|
try {
|
|
20
19
|
await axios.request({
|
|
21
20
|
method: 'post',
|
package/dist/utils/getCliJson.js
CHANGED
|
@@ -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({
|
|
19
|
-
const filePath = path.resolve(
|
|
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
|
-
|
|
25
|
-
|
|
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,18 +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({
|
|
16
|
+
function getDirectories({ configDirectory , options }) {
|
|
17
17
|
let dotLowdefy;
|
|
18
18
|
if (options.outputDirectory) {
|
|
19
19
|
dotLowdefy = path.resolve(options.outputDirectory);
|
|
20
20
|
} else {
|
|
21
|
-
dotLowdefy = path.resolve(
|
|
21
|
+
dotLowdefy = path.resolve(configDirectory, '.lowdefy');
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
|
-
|
|
24
|
+
config: configDirectory,
|
|
25
25
|
build: path.join(dotLowdefy, 'server', 'build'),
|
|
26
26
|
dotLowdefy,
|
|
27
|
-
server: path.join(dotLowdefy, 'server')
|
|
27
|
+
server: options.serverDirectory ? path.resolve(options.serverDirectory) : path.join(dotLowdefy, 'server'),
|
|
28
|
+
dev: options.devDirectory ? path.resolve(options.devDirectory) : path.join(dotLowdefy, 'dev')
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
export default getDirectories;
|
|
@@ -15,26 +15,25 @@
|
|
|
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 '
|
|
19
|
-
async function getLowdefyYaml({
|
|
20
|
-
let lowdefyYaml = await readFile(path.
|
|
18
|
+
import YAML from 'yaml';
|
|
19
|
+
async function getLowdefyYaml({ configDirectory , command }) {
|
|
20
|
+
let lowdefyYaml = await readFile(path.join(configDirectory, 'lowdefy.yaml'));
|
|
21
21
|
if (!lowdefyYaml) {
|
|
22
|
-
lowdefyYaml = await readFile(path.
|
|
22
|
+
lowdefyYaml = await readFile(path.join(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
|
|
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.
|
|
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
|
}
|
|
@@ -44,11 +43,14 @@ async function getLowdefyYaml({ baseDirectory , command }) {
|
|
|
44
43
|
if (!type.isString(lowdefy.lowdefy)) {
|
|
45
44
|
throw new Error(`Version number specified in "lowdefy.yaml" file should be a string. Received ${JSON.stringify(lowdefy.lowdefy)}.`);
|
|
46
45
|
}
|
|
46
|
+
// TODO: Validate plugins
|
|
47
47
|
return {
|
|
48
48
|
lowdefyVersion: lowdefy.lowdefy,
|
|
49
49
|
cliConfig: get(lowdefy, 'cli', {
|
|
50
|
-
default: {
|
|
51
|
-
|
|
50
|
+
default: {}
|
|
51
|
+
}),
|
|
52
|
+
plugins: get(lowdefy, 'plugins', {
|
|
53
|
+
default: []
|
|
52
54
|
})
|
|
53
55
|
};
|
|
54
56
|
}
|
|
@@ -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({
|
|
@@ -15,28 +15,31 @@
|
|
|
15
15
|
*/ import fs from 'fs';
|
|
16
16
|
import path from 'path';
|
|
17
17
|
import { cleanDirectory, readFile } from '@lowdefy/node-utils';
|
|
18
|
-
import fetchNpmTarball from '
|
|
19
|
-
async function getServer({ context }) {
|
|
18
|
+
import fetchNpmTarball from './fetchNpmTarball.js';
|
|
19
|
+
async function getServer({ context , packageName , directory }) {
|
|
20
|
+
if (context.lowdefyVersion === 'local') {
|
|
21
|
+
context.print.warn(`Running local ${packageName}.`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
20
24
|
let fetchServer = false;
|
|
21
|
-
const serverExists = fs.existsSync(path.join(
|
|
25
|
+
const serverExists = fs.existsSync(path.join(directory, 'package.json'));
|
|
22
26
|
if (!serverExists) fetchServer = true;
|
|
23
27
|
if (serverExists) {
|
|
24
|
-
const serverPackageConfig = JSON.parse(await readFile(path.join(
|
|
28
|
+
const serverPackageConfig = JSON.parse(await readFile(path.join(directory, 'package.json')));
|
|
25
29
|
if (serverPackageConfig.version !== context.lowdefyVersion) {
|
|
26
30
|
fetchServer = true;
|
|
27
|
-
context.print.warn(`Removing
|
|
28
|
-
await cleanDirectory(
|
|
31
|
+
context.print.warn(`Removing ${packageName} with version ${serverPackageConfig.version}`);
|
|
32
|
+
await cleanDirectory(directory);
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
if (fetchServer) {
|
|
32
|
-
context.print.spin(
|
|
36
|
+
context.print.spin(`Fetching ${packageName} from npm.`);
|
|
33
37
|
await fetchNpmTarball({
|
|
34
|
-
packageName
|
|
38
|
+
packageName,
|
|
35
39
|
version: context.lowdefyVersion,
|
|
36
|
-
directory:
|
|
40
|
+
directory: directory
|
|
37
41
|
});
|
|
38
|
-
context.print.log(
|
|
39
|
-
return;
|
|
42
|
+
context.print.log(`Fetched ${packageName} from npm.`);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
export default getServer;
|
|
@@ -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 '
|
|
15
|
+
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
16
|
const args = {
|
|
17
17
|
npm: [
|
|
18
18
|
'install',
|
|
@@ -22,15 +22,15 @@ const args = {
|
|
|
22
22
|
'install'
|
|
23
23
|
]
|
|
24
24
|
};
|
|
25
|
-
async function installServer({ context }) {
|
|
25
|
+
async function installServer({ context , directory }) {
|
|
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: {
|
|
33
|
-
cwd:
|
|
33
|
+
cwd: directory
|
|
34
34
|
},
|
|
35
35
|
silent: false
|
|
36
36
|
});
|
package/dist/utils/runCommand.js
CHANGED
|
@@ -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 })=>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
|
@@ -12,24 +12,25 @@
|
|
|
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 '
|
|
16
|
-
async function runLowdefyBuild({ context }) {
|
|
15
|
+
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
async function runLowdefyBuild({ context , directory }) {
|
|
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',
|
|
24
24
|
'build:lowdefy'
|
|
25
25
|
],
|
|
26
26
|
processOptions: {
|
|
27
|
-
cwd:
|
|
27
|
+
cwd: directory,
|
|
28
28
|
env: {
|
|
29
29
|
...process.env,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
|
31
|
+
LOWDEFY_DIRECTORY_BUILD: context.directories.build,
|
|
32
|
+
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
33
|
+
LOWDEFY_DIRECTORY_SERVER: context.directories.server
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
silent: false
|
|
@@ -12,19 +12,19 @@
|
|
|
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 '
|
|
16
|
-
async function runNextBuild({ context }) {
|
|
15
|
+
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
async function runNextBuild({ context , directory }) {
|
|
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',
|
|
24
24
|
'build:next'
|
|
25
25
|
],
|
|
26
26
|
processOptions: {
|
|
27
|
-
cwd:
|
|
27
|
+
cwd: directory
|
|
28
28
|
},
|
|
29
29
|
silent: false
|
|
30
30
|
});
|
package/dist/utils/startUp.js
CHANGED
|
@@ -21,16 +21,16 @@ import getLowdefyYaml from './getLowdefyYaml.js';
|
|
|
21
21
|
import getOptions from './getOptions.js';
|
|
22
22
|
import getPackageManager from './getPackageManager.js';
|
|
23
23
|
import getSendTelemetry from './getSendTelemetry.js';
|
|
24
|
-
import createPrint from './
|
|
25
|
-
async function startUp({ context , options ={
|
|
26
|
-
} , command }) {
|
|
24
|
+
import createPrint from './createPrint.js';
|
|
25
|
+
async function startUp({ context , options ={} , command }) {
|
|
27
26
|
context.command = command.name();
|
|
28
27
|
context.commandLineOptions = options;
|
|
29
28
|
context.print = createPrint();
|
|
30
|
-
context.
|
|
31
|
-
const { cliConfig , lowdefyVersion } = await getLowdefyYaml(context);
|
|
29
|
+
context.configDirectory = path.resolve(options.configDirectory || process.cwd());
|
|
30
|
+
const { cliConfig , lowdefyVersion , plugins } = await getLowdefyYaml(context);
|
|
32
31
|
context.cliConfig = cliConfig;
|
|
33
32
|
context.lowdefyVersion = lowdefyVersion;
|
|
33
|
+
context.plugins = plugins;
|
|
34
34
|
const { appId } = await getCliJson(context);
|
|
35
35
|
context.appId = appId;
|
|
36
36
|
context.options = getOptions(context);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lowdefy",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.8",
|
|
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
|
|
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.
|
|
44
|
-
"@lowdefy/node-utils": "4.0.0-alpha.
|
|
45
|
-
"axios": "0.
|
|
43
|
+
"@lowdefy/helpers": "4.0.0-alpha.8",
|
|
44
|
+
"@lowdefy/node-utils": "4.0.0-alpha.8",
|
|
45
|
+
"axios": "0.25.0",
|
|
46
46
|
"chalk": "4.1.2",
|
|
47
|
-
"
|
|
48
|
-
"commander": "8.3.0",
|
|
47
|
+
"commander": "9.0.0",
|
|
49
48
|
"decompress": "4.2.1",
|
|
50
49
|
"decompress-targz": "4.1.1",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
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
|
-
"@
|
|
60
|
-
"@swc/
|
|
61
|
-
"@swc/
|
|
62
|
-
"jest": "
|
|
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": "
|
|
64
|
+
"gitHead": "9d56b83cf45e868afe3a1eeba750fe826eb74c8c"
|
|
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,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;
|