lowdefy 4.0.0-alpha.29 → 4.0.0-alpha.30
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 +62 -0
- package/dist/commands/dev/dev.js +46 -0
- package/dist/commands/dev/runDevServer.js +43 -0
- package/dist/commands/init/init.js +36 -0
- package/dist/commands/init/lowdefyFile.js +66 -0
- package/dist/commands/start/runStart.js +37 -0
- package/dist/commands/start/start.js +30 -0
- package/dist/index.js +25 -0
- package/dist/program.js +59 -0
- package/dist/utils/addCustomPluginsAsDeps.js +32 -0
- package/dist/utils/checkForUpdatedVersions.js +53 -0
- package/dist/utils/checkPnpmIsInstalled.js +32 -0
- package/dist/utils/copyPluginsFolder.js +26 -0
- package/dist/utils/createPrint.js +105 -0
- package/dist/utils/createStdOutLineHandler.js +26 -0
- package/dist/utils/errorHandler.js +51 -0
- package/dist/utils/fetchNpmTarball.js +56 -0
- package/dist/utils/findOpenPort.js +58 -0
- package/dist/utils/getCliJson.js +32 -0
- package/dist/utils/getDirectories.js +28 -0
- package/dist/utils/getLowdefyYaml.js +57 -0
- package/dist/utils/getOptions.js +23 -0
- package/dist/utils/getSendTelemetry.js +54 -0
- package/dist/utils/getServer.js +45 -0
- package/dist/utils/installServer.js +35 -0
- package/dist/utils/readDotEnv.js +23 -0
- package/dist/utils/runCommand.js +41 -0
- package/dist/utils/runLowdefyBuild.js +44 -0
- package/dist/utils/runNextBuild.js +48 -0
- package/dist/utils/startUp.js +51 -0
- package/package.json +4 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 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 readDotEnv from '../../utils/readDotEnv.js';
|
|
20
|
+
import runLowdefyBuild from '../../utils/runLowdefyBuild.js';
|
|
21
|
+
import runNextBuild from '../../utils/runNextBuild.js';
|
|
22
|
+
async function build({ context }) {
|
|
23
|
+
context.print.info('Starting build.');
|
|
24
|
+
readDotEnv(context);
|
|
25
|
+
const directory = context.directories.server;
|
|
26
|
+
await getServer({
|
|
27
|
+
context,
|
|
28
|
+
packageName: '@lowdefy/server',
|
|
29
|
+
directory
|
|
30
|
+
});
|
|
31
|
+
await copyPluginsFolder({
|
|
32
|
+
context,
|
|
33
|
+
directory
|
|
34
|
+
});
|
|
35
|
+
await addCustomPluginsAsDeps({
|
|
36
|
+
context,
|
|
37
|
+
directory
|
|
38
|
+
});
|
|
39
|
+
await installServer({
|
|
40
|
+
context,
|
|
41
|
+
directory
|
|
42
|
+
});
|
|
43
|
+
await runLowdefyBuild({
|
|
44
|
+
context,
|
|
45
|
+
directory
|
|
46
|
+
});
|
|
47
|
+
await installServer({
|
|
48
|
+
context,
|
|
49
|
+
directory
|
|
50
|
+
});
|
|
51
|
+
if (context.options.nextBuild !== false) {
|
|
52
|
+
await runNextBuild({
|
|
53
|
+
context,
|
|
54
|
+
directory
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
await context.sendTelemetry({
|
|
58
|
+
sendTypes: true
|
|
59
|
+
});
|
|
60
|
+
context.print.succeed(`Build successful.`);
|
|
61
|
+
}
|
|
62
|
+
export default build;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 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';
|
|
20
|
+
async function dev({ context }) {
|
|
21
|
+
const directory = context.directories.dev;
|
|
22
|
+
context.print.info('Starting development server.');
|
|
23
|
+
await getServer({
|
|
24
|
+
context,
|
|
25
|
+
packageName: '@lowdefy/server-dev',
|
|
26
|
+
directory
|
|
27
|
+
});
|
|
28
|
+
await copyPluginsFolder({
|
|
29
|
+
context,
|
|
30
|
+
directory
|
|
31
|
+
});
|
|
32
|
+
await addCustomPluginsAsDeps({
|
|
33
|
+
context,
|
|
34
|
+
directory
|
|
35
|
+
});
|
|
36
|
+
await installServer({
|
|
37
|
+
context,
|
|
38
|
+
directory
|
|
39
|
+
});
|
|
40
|
+
context.sendTelemetry();
|
|
41
|
+
await runDevServer({
|
|
42
|
+
context,
|
|
43
|
+
directory
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export default dev;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
import createStdOutLineHandler from '../../utils/createStdOutLineHandler.js';
|
|
17
|
+
async function runDevServer({ context , directory }) {
|
|
18
|
+
await spawnProcess({
|
|
19
|
+
args: [
|
|
20
|
+
'run',
|
|
21
|
+
'start'
|
|
22
|
+
],
|
|
23
|
+
command: context.pnpmCmd,
|
|
24
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
25
|
+
context
|
|
26
|
+
}),
|
|
27
|
+
processOptions: {
|
|
28
|
+
cwd: directory,
|
|
29
|
+
env: {
|
|
30
|
+
...process.env,
|
|
31
|
+
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
|
32
|
+
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
33
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel,
|
|
34
|
+
LOWDEFY_SERVER_DEV_OPEN_BROWSER: !!context.options.open,
|
|
35
|
+
LOWDEFY_SERVER_DEV_WATCH: JSON.stringify(context.options.watch),
|
|
36
|
+
LOWDEFY_SERVER_DEV_WATCH_IGNORE: JSON.stringify(context.options.watchIgnore),
|
|
37
|
+
PORT: context.options.port
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
silent: false
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export default runDevServer;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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(lowdefyFilePath, lowdefyFile({
|
|
27
|
+
version: context.cliVersion
|
|
28
|
+
}));
|
|
29
|
+
context.print.log(`Created 'lowdefy.yaml'.`);
|
|
30
|
+
await writeFile(path.resolve('./.gitignore'), `.lowdefy/**
|
|
31
|
+
.env`);
|
|
32
|
+
context.print.log(`Created '.gitignore'.`);
|
|
33
|
+
await context.sendTelemetry();
|
|
34
|
+
context.print.succeed(`Project initialized.`);
|
|
35
|
+
}
|
|
36
|
+
export default init;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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: AiOutlineHeart
|
|
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
|
+
`);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
import createStdOutLineHandler from '../../utils/createStdOutLineHandler.js';
|
|
17
|
+
async function runStart({ context , directory }) {
|
|
18
|
+
await spawnProcess({
|
|
19
|
+
args: [
|
|
20
|
+
'run',
|
|
21
|
+
'start'
|
|
22
|
+
],
|
|
23
|
+
command: context.pnpmCmd,
|
|
24
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
25
|
+
context
|
|
26
|
+
}),
|
|
27
|
+
processOptions: {
|
|
28
|
+
cwd: directory,
|
|
29
|
+
env: {
|
|
30
|
+
...process.env,
|
|
31
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel,
|
|
32
|
+
PORT: context.options.port
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export default runStart;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 runStart from './runStart.js';
|
|
16
|
+
import readDotEnv from '../../utils/readDotEnv.js';
|
|
17
|
+
// TODO: Handle "spawn yarn ENOENT" error if no built server exists.
|
|
18
|
+
async function build({ context }) {
|
|
19
|
+
context.sendTelemetry({
|
|
20
|
+
sendTypes: true
|
|
21
|
+
});
|
|
22
|
+
readDotEnv(context);
|
|
23
|
+
const serverProcess = runStart({
|
|
24
|
+
context,
|
|
25
|
+
directory: context.directories.server
|
|
26
|
+
});
|
|
27
|
+
context.print.succeed('Started server.');
|
|
28
|
+
await serverProcess;
|
|
29
|
+
}
|
|
30
|
+
export default build;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2020-2022 Lowdefy, Inc
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
*/ const nodeMajorVersion = process.version.split(/^v(\d+)/)[1];
|
|
17
|
+
if (Number(nodeMajorVersion) < 14) {
|
|
18
|
+
// TODO: This error handled with telemetry.
|
|
19
|
+
throw new Error(`Nodejs versions below v14 are not supported. You are using ${process.version}. Update Nodejs to the latest LTS version to use Lowdefy.`);
|
|
20
|
+
}
|
|
21
|
+
async function run() {
|
|
22
|
+
const { default: program } = await import('./program.js');
|
|
23
|
+
program.parse(process.argv);
|
|
24
|
+
}
|
|
25
|
+
run().then(()=>{});
|
package/dist/program.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 { createRequire } from 'module';
|
|
16
|
+
import { Command, Option } 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 start from './commands/start/start.js';
|
|
21
|
+
import runCommand from './utils/runCommand.js';
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
const packageJson = require('../package.json');
|
|
24
|
+
const { description , version: cliVersion } = packageJson;
|
|
25
|
+
const program = new Command();
|
|
26
|
+
program.name('lowdefy').description(description).version(cliVersion, '-v, --version');
|
|
27
|
+
const options = {
|
|
28
|
+
configDirectory: new Option('--config-directory <config-directory>', 'Change config directory. Default is the current working directory.').env('LOWDEFY_DIRECTORY_CONFIG'),
|
|
29
|
+
devDirectory: new Option('--dev-directory <dev-directory>', 'Change the development server directory. Default is "<config-directory>/.lowdefy/dev".').env('LOWDEFY_DIRECTORY_DEV'),
|
|
30
|
+
disableTelemetry: new Option('--disable-telemetry', 'Disable telemetry.').env('LOWDEFY_DISABLE_TELEMETRY'),
|
|
31
|
+
logLevel: new Option('--log-level <level>', 'The minimum severity of logs to show in the CLI output.').choices([
|
|
32
|
+
'error',
|
|
33
|
+
'warn',
|
|
34
|
+
'info',
|
|
35
|
+
'debug'
|
|
36
|
+
]).default('info').env('LOWDEFY_LOG_LEVEL'),
|
|
37
|
+
port: new Option('--port <port>', 'Change the port the development server is hosted at. Default is 3000.').env('PORT'),
|
|
38
|
+
refResolver: new 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.'),
|
|
39
|
+
serverDirectory: new Option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').env('LOWDEFY_DIRECTORY_SERVER'),
|
|
40
|
+
watch: new 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.'),
|
|
41
|
+
watchIgnore: new 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.')
|
|
42
|
+
};
|
|
43
|
+
program.command('build').description('Build a Lowdefy production app.').usage(`[options]`).addOption(options.configDirectory).addOption(options.disableTelemetry).addOption(options.logLevel).option('--no-next-build', 'Do not build the Next.js server.').addOption(options.refResolver).addOption(options.serverDirectory).action(runCommand({
|
|
44
|
+
cliVersion,
|
|
45
|
+
handler: build
|
|
46
|
+
}));
|
|
47
|
+
program.command('dev').description('Start a Lowdefy development server.').usage(`[options]`).addOption(options.configDirectory).addOption(options.devDirectory).addOption(options.disableTelemetry).addOption(options.logLevel).option('--no-open', 'Do not open a new tab in the default browser.').addOption(options.port).addOption(options.refResolver).addOption(options.watch).addOption(options.watchIgnore).action(runCommand({
|
|
48
|
+
cliVersion,
|
|
49
|
+
handler: dev
|
|
50
|
+
}));
|
|
51
|
+
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).addOption(options.disableTelemetry).addOption(options.logLevel).action(runCommand({
|
|
52
|
+
cliVersion,
|
|
53
|
+
handler: init
|
|
54
|
+
}));
|
|
55
|
+
program.command('start').description('Start a Lowdefy production app.').usage(`[options]`).addOption(options.configDirectory).addOption(options.disableTelemetry).addOption(options.logLevel).addOption(options.port).addOption(options.serverDirectory).action(runCommand({
|
|
56
|
+
cliVersion,
|
|
57
|
+
handler: start
|
|
58
|
+
}));
|
|
59
|
+
export default program;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 dependencies = packageJson.dependencies;
|
|
21
|
+
Object.values(context.plugins).forEach((plugin)=>{
|
|
22
|
+
dependencies[plugin.name] = plugin.version;
|
|
23
|
+
});
|
|
24
|
+
// Sort dependencies
|
|
25
|
+
packageJson.dependencies = {};
|
|
26
|
+
Object.keys(dependencies).sort().forEach((name)=>{
|
|
27
|
+
packageJson.dependencies[name] = dependencies[name];
|
|
28
|
+
});
|
|
29
|
+
const newPackageJsonContent = JSON.stringify(packageJson, null, 2).concat('\n');
|
|
30
|
+
await writeFile(packageJsonPath, newPackageJsonContent);
|
|
31
|
+
}
|
|
32
|
+
export default addCustomPluginsAsDeps;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 axios from 'axios';
|
|
16
|
+
async function checkForUpdatedVersions({ cliVersion , lowdefyVersion , print }) {
|
|
17
|
+
if (isExperimentalVersion(cliVersion) || isExperimentalVersion(lowdefyVersion)) {
|
|
18
|
+
print.warn(`
|
|
19
|
+
---------------------------------------------------
|
|
20
|
+
You are using an experimental version of Lowdefy.
|
|
21
|
+
Features may change at any time.
|
|
22
|
+
---------------------------------------------------`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const registryUrl = 'https://registry.npmjs.org/lowdefy';
|
|
26
|
+
try {
|
|
27
|
+
const packageInfo = await axios.get(registryUrl);
|
|
28
|
+
const latestVersion = packageInfo.data['dist-tags'].latest;
|
|
29
|
+
if (cliVersion !== latestVersion) {
|
|
30
|
+
print.warn(`
|
|
31
|
+
-------------------------------------------------------------
|
|
32
|
+
You are not using the latest version of the Lowdefy CLI.
|
|
33
|
+
Please update to version ${latestVersion}.
|
|
34
|
+
To always use the latest version, run 'npx lowdefy@latest'.
|
|
35
|
+
-------------------------------------------------------------`);
|
|
36
|
+
}
|
|
37
|
+
if (lowdefyVersion && lowdefyVersion !== latestVersion) {
|
|
38
|
+
print.warn(`
|
|
39
|
+
-------------------------------------------------------------
|
|
40
|
+
Your app is not using the latest Lowdefy version, ${lowdefyVersion}.
|
|
41
|
+
Please update your app to version ${latestVersion}.
|
|
42
|
+
View the changelog here:
|
|
43
|
+
https://github.com/lowdefy/lowdefy/blob/main/CHANGELOG.md
|
|
44
|
+
-------------------------------------------------------------`);
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
print.warn('Failed to check for latest Lowdefy version.');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function isExperimentalVersion(version) {
|
|
51
|
+
return version.includes('alpha') || version.includes('beta') || version.includes('rc');
|
|
52
|
+
}
|
|
53
|
+
export default checkForUpdatedVersions;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 { execSync } from 'child_process';
|
|
16
|
+
function checkPnpmIsInstalled({ print , pnpmCmd }) {
|
|
17
|
+
try {
|
|
18
|
+
execSync(`${pnpmCmd} --version`, {
|
|
19
|
+
stdio: 'ignore'
|
|
20
|
+
});
|
|
21
|
+
} catch (e) {
|
|
22
|
+
print.error(`
|
|
23
|
+
-------------------------------------------------------------
|
|
24
|
+
The package manager "pnpm" is required to run Lowdefy.
|
|
25
|
+
Install pnpm as describe here:
|
|
26
|
+
https://pnpm.io/installation
|
|
27
|
+
or run 'corepack enable'.
|
|
28
|
+
-------------------------------------------------------------`);
|
|
29
|
+
throw new Error('The package manager "pnpm" is required to run Lowdefy.');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export default checkPnpmIsInstalled;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 { cleanDirectory, copyDirectory } from '@lowdefy/node-utils';
|
|
18
|
+
async function copyPluginsFolder({ context , directory }) {
|
|
19
|
+
if (context.directories.config === directory) return;
|
|
20
|
+
if (!fs.existsSync(path.join(context.directories.config, 'plugins'))) return;
|
|
21
|
+
await cleanDirectory(path.join(directory, 'plugins'));
|
|
22
|
+
await copyDirectory(path.join(context.directories.config, 'plugins'), path.join(directory, 'plugins'), {
|
|
23
|
+
filter: (path1)=>!path1.includes('node_modules')
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export default copyPluginsFolder;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 ora from 'ora';
|
|
16
|
+
const reset = '\x1b[0m';
|
|
17
|
+
const red = (text)=>`\x1b[31m${text}${reset}`;
|
|
18
|
+
const green = (text)=>`\x1b[32m${text}${reset}`;
|
|
19
|
+
const yellow = (text)=>`\x1b[33m${text}${reset}`;
|
|
20
|
+
const blue = (text)=>`\x1b[34m${text}${reset}`;
|
|
21
|
+
const dim = (text)=>`\x1b[2m${text}${reset}`;
|
|
22
|
+
function getTime() {
|
|
23
|
+
const time = new Date(Date.now());
|
|
24
|
+
const h = time.getHours();
|
|
25
|
+
const m = time.getMinutes();
|
|
26
|
+
const s = time.getSeconds();
|
|
27
|
+
return `${h > 9 ? '' : '0'}${h}:${m > 9 ? '' : '0'}${m}:${s > 9 ? '' : '0'}${s}`;
|
|
28
|
+
}
|
|
29
|
+
// Same levels as pino with added custom levels
|
|
30
|
+
const logLevelValues = {
|
|
31
|
+
error: 50,
|
|
32
|
+
warn: 40,
|
|
33
|
+
succeed: 33,
|
|
34
|
+
spin: 32,
|
|
35
|
+
log: 31,
|
|
36
|
+
info: 30,
|
|
37
|
+
debug: 20
|
|
38
|
+
};
|
|
39
|
+
function filterLevels(logger, level) {
|
|
40
|
+
const levelValue = logLevelValues[level];
|
|
41
|
+
Object.keys(logger).forEach((key)=>{
|
|
42
|
+
if (logLevelValues[key] < levelValue) {
|
|
43
|
+
logger[key] = ()=>{};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return logger;
|
|
47
|
+
}
|
|
48
|
+
function createOraPrint({ logLevel }) {
|
|
49
|
+
const spinner = ora({
|
|
50
|
+
spinner: 'random',
|
|
51
|
+
prefixText: ()=>dim(getTime()),
|
|
52
|
+
color: 'blue'
|
|
53
|
+
});
|
|
54
|
+
return filterLevels({
|
|
55
|
+
error: (text)=>spinner.fail(red(text)),
|
|
56
|
+
info: (text)=>spinner.info(blue(text)),
|
|
57
|
+
log: (text)=>spinner.stopAndPersist({
|
|
58
|
+
symbol: '∙',
|
|
59
|
+
text
|
|
60
|
+
}),
|
|
61
|
+
spin: (text)=>spinner.start(text),
|
|
62
|
+
succeed: (text)=>spinner.succeed(green(text)),
|
|
63
|
+
warn: (text)=>spinner.warn(yellow(text)),
|
|
64
|
+
debug: (text)=>{
|
|
65
|
+
if (spinner.isSpinning) {
|
|
66
|
+
spinner.stopAndPersist({
|
|
67
|
+
symbol: '∙'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
spinner.stopAndPersist({
|
|
71
|
+
symbol: dim('+'),
|
|
72
|
+
text: dim(text)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}, logLevel);
|
|
76
|
+
}
|
|
77
|
+
function createBasicPrint({ logLevel ='info' }) {
|
|
78
|
+
const { error , info , log , warn , debug } = console;
|
|
79
|
+
return filterLevels({
|
|
80
|
+
error,
|
|
81
|
+
info,
|
|
82
|
+
log,
|
|
83
|
+
spin: log,
|
|
84
|
+
succeed: log,
|
|
85
|
+
warn,
|
|
86
|
+
debug
|
|
87
|
+
}, logLevel);
|
|
88
|
+
}
|
|
89
|
+
// Memoise print so that error handler can get the same spinner object
|
|
90
|
+
let print;
|
|
91
|
+
function createPrint({ logLevel }) {
|
|
92
|
+
if (print) return print;
|
|
93
|
+
if (process.env.CI === 'true' || process.env.CI === '1') {
|
|
94
|
+
print = createBasicPrint({
|
|
95
|
+
logLevel
|
|
96
|
+
});
|
|
97
|
+
return print;
|
|
98
|
+
}
|
|
99
|
+
print = createOraPrint({
|
|
100
|
+
logLevel
|
|
101
|
+
});
|
|
102
|
+
return print;
|
|
103
|
+
}
|
|
104
|
+
export { createOraPrint, createBasicPrint };
|
|
105
|
+
export default createPrint;
|