mirror of
https://github.com/hexastack/hexabot
synced 2024-11-22 09:38:13 +00:00
fix: remove old way of handling extensions
This commit is contained in:
parent
357e058e65
commit
1fc58f4496
@ -4,10 +4,6 @@ WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
COPY merge-extensions-deps.js ./
|
||||
|
||||
COPY src/extensions ./src/extensions
|
||||
|
||||
COPY patches ./patches
|
||||
|
||||
RUN npm ci
|
||||
@ -22,8 +18,6 @@ WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
COPY --from=builder /app/merge-extensions-deps.js ./
|
||||
|
||||
COPY --from=builder /app/src/extensions ./src/extensions
|
||||
|
||||
COPY --from=builder /app/patches ./patches
|
||||
@ -44,8 +38,6 @@ WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
COPY --from=builder /app/merge-extensions-deps.js ./
|
||||
|
||||
COPY --from=builder /app/src/extensions ./src/extensions
|
||||
|
||||
COPY --from=builder /app/patches ./patches
|
||||
|
@ -1,80 +0,0 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const fs = require('fs');
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const path = require('path');
|
||||
|
||||
// Define the paths
|
||||
const rootPackageJsonPath = path.join(__dirname, 'package.json');
|
||||
const pluginsDir = path.join(__dirname, 'src', 'extensions', 'plugins');
|
||||
const channelsDir = path.join(__dirname, 'src', 'extensions', 'channels');
|
||||
const helpersDir = path.join(__dirname, 'src', 'extensions', 'helpers');
|
||||
|
||||
// Helper function to merge dependencies
|
||||
function mergeDependencies(rootDeps, pluginDeps) {
|
||||
return {
|
||||
...rootDeps,
|
||||
...Object.entries(pluginDeps).reduce((acc, [key, version]) => {
|
||||
if (!rootDeps[key]) {
|
||||
acc[key] = version;
|
||||
}
|
||||
return acc;
|
||||
}, {}),
|
||||
};
|
||||
}
|
||||
|
||||
// Read the root package.json
|
||||
const rootPackageJson = JSON.parse(
|
||||
fs.readFileSync(rootPackageJsonPath, 'utf-8'),
|
||||
);
|
||||
|
||||
// Initialize dependencies if not already present
|
||||
if (!rootPackageJson.dependencies) {
|
||||
rootPackageJson.dependencies = {};
|
||||
}
|
||||
|
||||
// Iterate over extension directories
|
||||
[
|
||||
...fs.readdirSync(pluginsDir),
|
||||
...fs.readdirSync(helpersDir),
|
||||
...fs.readdirSync(channelsDir),
|
||||
].forEach((pluginFolder) => {
|
||||
const pluginPackageJsonPath = path.join(
|
||||
pluginsDir,
|
||||
pluginFolder,
|
||||
'package.json',
|
||||
);
|
||||
|
||||
if (fs.existsSync(pluginPackageJsonPath)) {
|
||||
const pluginPackageJson = JSON.parse(
|
||||
fs.readFileSync(pluginPackageJsonPath, 'utf-8'),
|
||||
);
|
||||
|
||||
// Merge extension dependencies into root dependencies
|
||||
if (pluginPackageJson.dependencies) {
|
||||
rootPackageJson.dependencies = mergeDependencies(
|
||||
rootPackageJson.dependencies,
|
||||
pluginPackageJson.dependencies,
|
||||
);
|
||||
}
|
||||
|
||||
// Merge extension devDependencies into root devDependencies
|
||||
if (pluginPackageJson.devDependencies) {
|
||||
rootPackageJson.devDependencies = mergeDependencies(
|
||||
rootPackageJson.devDependencies,
|
||||
pluginPackageJson.devDependencies,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Write the updated root package.json
|
||||
fs.writeFileSync(
|
||||
rootPackageJsonPath,
|
||||
JSON.stringify(rootPackageJson, null, 2),
|
||||
'utf-8',
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
'Dependencies from extensions have been merged into the root package.json',
|
||||
);
|
@ -6,7 +6,6 @@
|
||||
"author": "Hexastack",
|
||||
"license": "AGPL-3.0-only",
|
||||
"scripts": {
|
||||
"preinstall": "node merge-extensions-deps.js",
|
||||
"postinstall": "patch-package",
|
||||
"build:clean": "rm -rf src/.hexabot",
|
||||
"build:channels": "mkdir -p src/.hexabot/channels && find node_modules/ -name 'hexabot-channel-*' -exec cp -R {} src/.hexabot/channels/ \\;",
|
||||
|
@ -94,7 +94,7 @@ export class BlockController extends BaseController<
|
||||
try {
|
||||
if (!pluginName) {
|
||||
throw new BadRequestException(
|
||||
'Plugin id must be supplied as a query param',
|
||||
'Plugin name must be supplied as a query param',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import figlet from 'figlet';
|
||||
import { Command } from 'commander';
|
||||
import chalk from 'chalk';
|
||||
import { execSync } from 'child_process';
|
||||
import { Command } from 'commander';
|
||||
import figlet from 'figlet';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import chalk from 'chalk';
|
||||
import degit from 'degit';
|
||||
|
||||
console.log(figlet.textSync('Hexabot'));
|
||||
|
||||
@ -95,7 +94,7 @@ const dockerCompose = (args: string): void => {
|
||||
const dockerExec = (
|
||||
container: string,
|
||||
command: string,
|
||||
options?: string
|
||||
options?: string,
|
||||
): void => {
|
||||
try {
|
||||
execSync(`docker exec -it ${options} ${container} ${command}`, {
|
||||
@ -179,7 +178,11 @@ program
|
||||
.description('Run database migrations')
|
||||
.action((args) => {
|
||||
const migrateArgs = args.join(' ');
|
||||
dockerExec('api', `npm run migrate ${migrateArgs}`, '--user $(id -u):$(id -g)');
|
||||
dockerExec(
|
||||
'api',
|
||||
`npm run migrate ${migrateArgs}`,
|
||||
'--user $(id -u):$(id -g)',
|
||||
);
|
||||
});
|
||||
|
||||
program
|
||||
@ -222,81 +225,6 @@ program
|
||||
dockerCompose(`${composeArgs} down -v`);
|
||||
});
|
||||
|
||||
// Add install command to install extensions (e.g., channels, plugins)
|
||||
program
|
||||
.command('install')
|
||||
.description('Install an extension for Hexabot')
|
||||
.argument('<type>', 'The type of extension (e.g., channel, plugin)')
|
||||
.argument(
|
||||
'<repository>',
|
||||
'GitHub repository for the extension (user/repo format)',
|
||||
)
|
||||
.action(async (type, repository) => {
|
||||
// Define the target folder based on the extension type
|
||||
let targetFolder = '';
|
||||
switch (type) {
|
||||
case 'channel':
|
||||
targetFolder = 'api/src/extensions/channels/';
|
||||
break;
|
||||
case 'plugin':
|
||||
targetFolder = 'api/src/extensions/plugins/';
|
||||
break;
|
||||
default:
|
||||
console.error(chalk.red(`Unknown extension type: ${type}`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Get the last part of the repository name
|
||||
const repoName = repository.split('/').pop();
|
||||
|
||||
// If the repo name starts with "hexabot-<TYPE>-", remove that prefix
|
||||
const extensionName = repoName.startsWith(`hexabot-${type}-`)
|
||||
? repoName.replace(`hexabot-${type}-`, '')
|
||||
: repoName;
|
||||
|
||||
const extensionPath = path.resolve(
|
||||
process.cwd(),
|
||||
targetFolder,
|
||||
extensionName,
|
||||
);
|
||||
|
||||
// Check if the extension folder already exists
|
||||
if (fs.existsSync(extensionPath)) {
|
||||
console.error(
|
||||
chalk.red(`Error: Extension already exists at ${extensionPath}`),
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(
|
||||
chalk.cyan(`Fetching ${repository} into ${extensionPath}...`),
|
||||
);
|
||||
|
||||
// Use degit to fetch the repository without .git history
|
||||
const emitter = degit(repository);
|
||||
await emitter.clone(extensionPath);
|
||||
|
||||
console.log(chalk.cyan('Running npm install in the api/ folder...'));
|
||||
// Run npm install in the api folder to install dependencies
|
||||
execSync('npm run preinstall', {
|
||||
cwd: path.resolve(process.cwd(), 'api'),
|
||||
stdio: 'inherit',
|
||||
});
|
||||
execSync('npm install', {
|
||||
cwd: path.resolve(process.cwd(), 'api'),
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
console.log(
|
||||
chalk.green(`Successfully installed ${extensionName} as a ${type}.`),
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(chalk.red('Error during installation:'), error);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Parse arguments
|
||||
program.parse(process.argv);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user