feat(cli): Add install custom plugins as dev dependencies.

This commit is contained in:
Sam 2022-03-01 16:45:18 +02:00
parent 05dcaa73a7
commit b6ab43bae0
No known key found for this signature in database
GPG Key ID: D004126FCD1A6DF0
5 changed files with 53 additions and 5 deletions

View File

@ -14,6 +14,7 @@
limitations under the License.
*/
import addCustomPluginsAsDeps from '../../utils/addCustomPluginsAsDeps.js';
import getServer from '../../utils/getServer.js';
import installServer from '../../utils/installServer.js';
import mergePackageJson from '../../utils/mergePackageJson.js';
@ -22,12 +23,13 @@ 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' });
const directory = context.directories.server;
await getServer({ context, packageName: '@lowdefy/server', directory });
await mergePackageJson({
context,
serverDirectory: directory,
});
await addCustomPluginsAsDeps({ context, directory });
await installServer({ context, directory });
await runLowdefyBuild({ context, directory });
await installServer({ context, directory });

View File

@ -14,19 +14,21 @@
limitations under the License.
*/
import addCustomPluginsAsDeps from '../../utils/addCustomPluginsAsDeps.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;
const directory = context.directories.dev;
context.print.info('Starting development server.');
await getServer({ context, packageName: '@lowdefy/server-dev' });
await getServer({ context, packageName: '@lowdefy/server-dev', directory });
await mergePackageJson({
context,
serverDirectory: directory,
});
await addCustomPluginsAsDeps({ context, directory });
await installServer({ context, directory });
context.sendTelemetry();
await runDevServer({ context, directory });

View File

@ -0,0 +1,42 @@
/*
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 { readFile, writeFile } from '@lowdefy/node-utils';
async function addCustomPluginsAsDeps({ context, directory }) {
const packageJsonPath = path.join(directory, 'package.json');
const packageJson = JSON.parse(await readFile(packageJsonPath));
const devDependencies = packageJson.devDependencies;
Object.values(context.plugins).forEach((plugin) => {
devDependencies[plugin.name] = plugin.version;
});
// Sort dependencies
packageJson.devDependencies = {};
Object.keys(devDependencies)
.sort()
.forEach((name) => {
packageJson.devDependencies[name] = devDependencies[name];
});
const newPackageJsonContent = JSON.stringify(packageJson, null, 2).concat('\n');
await writeFile(packageJsonPath, newPackageJsonContent);
}
export default addCustomPluginsAsDeps;

View File

@ -53,6 +53,7 @@ async function getLowdefyYaml({ configDirectory, command }) {
return {
lowdefyVersion: lowdefy.lowdefy,
cliConfig: get(lowdefy, 'cli', { default: {} }),
plugins: get(lowdefy, 'plugins', { default: [] }),
};
}

View File

@ -32,9 +32,10 @@ async function startUp({ context, options = {}, command }) {
context.print = createPrint();
context.configDirectory = path.resolve(options.configDirectory || process.cwd());
const { cliConfig, lowdefyVersion } = await getLowdefyYaml(context);
const { cliConfig, lowdefyVersion, plugins } = await getLowdefyYaml(context);
context.cliConfig = cliConfig;
context.lowdefyVersion = lowdefyVersion;
context.plugins = plugins;
const { appId } = await getCliJson(context);
context.appId = appId;