Skip to content

Commit

Permalink
fix: turbowatch for the pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
abuaboud committed Jan 18, 2024
1 parent 5d520b6 commit 52b448f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function traverseFolder(folderPath: string): Promise<string[]> {
for (const file of files) {
const filePath = join(folderPath, file)
const fileStats = await stat(filePath)
if (fileStats.isDirectory() && file !== 'node_modules' && file !== 'dist') {
if (fileStats.isDirectory() && file !== 'node_modules' && file !== 'dist' && file !== 'framework' && file !== 'common') {
paths.push(...await traverseFolder(filePath))
}
else if (file === 'package.json') {
Expand Down
6 changes: 5 additions & 1 deletion packages/backend/src/app/workers/engine/engine-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { system } from '../../helper/system/system'
import { SystemProp } from '../../helper/system/system-prop'
import { logger } from '../../helper/logger'
import { packageManager } from '../../helper/package-manager'
import { CodeExecutorSandboxType } from '@activepieces/shared'

const engineExecutablePath = system.getOrThrow(SystemProp.ENGINE_EXECUTABLE_PATH)

Expand All @@ -15,7 +16,10 @@ export const engineInstaller = {

await copyFile(engineExecutablePath, `${path}/main.js`)
await copyFile(`${engineExecutablePath}.map`, `${path}/main.js.map`)
await installDependencies(path)
const codeExecutionType = system.getOrThrow<CodeExecutorSandboxType>(SystemProp.CODE_EXECUTOR_SANDBOX_TYPE)
if (codeExecutionType === CodeExecutorSandboxType.ISOLATE) {
await installDependencies(path)
}
},
}

Expand Down
13 changes: 7 additions & 6 deletions tools/scripts/pieces/turbowatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ import chalk from 'chalk'; // Import the chalk library
import { config } from 'dotenv';
import { watch } from 'turbowatch';
import { exec } from 'child_process';
import { findPiece } from '../utils/piece-script-utils';
import { findPieceDirectoryInSource } from '../utils/piece-script-utils';
import path from 'path';
import { assertNotNullOrUndefined } from '../../../packages/shared/src';

config({ path: 'packages/backend/.env' });

const packages = process.env.AP_DEV_PIECES?.split(',') || [];

async function main(){
for(const packageName of packages){
async function main() {
for (const packageName of packages) {
console.log(chalk.blue(`Starting Turbowatch for package: ${packageName}`));

// Define the inline configuration
const piece = await findPiece(packageName)
const pieceDirectory = await findPieceDirectoryInSource(packageName)
assertNotNullOrUndefined(pieceDirectory, 'pieceDirectory')
const piecePackageName = `pieces-${packageName}`;
void watch({
project: path.resolve(piece?.directoryPath!),
project: path.resolve(pieceDirectory),
triggers: [
{
expression: ['match', '**/*.ts', 'basename'],
Expand Down
11 changes: 11 additions & 0 deletions tools/scripts/utils/piece-script-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ export async function findPiece(pieceName: string): Promise<PieceMetadata | null
return pieces.find((p) => p.name === pieceName) ?? null
}

export async function findAllPiecesDirectoryInSource(): Promise<string[]> {
const piecesPath = resolve(cwd(), 'packages', 'pieces')
const paths = await traverseFolder(piecesPath)
return paths
}
export async function findPieceDirectoryInSource(pieceName: string): Promise<string | null> {
const piecesPath = await findAllPiecesDirectoryInSource()
const piecePath = piecesPath.find((p) => p.includes(pieceName))
return piecePath ?? null
}

export async function findAllPieces(): Promise<PieceMetadata[]> {
const piecesPath = resolve(cwd(), 'dist', 'packages', 'pieces')
const paths = await traverseFolder(piecesPath)
Expand Down

0 comments on commit 52b448f

Please sign in to comment.