mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-13 14:56:54 +08:00
feat: Custom plugins on dev server.
This commit is contained in:
parent
fa46d22675
commit
9f65d130d7
2
.gitignore
vendored
2
.gitignore
vendored
@ -32,3 +32,5 @@ packages/utils/node-utils/test/writeFile/writeFile.txt
|
||||
packages/utils/node-utils/test/copyDirectory/**
|
||||
|
||||
app/**
|
||||
packages/server-dev/plugins/**
|
||||
packages/server/plugins/**
|
||||
|
@ -25,7 +25,7 @@ async function build({ context }) {
|
||||
context.print.info('Starting build.');
|
||||
const directory = context.directories.server;
|
||||
await getServer({ context, packageName: '@lowdefy/server', directory });
|
||||
await copyPluginsFolder({ context });
|
||||
await copyPluginsFolder({ context, directory });
|
||||
await addCustomPluginsAsDeps({ context, directory });
|
||||
await installServer({ context, directory });
|
||||
await runLowdefyBuild({ context, directory });
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import addCustomPluginsAsDeps from '../../utils/addCustomPluginsAsDeps.js';
|
||||
import copyPluginsFolder from '../../utils/copyPluginsFolder.js';
|
||||
import installServer from '../../utils/installServer.js';
|
||||
import runDevServer from './runDevServer.js';
|
||||
import getServer from '../../utils/getServer.js';
|
||||
@ -23,6 +24,7 @@ async function dev({ context }) {
|
||||
const directory = context.directories.dev;
|
||||
context.print.info('Starting development server.');
|
||||
await getServer({ context, packageName: '@lowdefy/server-dev', directory });
|
||||
await copyPluginsFolder({ context, directory });
|
||||
await addCustomPluginsAsDeps({ context, directory });
|
||||
await installServer({ context, directory });
|
||||
context.sendTelemetry();
|
||||
|
@ -18,13 +18,13 @@ import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { copyDirectory } from '@lowdefy/node-utils';
|
||||
|
||||
async function copyPluginsFolder({ context }) {
|
||||
if (context.directories.config === context.directories.server) return;
|
||||
async function copyPluginsFolder({ context, directory }) {
|
||||
if (context.directories.config === directory) return;
|
||||
if (!fs.existsSync(path.resolve(context.directories.config, 'plugins'))) return;
|
||||
|
||||
await copyDirectory(
|
||||
path.resolve(context.directories.config, 'plugins'),
|
||||
path.resolve(context.directories.server, 'plugins')
|
||||
path.resolve(directory, 'plugins')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -14,24 +14,17 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { spawnProcess } from '@lowdefy/node-utils';
|
||||
import build from '@lowdefy/build';
|
||||
import createCustomPluginTypesMap from '../utils/createCustomPluginTypesMap.mjs';
|
||||
|
||||
function lowdefyBuild({ bin, directories, options }) {
|
||||
function lowdefyBuild({ directories, options }) {
|
||||
return async () => {
|
||||
await spawnProcess({
|
||||
command: 'node',
|
||||
args: [bin.lowdefyBuild],
|
||||
const customTypesMap = await createCustomPluginTypesMap({ directories });
|
||||
await build({
|
||||
customTypesMap,
|
||||
directories,
|
||||
logger: console,
|
||||
processOptions: {
|
||||
env: {
|
||||
...process.env,
|
||||
LOWDEFY_BUILD_REF_RESOLVER: options.refResolver,
|
||||
LOWDEFY_DIRECTORY_BUILD: directories.build,
|
||||
LOWDEFY_DIRECTORY_CONFIG: directories.config,
|
||||
LOWDEFY_DIRECTORY_SERVER: process.cwd(),
|
||||
},
|
||||
},
|
||||
silent: false,
|
||||
refResolver: options.refResolver,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
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 { get } from '@lowdefy/helpers';
|
||||
import { readFile } from '@lowdefy/node-utils';
|
||||
import { createPluginTypesMap } from '@lowdefy/build';
|
||||
import YAML from 'yaml';
|
||||
|
||||
async function getPluginDefinitions({ directories }) {
|
||||
let lowdefyYaml = await readFile(path.join(directories.config, 'lowdefy.yaml'));
|
||||
if (!lowdefyYaml) {
|
||||
lowdefyYaml = await readFile(path.join(directories.config, 'lowdefy.yml'));
|
||||
}
|
||||
const lowdefy = YAML.parse(lowdefyYaml);
|
||||
return get(lowdefy, 'plugins', { default: [] });
|
||||
}
|
||||
|
||||
async function createCustomPluginTypesMap({ directories }) {
|
||||
const customTypesMap = {
|
||||
actions: {},
|
||||
blocks: {},
|
||||
connections: {},
|
||||
icons: {},
|
||||
operators: {
|
||||
client: {},
|
||||
server: {},
|
||||
},
|
||||
requests: {},
|
||||
styles: {
|
||||
packages: {},
|
||||
blocks: {},
|
||||
},
|
||||
};
|
||||
|
||||
const pluginDefinitions = await getPluginDefinitions({ directories });
|
||||
|
||||
for (const plugin of pluginDefinitions) {
|
||||
const { default: types } = await import(`${plugin.name}/types`);
|
||||
createPluginTypesMap({
|
||||
packageTypes: types,
|
||||
typesMap: customTypesMap,
|
||||
packageName: plugin.name,
|
||||
version: plugin.version,
|
||||
typePrefix: plugin.typePrefix,
|
||||
});
|
||||
}
|
||||
|
||||
return customTypesMap;
|
||||
}
|
||||
|
||||
export default createCustomPluginTypesMap;
|
@ -32,8 +32,6 @@
|
||||
".eslintrc.yaml"
|
||||
],
|
||||
"scripts": {
|
||||
"build:lowdefy": "lowdefy-build",
|
||||
"build:next": "next build",
|
||||
"start": "node manager/run.mjs",
|
||||
"lint": "next lint",
|
||||
"next": "next"
|
||||
|
@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import React, { Suspense } from 'react';
|
||||
import dynamic from 'next/dynamic';
|
||||
|
||||
import { ErrorBoundary } from '@lowdefy/block-utils';
|
||||
@ -27,11 +27,13 @@ const lowdefy = {};
|
||||
|
||||
function App({ Component, pageProps }) {
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
<LowdefyContext lowdefy={lowdefy}>
|
||||
<Component lowdefy={lowdefy} {...pageProps} />
|
||||
</LowdefyContext>
|
||||
</ErrorBoundary>
|
||||
<Suspense fallback="">
|
||||
<ErrorBoundary>
|
||||
<LowdefyContext lowdefy={lowdefy}>
|
||||
<Component lowdefy={lowdefy} {...pageProps} />
|
||||
</LowdefyContext>
|
||||
</ErrorBoundary>
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,7 @@ import path from 'path';
|
||||
import yargs from 'yargs';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
|
||||
import build from '@lowdefy/build';
|
||||
import createCustomTypesMap from './createCustomTypesMap.mjs';
|
||||
import build, { createCustomPluginTypesMap } from '@lowdefy/build';
|
||||
|
||||
const argv = yargs(hideBin(process.argv)).argv;
|
||||
|
||||
@ -39,7 +38,7 @@ async function run() {
|
||||
),
|
||||
};
|
||||
|
||||
const customTypesMap = await createCustomTypesMap({ directories });
|
||||
const customTypesMap = await createCustomPluginTypesMap({ directories });
|
||||
await build({
|
||||
customTypesMap,
|
||||
directories,
|
||||
|
Loading…
x
Reference in New Issue
Block a user