fix: Fixes for CLI build.

This commit is contained in:
Sam Tolmay 2021-11-25 21:00:55 +02:00
parent f1d53e80ed
commit 3e58d59982
No known key found for this signature in database
GPG Key ID: D004126FCD1A6DF0
17 changed files with 72 additions and 53 deletions

2
.gitignore vendored
View File

@ -12,6 +12,8 @@
**/.next/*
**/.env
**/lowdefy.yaml
packages/server/build/**
!packages/docs/lowdefy.yaml
!packages/docs/howto/**/lowdefy.yaml

View File

@ -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) => {

View File

@ -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');

View File

@ -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();

View File

@ -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();

View File

@ -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.`);
}

View File

@ -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'],

View File

@ -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,
});

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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
)}.`
);

View File

@ -59,6 +59,7 @@ function createBasicPrint() {
let print;
function createPrint() {
// TODO: Add debug
if (print) return print;
if (process.env.CI === 'true') {
print = createBasicPrint();

View File

@ -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}`));

View File

@ -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",

View File

@ -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 }) => {

View File

@ -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 {