Skip to content

Commit 72802cb

Browse files
committed
Trying to improve more issues.
1 parent d51e339 commit 72802cb

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

src/api.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
WorkerMessageUnknown,
1515
allApplications,
1616
childProcesses,
17-
currentFile,
1817
deleteBody,
1918
deployBody,
2019
fetchBranchListBody,
@@ -23,7 +22,6 @@ import {
2322

2423
import AppError from './utils/appError';
2524
import {
26-
calculatePackages,
2725
catchAsync,
2826
deleteRepoFolderIfExist,
2927
dirName,
@@ -159,8 +157,9 @@ export const fetchFilesFromRepo = catchAsync(
159157

160158
const id = dirName(req.body.url);
161159

162-
currentFile['id'] = id;
163-
currentFile.path = `${appsDir}/${id}`;
160+
// TODO: This method is wrong
161+
// currentFile['id'] = id;
162+
// currentFile.path = `${appsDir}/${id}`;
164163

165164
return res.status(201).send({ id });
166165
}
@@ -230,12 +229,20 @@ export const deploy = catchAsync(
230229
next: NextFunction
231230
) => {
232231
try {
233-
req.body.resourceType == 'Repository' &&
234-
(await calculatePackages(next));
235-
236232
// TODO Currently Deploy function will only work for workdir, we will add the addRepo
233+
// req.body.resourceType == 'Repository' &&
234+
// (await calculatePackages(next));
235+
236+
console.log(req.body);
237+
238+
const currentFile: CurrentUploadedFile = {
239+
id: '',
240+
type: '',
241+
path: '',
242+
jsons: []
243+
};
237244

238-
await installDependencies();
245+
await installDependencies(currentFile);
239246

240247
const desiredPath = path.join(__dirname, '/worker/index.js');
241248

src/constants.ts

-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ export interface CurrentUploadedFile {
99
path: string;
1010
}
1111

12-
export const currentFile: CurrentUploadedFile = {
13-
id: '',
14-
type: '',
15-
jsons: [],
16-
runners: [],
17-
path: ''
18-
};
19-
2012
export const createInstallDependenciesScript = (
2113
runner: string,
2214
path: string

src/controller/upload.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import busboy from 'busboy';
55
import { NextFunction, Request, Response } from 'express';
66
import { Extract } from 'unzipper';
77

8-
import { currentFile, namearg } from '../constants';
8+
import { CurrentUploadedFile, namearg } from '../constants';
99

1010
import { MetaCallJSON } from '@metacall/protocol/deployment';
1111
import AppError from '../utils/appError';
@@ -29,6 +29,12 @@ const getUploadError = (on: keyof busboy.BusboyEvents): AppError => {
2929

3030
export default (req: Request, res: Response, next: NextFunction): void => {
3131
const bb = busboy({ headers: req.headers });
32+
const currentFile: CurrentUploadedFile = {
33+
id: '',
34+
type: '',
35+
path: '',
36+
jsons: []
37+
};
3238

3339
const handleError = (fn: () => void, on: keyof busboy.BusboyEvents) => {
3440
try {
@@ -69,7 +75,7 @@ export default (req: Request, res: Response, next: NextFunction): void => {
6975

7076
bb.on('finish', () => {
7177
handleError(() => {
72-
const appLocation = path.join(appsDir, `${currentFile.id}`);
78+
const appLocation = path.join(appsDir, currentFile.id);
7379

7480
fs.createReadStream(currentFile.path).pipe(
7581
Extract({ path: appLocation })

src/utils/autoDeploy.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import {
99
WorkerMessage,
1010
WorkerMessageUnknown,
1111
allApplications,
12-
childProcesses,
13-
currentFile
12+
childProcesses
1413
} from '../constants';
1514
import { isIAllApps, logProcessOutput } from './utils';
1615

@@ -26,9 +25,12 @@ export const findJsonFilesRecursively = async (
2625
const desiredPath = path.join(__dirname, '../worker/index.js');
2726
const id = path.basename(appsDir);
2827

29-
currentFile.id = id;
30-
(currentFile.type = 'application/x-zip-compressed'),
31-
(currentFile.path = appsDir);
28+
const currentFile: CurrentUploadedFile = {
29+
id,
30+
type: 'application/x-zip-compressed',
31+
path: appsDir,
32+
jsons: []
33+
};
3234

3335
const proc = spawn('metacall', [desiredPath, filePath], {
3436
stdio: ['pipe', 'pipe', 'pipe', 'ipc']

src/utils/utils.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ import { PackageError, generatePackage } from '@metacall/protocol/package';
88
import { NextFunction, Request, RequestHandler, Response } from 'express';
99

1010
import {
11+
CurrentUploadedFile,
1112
IAllApps,
1213
InspectObject,
1314
PIDToColorCodeMap,
1415
allApplications,
1516
asniCode,
1617
assignedColorCodes,
17-
createInstallDependenciesScript,
18-
currentFile
18+
createInstallDependenciesScript
1919
} from '../constants';
2020
import { logger } from './logger';
2121

2222
export const dirName = (gitUrl: string): string =>
2323
String(gitUrl.split('/')[gitUrl.split('/').length - 1]).replace('.git', '');
2424

2525
// Create a proper hashmap that contains all the installation commands mapped to their runner name and shorten this function
26-
export const installDependencies = async (): Promise<void> => {
26+
export const installDependencies = async (
27+
currentFile: CurrentUploadedFile
28+
): Promise<void> => {
2729
if (!currentFile.runners) return;
2830

2931
for (const runner of currentFile.runners) {
@@ -37,7 +39,10 @@ export const installDependencies = async (): Promise<void> => {
3739
};
3840

3941
//check if repo contains metacall-*.json if not create and calculate runners then install dependencies
40-
export const calculatePackages = async (next: NextFunction): Promise<void> => {
42+
export const calculatePackages = async (
43+
currentFile: CurrentUploadedFile,
44+
next: NextFunction
45+
): Promise<void> => {
4146
const data = await generatePackage(currentFile.path);
4247

4348
if (data.error == PackageError.Empty) {

0 commit comments

Comments
 (0)