lowdefy 3.23.1 → 4.0.0-alpha.1
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 +40 -0
- package/dist/commands/dev/buildWatcher.js +48 -0
- package/dist/commands/dev/dev.js +80 -0
- package/dist/commands/dev/envWatcher.js +32 -0
- package/dist/commands/dev/getBuild.js +37 -0
- package/dist/commands/dev/getExpress.js +71 -0
- package/dist/commands/dev/getGraphQL.js +39 -0
- package/dist/commands/dev/prepare.js +27 -0
- package/dist/commands/dev/versionWatcher.js +36 -0
- package/dist/commands/init/init.js +42 -0
- package/dist/commands/init/lowdefyFile.js +67 -0
- package/dist/index.js +76 -2
- package/dist/utils/BatchChanges.js +48 -0
- package/dist/utils/checkChildProcessError.js +21 -0
- package/dist/utils/checkForUpdatedVersions.js +42 -0
- package/dist/utils/errorHandler.js +50 -0
- package/dist/utils/fetchNpmTarball.js +55 -0
- package/dist/utils/findOpenPort.js +58 -0
- package/dist/utils/getCliJson.js +35 -0
- package/dist/utils/getDirectories.js +27 -0
- package/dist/utils/getLowdefyYaml.js +55 -0
- package/dist/utils/getOptions.js +23 -0
- package/dist/utils/getSendTelemetry.js +45 -0
- package/dist/utils/print.js +72 -0
- package/dist/utils/runCommand.js +42 -0
- package/dist/utils/startUp.js +47 -0
- package/package.json +21 -43
- package/dist/shell/185.59f79d0f067f50c8b219.js +0 -1
- package/dist/shell/246.b57dcf8b9c7a314f7bb9.js +0 -2
- package/dist/shell/246.b57dcf8b9c7a314f7bb9.js.LICENSE.txt +0 -8
- package/dist/shell/454.a5de9976bd8feff1520a.js +0 -2
- package/dist/shell/454.a5de9976bd8feff1520a.js.LICENSE.txt +0 -14
- package/dist/shell/612.66e41a27dabae3a38f9c.js +0 -1
- package/dist/shell/625.859c7a1f9e198e3ae56f.js +0 -1
- package/dist/shell/706.055a587fb77f64a5299e.js +0 -2
- package/dist/shell/706.055a587fb77f64a5299e.js.LICENSE.txt +0 -8
- package/dist/shell/909.623901103ad312dc3ad4.js +0 -2
- package/dist/shell/909.623901103ad312dc3ad4.js.LICENSE.txt +0 -45
- package/dist/shell/922.8370fab8ada1985a0f4f.js +0 -2
- package/dist/shell/922.8370fab8ada1985a0f4f.js.LICENSE.txt +0 -14
- package/dist/shell/index.html +0 -58
- package/dist/shell/main.a0212229781d28e55f9b.js +0 -1
- package/dist/shell/public/apple-touch-icon.png +0 -0
- package/dist/shell/public/icon-32.png +0 -0
- package/dist/shell/public/icon-512.png +0 -0
- package/dist/shell/public/icon.svg +0 -17
- package/dist/shell/public/logo-dark-theme.png +0 -0
- package/dist/shell/public/logo-light-theme.png +0 -0
- package/dist/shell/public/logo-square-dark-theme.png +0 -0
- package/dist/shell/public/logo-square-light-theme.png +0 -0
- package/dist/shell/public/manifest.webmanifest +0 -16
- package/dist/shell/runtime.d3f0e00b3695f2e971f2.js +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
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 fse from 'fs-extra';
|
|
17
|
+
import getFederatedModule from '../../utils/getFederatedModule';
|
|
18
|
+
async function build({ context }) {
|
|
19
|
+
const { default: buildScript } = await getFederatedModule({
|
|
20
|
+
module: 'build',
|
|
21
|
+
packageName: '@lowdefy/build',
|
|
22
|
+
version: context.lowdefyVersion,
|
|
23
|
+
context
|
|
24
|
+
});
|
|
25
|
+
context.print.log(`Cleaning block meta cache at "${path.resolve(context.cacheDirectory, './meta')}".`);
|
|
26
|
+
await fse.emptyDir(path.resolve(context.cacheDirectory, './meta'));
|
|
27
|
+
context.print.info('Starting build.');
|
|
28
|
+
await buildScript({
|
|
29
|
+
blocksServerUrl: context.options.blocksServerUrl,
|
|
30
|
+
buildDirectory: context.buildDirectory,
|
|
31
|
+
cacheDirectory: context.cacheDirectory,
|
|
32
|
+
configDirectory: context.baseDirectory,
|
|
33
|
+
logger: context.print,
|
|
34
|
+
refResolver: context.options.refResolver
|
|
35
|
+
});
|
|
36
|
+
await context.sendTelemetry();
|
|
37
|
+
context.print.log(`Build artifacts saved at ${context.buildDirectory}.`);
|
|
38
|
+
context.print.succeed(`Build successful.`);
|
|
39
|
+
}
|
|
40
|
+
export default build;
|
|
@@ -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;
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
*/ export default (({ version })=>`
|
|
16
|
+
lowdefy: ${version}
|
|
17
|
+
name: Lowdefy starter
|
|
18
|
+
|
|
19
|
+
pages:
|
|
20
|
+
- id: welcome
|
|
21
|
+
type: PageHeaderMenu
|
|
22
|
+
properties:
|
|
23
|
+
title: Welcome
|
|
24
|
+
areas:
|
|
25
|
+
content:
|
|
26
|
+
justify: center
|
|
27
|
+
blocks:
|
|
28
|
+
- id: content_card
|
|
29
|
+
type: Card
|
|
30
|
+
style:
|
|
31
|
+
maxWidth: 800
|
|
32
|
+
blocks:
|
|
33
|
+
- id: content
|
|
34
|
+
type: Result
|
|
35
|
+
properties:
|
|
36
|
+
title: Welcome to your Lowdefy app
|
|
37
|
+
subTitle: We are excited to see what you are going to build
|
|
38
|
+
icon:
|
|
39
|
+
name: HeartTwoTone
|
|
40
|
+
color: '#f00'
|
|
41
|
+
areas:
|
|
42
|
+
extra:
|
|
43
|
+
blocks:
|
|
44
|
+
- id: docs_button
|
|
45
|
+
type: Button
|
|
46
|
+
properties:
|
|
47
|
+
size: large
|
|
48
|
+
title: Let's build something
|
|
49
|
+
color: '#1890ff'
|
|
50
|
+
events:
|
|
51
|
+
onClick:
|
|
52
|
+
- id: link_to_docs
|
|
53
|
+
type: Link
|
|
54
|
+
params:
|
|
55
|
+
url: https://docs.lowdefy.com
|
|
56
|
+
newTab: true
|
|
57
|
+
footer:
|
|
58
|
+
blocks:
|
|
59
|
+
- id: footer
|
|
60
|
+
type: Paragraph
|
|
61
|
+
properties:
|
|
62
|
+
type: secondary
|
|
63
|
+
content: |
|
|
64
|
+
Made by a Lowdefy 🤖
|
|
65
|
+
|
|
66
|
+
`
|
|
67
|
+
);
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
(()=>{"use strict";var e={153:(e,t,o)=>{o.r(t);const r=require("commander");var n=o.n(r);const i=JSON.parse('{"name":"lowdefy","version":"3.23.1","license":"Apache-2.0","description":"Lowdefy CLI","homepage":"https://lowdefy.com","keywords":["lowdefy","cli"],"bugs":{"url":"https://github.com/lowdefy/lowdefy/issues"},"contributors":[{"name":"Sam Tolmay","url":"https://github.com/SamTolmay"},{"name":"Gerrie van Wyk","url":"https://github.com/Gervwyk"}],"repository":{"type":"git","url":"https://github.com/lowdefy/lowdefy.git"},"bin":"dist/index.js","files":["dist/*"],"main":"dist/index.js","scripts":{"build":"yarn webpack","clean":"rm -rf dist && rm -rf .lowdefy","cli":"yarn node ./dist/index.js","cli:build":"yarn build && yarn node ./dist/index.js","prepare":"yarn build","test":"FORCE_COLOR=3 jest --coverage","webpack":"webpack --config webpack.config.js"},"dependencies":{"@lowdefy/helpers":"3.23.1","@lowdefy/node-utils":"3.23.1","apollo-server-express":"2.25.0","axios":"0.21.4","chalk":"4.1.1","chokidar":"3.5.1","commander":"7.2.0","decompress":"4.2.1","decompress-targz":"4.1.1","dotenv":"10.0.0","express":"4.17.1","fs-extra":"10.0.0","graphql":"15.5.0","js-yaml":"4.1.0","mssql":"7.1.0","mysql":"2.18.1","opener":"1.5.2","ora":"5.4.0","pg":"8.6.0","reload":"3.1.1","saslprep":"1.0.3","sqlite3":"5.0.2","uuid":"8.3.2"},"devDependencies":{"@babel/cli":"7.14.3","@babel/core":"7.14.3","@babel/preset-env":"7.14.4","@babel/preset-react":"7.13.13","@lowdefy/block-tools":"3.23.1","babel-jest":"26.6.3","babel-loader":"8.2.2","clean-webpack-plugin":"3.0.0","copy-webpack-plugin":"9.0.0","css-loader":"5.2.6","html-webpack-plugin":"5.3.1","jest":"26.6.3","react":"17.0.2","react-dom":"17.0.2","style-loader":"2.0.0","webpack":"5.38.1","webpack-cli":"4.7.0"},"publishConfig":{"access":"public"}}'),a=require("path");var s=o.n(a);const c=require("fs-extra");var l=o.n(c);const d=require("fs");var p=o.n(d);const u=require("axios");var y=o.n(u);const f=require("decompress");var w=o.n(f);const h=require("decompress-targz");var m=o.n(h);const g=async function({packageName:e,version:t,directory:o}){const r=`https://registry.npmjs.org/${e}`;let n,i;try{n=await y().get(r)}catch(t){if(t.response&&404===t.response.status)throw new Error(`Package "${e}" could not be found at ${r}.`);throw t}if(!n||!n.data)throw new Error(`Package "${e}" could not be found at ${r}.`);if(!n.data.versions[t])throw new Error(`Invalid version. "${e}" does not have version "${t}".`);try{i=await y().get(n.data.versions[t].dist.tarball,{responseType:"arraybuffer"})}catch(o){if(o.response&&404===o.response.status)throw new Error(`Package "${e}" tarball could not be found at ${n.data.versions[t].dist.tarball}.`);throw o}if(!i||!i.data)throw new Error(`Package "${e}" tarball could not be found at ${n.data.versions[t].dist.tarball}.`);await w()(i.data,o,{plugins:[m()()]})},v=async function({module:e,packageName:t,version:r,context:n}){const i=r.replace(/[-.]/g,"_"),a=s().resolve(n.cacheDirectory,`scripts/${e}/${i}`);return p().existsSync(s().resolve(a,"package/dist/remoteEntry.js"))||(n.print.spin(`Fetching ${t}@${r} to cache.`),await g({packageName:t,version:r,directory:a}),n.print.log(`Fetched ${t}@${r} to cache.`)),async function({directory:e,module:t,remoteEntry:r="remoteEntry.js"}){return(await(async e=>(o.S.default&&await o.I("default"),new Promise((t=>{const r=require(e);new Promise((e=>{o.S.default?e(r.init(o.S.default)):e()})).then((()=>{t(r)}))}))))(s().resolve(`${e}/${r}`))).get(t).then((e=>e()))}({directory:s().resolve(a,"package/dist"),module:`./${e}`})},b=require("child_process"),x=require("@lowdefy/node-utils"),D=require("opener");var k=o.n(D);const _=require("chokidar");var S=o.n(_);const L=class{constructor({fn:e,context:t,minDelay:o}){this.fn=e,this.context=t,this.delay=o||500,this.minDelay=o||500,this._call=this._call.bind(this)}newChange(){this.delay=this.minDelay,this._startTimer()}_startTimer(){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(this._call,this.delay)}async _call(){try{await this.fn()}catch(e){this.context.print.error(e.message,{timestamp:!0}),this.delay*=2,this.context.print.warn(`Retrying in ${this.delay/1e3}s.`,{timestamp:!0}),this._startTimer()}}},$=require("express");var C=o.n($);const P=require("reload");var j=o.n(P);const q=require("@lowdefy/helpers"),T=require("net");var F=o.n(T);const O=async function({context:e,gqlServer:t}){const o=async(t,o)=>{let r=await(0,x.readFile)(s().resolve(__dirname,"shell/index.html")),n=await(0,x.readFile)(s().resolve(e.outputDirectory,"app.json"));n=JSON.parse(n),r=r.replace("\x3c!-- __LOWDEFY_APP_HEAD_HTML__ --\x3e",(0,q.get)(n,"html.appendHead",{default:""})),r=r.replace("\x3c!-- __LOWDEFY_APP_BODY_HTML__ --\x3e",(0,q.get)(n,"html.appendBody",{default:""})),o.send(r)},r=C()();r.set("port",parseInt(e.options.port)),t.applyMiddleware({app:r,path:"/api/graphql"});const n=await async function(){return new Promise(((e,t)=>{const o=F().createServer();o.on("error",t),o.listen(0,(()=>{const{port:t}=o.address();o.on("close",e.bind(null,t)),o.close()}))}))}(),i=await j()(r,{route:"/api/dev/reload.js",port:n});return r.get("/",o),r.use("/public",C().static(s().resolve(process.cwd(),"public"))),r.use(C().static(s().resolve(__dirname,"shell"))),r.use("/api/dev/rendererRemoteEntryUrl",((t,o)=>{let r;r=e.options.blocksServerUrl?`${e.options.blocksServerUrl}/renderer/remoteEntry.js`:`https://blocks-cdn.lowdefy.com/v${e.lowdefyVersion}/renderer/remoteEntry.js`,o.json(r)})),r.use(o),{expressApp:r,reloadFn:i.reload}},E=require("apollo-server-express"),N=require("dotenv");var I=o.n(N);const V=require("js-yaml");var A=o.n(V);const R=async function({baseDirectory:e,command:t}){let o,r=await(0,x.readFile)(s().resolve(e,"lowdefy.yaml"));if(r||(r=await(0,x.readFile)(s().resolve(e,"lowdefy.yml"))),!r){if(!["init","clean-cache"].includes(t))throw new Error(`Could not find "lowdefy.yaml" file in specified base directory ${e}.`);return{cliConfig:{}}}try{o=A().load(r)}catch(e){throw new Error(`Could not parse "lowdefy.yaml" file. Received error ${e.message}.`)}if(!o.lowdefy)throw new Error('No version specified in "lowdefy.yaml" file. Specify a version in the "lowdefy" field.');if(!q.type.isString(o.lowdefy)||!o.lowdefy.match(/\d+\.\d+\.\d+(-\w+\.\d+)?/))throw new Error(`Version number specified in "lowdefy.yaml" file is not valid. Received ${JSON.stringify(o.lowdefy)}.`);return{lowdefyVersion:o.lowdefy,cliConfig:(0,q.get)(o,"cli",{default:{}})}},{version:M}=i,U=`\nlowdefy: ${M}\nname: Lowdefy starter\n\npages:\n - id: welcome\n type: PageHeaderMenu\n properties:\n title: Welcome\n areas:\n content:\n justify: center\n blocks:\n - id: content_card\n type: Card\n style:\n maxWidth: 800\n blocks:\n - id: content\n type: Result\n properties:\n title: Welcome to your Lowdefy app\n subTitle: We are excited to see what you are going to build\n icon:\n name: HeartTwoTone\n color: '#f00'\n areas:\n extra:\n blocks:\n - id: docs_button\n type: Button\n properties:\n size: large\n title: Let's build something\n color: '#1890ff'\n events:\n onClick:\n - id: link_to_docs\n type: Link\n params:\n url: https://docs.lowdefy.com\n newTab: true\n footer:\n blocks:\n - id: footer\n type: Paragraph\n properties:\n type: secondary\n content: |\n Made by a Lowdefy 🤖\n\n`,B=require("ora");var H=o.n(B);const Y=require("chalk");var J=o.n(Y);let W;const z=function(){return W||("true"===process.env.CI?(W=function(){const{error:e,info:t,log:o,warn:r}=console;return{type:"basic",error:e,info:t,log:o,spin:o,succeed:o,warn:r}}(),W):(W=function(){const e=H()({spinner:"random",prefixText:()=>J().dim(function(){const e=new Date(Date.now()),t=e.getHours(),o=e.getMinutes(),r=e.getSeconds();return`${t>9?"":"0"}${t}:${o>9?"":"0"}${o}:${r>9?"":"0"}${r}`}()),color:"blue"});return{type:"ora",error:t=>e.fail(J().red(t)),info:t=>e.info(J().blue(t)),log:t=>e.start(t).stopAndPersist({symbol:"∙"}),spin:t=>e.start(t),succeed:t=>e.succeed(J().green(t)),warn:t=>e.warn(J().yellow(t))}}(),W))},{version:G}=i,K=require("uuid"),{version:Q}=i,X=async function({context:e,options:t={},command:o}){e.command=o.name(),e.cliVersion=Q,e.commandLineOptions=t,e.print=z(),e.baseDirectory=s().resolve(t.baseDirectory||process.cwd());const{cliConfig:r,lowdefyVersion:n}=await R(e);e.cliConfig=r,e.lowdefyVersion=n;const{appId:i}=await async function({baseDirectory:e}){const t=s().resolve(e,"./.lowdefy/cli.json"),o=await(0,x.readFile)(t);if(!o){const e=(0,K.v4)();return await(0,x.writeFile)({filePath:t,content:JSON.stringify({appId:e},null,2)}),{appId:e}}return JSON.parse(o)}(e);e.appId=i,e.options=function({commandLineOptions:e,cliConfig:t}){return{...t,...e}}(e);const{cacheDirectory:a,outputDirectory:c}=function({baseDirectory:e,options:t}){const o=s().resolve(e,"./.lowdefy/.cache");let r;return r=t.outputDirectory?s().resolve(t.outputDirectory):s().resolve(e,"./.lowdefy/build"),{cacheDirectory:o,outputDirectory:r}}(e);return e.cacheDirectory=a,e.outputDirectory=c,await async function({cliVersion:e,lowdefyVersion:t,print:o}){try{const r=(await y().get("https://registry.npmjs.org/lowdefy")).data["dist-tags"].latest;e!==r&&o.warn(`\n-------------------------------------------------------------\n You are using an outdated Lowdefy CLI.\n Please update to version ${r}.\n To always use the latest version, run 'npx lowdefy@latest'.\n-------------------------------------------------------------`),t&&t!==r&&o.warn(`\n-------------------------------------------------------------\n Your app is using an outdated Lowdefy version, ${t}.\n Please update your app to version ${r}.\n View the changelog here:\n https://github.com/lowdefy/lowdefy/blob/main/CHANGELOG.md\n-------------------------------------------------------------`)}catch(e){o.warn("Failed to check for latest Lowdefy version.")}}(e),e.sendTelemetry=function({appId:e,cliVersion:t,command:o,lowdefyVersion:r,options:n}){return n.disableTelemetry?()=>{}:async function({data:n={}}={}){try{await y().request({method:"post",url:"https://api.lowdefy.net/telemetry/cli",headers:{"User-Agent":`Lowdefy CLI v${t}`},data:{...n,app_id:e,cli_version:t,command:o,lowdefy_version:r}})}catch(e){}}}(e),q.type.isNone(n)?e.print.log(`Running 'lowdefy ${e.command}'.`):e.print.log(`Running 'lowdefy ${e.command}'. Lowdefy app version ${n}.`),e},Z=function(e){return async function(t,o){const r={};try{return await X({context:r,options:t,command:o}),await e({context:r})}catch(e){await async function({context:e,error:t}){z().error(t.message),e.disableTelemetry||await async function({error:e,context:t={}}){try{await y().request({method:"post",url:"https://api.lowdefy.net/errors",headers:{"User-Agent":`Lowdefy CLI v${G}`},data:{source:"cli",cliVersion:G,command:t.command,lowdefyVersion:t.lowdefyVersion,message:e.message,name:e.name,stack:e.stack}})}catch(e){}}({context:e,error:t})}({context:r,error:e})}}},{description:ee,version:te}=i;n().name("lowdefy").description(ee).version(te,"-v, --version"),n().command("build").description("Build a Lowdefy deployment.").usage("[options]").option("--base-directory <base-directory>","Change base directory. Default is the current working directory.").option("--blocks-server-url <blocks-server-url>","The URL from where Lowdefy blocks will be served.").option("--disable-telemetry","Disable telemetry.").option("--output-directory <output-directory>",'Change the directory to which build artifacts are saved. Default is "<base-directory>/.lowdefy/build".').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(Z((async function({context:e}){const{default:t}=await v({module:"build",packageName:"@lowdefy/build",version:e.lowdefyVersion,context:e});e.print.log(`Cleaning block meta cache at "${s().resolve(e.cacheDirectory,"./meta")}".`),await l().emptyDir(s().resolve(e.cacheDirectory,"./meta")),e.print.info("Starting build."),await t({blocksServerUrl:e.options.blocksServerUrl,cacheDirectory:e.cacheDirectory,configDirectory:e.baseDirectory,logger:e.print,outputDirectory:e.outputDirectory,refResolver:e.options.refResolver}),await e.sendTelemetry(),e.print.log(`Build artifacts saved at ${e.outputDirectory}.`),e.print.succeed("Build successful.")}))),n().command("build-netlify").description("Build a Lowdefy deployment to deploy in netlify.").usage("[options]").option("--base-directory <base-directory>","Change base directory. Default is the current working directory.").option("--blocks-server-url <blocks-server-url>","The URL from where Lowdefy blocks will be served.").option("--disable-telemetry","Disable telemetry.").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(Z((async function({context:e}){e.netlifyDir=s().resolve(e.baseDirectory,"./.lowdefy/netlify"),e.print.info("Starting build.");const t=await async function({context:e}){e.print.log("Fetching Lowdefy build script.");const{default:t}=await v({module:"build",packageName:"@lowdefy/build",version:e.lowdefyVersion,context:e});return e.print.log("Fetched Lowdefy build script."),t}({context:e});await async function({context:e,buildScript:t}){e.print.log("Starting Lowdefy build.");const o=s().resolve(e.netlifyDir,"./package/dist/functions/graphql/build");await t({blocksServerUrl:e.options.blocksServerUrl,cacheDirectory:e.cacheDirectory,configDirectory:e.baseDirectory,logger:e.print,outputDirectory:o,refResolver:e.options.refResolver}),e.print.log(`Build artifacts saved at ${o}.`)}({context:e,buildScript:t}),e.print.info("Installing Lowdefy server."),await async function({context:e}){e.print.log("Fetching Lowdefy Netlify server."),await g({packageName:"@lowdefy/server-netlify",version:e.lowdefyVersion,directory:e.netlifyDir}),e.print.log("Fetched Lowdefy Netlify server.")}({context:e}),await async function({context:e}){await l().copy(s().resolve(e.netlifyDir,"package/package.json"),s().resolve("./package.json")),await l().remove(s().resolve("./package-lock.json")),await l().remove(s().resolve("./package-lock.json")),await l().emptyDir(s().resolve("./node_modules")),e.print.log("npm install production.");let t=(0,b.spawnSync)("npm",["install","--production","--legacy-peer-deps"]);(function({context:e,processOutput:t,message:o}){if(1===t.status)throw e.print.error(t.stderr.toString("utf8")),new Error(o)})({context:e,processOutput:t,message:"Failed to npm install Netlify server."}),e.print.log("npm install successful."),e.print.log(t.stdout.toString("utf8"))}({context:e}),e.print.log("Moving artifacts."),await async function({context:e}){await l().copy(s().resolve(e.netlifyDir,"package/dist/shell"),s().resolve("./.lowdefy/publish")),e.print.log('Netlify publish artifacts moved to "./lowdefy/publish".')}({context:e}),await async function({context:e}){await l().copy(s().resolve(e.netlifyDir,"package/dist/functions"),s().resolve("./.lowdefy/functions")),e.print.log('Netlify functions artifacts moved to "./lowdefy/functions".')}({context:e}),await async function({context:e}){e.print.log("Moving public assets."),await l().ensureDir(s().resolve("./public")),await l().copy(s().resolve("./public"),s().resolve("./.lowdefy/publish/public")),e.print.log('Public assets moved to "./lowdefy/publish/public".')}({context:e}),e.print.log("Build artifacts."),await async function({context:e}){e.print.log("Starting Lowdefy index.html build.");let t=await(0,x.readFile)(s().resolve("./.lowdefy/functions/graphql/build/app.json"));t=JSON.parse(t);const o=s().resolve("./.lowdefy/publish/index.html");let r=await(0,x.readFile)(o);r=r.replace("\x3c!-- __LOWDEFY_APP_HEAD_HTML__ --\x3e",t.html.appendHead),r=r.replace("\x3c!-- __LOWDEFY_APP_BODY_HTML__ --\x3e",t.html.appendBody),await(0,x.writeFile)({filePath:o,content:r}),e.print.log("Lowdefy index.html build complete.")}({context:e}),await e.sendTelemetry({data:{netlify:"true"===process.env.NETLIFY}}),e.print.succeed("Netlify build completed successfully.")}))),n().command("clean-cache").description("Clean cached scripts and block meta descriptions.").usage("[options]").option("--base-directory <base-directory>","Change base directory. Default is the current working directory.").option("--disable-telemetry","Disable telemetry.").action(Z((async function({context:e}){e.print.log(`Cleaning cache at "${e.cacheDirectory}".`),await l().emptyDir(e.cacheDirectory),await e.sendTelemetry(),e.print.succeed("Cache cleaned.")}))),n().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("--blocks-server-url <blocks-server-url>","The URL from where Lowdefy blocks will be served.").option("--disable-telemetry","Disable telemetry.").option("--port <port>","Change the port the 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.").option("--watch-ignore <paths...>","A list of paths to files or directories that should be ignored by the file watcher. Globs are supported.").action(Z((async function({context:e}){await async function({context:e}){I().config({silent:!0}),e.options.port||(e.options.port=3e3),e.print.log(`Cleaning block meta cache at "${s().resolve(e.cacheDirectory,"./meta")}".`),await l().emptyDir(s().resolve(e.cacheDirectory,"./meta"))}({context:e});const t=async function({context:e}){const t=await async function({context:e}){const{default:t}=await v({module:"build",packageName:"@lowdefy/build",version:e.lowdefyVersion,context:e});return async function(){e.print.log("Building configuration."),await t({blocksServerUrl:e.options.blocksServerUrl,cacheDirectory:e.cacheDirectory,configDirectory:e.baseDirectory,logger:e.print,outputDirectory:e.outputDirectory,refResolver:e.options.refResolver}),e.print.succeed("Built successfully.")}}({context:e});try{await t()}catch(e){}return t}({context:e}),o=async function({context:e}){const t=await async function({context:e}){const{typeDefs:t,resolvers:o,createContext:r}=await v({module:"graphql",packageName:"@lowdefy/graphql-federated",version:e.lowdefyVersion,context:e}),n=r({CONFIGURATION_BASE_PATH:e.outputDirectory,development:!0,logger:console,getSecrets:(0,x.createGetSecretsFromEnv)()});return new E.ApolloServer({typeDefs:t,resolvers:o,context:n})}({context:e});return O({context:e,gqlServer:t})}({context:e}),[r,{expressApp:n,reloadFn:i}]=await Promise.all([t,o]);(function({build:e,context:t,reloadFn:o}){const{watch:r=[],watchIgnore:n=[]}=t.options,i=r.map((e=>s().resolve(e))),a=new L({fn:async()=>{await e(),o()},context:t}),c=S().watch([".",...i],{ignored:[/(^|[/\\])\../,...n],persistent:!0,ignoreInitial:!0});c.on("add",(()=>a.newChange())),c.on("change",(()=>a.newChange())),c.on("unlink",(()=>a.newChange()))})({build:r,context:e,reloadFn:i}),function({context:e}){const t=new L({fn:async()=>{e.print.warn(".env file changed. You should restart your development server."),process.exit()},context:e});S().watch("./.env",{persistent:!0}).on("change",(()=>t.newChange()))}({context:e}),function({context:e}){const t=new L({fn:async()=>{const{lowdefyVersion:t}=await R(e);t!==e.lowdefyVersion&&(e.print.warn("Lowdefy version changed. You should restart your development server."),process.exit())},context:e});S().watch("./lowdefy.yaml",{persistent:!0}).on("change",(()=>t.newChange()))}({context:e}),e.print.log("Starting Lowdefy development server.");const a=n.get("port");n.listen(a,(function(){e.print.info(`Development server listening on port ${a}`)})),k()(`http://localhost:${a}`),await e.sendTelemetry({data:{type:"startup"}})}))),n().command("init").description("Initialize a Lowdefy project.").usage("[options]").action(Z((async function({context:e}){const t=s().resolve("./lowdefy.yaml");if(l().existsSync(t))throw new Error('Cannot initialize a Lowdefy project, a "lowdefy.yaml" file already exists');e.print.log("Initializing Lowdefy project"),await(0,x.writeFile)({filePath:t,content:U}),e.print.log("Created 'lowdefy.yaml'."),await(0,x.writeFile)({filePath:s().resolve("./.gitignore"),content:".lowdefy/**\n.env"}),e.print.log("Created '.gitignore'."),await e.sendTelemetry(),e.print.succeed("Project initialized.")}))),n().parse(process.argv)}},t={};function o(r){var n=t[r];if(void 0!==n)return n.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,o),i.exports}o.m=e,o.c=t,o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{o.S={};var e={},t={};o.I=(r,n)=>{n||(n=[]);var i=t[r];if(i||(i=t[r]={}),!(n.indexOf(i)>=0)){if(n.push(i),e[r])return e[r];o.o(o.S,r)||(o.S[r]={}),o.S[r];var a=[];return e[r]=a.length?Promise.all(a).then((()=>e[r]=1)):1}}})();var r=o(153),n=exports;for(var i in r)n[i]=r[i];r.__esModule&&Object.defineProperty(n,"__esModule",{value:!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 { readFile } from '@lowdefy/node-utils';
|
|
16
|
+
import program from 'commander';
|
|
17
|
+
// import build from './commands/build/build.js';
|
|
18
|
+
// import dev from './commands/dev/dev.js';
|
|
19
|
+
import init from './commands/init/init.js';
|
|
20
|
+
import runCommand from './utils/runCommand.js';
|
|
21
|
+
const packageJson = JSON.parse(await readFile(new URL('../package.json', import.meta.url).pathname));
|
|
22
|
+
const { description , version } = packageJson;
|
|
23
|
+
program.name('lowdefy').description(description).version(version, '-v, --version');
|
|
24
|
+
// program
|
|
25
|
+
// .command('build')
|
|
26
|
+
// .description('Build a Lowdefy deployment.')
|
|
27
|
+
// .usage(`[options]`)
|
|
28
|
+
// .option(
|
|
29
|
+
// '--base-directory <base-directory>',
|
|
30
|
+
// 'Change base directory. Default is the current working directory.'
|
|
31
|
+
// )
|
|
32
|
+
// .option(
|
|
33
|
+
// '--blocks-server-url <blocks-server-url>',
|
|
34
|
+
// 'The URL from where Lowdefy blocks will be served.'
|
|
35
|
+
// )
|
|
36
|
+
// .option('--disable-telemetry', 'Disable telemetry.')
|
|
37
|
+
// .option(
|
|
38
|
+
// '--output-directory <output-directory>',
|
|
39
|
+
// 'Change the directory to which build artifacts are saved. Default is "<base-directory>/.lowdefy/build".'
|
|
40
|
+
// )
|
|
41
|
+
// .option(
|
|
42
|
+
// '--ref-resolver <ref-resolver-function-path>',
|
|
43
|
+
// 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.'
|
|
44
|
+
// )
|
|
45
|
+
// .action(runCommand(build));
|
|
46
|
+
// program
|
|
47
|
+
// .command('dev')
|
|
48
|
+
// .description('Start a Lowdefy development server.')
|
|
49
|
+
// .usage(`[options]`)
|
|
50
|
+
// .option(
|
|
51
|
+
// '--base-directory <base-directory>',
|
|
52
|
+
// 'Change base directory. Default is the current working directory.'
|
|
53
|
+
// )
|
|
54
|
+
// .option(
|
|
55
|
+
// '--blocks-server-url <blocks-server-url>',
|
|
56
|
+
// 'The URL from where Lowdefy blocks will be served.'
|
|
57
|
+
// )
|
|
58
|
+
// .option('--disable-telemetry', 'Disable telemetry.')
|
|
59
|
+
// .option('--port <port>', 'Change the port the server is hosted at. Default is 3000.')
|
|
60
|
+
// .option(
|
|
61
|
+
// '--ref-resolver <ref-resolver-function-path>',
|
|
62
|
+
// 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.'
|
|
63
|
+
// )
|
|
64
|
+
// .option(
|
|
65
|
+
// '--watch <paths...>',
|
|
66
|
+
// 'A list of paths to files or directories that should be watched for changes.'
|
|
67
|
+
// )
|
|
68
|
+
// .option(
|
|
69
|
+
// '--watch-ignore <paths...>',
|
|
70
|
+
// 'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported.'
|
|
71
|
+
// )
|
|
72
|
+
// .action(runCommand(dev));
|
|
73
|
+
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).action(runCommand({
|
|
74
|
+
cliVersion: version
|
|
75
|
+
})(init));
|
|
76
|
+
program.parse(process.argv);
|