lowdefy 4.0.0-alpha.9 → 4.0.0-rc.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 +11 -7
- package/dist/commands/dev/dev.js +3 -3
- package/dist/commands/dev/runDevServer.js +8 -4
- package/dist/commands/init/init.js +2 -2
- package/dist/commands/init/lowdefyFile.js +2 -3
- package/dist/commands/init-docker/Dockerfile +34 -0
- package/dist/commands/init-docker/initDocker.js +29 -0
- package/dist/commands/init-vercel/README.md +30 -0
- package/dist/commands/init-vercel/initVercel.js +29 -0
- package/dist/commands/init-vercel/vercel.install.sh +4 -0
- package/dist/commands/start/runStart.js +8 -7
- package/dist/commands/start/start.js +6 -3
- package/dist/index.js +11 -29
- package/dist/program.js +69 -0
- package/dist/utils/addCustomPluginsAsDeps.js +6 -6
- package/dist/utils/checkForUpdatedVersions.js +23 -2
- package/dist/utils/checkPnpmIsInstalled.js +32 -0
- package/dist/utils/createPrint.js +64 -32
- package/dist/utils/createStdOutLineHandler.js +26 -0
- package/dist/utils/errorHandler.js +4 -2
- package/dist/utils/fetchNpmTarball.js +1 -1
- package/dist/utils/findOpenPort.js +1 -1
- package/dist/utils/getCliJson.js +1 -1
- package/dist/utils/getDirectories.js +7 -10
- package/dist/utils/getLowdefyYaml.js +1 -1
- package/dist/utils/getOptions.js +1 -1
- package/dist/utils/getSendTelemetry.js +1 -1
- package/dist/utils/getServer.js +1 -1
- package/dist/utils/installServer.js +11 -18
- package/dist/utils/{copyPluginsFolder.js → readDotEnv.js} +8 -8
- package/dist/utils/resetServerPackageJson.js +20 -0
- package/dist/utils/runCommand.js +1 -1
- package/dist/utils/runLowdefyBuild.js +9 -8
- package/dist/utils/runNextBuild.js +18 -6
- package/dist/utils/startUp.js +7 -4
- package/package.json +20 -20
- package/dist/utils/BatchChanges.js +0 -61
- package/dist/utils/getPackageManager.js +0 -54
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,20 +13,22 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import addCustomPluginsAsDeps from '../../utils/addCustomPluginsAsDeps.js';
|
|
16
|
-
import copyPluginsFolder from '../../utils/copyPluginsFolder.js';
|
|
17
16
|
import getServer from '../../utils/getServer.js';
|
|
18
17
|
import installServer from '../../utils/installServer.js';
|
|
18
|
+
import readDotEnv from '../../utils/readDotEnv.js';
|
|
19
|
+
import resetServerPackageJson from '../../utils/resetServerPackageJson.js';
|
|
19
20
|
import runLowdefyBuild from '../../utils/runLowdefyBuild.js';
|
|
20
21
|
import runNextBuild from '../../utils/runNextBuild.js';
|
|
21
22
|
async function build({ context }) {
|
|
22
23
|
context.print.info('Starting build.');
|
|
24
|
+
readDotEnv(context);
|
|
23
25
|
const directory = context.directories.server;
|
|
24
26
|
await getServer({
|
|
25
27
|
context,
|
|
26
28
|
packageName: '@lowdefy/server',
|
|
27
29
|
directory
|
|
28
30
|
});
|
|
29
|
-
await
|
|
31
|
+
await resetServerPackageJson({
|
|
30
32
|
context,
|
|
31
33
|
directory
|
|
32
34
|
});
|
|
@@ -46,10 +48,12 @@ async function build({ context }) {
|
|
|
46
48
|
context,
|
|
47
49
|
directory
|
|
48
50
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
if (context.options.nextBuild !== false) {
|
|
52
|
+
await runNextBuild({
|
|
53
|
+
context,
|
|
54
|
+
directory
|
|
55
|
+
});
|
|
56
|
+
}
|
|
53
57
|
await context.sendTelemetry({
|
|
54
58
|
sendTypes: true
|
|
55
59
|
});
|
package/dist/commands/dev/dev.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import addCustomPluginsAsDeps from '../../utils/addCustomPluginsAsDeps.js';
|
|
16
|
-
import copyPluginsFolder from '../../utils/copyPluginsFolder.js';
|
|
17
16
|
import installServer from '../../utils/installServer.js';
|
|
17
|
+
import resetServerPackageJson from '../../utils/resetServerPackageJson.js';
|
|
18
18
|
import runDevServer from './runDevServer.js';
|
|
19
19
|
import getServer from '../../utils/getServer.js';
|
|
20
20
|
async function dev({ context }) {
|
|
@@ -25,7 +25,7 @@ async function dev({ context }) {
|
|
|
25
25
|
packageName: '@lowdefy/server-dev',
|
|
26
26
|
directory
|
|
27
27
|
});
|
|
28
|
-
await
|
|
28
|
+
await resetServerPackageJson({
|
|
29
29
|
context,
|
|
30
30
|
directory
|
|
31
31
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,21 +13,25 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
import createStdOutLineHandler from '../../utils/createStdOutLineHandler.js';
|
|
16
17
|
async function runDevServer({ context , directory }) {
|
|
17
18
|
await spawnProcess({
|
|
18
|
-
logger: context.print,
|
|
19
19
|
args: [
|
|
20
20
|
'run',
|
|
21
21
|
'start'
|
|
22
22
|
],
|
|
23
|
-
command: context.
|
|
23
|
+
command: context.pnpmCmd,
|
|
24
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
25
|
+
context
|
|
26
|
+
}),
|
|
24
27
|
processOptions: {
|
|
25
28
|
cwd: directory,
|
|
26
29
|
env: {
|
|
27
30
|
...process.env,
|
|
28
31
|
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
|
29
32
|
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
30
|
-
|
|
33
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel,
|
|
34
|
+
LOWDEFY_SERVER_DEV_OPEN_BROWSER: !!context.options.open,
|
|
31
35
|
LOWDEFY_SERVER_DEV_WATCH: JSON.stringify(context.options.watch),
|
|
32
36
|
LOWDEFY_SERVER_DEV_WATCH_IGNORE: JSON.stringify(context.options.watchIgnore),
|
|
33
37
|
PORT: context.options.port
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -22,7 +22,7 @@ async function init({ context }) {
|
|
|
22
22
|
if (fileExists) {
|
|
23
23
|
throw new Error('Cannot initialize a Lowdefy project, a "lowdefy.yaml" file already exists');
|
|
24
24
|
}
|
|
25
|
-
context.print.log(`Initializing Lowdefy project
|
|
25
|
+
context.print.log(`Initializing Lowdefy project.`);
|
|
26
26
|
await writeFile(lowdefyFilePath, lowdefyFile({
|
|
27
27
|
version: context.cliVersion
|
|
28
28
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -63,5 +63,4 @@ pages:
|
|
|
63
63
|
content: |
|
|
64
64
|
Made by a Lowdefy 🤖
|
|
65
65
|
|
|
66
|
-
`
|
|
67
|
-
);
|
|
66
|
+
`);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
FROM node:18-buster AS builder
|
|
2
|
+
|
|
3
|
+
WORKDIR /lowdefy
|
|
4
|
+
|
|
5
|
+
COPY . .
|
|
6
|
+
# Configure standalone next build
|
|
7
|
+
ENV LOWDEFY_BUILD_OUTPUT_STANDALONE 1
|
|
8
|
+
|
|
9
|
+
# Enable pnpm using corepack
|
|
10
|
+
RUN corepack enable
|
|
11
|
+
|
|
12
|
+
# Build lowdefy app
|
|
13
|
+
RUN pnpx lowdefy@4 build --log-level=debug
|
|
14
|
+
|
|
15
|
+
FROM node:18-alpine AS runner
|
|
16
|
+
|
|
17
|
+
ENV NODE_ENV production
|
|
18
|
+
ENV NEXT_TELEMETRY_DISABLED 1
|
|
19
|
+
|
|
20
|
+
WORKDIR /lowdefy
|
|
21
|
+
|
|
22
|
+
RUN addgroup --system --gid 1001 nodejs
|
|
23
|
+
RUN adduser --system --uid 1001 lowdefy
|
|
24
|
+
|
|
25
|
+
COPY --from=builder /lowdefy/.lowdefy/server/public ./public
|
|
26
|
+
COPY --from=builder --chown=lowdefy:nodejs /lowdefy/.lowdefy/server/.next/standalone ./
|
|
27
|
+
|
|
28
|
+
USER lowdefy
|
|
29
|
+
|
|
30
|
+
EXPOSE 3000
|
|
31
|
+
|
|
32
|
+
ENV PORT 3000
|
|
33
|
+
|
|
34
|
+
CMD ["node", "server.js"]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 url from 'url';
|
|
17
|
+
import { readFile, writeFile } from '@lowdefy/node-utils';
|
|
18
|
+
async function initDocker({ context }) {
|
|
19
|
+
context.print.log(`Initializing Docker deployment.`);
|
|
20
|
+
const dockerfile = await readFile(url.fileURLToPath(new URL('./Dockerfile', import.meta.url)));
|
|
21
|
+
await writeFile(path.join(context.directories.config, 'Dockerfile'), dockerfile);
|
|
22
|
+
context.print.log(`Created 'Dockerfile'.`);
|
|
23
|
+
const dockerignore = await readFile(url.fileURLToPath(new URL('./.dockerignore', import.meta.url)));
|
|
24
|
+
await writeFile(path.join(context.directories.config, '.dockerignore'), dockerignore);
|
|
25
|
+
context.print.log(`Created '.dockerignore'.`);
|
|
26
|
+
await context.sendTelemetry();
|
|
27
|
+
context.print.succeed(`Docker deployment initialized.`);
|
|
28
|
+
}
|
|
29
|
+
export default initDocker;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Vercel Deployment
|
|
2
|
+
|
|
3
|
+
To deploy a Lowdefy app on Vercel a custom install script needs to run to download the server and build the Lowdefy configuration. This script creates a Next.js application that can then be built by Vercel. The install script needs to be placed in an empty directory and it installs the server in its working directory - by default this directory is called `deploy`.
|
|
4
|
+
|
|
5
|
+
The script can be created using the `init-vercel` CLI command, or the following file can be created at `<config-directory>/deploy/vercel.install.sh`:
|
|
6
|
+
|
|
7
|
+
###### vercel.install.sh
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Read Lowdefy version from lowdefy.yaml using sed
|
|
11
|
+
LOWDEFY_VERSION=$(sed -nE "s/lowdefy:(.*)/\1/p" ../lowdefy.yaml)
|
|
12
|
+
# Substitution params are to trim whitespace from the LOWDEFY_VERSION var
|
|
13
|
+
npx lowdefy@${LOWDEFY_VERSION//[[:space:]]/} build --config-directory ../ --server-directory . --no-next-build --log-level=debug
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
To deploy a Lowdefy app on Vercel:
|
|
17
|
+
|
|
18
|
+
- Create a new project
|
|
19
|
+
- Connect the GitHub, Gitlab or BitBucket repository with your Lowdefy app to the Vercel project
|
|
20
|
+
- The framework preset should be Next.js
|
|
21
|
+
- The root directory should be `<config-directory>/deploy`
|
|
22
|
+
- `<config-directory>` is the path to the directory in which the `lowdefy.yaml` file is placed
|
|
23
|
+
- Eg: If the `lowdefy.yaml` is in the top level of the repository the configured root directory should be `deploy`
|
|
24
|
+
- Eg: If the `lowdefy.yaml` is in the directory `apps/app_name` the configured root directory should be `apps/app_name/deploy`
|
|
25
|
+
- The build command should be `pnpm next build`
|
|
26
|
+
- The install command should be `sh vercel.install.sh`
|
|
27
|
+
|
|
28
|
+
Secrets can be set in the Environment Variables settings section by creating environment variables prefixed with `LOWDEFY_SECRET_`. Different secrets can be set for production and preview deployments.
|
|
29
|
+
|
|
30
|
+
All other Vercel configuration like domain names, preview deploy branches, serverless regions and redirects can be configured as desired.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 url from 'url';
|
|
17
|
+
import { readFile, writeFile } from '@lowdefy/node-utils';
|
|
18
|
+
async function initVercel({ context }) {
|
|
19
|
+
context.print.log(`Initializing Vercel deployment.`);
|
|
20
|
+
const installScript = await readFile(url.fileURLToPath(new URL('./vercel.install.sh', import.meta.url)));
|
|
21
|
+
await writeFile(path.join(context.directories.config, 'deploy', 'vercel.install.sh'), installScript);
|
|
22
|
+
context.print.log(`Created 'vercel.install.sh'.`);
|
|
23
|
+
const readMe = await readFile(url.fileURLToPath(new URL('./README.md', import.meta.url)));
|
|
24
|
+
await writeFile(path.join(context.directories.config, 'deploy', 'README.md'), readMe);
|
|
25
|
+
context.print.log(`Created 'README.md'.`);
|
|
26
|
+
await context.sendTelemetry();
|
|
27
|
+
context.print.succeed(`Vercel deployment initialized.`);
|
|
28
|
+
}
|
|
29
|
+
export default initVercel;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# Read Lowdefy version from lowdefy.yaml using sed
|
|
2
|
+
LOWDEFY_VERSION=$(sed -nE "s/lowdefy:(.*)/\1/p" ../lowdefy.yaml)
|
|
3
|
+
# Substitution params are to trim whitespace from the LOWDEFY_VERSION var
|
|
4
|
+
npx lowdefy@${LOWDEFY_VERSION//[[:space:]]/} build --config-directory ../ --server-directory . --no-next-build --log-level=debug
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,24 +13,25 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
import createStdOutLineHandler from '../../utils/createStdOutLineHandler.js';
|
|
16
17
|
async function runStart({ context , directory }) {
|
|
17
|
-
context.print.spin(`Running "${context.packageManager} run start".`);
|
|
18
18
|
await spawnProcess({
|
|
19
|
-
logger: context.print,
|
|
20
19
|
args: [
|
|
21
20
|
'run',
|
|
22
21
|
'start'
|
|
23
22
|
],
|
|
24
|
-
command: context.
|
|
23
|
+
command: context.pnpmCmd,
|
|
24
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
25
|
+
context
|
|
26
|
+
}),
|
|
25
27
|
processOptions: {
|
|
26
28
|
cwd: directory,
|
|
27
29
|
env: {
|
|
28
30
|
...process.env,
|
|
29
|
-
|
|
31
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel,
|
|
30
32
|
PORT: context.options.port
|
|
31
33
|
}
|
|
32
|
-
}
|
|
33
|
-
silent: false
|
|
34
|
+
}
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
export default runStart;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,15 +13,18 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import runStart from './runStart.js';
|
|
16
|
+
import readDotEnv from '../../utils/readDotEnv.js';
|
|
16
17
|
// TODO: Handle "spawn yarn ENOENT" error if no built server exists.
|
|
17
18
|
async function build({ context }) {
|
|
18
|
-
context.print.info('Starting server.');
|
|
19
19
|
context.sendTelemetry({
|
|
20
20
|
sendTypes: true
|
|
21
21
|
});
|
|
22
|
-
|
|
22
|
+
readDotEnv(context);
|
|
23
|
+
const serverProcess = runStart({
|
|
23
24
|
context,
|
|
24
25
|
directory: context.directories.server
|
|
25
26
|
});
|
|
27
|
+
context.print.succeed('Started server.');
|
|
28
|
+
await serverProcess;
|
|
26
29
|
}
|
|
27
30
|
export default build;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*
|
|
3
|
-
Copyright 2020-
|
|
3
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
4
4
|
|
|
5
5
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
you may not use this file except in compliance with the License.
|
|
@@ -13,31 +13,13 @@
|
|
|
13
13
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
See the License for the specific language governing permissions and
|
|
15
15
|
limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
program.name('lowdefy').description(description).version(cliVersion, '-v, --version');
|
|
27
|
-
program.command('build').description('Build a Lowdefy production app.').usage(`[options]`).option('--config-directory <config-directory>', 'Change config directory. Default is the current working directory.').option('--disable-telemetry', 'Disable telemetry.').option('--output-directory <output-directory>', 'Change the directory to which build artifacts are saved. Default is "<config-directory>/.lowdefy".').option('--package-manager <package-manager>', 'The package manager to use. Options are "npm" or "yarn".').option('--ref-resolver <ref-resolver-function-path>', 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.').option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').action(runCommand({
|
|
28
|
-
cliVersion,
|
|
29
|
-
handler: build
|
|
30
|
-
}));
|
|
31
|
-
program.command('dev').description('Start a Lowdefy development server.').usage(`[options]`).option('--config-directory <config-directory>', 'Change config directory. Default is the current working directory.').option('--disable-telemetry', 'Disable telemetry.').option('--package-manager <package-manager>', 'The package manager to use. Options are "npm" or "yarn".').option('--port <port>', 'Change the port the development server is hosted at. Default is 3000.').option('--ref-resolver <ref-resolver-function-path>', 'Path to a JavaScript file containing a _ref resolver function to be used as the app default _ref resolver.').option('--watch <paths...>', 'A list of paths to files or directories that should be watched for changes. Globs are supported. Specify each path to watch separated by spaces.').option('--watch-ignore <paths...>', 'A list of paths to files or directories that should be ignored by the file watcher. Globs are supported. Specify each path to watch separated by spaces.').option('--dev-directory <dev-directory>', 'Change the development server directory. Default is "<config-directory>/.lowdefy/dev".').action(runCommand({
|
|
32
|
-
cliVersion,
|
|
33
|
-
handler: dev
|
|
34
|
-
}));
|
|
35
|
-
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).action(runCommand({
|
|
36
|
-
cliVersion,
|
|
37
|
-
handler: init
|
|
38
|
-
}));
|
|
39
|
-
program.command('start').description('Start a Lowdefy production app.').usage(`[options]`).option('--config-directory <config-directory>', 'Change config directory. Default is the current working directory.').option('--disable-telemetry', 'Disable telemetry.').option('--output-directory <output-directory>', 'Change the directory to which build artifacts are saved. Default is "<config-directory>/.lowdefy".').option('--package-manager <package-manager>', 'The package manager to use. Options are "npm" or "yarn".').option('--port <port>', 'Change the port the server is hosted at. Default is 3000.').option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').action(runCommand({
|
|
40
|
-
cliVersion,
|
|
41
|
-
handler: start
|
|
42
|
-
}));
|
|
43
|
-
program.parse(process.argv);
|
|
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,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 initDocker from './commands/init-docker/initDocker.js';
|
|
21
|
+
import initVercel from './commands/init-vercel/initVercel.js';
|
|
22
|
+
import start from './commands/start/start.js';
|
|
23
|
+
import runCommand from './utils/runCommand.js';
|
|
24
|
+
const require = createRequire(import.meta.url);
|
|
25
|
+
const packageJson = require('../package.json');
|
|
26
|
+
const { description , version: cliVersion } = packageJson;
|
|
27
|
+
const program = new Command();
|
|
28
|
+
program.name('lowdefy').description(description).version(cliVersion, '-v, --version');
|
|
29
|
+
const options = {
|
|
30
|
+
configDirectory: new Option('--config-directory <config-directory>', 'Change config directory. Default is the current working directory.').env('LOWDEFY_DIRECTORY_CONFIG'),
|
|
31
|
+
devDirectory: new Option('--dev-directory <dev-directory>', 'Change the development server directory. Default is "<config-directory>/.lowdefy/dev".').env('LOWDEFY_DIRECTORY_DEV'),
|
|
32
|
+
disableTelemetry: new Option('--disable-telemetry', 'Disable telemetry.').env('LOWDEFY_DISABLE_TELEMETRY'),
|
|
33
|
+
logLevel: new Option('--log-level <level>', 'The minimum severity of logs to show in the CLI output.').choices([
|
|
34
|
+
'error',
|
|
35
|
+
'warn',
|
|
36
|
+
'info',
|
|
37
|
+
'debug'
|
|
38
|
+
]).default('info').env('LOWDEFY_LOG_LEVEL'),
|
|
39
|
+
port: new Option('--port <port>', 'Change the port the development server is hosted at. Default is 3000.').env('PORT'),
|
|
40
|
+
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.'),
|
|
41
|
+
serverDirectory: new Option('--server-directory <server-directory>', 'Change the server directory. Default is "<config-directory>/.lowdefy/server".').env('LOWDEFY_DIRECTORY_SERVER'),
|
|
42
|
+
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.'),
|
|
43
|
+
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.')
|
|
44
|
+
};
|
|
45
|
+
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({
|
|
46
|
+
cliVersion,
|
|
47
|
+
handler: build
|
|
48
|
+
}));
|
|
49
|
+
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({
|
|
50
|
+
cliVersion,
|
|
51
|
+
handler: dev
|
|
52
|
+
}));
|
|
53
|
+
program.command('init').description('Initialize a Lowdefy project.').usage(`[options]`).addOption(options.disableTelemetry).addOption(options.logLevel).action(runCommand({
|
|
54
|
+
cliVersion,
|
|
55
|
+
handler: init
|
|
56
|
+
}));
|
|
57
|
+
program.command('init-docker').description('Initialize Dockerfile.').usage(`[options]`).addOption(options.configDirectory).addOption(options.disableTelemetry).addOption(options.logLevel).action(runCommand({
|
|
58
|
+
cliVersion,
|
|
59
|
+
handler: initDocker
|
|
60
|
+
}));
|
|
61
|
+
program.command('init-vercel').description('Initialize Vercel deployment installation scripts.').usage(`[options]`).addOption(options.configDirectory).addOption(options.disableTelemetry).addOption(options.logLevel).action(runCommand({
|
|
62
|
+
cliVersion,
|
|
63
|
+
handler: initVercel
|
|
64
|
+
}));
|
|
65
|
+
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({
|
|
66
|
+
cliVersion,
|
|
67
|
+
handler: start
|
|
68
|
+
}));
|
|
69
|
+
export default program;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -17,14 +17,14 @@ import { readFile, writeFile } from '@lowdefy/node-utils';
|
|
|
17
17
|
async function addCustomPluginsAsDeps({ context , directory }) {
|
|
18
18
|
const packageJsonPath = path.join(directory, 'package.json');
|
|
19
19
|
const packageJson = JSON.parse(await readFile(packageJsonPath));
|
|
20
|
-
const
|
|
20
|
+
const dependencies = packageJson.dependencies;
|
|
21
21
|
Object.values(context.plugins).forEach((plugin)=>{
|
|
22
|
-
|
|
22
|
+
dependencies[plugin.name] = plugin.version;
|
|
23
23
|
});
|
|
24
24
|
// Sort dependencies
|
|
25
|
-
packageJson.
|
|
26
|
-
Object.keys(
|
|
27
|
-
packageJson.
|
|
25
|
+
packageJson.dependencies = {};
|
|
26
|
+
Object.keys(dependencies).sort().forEach((name)=>{
|
|
27
|
+
packageJson.dependencies[name] = dependencies[name];
|
|
28
28
|
});
|
|
29
29
|
const newPackageJsonContent = JSON.stringify(packageJson, null, 2).concat('\n');
|
|
30
30
|
await writeFile(packageJsonPath, newPackageJsonContent);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,7 +13,28 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import axios from 'axios';
|
|
16
|
+
import semver from 'semver';
|
|
16
17
|
async function checkForUpdatedVersions({ cliVersion , lowdefyVersion , print }) {
|
|
18
|
+
if (lowdefyVersion === 'local') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (!semver.valid(lowdefyVersion)) {
|
|
22
|
+
throw new Error(`
|
|
23
|
+
---------------------------------------------------
|
|
24
|
+
Version ${lowdefyVersion} is not a valid version.
|
|
25
|
+
---------------------------------------------------`);
|
|
26
|
+
}
|
|
27
|
+
if (semver.major(lowdefyVersion) === 3) {
|
|
28
|
+
throw new Error(`
|
|
29
|
+
---------------------------------------------------
|
|
30
|
+
You are attempting to run a version 3 app with the version 4 CLI.
|
|
31
|
+
Please update your app to version 4 using the migration guide.
|
|
32
|
+
View the migration guide here:
|
|
33
|
+
https://docs.lowdefy.com/v3-to-v4
|
|
34
|
+
Alternatively, run the app with the version 3 CLI.
|
|
35
|
+
To do this, run 'npx lowdefy@3'.
|
|
36
|
+
---------------------------------------------------`);
|
|
37
|
+
}
|
|
17
38
|
if (isExperimentalVersion(cliVersion) || isExperimentalVersion(lowdefyVersion)) {
|
|
18
39
|
print.warn(`
|
|
19
40
|
---------------------------------------------------
|
|
@@ -31,7 +52,7 @@ async function checkForUpdatedVersions({ cliVersion , lowdefyVersion , print })
|
|
|
31
52
|
-------------------------------------------------------------
|
|
32
53
|
You are not using the latest version of the Lowdefy CLI.
|
|
33
54
|
Please update to version ${latestVersion}.
|
|
34
|
-
To always use the latest version, run '
|
|
55
|
+
To always use the latest version, run 'pnpx lowdefy@4'.
|
|
35
56
|
-------------------------------------------------------------`);
|
|
36
57
|
}
|
|
37
58
|
if (lowdefyVersion && lowdefyVersion !== latestVersion) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,7 +13,12 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import ora from 'ora';
|
|
16
|
-
|
|
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}`;
|
|
17
22
|
function getTime() {
|
|
18
23
|
const time = new Date(Date.now());
|
|
19
24
|
const h = time.getHours();
|
|
@@ -21,52 +26,79 @@ function getTime() {
|
|
|
21
26
|
const s = time.getSeconds();
|
|
22
27
|
return `${h > 9 ? '' : '0'}${h}:${m > 9 ? '' : '0'}${m}:${s > 9 ? '' : '0'}${s}`;
|
|
23
28
|
}
|
|
24
|
-
|
|
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 }) {
|
|
25
49
|
const spinner = ora({
|
|
26
50
|
spinner: 'random',
|
|
27
|
-
prefixText: ()=>
|
|
28
|
-
,
|
|
51
|
+
prefixText: ()=>dim(getTime()),
|
|
29
52
|
color: 'blue'
|
|
30
53
|
});
|
|
31
|
-
return {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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);
|
|
47
76
|
}
|
|
48
|
-
function createBasicPrint() {
|
|
49
|
-
const { error , info , log , warn } = console;
|
|
50
|
-
return {
|
|
51
|
-
type: 'basic',
|
|
77
|
+
function createBasicPrint({ logLevel ='info' }) {
|
|
78
|
+
const { error , info , log , warn , debug } = console;
|
|
79
|
+
return filterLevels({
|
|
52
80
|
error,
|
|
53
81
|
info,
|
|
54
82
|
log,
|
|
55
83
|
spin: log,
|
|
56
84
|
succeed: log,
|
|
57
|
-
warn
|
|
58
|
-
|
|
85
|
+
warn,
|
|
86
|
+
debug
|
|
87
|
+
}, logLevel);
|
|
59
88
|
}
|
|
60
89
|
// Memoise print so that error handler can get the same spinner object
|
|
61
90
|
let print;
|
|
62
|
-
function createPrint() {
|
|
63
|
-
// TODO: Add debug
|
|
91
|
+
function createPrint({ logLevel }) {
|
|
64
92
|
if (print) return print;
|
|
65
|
-
if (process.env.CI === 'true') {
|
|
66
|
-
print = createBasicPrint(
|
|
93
|
+
if (process.env.CI === 'true' || process.env.CI === '1') {
|
|
94
|
+
print = createBasicPrint({
|
|
95
|
+
logLevel
|
|
96
|
+
});
|
|
67
97
|
return print;
|
|
68
98
|
}
|
|
69
|
-
print = createOraPrint(
|
|
99
|
+
print = createOraPrint({
|
|
100
|
+
logLevel
|
|
101
|
+
});
|
|
70
102
|
return print;
|
|
71
103
|
}
|
|
72
104
|
export { createOraPrint, createBasicPrint };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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
|
+
*/ function createStdOutLineHandler({ context }) {
|
|
16
|
+
function stdOutLineHandler(line) {
|
|
17
|
+
try {
|
|
18
|
+
const { print , msg } = JSON.parse(line);
|
|
19
|
+
context.print[print](msg);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
context.print.log(line);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return stdOutLineHandler;
|
|
25
|
+
}
|
|
26
|
+
export default createStdOutLineHandler;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -37,7 +37,9 @@ async function logError({ error , context ={} }) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
async function errorHandler({ context , error }) {
|
|
40
|
-
const print = createPrint(
|
|
40
|
+
const print = createPrint({
|
|
41
|
+
logLevel: 'info'
|
|
42
|
+
});
|
|
41
43
|
print.error(error.message);
|
|
42
44
|
if (!context.disableTelemetry) {
|
|
43
45
|
await logError({
|
package/dist/utils/getCliJson.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,17 +14,14 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import path from 'path';
|
|
16
16
|
function getDirectories({ configDirectory , options }) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
dotLowdefy = path.resolve(configDirectory, '.lowdefy');
|
|
22
|
-
}
|
|
17
|
+
const dotLowdefy = path.resolve(configDirectory, '.lowdefy');
|
|
18
|
+
const server = options.serverDirectory ? path.resolve(options.serverDirectory) : path.join(dotLowdefy, 'server');
|
|
19
|
+
// TODO: Read server directory from env var
|
|
20
|
+
// Priority should be CLI arguments, env var, CLI options in Lowdefy config
|
|
23
21
|
return {
|
|
24
22
|
config: configDirectory,
|
|
25
|
-
build: path.join(
|
|
26
|
-
|
|
27
|
-
server: options.serverDirectory ? path.resolve(options.serverDirectory) : path.join(dotLowdefy, 'server'),
|
|
23
|
+
build: path.join(server, 'build'),
|
|
24
|
+
server,
|
|
28
25
|
dev: options.devDirectory ? path.resolve(options.devDirectory) : path.join(dotLowdefy, 'dev')
|
|
29
26
|
};
|
|
30
27
|
}
|
package/dist/utils/getOptions.js
CHANGED
package/dist/utils/getServer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,31 +13,24 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
-
const args = {
|
|
17
|
-
npm: [
|
|
18
|
-
'install',
|
|
19
|
-
'--legacy-peer-deps'
|
|
20
|
-
],
|
|
21
|
-
yarn: [
|
|
22
|
-
'install'
|
|
23
|
-
]
|
|
24
|
-
};
|
|
25
16
|
async function installServer({ context , directory }) {
|
|
26
|
-
context.print.spin(
|
|
17
|
+
context.print.spin('Installing dependencies.');
|
|
27
18
|
try {
|
|
28
19
|
await spawnProcess({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
command: context.pnpmCmd,
|
|
21
|
+
args: [
|
|
22
|
+
'install',
|
|
23
|
+
'--no-frozen-lockfile'
|
|
24
|
+
],
|
|
25
|
+
stdOutLineHandler: (line)=>context.print.debug(line),
|
|
32
26
|
processOptions: {
|
|
33
27
|
cwd: directory
|
|
34
|
-
}
|
|
35
|
-
silent: false
|
|
28
|
+
}
|
|
36
29
|
});
|
|
37
30
|
} catch (error) {
|
|
38
31
|
console.log(error);
|
|
39
|
-
throw new Error(
|
|
32
|
+
throw new Error('Dependency installation failed.');
|
|
40
33
|
}
|
|
41
|
-
context.print.log(
|
|
34
|
+
context.print.log('Dependencies install successfully.');
|
|
42
35
|
}
|
|
43
36
|
export default installServer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import path from 'path';
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
import dotenv from 'dotenv';
|
|
17
|
+
function readDotEnv(context) {
|
|
18
|
+
dotenv.config({
|
|
19
|
+
path: path.join(context.directories.config, '.env'),
|
|
20
|
+
silent: true
|
|
21
|
+
});
|
|
22
22
|
}
|
|
23
|
-
export default
|
|
23
|
+
export default readDotEnv;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2023 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 { copyFileOrDirectory } from '@lowdefy/node-utils';
|
|
17
|
+
async function resetServerPackageJson({ directory }) {
|
|
18
|
+
await copyFileOrDirectory(path.join(directory, 'package.original.json'), path.join(directory, 'package.json'));
|
|
19
|
+
}
|
|
20
|
+
export default resetServerPackageJson;
|
package/dist/utils/runCommand.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,27 +13,28 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
import createStdOutLineHandler from './createStdOutLineHandler.js';
|
|
16
17
|
async function runLowdefyBuild({ context , directory }) {
|
|
17
|
-
context.print.
|
|
18
|
+
context.print.spin('Running Lowdefy build.');
|
|
18
19
|
try {
|
|
19
20
|
await spawnProcess({
|
|
20
|
-
logger: context.print,
|
|
21
|
-
command: context.packageManager,
|
|
22
21
|
args: [
|
|
23
22
|
'run',
|
|
24
23
|
'build:lowdefy'
|
|
25
24
|
],
|
|
25
|
+
command: context.pnpmCmd,
|
|
26
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
27
|
+
context
|
|
28
|
+
}),
|
|
26
29
|
processOptions: {
|
|
27
30
|
cwd: directory,
|
|
28
31
|
env: {
|
|
29
32
|
...process.env,
|
|
30
33
|
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,
|
|
31
|
-
LOWDEFY_DIRECTORY_BUILD: context.directories.build,
|
|
32
34
|
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,
|
|
33
|
-
|
|
35
|
+
LOWDEFY_LOG_LEVEL: context.options.logLevel
|
|
34
36
|
}
|
|
35
|
-
}
|
|
36
|
-
silent: false
|
|
37
|
+
}
|
|
37
38
|
});
|
|
38
39
|
} catch (error) {
|
|
39
40
|
throw new Error('Lowdefy build failed.');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -13,20 +13,32 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { spawnProcess } from '@lowdefy/node-utils';
|
|
16
|
+
function createStdOutLineHandler({ context }) {
|
|
17
|
+
function stdOutLineHandler(line) {
|
|
18
|
+
// Matches next build output of form: ┌ λ / 261 B 403 kB
|
|
19
|
+
const match = line.match(/┌ λ \/\s*\d* [a-zA-Z]*\s*(\d* [a-zA-Z]*)/);
|
|
20
|
+
if (match) {
|
|
21
|
+
context.print.info(`Home page first load JS size: ${match[1]}.`);
|
|
22
|
+
}
|
|
23
|
+
context.print.debug(line);
|
|
24
|
+
}
|
|
25
|
+
return stdOutLineHandler;
|
|
26
|
+
}
|
|
16
27
|
async function runNextBuild({ context , directory }) {
|
|
17
|
-
context.print.
|
|
28
|
+
context.print.spin('Running Next build.');
|
|
18
29
|
try {
|
|
19
30
|
await spawnProcess({
|
|
20
|
-
|
|
21
|
-
command: context.packageManager,
|
|
31
|
+
command: context.pnpmCmd,
|
|
22
32
|
args: [
|
|
23
33
|
'run',
|
|
24
34
|
'build:next'
|
|
25
35
|
],
|
|
36
|
+
stdOutLineHandler: createStdOutLineHandler({
|
|
37
|
+
context
|
|
38
|
+
}),
|
|
26
39
|
processOptions: {
|
|
27
40
|
cwd: directory
|
|
28
|
-
}
|
|
29
|
-
silent: false
|
|
41
|
+
}
|
|
30
42
|
});
|
|
31
43
|
} catch (error) {
|
|
32
44
|
throw new Error('Next build failed.');
|
package/dist/utils/startUp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -15,17 +15,16 @@
|
|
|
15
15
|
*/ import path from 'path';
|
|
16
16
|
import { type } from '@lowdefy/helpers';
|
|
17
17
|
import checkForUpdatedVersions from './checkForUpdatedVersions.js';
|
|
18
|
+
import checkPnpmIsInstalled from './checkPnpmIsInstalled.js';
|
|
18
19
|
import getCliJson from './getCliJson.js';
|
|
19
20
|
import getDirectories from './getDirectories.js';
|
|
20
21
|
import getLowdefyYaml from './getLowdefyYaml.js';
|
|
21
22
|
import getOptions from './getOptions.js';
|
|
22
|
-
import getPackageManager from './getPackageManager.js';
|
|
23
23
|
import getSendTelemetry from './getSendTelemetry.js';
|
|
24
24
|
import createPrint from './createPrint.js';
|
|
25
25
|
async function startUp({ context , options ={} , command }) {
|
|
26
26
|
context.command = command.name();
|
|
27
27
|
context.commandLineOptions = options;
|
|
28
|
-
context.print = createPrint();
|
|
29
28
|
context.configDirectory = path.resolve(options.configDirectory || process.cwd());
|
|
30
29
|
const { cliConfig , lowdefyVersion , plugins } = await getLowdefyYaml(context);
|
|
31
30
|
context.cliConfig = cliConfig;
|
|
@@ -34,8 +33,12 @@ async function startUp({ context , options ={} , command }) {
|
|
|
34
33
|
const { appId } = await getCliJson(context);
|
|
35
34
|
context.appId = appId;
|
|
36
35
|
context.options = getOptions(context);
|
|
36
|
+
context.print = createPrint({
|
|
37
|
+
logLevel: context.options.logLevel
|
|
38
|
+
});
|
|
37
39
|
context.directories = getDirectories(context);
|
|
38
|
-
context.
|
|
40
|
+
context.pnpmCmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';
|
|
41
|
+
checkPnpmIsInstalled(context);
|
|
39
42
|
await checkForUpdatedVersions(context);
|
|
40
43
|
context.sendTelemetry = getSendTelemetry(context);
|
|
41
44
|
if (type.isNone(lowdefyVersion)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lowdefy",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Lowdefy CLI",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -32,34 +32,34 @@
|
|
|
32
32
|
],
|
|
33
33
|
"exports": "./dist/index.js",
|
|
34
34
|
"scripts": {
|
|
35
|
-
"build": "
|
|
35
|
+
"build": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start --copy-files",
|
|
36
36
|
"clean": "rm -rf dist && rm -rf .lowdefy",
|
|
37
|
-
"start": "
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"test": "FORCE_COLOR=3 yarn node --experimental-vm-modules $(yarn bin jest)"
|
|
37
|
+
"start": "node ./dist/index.js",
|
|
38
|
+
"prepublishOnly": "pnpm build",
|
|
39
|
+
"test": "FORCE_COLOR=3 node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
41
40
|
},
|
|
42
41
|
"dependencies": {
|
|
43
|
-
"@lowdefy/helpers": "4.0.0-
|
|
44
|
-
"@lowdefy/node-utils": "4.0.0-
|
|
45
|
-
"axios": "
|
|
46
|
-
"
|
|
47
|
-
"commander": "9.0.0",
|
|
42
|
+
"@lowdefy/helpers": "4.0.0-rc.1",
|
|
43
|
+
"@lowdefy/node-utils": "4.0.0-rc.1",
|
|
44
|
+
"axios": "1.2.2",
|
|
45
|
+
"commander": "9.4.1",
|
|
48
46
|
"decompress": "4.2.1",
|
|
49
47
|
"decompress-targz": "4.1.1",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
48
|
+
"dotenv": "16.0.3",
|
|
49
|
+
"ora": "6.1.2",
|
|
50
|
+
"semver": "7.3.8",
|
|
51
|
+
"uuid": "9.0.0",
|
|
52
|
+
"yaml": "2.2.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@jest/globals": "
|
|
56
|
-
"@swc/cli": "0.1.
|
|
57
|
-
"@swc/core": "1.
|
|
58
|
-
"@swc/jest": "0.2.
|
|
59
|
-
"jest": "
|
|
55
|
+
"@jest/globals": "28.1.0",
|
|
56
|
+
"@swc/cli": "0.1.59",
|
|
57
|
+
"@swc/core": "1.3.24",
|
|
58
|
+
"@swc/jest": "0.2.24",
|
|
59
|
+
"jest": "28.1.0"
|
|
60
60
|
},
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "ecc4f16c19eede929eda177db524cf13a8053379"
|
|
65
65
|
}
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
*/ let BatchChanges = class BatchChanges {
|
|
16
|
-
newChange(...args) {
|
|
17
|
-
this.args.push(args);
|
|
18
|
-
this.delay = this.minDelay;
|
|
19
|
-
this._startTimer();
|
|
20
|
-
}
|
|
21
|
-
_startTimer() {
|
|
22
|
-
if (this.timer) {
|
|
23
|
-
clearTimeout(this.timer);
|
|
24
|
-
}
|
|
25
|
-
if (this.running) {
|
|
26
|
-
this.repeat = true;
|
|
27
|
-
} else {
|
|
28
|
-
this.timer = setTimeout(this._call, this.delay);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async _call() {
|
|
32
|
-
this.running = true;
|
|
33
|
-
try {
|
|
34
|
-
const args = this.args;
|
|
35
|
-
this.args = [];
|
|
36
|
-
await this.fn(args);
|
|
37
|
-
this.running = false;
|
|
38
|
-
if (this.repeat) {
|
|
39
|
-
this.repeat = false;
|
|
40
|
-
this._call();
|
|
41
|
-
}
|
|
42
|
-
} catch (error) {
|
|
43
|
-
this.running = false;
|
|
44
|
-
this.context.print.error(error.message);
|
|
45
|
-
this.delay *= 2;
|
|
46
|
-
this.context.print.warn(`Retrying in ${this.delay / 1000}s.`);
|
|
47
|
-
this._startTimer();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
constructor({ fn , context , minDelay }){
|
|
51
|
-
this._call = this._call.bind(this);
|
|
52
|
-
this.args = [];
|
|
53
|
-
this.context = context;
|
|
54
|
-
this.delay = minDelay || 500;
|
|
55
|
-
this.fn = fn;
|
|
56
|
-
this.minDelay = minDelay || 500;
|
|
57
|
-
this.repeat = false;
|
|
58
|
-
this.running = false;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
export default BatchChanges;
|
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
*/ // Source https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/should-use-yarn.ts
|
|
16
|
-
/*
|
|
17
|
-
The MIT License (MIT)
|
|
18
|
-
|
|
19
|
-
Copyright (c) 2021 Vercel, Inc.
|
|
20
|
-
|
|
21
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
-
in the Software without restriction, including without limitation the rights
|
|
24
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
-
furnished to do so, subject to the following conditions:
|
|
27
|
-
|
|
28
|
-
The above copyright notice and this permission notice shall be included in all
|
|
29
|
-
copies or substantial portions of the Software.
|
|
30
|
-
|
|
31
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
-
SOFTWARE.
|
|
38
|
-
*/ import { execSync } from 'child_process';
|
|
39
|
-
function getPackageManager({ options }) {
|
|
40
|
-
if (options.packageManager) return options.packageManager;
|
|
41
|
-
try {
|
|
42
|
-
const userAgent = process.env.npm_config_user_agent;
|
|
43
|
-
if (userAgent && userAgent.startsWith('yarn')) {
|
|
44
|
-
return 'yarn';
|
|
45
|
-
}
|
|
46
|
-
execSync('yarnpkg --version', {
|
|
47
|
-
stdio: 'ignore'
|
|
48
|
-
});
|
|
49
|
-
return 'yarn';
|
|
50
|
-
} catch (e) {
|
|
51
|
-
return 'npm';
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
export default getPackageManager;
|