Merge branch 'develop' into fix-docs

This commit is contained in:
Gervwyk 2022-03-01 08:32:30 +02:00
commit 35db96e54f
93 changed files with 105 additions and 96 deletions

2
.pnp.cjs generated
View File

@ -3571,7 +3571,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["@next/eslint-plugin-next", "npm:12.0.10"],
["chokidar", "npm:3.5.3"],
["dotenv", "npm:15.0.0"],
["js-yaml", "npm:4.1.0"],
["less", "npm:4.1.2"],
["less-loader", "virtual:003bebd8b7a948d12b44e2c11a621884feb1891eea3645171e827971487f79396db9f7422bc411ccf3f90877e94ec86f5c3da70b96efb5daddb2ee3b35eae5c6#npm:10.2.0"],
["next", "virtual:003bebd8b7a948d12b44e2c11a621884feb1891eea3645171e827971487f79396db9f7422bc411ccf3f90877e94ec86f5c3da70b96efb5daddb2ee3b35eae5c6#npm:12.0.10"],
@ -3582,6 +3581,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
["react-dom", "virtual:573fe255dffc9c89f4f7aa60da718603753ee98acc55d6772bbd0ebdcf07f9183fb8e54b4f3f2246c538a14ead402db8d2e076039c667d1538702638a0cc87b8#npm:17.0.2"],
["react-icons", "virtual:003bebd8b7a948d12b44e2c11a621884feb1891eea3645171e827971487f79396db9f7422bc411ccf3f90877e94ec86f5c3da70b96efb5daddb2ee3b35eae5c6#npm:4.3.1"],
["swr", "virtual:b951ea20ab6cada5f665e8389a50d828047e6b6f10e6ebaddde1e74a94868ec6ec703ff140742f295ef663cf92da1bc80fe9bbeaab30196cba0e992f38cd19ea#npm:1.1.2"],
["yaml", "npm:2.0.0-10"],
["yargs", "npm:17.3.1"]
],
"linkType": "SOFT",

View File

@ -6,7 +6,6 @@ packageExtensions:
dependencies:
react: "*"
react-dom: "*"
classnames: "*"
rc-checkbox@*:
dependencies:
react: "*"

View File

@ -20,7 +20,7 @@ import runRefResolver from './runRefResolver.js';
async function getRefContent({ context, refDef, referencedFrom }) {
let content;
if (refDef.path === 'lowdefy.yaml') {
if (refDef.path === 'lowdefy.yaml' || refDef.path === 'lowdefy.yml') {
content = await getConfigFile({ context, refDef, referencedFrom });
} else if (refDef.resolver || context.refResolver) {
content = await runRefResolver({ context, refDef, referencedFrom });

View File

@ -15,17 +15,23 @@
*/
import getServer from '../../utils/getServer.js';
import installServer from './installServer.js';
import runLowdefyBuild from './runLowdefyBuild.js';
import runNextBuild from './runNextBuild.js';
import installServer from '../../utils/installServer.js';
import mergePackageJson from '../../utils/mergePackageJson.js';
import runLowdefyBuild from '../../utils/runLowdefyBuild.js';
import runNextBuild from '../../utils/runNextBuild.js';
async function build({ context }) {
context.print.info('Starting build.');
const directory = context.directory.server;
await getServer({ context, packageName: '@lowdefy/server' });
await installServer({ context });
await runLowdefyBuild({ context });
await installServer({ context });
await runNextBuild({ context });
await mergePackageJson({
context,
serverDirectory: directory,
});
await installServer({ context, directory });
await runLowdefyBuild({ context, directory });
await installServer({ context, directory });
await runNextBuild({ context, directory });
await context.sendTelemetry({ sendTypes: true });
context.print.succeed(`Build successful.`);
}

View File

@ -1,43 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { spawnProcess } from '@lowdefy/node-utils';
const args = {
npm: ['install', '--legacy-peer-deps'],
yarn: ['install'],
};
async function installServer({ context }) {
context.print.spin(`Running ${context.packageManager} install.`);
try {
await spawnProcess({
logger: context.print,
command: context.packageManager, // npm or yarn
args: args[context.packageManager],
processOptions: {
cwd: context.directories.server,
},
silent: false,
});
} catch (error) {
console.log(error);
throw new Error(`${context.packageManager} install failed.`);
}
context.print.log(`${context.packageManager} install successful.`);
}
export default installServer;

View File

@ -14,16 +14,22 @@
limitations under the License.
*/
import installServer from './installServer.js';
import installServer from '../../utils/installServer.js';
import mergePackageJson from '../../utils/mergePackageJson.js';
import runDevServer from './runDevServer.js';
import getServer from '../../utils/getServer.js';
async function dev({ context }) {
const directory = context.directory.dev;
context.print.info('Starting development server.');
await getServer({ context, packageName: '@lowdefy/server-dev' });
await installServer({ context });
await mergePackageJson({
context,
serverDirectory: directory,
});
await installServer({ context, directory });
context.sendTelemetry();
await runDevServer({ context });
await runDevServer({ context, directory });
}
export default dev;

View File

@ -16,13 +16,13 @@
import { spawnProcess } from '@lowdefy/node-utils';
async function runDevServer({ context }) {
async function runDevServer({ context, directory }) {
await spawnProcess({
logger: context.print,
args: ['run', 'start'],
command: context.packageManager, // npm or yarn
processOptions: {
cwd: context.directories.dev,
cwd: directory,
env: {
...process.env,
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,

View File

@ -16,14 +16,14 @@
import { spawnProcess } from '@lowdefy/node-utils';
async function runStart({ context }) {
async function runStart({ context, directory }) {
context.print.spin(`Running "${context.packageManager} run start".`);
await spawnProcess({
logger: context.print,
args: ['run', 'start'],
command: context.packageManager, // npm or yarn
processOptions: {
cwd: context.directories.server,
cwd: directory,
env: {
...process.env,
LOWDEFY_DIRECTORY_CONFIG: context.directories.config,

View File

@ -21,7 +21,7 @@ import runStart from './runStart.js';
async function build({ context }) {
context.print.info('Starting server.');
context.sendTelemetry({ sendTypes: true });
await runStart({ context });
await runStart({ context, directory: context.directory.server });
}
export default build;

View File

@ -19,7 +19,7 @@ import path from 'path';
import { cleanDirectory, readFile } from '@lowdefy/node-utils';
import fetchNpmTarball from './fetchNpmTarball.js';
async function getServer({ context, packageName }) {
async function getServer({ context, packageName, directory }) {
if (context.lowdefyVersion === 'local') {
context.print.warn(`Running local ${packageName}.`);
return;
@ -27,28 +27,26 @@ async function getServer({ context, packageName }) {
let fetchServer = false;
const serverExists = fs.existsSync(path.join(context.directories.server, 'package.json'));
const serverExists = fs.existsSync(path.join(directory, 'package.json'));
if (!serverExists) fetchServer = true;
if (serverExists) {
const serverPackageConfig = JSON.parse(
await readFile(path.join(context.directories.server, 'package.json'))
);
const serverPackageConfig = JSON.parse(await readFile(path.join(directory, 'package.json')));
if (serverPackageConfig.version !== context.lowdefyVersion) {
fetchServer = true;
context.print.warn(`Removing @lowdefy/server with version ${serverPackageConfig.version}`);
await cleanDirectory(context.directories.server);
context.print.warn(`Removing ${packageName} with version ${serverPackageConfig.version}`);
await cleanDirectory(directory);
}
}
if (fetchServer) {
context.print.spin('Fetching @lowdefy/server from npm.');
context.print.spin(`Fetching ${packageName} from npm.`);
await fetchNpmTarball({
packageName,
version: context.lowdefyVersion,
directory: context.directories.server,
directory: directory,
});
context.print.log('Fetched @lowdefy/server from npm.');
context.print.log(`Fetched ${packageName} from npm.`);
}
}

View File

@ -21,7 +21,7 @@ const args = {
yarn: ['install'],
};
async function installServer({ context }) {
async function installServer({ context, directory }) {
context.print.spin(`Running ${context.packageManager} install.`);
try {
await spawnProcess({
@ -29,7 +29,7 @@ async function installServer({ context }) {
command: context.packageManager, // npm or yarn
args: args[context.packageManager],
processOptions: {
cwd: context.directories.dev,
cwd: directory,
},
silent: false,
});

View File

@ -0,0 +1,34 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import path from 'path';
import { mergeObjects } from '@lowdefy/helpers';
import { readFile, writeFile } from '@lowdefy/node-utils';
async function mergePackageJson({ context, serverDirectory }) {
const serverPackageJsonPath = path.join(serverDirectory, 'package.json');
const serverPackageJson = JSON.parse(await readFile(serverPackageJsonPath));
const configPackageJson = JSON.parse(
await readFile(path.join(context.directories.config, 'package.json'))
);
const mergedPackageJson = mergeObjects([serverPackageJson, configPackageJson]);
const mergedPackageJsonContent = JSON.stringify(mergedPackageJson, null, 2).concat('\n');
await writeFile(serverPackageJsonPath, mergedPackageJsonContent);
}
export default mergePackageJson;

View File

@ -16,7 +16,7 @@
import { spawnProcess } from '@lowdefy/node-utils';
async function runLowdefyBuild({ context }) {
async function runLowdefyBuild({ context, directory }) {
context.print.log('Running Lowdefy build.');
try {
await spawnProcess({
@ -24,7 +24,7 @@ async function runLowdefyBuild({ context }) {
command: context.packageManager, // npm or yarn
args: ['run', 'build:lowdefy'],
processOptions: {
cwd: context.directories.server,
cwd: directory,
env: {
...process.env,
LOWDEFY_BUILD_REF_RESOLVER: context.options.refResolver,

View File

@ -16,7 +16,7 @@
import { spawnProcess } from '@lowdefy/node-utils';
async function runNextBuild({ context }) {
async function runNextBuild({ context, directory }) {
context.print.log('Running Next build.');
try {
await spawnProcess({
@ -24,7 +24,7 @@ async function runNextBuild({ context }) {
command: context.packageManager, // npm or yarn
args: ['run', 'build:next'],
processOptions: {
cwd: context.directories.server,
cwd: directory,
},
silent: false,
});

View File

@ -34,8 +34,7 @@
"scripts": {
"build:lowdefy": "lowdefy-build",
"build:next": "next build",
"dev": "next dev",
"start": "node src/manager/run.mjs",
"start": "node manager/run.mjs",
"lint": "next lint",
"next": "next"
},
@ -63,7 +62,6 @@
"@lowdefy/operators-yaml": "4.0.0-alpha.7",
"chokidar": "3.5.3",
"dotenv": "15.0.0",
"js-yaml": "4.1.0",
"next": "12.0.10",
"next-auth": "4.1.2",
"opener": "1.5.2",
@ -71,6 +69,7 @@
"react-dom": "17.0.2",
"react-icons": "4.3.1",
"swr": "1.1.2",
"yaml": "2.0.0-10",
"yargs": "17.3.1"
},
"devDependencies": {

View File

@ -14,6 +14,6 @@
limitations under the License.
*/
import App from '../components/App.js';
import App from '../lib/components/App.js';
export default App;

View File

@ -14,6 +14,6 @@
limitations under the License.
*/
import App from '../components/App.js';
import App from '../lib/components/App.js';
export default App;

View File

@ -19,9 +19,9 @@ import dynamic from 'next/dynamic';
import { ErrorBoundary } from '@lowdefy/block-utils';
import LowdefyContext from '../components/LowdefyContext.js';
import LowdefyContext from '../lib/components/LowdefyContext.js';
import '../../build/plugins/styles.less';
import '../build/plugins/styles.less';
const lowdefy = {};

View File

@ -16,8 +16,8 @@
import { callRequest, createApiContext } from '@lowdefy/api';
import { getSecretsFromEnv } from '@lowdefy/node-utils';
import connections from '../../../../../build/plugins/connections.js';
import operators from '../../../../../build/plugins/operatorsServer.js';
import connections from '../../../../build/plugins/connections.js';
import operators from '../../../../build/plugins/operatorsServer.js';
export default async function handler(req, res) {
try {

View File

@ -14,6 +14,6 @@
limitations under the License.
*/
import App from '../components/App.js';
import App from '../lib/components/App.js';
export default App;

View File

@ -1,7 +1,7 @@
const withLess = require('next-with-less');
const lowdefyConfig = require('./build/config.json');
// TODO: Trance env and args from cli that is required on the server.
// TODO: Trace env and args from cli that is required on the server.
module.exports = withLess({
basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
lessLoaderOptions: {

View File

@ -16,7 +16,7 @@
import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
import Page from '../components/Page.js';
import Page from '../lib/components/Page.js';
export async function getStaticProps() {
// TODO: get the right api context options

View File

@ -16,7 +16,7 @@
import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
import Page from '../components/Page.js';
import Page from '../lib/components/Page.js';
export async function getServerSideProps(context) {
const { pageId } = context.params;

View File

@ -18,9 +18,9 @@ import React from 'react';
import { ErrorBoundary } from '@lowdefy/block-utils';
import LowdefyContext from '../components/LowdefyContext.js';
import LowdefyContext from '../lib/components/LowdefyContext.js';
import '../../build/plugins/styles.less';
import '../build/plugins/styles.less';
const lowdefy = {};

View File

@ -16,8 +16,8 @@
import { callRequest, createApiContext } from '@lowdefy/api';
import { getSecretsFromEnv } from '@lowdefy/node-utils';
import connections from '../../../../../build/plugins/connections.js';
import operators from '../../../../../build/plugins/operatorsServer.js';
import connections from '../../../../build/plugins/connections.js';
import operators from '../../../../build/plugins/operatorsServer.js';
export default async function handler(req, res) {
try {

View File

@ -16,7 +16,7 @@
import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
import Page from '../components/Page.js';
import Page from '../lib/components/Page.js';
export async function getServerSideProps() {
// TODO: is this build directory configurable from the cli?

View File

@ -96,3 +96,13 @@ test('merge list of objects, larger indices overwrite smaller', () => {
}
`);
});
test('merge objects with null', () => {
const obj = {
a: 'a',
b: 1,
c: { a: 'b' },
};
expect(mergeObjects([obj, null])).toEqual(obj);
expect(mergeObjects([null, obj])).toEqual(obj);
});

View File

@ -2650,7 +2650,6 @@ __metadata:
"@next/eslint-plugin-next": 12.0.10
chokidar: 3.5.3
dotenv: 15.0.0
js-yaml: 4.1.0
less: 4.1.2
less-loader: 10.2.0
next: 12.0.10
@ -2661,6 +2660,7 @@ __metadata:
react-dom: 17.0.2
react-icons: 4.3.1
swr: 1.1.2
yaml: 2.0.0-10
yargs: 17.3.1
languageName: unknown
linkType: soft