diff --git a/.gitignore b/.gitignore index 138d17cb4..13901c802 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ **/.next/* **/.env **/lowdefy.yaml + +packages/server/build/** !packages/docs/lowdefy.yaml !packages/docs/howto/**/lowdefy.yaml diff --git a/packages/api/src/routes/rootConfig/menus/filterMenus.js b/packages/api/src/routes/rootConfig/menus/filterMenus.js index a946ecc6c..08bab2105 100644 --- a/packages/api/src/routes/rootConfig/menus/filterMenus.js +++ b/packages/api/src/routes/rootConfig/menus/filterMenus.js @@ -15,7 +15,7 @@ */ import { get } from '@lowdefy/helpers'; -import filterMenuList from './filterMenuList'; +import filterMenuList from './filterMenuList.js'; function filterMenus(context, { menus }) { return menus.map((menu) => { diff --git a/packages/api/src/routes/rootConfig/menus/getMenus.js b/packages/api/src/routes/rootConfig/menus/getMenus.js index a573fc9b0..7f3f7c8f5 100644 --- a/packages/api/src/routes/rootConfig/menus/getMenus.js +++ b/packages/api/src/routes/rootConfig/menus/getMenus.js @@ -14,7 +14,7 @@ limitations under the License. */ -import filterMenus from './filterMenus'; +import filterMenus from './filterMenus.js'; async function getMenus(context) { const unfilteredMenus = await context.readConfigFile('menus.json'); diff --git a/packages/api/src/routes/rootConfig/menus/getMenus.test.js b/packages/api/src/routes/rootConfig/menus/getMenus.test.js index f262aaf76..8ec7ae935 100644 --- a/packages/api/src/routes/rootConfig/menus/getMenus.test.js +++ b/packages/api/src/routes/rootConfig/menus/getMenus.test.js @@ -14,8 +14,8 @@ limitations under the License. */ -import getMenus from './getMenus'; -import testContext from '../../../test/testContext'; +import getMenus from './getMenus.js'; +import testContext from '../../../test/testContext.js'; const mockReadConfigFile = jest.fn(); diff --git a/packages/build/src/scripts/run.js b/packages/build/src/scripts/run.js index 0a8805c99..f67d7ea40 100644 --- a/packages/build/src/scripts/run.js +++ b/packages/build/src/scripts/run.js @@ -19,17 +19,13 @@ import path from 'path'; import build from '../index.js'; async function run() { - // TODO: resolve build with no config - try { - await build({ - logger: console, - buildDirectory: path.resolve(process.cwd(), './.lowdefy/build'), - cacheDirectory: path.resolve(process.cwd(), './.lowdefy/.cache'), - configDirectory: process.cwd(), - }); - } catch (e) { - console.error(e); - } + await build({ + logger: console, + buildDirectory: path.resolve( + process.env.LOWDEFY_BUILD_DIRECTORY || path.join(process.cwd(), './.lowdefy/server/build') + ), + configDirectory: path.resolve(process.env.LOWDEFY_CONFIG_DIRECTORY || process.cwd()), + }); } run(); diff --git a/packages/cli/src/commands/build/build.js b/packages/cli/src/commands/build/build.js index 230dac52d..0d10ad58f 100644 --- a/packages/cli/src/commands/build/build.js +++ b/packages/cli/src/commands/build/build.js @@ -17,13 +17,15 @@ import getServer from './getServer.js'; import installServer from './installServer.js'; import runLowdefyBuild from './runLowdefyBuild.js'; +import runNextBuild from './runNextBuild.js'; async function build({ context }) { context.print.info('Starting build.'); await getServer({ context }); await installServer({ context }); await runLowdefyBuild({ context }); - + await installServer({ context }); + await runNextBuild({ context }); await context.sendTelemetry(); context.print.succeed(`Build successful.`); } diff --git a/packages/cli/src/commands/build/installServer.js b/packages/cli/src/commands/build/installServer.js index cbeb6a1c4..7e6144293 100644 --- a/packages/cli/src/commands/build/installServer.js +++ b/packages/cli/src/commands/build/installServer.js @@ -14,14 +14,8 @@ limitations under the License. */ -import execProcess from '../../utils/execProcess.js'; import spawnProcess from '../../utils/spawnProcess.js'; -// const commands = { -// npm: 'npm install --legacy-peer-deps', -// yarn: 'yarn install', -// }; - const args = { npm: ['install', '--legacy-peer-deps'], yarn: ['install'], diff --git a/packages/cli/src/commands/build/runLowdefyBuild.js b/packages/cli/src/commands/build/runLowdefyBuild.js index 19b2a11be..c797c650c 100644 --- a/packages/cli/src/commands/build/runLowdefyBuild.js +++ b/packages/cli/src/commands/build/runLowdefyBuild.js @@ -14,21 +14,22 @@ limitations under the License. */ -import execProcess from '../../utils/execProcess.js'; - -const commands = { - npm: 'npm run build:lowdefy', - yarn: 'yarn run build:lowdefy', -}; +import spawnProcess from '../../utils/spawnProcess.js'; async function runLowdefyBuild({ context }) { context.print.log('Running Lowdefy build.'); try { - await execProcess({ + await spawnProcess({ context, - command: commands[context.packageManager], + command: context.packageManager, // npm or yarn + args: ['run', 'build:lowdefy'], processOptions: { cwd: context.directories.server, + env: { + ...process.env, + LOWDEFY_BUILD_DIRECTORY: context.directories.build, + LOWDEFY_CONFIG_DIRECTORY: context.directories.base, + }, }, silent: false, }); diff --git a/packages/cli/src/utils/execProcess.js b/packages/cli/src/commands/build/runNextBuild.js similarity index 53% rename from packages/cli/src/utils/execProcess.js rename to packages/cli/src/commands/build/runNextBuild.js index 18f4976af..f25313e86 100644 --- a/packages/cli/src/utils/execProcess.js +++ b/packages/cli/src/commands/build/runNextBuild.js @@ -14,25 +14,24 @@ limitations under the License. */ -import util from 'util'; -import { exec } from 'child_process'; +import spawnProcess from '../../utils/spawnProcess.js'; -const execPromise = util.promisify(exec); - -async function execProcess({ context, command, processOptions, silent }) { - const { stdout, stderr } = await execPromise(command, processOptions); - if (!silent) { - stderr.split('\n').forEach((line) => { - if (line) { - context.print.warn(line); - } - }); - stdout.split('\n').forEach((line) => { - if (line) { - context.print.log(line); - } +async function runNextBuild({ context }) { + context.print.log('Running Next build.'); + try { + await spawnProcess({ + context, + command: context.packageManager, // npm or yarn + args: ['run', 'build:next'], + processOptions: { + cwd: context.directories.server, + }, + silent: false, }); + } catch (error) { + throw new Error('Next build failed.'); } + context.print.log('Next build successful.'); } -export default execProcess; +export default runNextBuild; diff --git a/packages/cli/src/utils/checkForUpdatedVersions.js b/packages/cli/src/utils/checkForUpdatedVersions.js index 7772db122..98015b872 100644 --- a/packages/cli/src/utils/checkForUpdatedVersions.js +++ b/packages/cli/src/utils/checkForUpdatedVersions.js @@ -17,6 +17,14 @@ import axios from 'axios'; async function checkForUpdatedVersions({ cliVersion, lowdefyVersion, print }) { + if (isExperimentalVersion(cliVersion) || isExperimentalVersion(lowdefyVersion)) { + print.warn(` +--------------------------------------------------- + You are using an experimental version of Lowdefy. + Features may change at any time. +---------------------------------------------------`); + return; + } const registryUrl = 'https://registry.npmjs.org/lowdefy'; try { const packageInfo = await axios.get(registryUrl); @@ -44,4 +52,8 @@ async function checkForUpdatedVersions({ cliVersion, lowdefyVersion, print }) { } } +function isExperimentalVersion(version) { + return version.includes('alpha') || version.includes('beta') || version.includes('rc'); +} + export default checkForUpdatedVersions; diff --git a/packages/cli/src/utils/getDirectories.js b/packages/cli/src/utils/getDirectories.js index 059c38c97..d9249276a 100644 --- a/packages/cli/src/utils/getDirectories.js +++ b/packages/cli/src/utils/getDirectories.js @@ -23,7 +23,12 @@ function getDirectories({ baseDirectory, options }) { } else { dotLowdefy = path.resolve(baseDirectory, '.lowdefy'); } - return { dotLowdefy, server: path.join(dotLowdefy, 'server') }; + return { + base: baseDirectory, + build: path.join(dotLowdefy, 'server', 'build'), + dotLowdefy, + server: path.join(dotLowdefy, 'server'), + }; } export default getDirectories; diff --git a/packages/cli/src/utils/getLowdefyYaml.js b/packages/cli/src/utils/getLowdefyYaml.js index 356177512..806215300 100644 --- a/packages/cli/src/utils/getLowdefyYaml.js +++ b/packages/cli/src/utils/getLowdefyYaml.js @@ -43,9 +43,9 @@ async function getLowdefyYaml({ baseDirectory, command }) { `No version specified in "lowdefy.yaml" file. Specify a version in the "lowdefy" field.` ); } - if (!type.isString(lowdefy.lowdefy) || !lowdefy.lowdefy.match(/\d+\.\d+\.\d+(-\w+\.\d+)?/)) { + if (!type.isString(lowdefy.lowdefy)) { throw new Error( - `Version number specified in "lowdefy.yaml" file is not valid. Received ${JSON.stringify( + `Version number specified in "lowdefy.yaml" file should be a string. Received ${JSON.stringify( lowdefy.lowdefy )}.` ); diff --git a/packages/cli/src/utils/print.js b/packages/cli/src/utils/print.js index 66f7ea6e9..280ae641d 100644 --- a/packages/cli/src/utils/print.js +++ b/packages/cli/src/utils/print.js @@ -59,6 +59,7 @@ function createBasicPrint() { let print; function createPrint() { + // TODO: Add debug if (print) return print; if (process.env.CI === 'true') { print = createBasicPrint(); diff --git a/packages/cli/src/utils/spawnProcess.js b/packages/cli/src/utils/spawnProcess.js index ad4da16f3..d7c183964 100644 --- a/packages/cli/src/utils/spawnProcess.js +++ b/packages/cli/src/utils/spawnProcess.js @@ -46,6 +46,11 @@ async function spawnProcess({ context, command, args, processOptions, silent }) } }); + process.on('error', (error) => { + console.log(error); + reject(error); + }); + process.on('exit', (code) => { if (code !== 0) { reject(new Error(`${command} exited with code ${code}`)); diff --git a/packages/server/package.json b/packages/server/package.json index 29eb22507..fc8c89a6c 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -26,7 +26,9 @@ "url": "https://github.com/lowdefy/lowdefy.git" }, "files": [ - "src/*" + "src/*", + "next.config.js", + ".eslintrc.yaml" ], "scripts": { "build": "lowdefy-build && next build", diff --git a/packages/server/src/components/LowdefyContext.js b/packages/server/src/components/LowdefyContext.js index 8d73ca79c..f035c8ffe 100644 --- a/packages/server/src/components/LowdefyContext.js +++ b/packages/server/src/components/LowdefyContext.js @@ -17,7 +17,7 @@ import React from 'react'; import callRequest from '../utils/callRequest.js'; -import blockComponents from '../../.lowdefy/build/plugins/blocks.js'; +import blockComponents from '../../build/plugins/blocks.js'; import components from './components.js'; const LowdefyContext = ({ children }) => { diff --git a/packages/server/src/pages/api/request/[pageId]/[requestId].js b/packages/server/src/pages/api/request/[pageId]/[requestId].js index 43ba1ab62..74d514f88 100644 --- a/packages/server/src/pages/api/request/[pageId]/[requestId].js +++ b/packages/server/src/pages/api/request/[pageId]/[requestId].js @@ -15,7 +15,7 @@ */ import { callRequest, createApiContext } from '@lowdefy/api'; -import connections from '../../../../../.lowdefy/build/plugins/connections.js'; +import connections from '../../../../../build/plugins/connections.js'; export default async function handler(req, res) { try {