Skip to content

Commit

Permalink
Merge pull request #37 from dimitrov-d/master
Browse files Browse the repository at this point in the history
Indexer module updates
  • Loading branch information
dimitrov-d authored Oct 29, 2024
2 parents 1a3812b + 636a324 commit 677bcf7
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 35 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@apillon/cli",
"description": "▶◀ Apillon CLI tools ▶◀",
"version": "1.4.0",
"version": "1.5.0",
"author": "Apillon",
"license": "MIT",
"main": "./dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ export async function createCloudFunction(optsWithGlobals: GlobalOptions) {
name: optsWithGlobals.name,
description: optsWithGlobals.description,
});
if (data) {
console.log(data.serialize());
console.log('Cloud function created successfully!');
}

console.log(data.serialize());
console.log('Cloud function created successfully!');
});
}

Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/modules/indexing/indexing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ export async function deployIndexer(
) {
await withErrorHandler(async () => {
console.log(`Deploying indexer: ${path}`);
const res = await new Indexing(optsWithGlobals)
await new Indexing(optsWithGlobals)
.indexer(optsWithGlobals.indexerUuid)
.deployIndexer(path);

if (res) {
console.log(
`Indexer deployment successfully started! Check Apillon console for status.`,
);
}
console.log(
`Indexer deployment successfully started! Check Apillon console for status.`,
);
});
}
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@apillon/sdk",
"description": "▶◀ Apillon SDK for NodeJS ▶◀",
"version": "3.4.0",
"version": "3.5.0",
"author": "Apillon",
"license": "MIT",
"main": "./dist/index.js",
Expand Down
5 changes: 5 additions & 0 deletions packages/sdk/src/docs-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ export * from './modules/social/social';
export * from './modules/social/social-hub';
export * from './modules/social/social-channel';
export * from './modules/project/project';
export * from './modules/cloud-functions/cloud-functions';
export * from './modules/cloud-functions/cloud-function';
export * from './modules/cloud-functions/cloud-function-job';
export * from './modules/indexing/indexing';
export * from './modules/indexing/indexer';
11 changes: 7 additions & 4 deletions packages/sdk/src/modules/indexing/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable security/detect-non-literal-fs-filename */
import axios from 'axios';
import fs from 'fs';
import * as fs from 'fs';
import { ApillonModel } from '../../lib/apillon';
import { ApillonApi } from '../../lib/apillon-api';
import { ApillonLogger } from '../../lib/apillon-logger';
Expand Down Expand Up @@ -40,10 +41,12 @@ export class Indexer extends ApillonModel {
public async deployIndexer(path: string): Promise<any> {
//Check directory and if squid.yaml exists in it
if (!fs.existsSync(path)) {
return console.error('Invalid path');
throw new Error('Error deploying indexer: Invalid path');
}
if (!fs.existsSync(`${path}/squid.yaml`)) {
return console.error('squid.yaml not found in directory');
throw new Error(
'Error deploying indexer: squid.yaml not found in directory',
);
}

//Create tar.gz file
Expand All @@ -53,7 +56,7 @@ export class Indexer extends ApillonModel {
);

if (numOfFiles === 0) {
return console.error('Source directory is empty');
throw new Error('Error deploying indexer: Source directory is empty');
}
ApillonLogger.log(`Compressed ${numOfFiles} files. Uploading to s3...`);

Expand Down
16 changes: 8 additions & 8 deletions packages/sdk/src/tests/indexing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Indexing } from '../modules/indexing/indexing';
import { getConfig, getIndexerUUID } from './helpers/helper';

describe('Indexing tests', () => {
let indexing: Indexing = undefined;
let indexer_uuid: string = undefined;
let indexing: Indexing;
let indexer_uuid: string;

beforeAll(async () => {
indexing = new Indexing(getConfig());
Expand All @@ -22,14 +22,14 @@ describe('Indexing tests', () => {
});

test('Deploy a indexer with invalid path, should return error', async () => {
const logSpy = jest.spyOn(global.console, 'error');
await indexing.indexer(indexer_uuid).deployIndexer('some invalid path');
expect(logSpy).toHaveBeenCalled();
await expect(
indexing.indexer(getIndexerUUID()).deployIndexer('some invalid path'),
).rejects.toThrow('Path does not exist');
});

test('Deploy a indexer with valid path but invalid content, should return error', async () => {
const logSpy = jest.spyOn(global.console, 'error');
await indexing.indexer(indexer_uuid).deployIndexer('D:\\Sqd');
expect(logSpy).toHaveBeenCalled();
await expect(
indexing.indexer(getIndexerUUID()).deployIndexer('D:\\Sqd'),
).rejects.toThrow('squid.yaml not found in directory');
});
});
19 changes: 10 additions & 9 deletions packages/sdk/src/util/indexer-utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable security/detect-non-literal-fs-filename */
import fs from 'node:fs';
import path from 'node:path';
import { globSync } from 'glob';
import ignore from 'ignore';
import targz from 'targz';
import { ApillonLogger } from '../lib/apillon-logger';

export function createSquidIgnore(squidDir: string) {
const ig = ignore().add(
Expand Down Expand Up @@ -86,28 +88,27 @@ export function compressIndexerSourceCode(
src: srcDir,
dest: destDir,
tar: {
ignore: (name) => {
ignore: (name: string) => {
const relativePath = path.relative(
path.resolve(srcDir),
path.resolve(name),
);

if (squidIgnore.ignores(relativePath)) {
console.log('ignoring ' + relativePath);
ApillonLogger.log(`ignoring ${relativePath}`);
return true;
} else {
console.log('adding ' + relativePath);
filesCount++;
return false;
}
ApillonLogger.log(`adding ${relativePath}`);
filesCount++;
return false;
},
},
},
function (err) {
(err) => {
if (err) {
console.error(err);
ApillonLogger.log(err);
reject(
`Compression failed. ${err.message ? 'Error: ' + err.message : ''}`,
`Compression failed. ${err.message ? `Error: ${err.message}` : ''}`,
);
} else {
resolve(filesCount);
Expand Down

0 comments on commit 677bcf7

Please sign in to comment.