lowdefy 3.23.0-alpha.0 → 4.0.0-alpha.4

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 (57) hide show
  1. package/dist/commands/build/build.js +39 -0
  2. package/dist/commands/build/getServer.js +42 -0
  3. package/dist/commands/build/installServer.js +43 -0
  4. package/dist/commands/build/runLowdefyBuild.js +41 -0
  5. package/dist/commands/build/runNextBuild.js +36 -0
  6. package/dist/commands/dev/buildWatcher.js +48 -0
  7. package/dist/commands/dev/dev.js +80 -0
  8. package/dist/commands/dev/envWatcher.js +32 -0
  9. package/dist/commands/dev/getBuild.js +37 -0
  10. package/dist/commands/dev/getExpress.js +71 -0
  11. package/dist/commands/dev/getGraphQL.js +39 -0
  12. package/dist/commands/dev/prepare.js +27 -0
  13. package/dist/commands/dev/versionWatcher.js +36 -0
  14. package/dist/commands/init/init.js +42 -0
  15. package/dist/commands/init/lowdefyFile.js +67 -0
  16. package/dist/index.js +57 -2
  17. package/dist/utils/BatchChanges.js +48 -0
  18. package/dist/utils/checkForUpdatedVersions.js +53 -0
  19. package/dist/utils/errorHandler.js +50 -0
  20. package/dist/utils/fetchNpmTarball.js +56 -0
  21. package/dist/utils/findOpenPort.js +58 -0
  22. package/dist/utils/getCliJson.js +35 -0
  23. package/dist/utils/getDirectories.js +30 -0
  24. package/dist/utils/getLowdefyYaml.js +55 -0
  25. package/dist/utils/getOptions.js +23 -0
  26. package/dist/utils/getPackageManager.js +54 -0
  27. package/dist/utils/getSendTelemetry.js +45 -0
  28. package/dist/utils/print.js +73 -0
  29. package/dist/utils/runCommand.js +42 -0
  30. package/dist/utils/spawnProcess.js +49 -0
  31. package/dist/utils/startUp.js +48 -0
  32. package/package.json +21 -43
  33. package/dist/shell/185.59f79d0f067f50c8b219.js +0 -1
  34. package/dist/shell/246.b57dcf8b9c7a314f7bb9.js +0 -2
  35. package/dist/shell/246.b57dcf8b9c7a314f7bb9.js.LICENSE.txt +0 -8
  36. package/dist/shell/454.a5de9976bd8feff1520a.js +0 -2
  37. package/dist/shell/454.a5de9976bd8feff1520a.js.LICENSE.txt +0 -14
  38. package/dist/shell/612.5e25cda0219ebab6ddae.js +0 -1
  39. package/dist/shell/625.859c7a1f9e198e3ae56f.js +0 -1
  40. package/dist/shell/706.055a587fb77f64a5299e.js +0 -2
  41. package/dist/shell/706.055a587fb77f64a5299e.js.LICENSE.txt +0 -8
  42. package/dist/shell/909.623901103ad312dc3ad4.js +0 -2
  43. package/dist/shell/909.623901103ad312dc3ad4.js.LICENSE.txt +0 -45
  44. package/dist/shell/922.8370fab8ada1985a0f4f.js +0 -2
  45. package/dist/shell/922.8370fab8ada1985a0f4f.js.LICENSE.txt +0 -14
  46. package/dist/shell/index.html +0 -58
  47. package/dist/shell/main.a0212229781d28e55f9b.js +0 -1
  48. package/dist/shell/public/apple-touch-icon.png +0 -0
  49. package/dist/shell/public/icon-32.png +0 -0
  50. package/dist/shell/public/icon-512.png +0 -0
  51. package/dist/shell/public/icon.svg +0 -17
  52. package/dist/shell/public/logo-dark-theme.png +0 -0
  53. package/dist/shell/public/logo-light-theme.png +0 -0
  54. package/dist/shell/public/logo-square-dark-theme.png +0 -0
  55. package/dist/shell/public/logo-square-light-theme.png +0 -0
  56. package/dist/shell/public/manifest.webmanifest +0 -16
  57. package/dist/shell/runtime.73a008a77ccc03d87d76.js +0 -1
@@ -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 getServer from './getServer.js';
16
+ import installServer from './installServer.js';
17
+ import runLowdefyBuild from './runLowdefyBuild.js';
18
+ import runNextBuild from './runNextBuild.js';
19
+ async function build({ context }) {
20
+ context.print.info('Starting build.');
21
+ await getServer({
22
+ context
23
+ });
24
+ await installServer({
25
+ context
26
+ });
27
+ await runLowdefyBuild({
28
+ context
29
+ });
30
+ await installServer({
31
+ context
32
+ });
33
+ await runNextBuild({
34
+ context
35
+ });
36
+ await context.sendTelemetry();
37
+ context.print.succeed(`Build successful.`);
38
+ }
39
+ export default build;
@@ -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.server, 'package.json'));
22
+ if (!serverExists) fetchServer = true;
23
+ if (serverExists) {
24
+ const serverPackageConfig = JSON.parse(await readFile(path.join(context.directories.server, 'package.json')));
25
+ if (serverPackageConfig.version !== context.lowdefyVersion) {
26
+ fetchServer = true;
27
+ context.print.warn(`Removing @lowdefy/server with version ${serverPackageConfig.version}`);
28
+ await cleanDirectory(context.directories.server);
29
+ }
30
+ }
31
+ if (fetchServer) {
32
+ context.print.spin('Fetching @lowdefy/server from npm.');
33
+ await fetchNpmTarball({
34
+ packageName: '@lowdefy/server',
35
+ version: context.lowdefyVersion,
36
+ directory: context.directories.server
37
+ });
38
+ context.print.log('Fetched @lowdefy/server 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 '../../utils/spawnProcess.js';
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
+ context,
30
+ command: context.packageManager,
31
+ args: args[context.packageManager],
32
+ processOptions: {
33
+ cwd: context.directories.server
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;
@@ -0,0 +1,41 @@
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 '../../utils/spawnProcess.js';
16
+ async function runLowdefyBuild({ context }) {
17
+ context.print.log('Running Lowdefy build.');
18
+ try {
19
+ await spawnProcess({
20
+ context,
21
+ command: context.packageManager,
22
+ args: [
23
+ 'run',
24
+ 'build:lowdefy'
25
+ ],
26
+ processOptions: {
27
+ cwd: context.directories.server,
28
+ env: {
29
+ ...process.env,
30
+ LOWDEFY_BUILD_DIRECTORY: context.directories.build,
31
+ LOWDEFY_CONFIG_DIRECTORY: context.directories.base
32
+ }
33
+ },
34
+ silent: false
35
+ });
36
+ } catch (error) {
37
+ throw new Error('Lowdefy build failed.');
38
+ }
39
+ context.print.log('Lowdefy build successful.');
40
+ }
41
+ export default runLowdefyBuild;
@@ -0,0 +1,36 @@
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 '../../utils/spawnProcess.js';
16
+ async function runNextBuild({ context }) {
17
+ context.print.log('Running Next build.');
18
+ try {
19
+ await spawnProcess({
20
+ context,
21
+ command: context.packageManager,
22
+ args: [
23
+ 'run',
24
+ 'build:next'
25
+ ],
26
+ processOptions: {
27
+ cwd: context.directories.server
28
+ },
29
+ silent: false
30
+ });
31
+ } catch (error) {
32
+ throw new Error('Next build failed.');
33
+ }
34
+ context.print.log('Next build successful.');
35
+ }
36
+ export default runNextBuild;
@@ -0,0 +1,48 @@
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;
@@ -0,0 +1,80 @@
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 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
+ }
43
+ async function dev({ context }) {
44
+ await prepare({
45
+ context
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,
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
+ }
80
+ export default dev;
@@ -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 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;
@@ -0,0 +1,37 @@
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;
@@ -0,0 +1,71 @@
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;
@@ -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 { 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;
@@ -0,0 +1,27 @@
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;
@@ -0,0 +1,36 @@
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;
@@ -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 path from 'path';
16
+ import fs from 'fs';
17
+ import { writeFile } from '@lowdefy/node-utils';
18
+ import lowdefyFile from './lowdefyFile.js';
19
+ async function init({ context }) {
20
+ const lowdefyFilePath = path.resolve('./lowdefy.yaml');
21
+ const fileExists = fs.existsSync(lowdefyFilePath);
22
+ if (fileExists) {
23
+ throw new Error('Cannot initialize a Lowdefy project, a "lowdefy.yaml" file already exists');
24
+ }
25
+ context.print.log(`Initializing Lowdefy project`);
26
+ await writeFile({
27
+ filePath: lowdefyFilePath,
28
+ content: lowdefyFile({
29
+ version: context.cliVersion
30
+ })
31
+ });
32
+ context.print.log(`Created 'lowdefy.yaml'.`);
33
+ await writeFile({
34
+ filePath: path.resolve('./.gitignore'),
35
+ content: `.lowdefy/**
36
+ .env`
37
+ });
38
+ context.print.log(`Created '.gitignore'.`);
39
+ await context.sendTelemetry();
40
+ context.print.succeed(`Project initialized.`);
41
+ }
42
+ export default init;