@into-cps-association/libms 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/config/http.json +1 -0
- package/dist/src/app.module.js +5 -6
- package/dist/src/app.module.js.map +1 -1
- package/dist/src/bootstrap.js +11 -21
- package/dist/src/bootstrap.js.map +1 -1
- package/dist/src/config/config.interface.d.ts +14 -0
- package/dist/src/config/config.interface.js +2 -0
- package/dist/src/config/config.interface.js.map +1 -0
- package/dist/src/config/config.model.d.ts +14 -0
- package/dist/src/config/config.model.js +2 -0
- package/dist/src/config/config.model.js.map +1 -0
- package/dist/src/config/config.module.d.ts +2 -0
- package/dist/src/config/config.module.js +33 -0
- package/dist/src/config/config.module.js.map +1 -0
- package/dist/src/config/config.service.d.ts +17 -0
- package/dist/src/config/config.service.js +61 -0
- package/dist/src/config/config.service.js.map +1 -0
- package/dist/src/config/util.d.ts +1 -0
- package/dist/src/config/util.js +5 -0
- package/dist/src/config/util.js.map +1 -0
- package/dist/src/files/files-service.factory.d.ts +2 -2
- package/dist/src/files/files-service.factory.js +4 -1
- package/dist/src/files/files-service.factory.js.map +1 -1
- package/dist/src/files/files.module.js +2 -2
- package/dist/src/files/files.module.js.map +1 -1
- package/dist/src/files/git/git-files.service.d.ts +4 -2
- package/dist/src/files/git/git-files.service.js +31 -20
- package/dist/src/files/git/git-files.service.js.map +1 -1
- package/dist/src/files/interfaces/files.service.interface.d.ts +1 -0
- package/dist/src/files/local/local-files.service.d.ts +3 -2
- package/dist/src/files/local/local-files.service.js +12 -4
- package/dist/src/files/local/local-files.service.js.map +1 -1
- package/dist/src/main.d.ts +4 -1
- package/dist/test/cloudcmd/cloudcmd.spec.js +3 -3
- package/dist/test/cloudcmd/cloudcmd.spec.js.map +1 -1
- package/dist/test/e2e/app.e2e.spec.js +18 -12
- package/dist/test/e2e/app.e2e.spec.js.map +1 -1
- package/dist/test/integration/files.service.integration.spec.js +6 -6
- package/dist/test/integration/files.service.integration.spec.js.map +1 -1
- package/dist/test/testUtil.d.ts +7 -1
- package/dist/test/testUtil.js +20 -17
- package/dist/test/testUtil.js.map +1 -1
- package/dist/test/unit/files-service.factory.unit.spec.js +20 -8
- package/dist/test/unit/files-service.factory.unit.spec.js.map +1 -1
- package/dist/test/unit/files.resolver.unit.spec.js +1 -0
- package/dist/test/unit/files.resolver.unit.spec.js.map +1 -1
- package/dist/test/unit/git-files.service.unit.spec.js +6 -5
- package/dist/test/unit/git-files.service.unit.spec.js.map +1 -1
- package/dist/test/unit/local-files.service.unit.spec.js +36 -21
- package/dist/test/unit/local-files.service.unit.spec.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/eslint.config.js +5 -0
- package/libms.yaml.sample +12 -0
- package/package.json +9 -7
- package/src/app.module.ts +6 -7
- package/src/bootstrap.ts +14 -21
- package/src/config/config.interface.ts +14 -0
- package/src/config/config.model.ts +13 -0
- package/src/config/config.module.ts +23 -0
- package/src/config/config.service.ts +54 -0
- package/src/config/util.ts +5 -0
- package/src/files/files-service.factory.ts +5 -3
- package/src/files/files.module.ts +3 -3
- package/src/files/git/git-files.service.ts +28 -21
- package/src/files/interfaces/files.service.interface.ts +1 -0
- package/src/files/local/local-files.service.ts +13 -4
- package/src/main.ts +1 -1
- package/test/cloudcmd/cloudcmd.spec.ts +4 -4
- package/test/data/user2/tools/large_file.md +1 -0
- package/test/e2e/app.e2e.spec.ts +23 -13
- package/test/integration/files.service.integration.spec.ts +9 -10
- package/test/jest-e2e.json +3 -0
- package/test/libms.test.yaml +6 -0
- package/test/testUtil.ts +23 -19
- package/test/unit/files-service.factory.unit.spec.ts +22 -11
- package/test/unit/files.resolver.unit.spec.ts +1 -0
- package/test/unit/git-files.service.unit.spec.ts +6 -5
- package/test/unit/local-files.service.unit.spec.ts +41 -25
- package/test/update-config.js +25 -0
package/eslint.config.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
port: '4001'
|
|
2
|
+
mode: 'git'
|
|
3
|
+
local-path: '..\..\files'
|
|
4
|
+
log-level: 'debug'
|
|
5
|
+
apollo-path: '/lib'
|
|
6
|
+
graphql-playground: 'true'
|
|
7
|
+
|
|
8
|
+
git-repos:
|
|
9
|
+
- user-1:
|
|
10
|
+
repo-url: 'https://github.com/isomorphic-git/lightning-fs'
|
|
11
|
+
- user-2:
|
|
12
|
+
repo-url: 'https://github.com/isomorphic-git/lightning-fs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@into-cps-association/libms",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "microservices that handles request by fetching and returning the file-names and folders of given directory",
|
|
5
5
|
"author": "phillip.boe.jensen@gmail.com",
|
|
6
6
|
"contributors": [
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"syntax": "eslint . --fix",
|
|
25
25
|
"pretest": "npx shx cp test/data/user2/tools/README.md ../../files/user2/tools/README.md",
|
|
26
26
|
"posttest": "npx rimraf ../../files/user2/tools/README.md",
|
|
27
|
-
"test:all": "npx cross-env NODE_OPTIONS=--experimental-vm-modules
|
|
28
|
-
"test:e2e": "npx cross-env NODE_OPTIONS=--experimental-vm-modules
|
|
27
|
+
"test:all": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LIBMS_CONFIG_PATH=test/libms.test.yaml jest --testPathIgnorePatterns=cloudcmd --coverage",
|
|
28
|
+
"test:e2e": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LIBMS_CONFIG_PATH=test/libms.test.yaml jest --config ./test/jest-e2e.json --coverage",
|
|
29
29
|
"test:http": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage --coverageThreshold=\"{}\" && pm2 delete libms-test",
|
|
30
30
|
"test:http-nocov": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage=false && pm2 delete libms-test",
|
|
31
31
|
"test:http-github": "jest test/cloudcmd --coverage --coverageThreshold=\"{}\"",
|
|
32
|
-
"test:int": "npx cross-env NODE_OPTIONS=--experimental-vm-modules
|
|
33
|
-
"test:nocov": "yarn test:http-nocov && npx cross-env
|
|
34
|
-
"test:unit": "npx cross-env NODE_OPTIONS=--experimental-vm-modules
|
|
32
|
+
"test:int": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LIBMS_CONFIG_PATH=test/libms.test.yaml jest ../test/integration --coverage",
|
|
33
|
+
"test:nocov": "yarn test:http-nocov && npx cross-env LIBMS_CONFIG_PATH=test/libms.test.yaml jest --testPathIgnorePatterns=cloudcmd --coverage=false",
|
|
34
|
+
"test:unit": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LIBMS_CONFIG_PATH=test/libms.test.yaml jest ../test/unit --coverage"
|
|
35
35
|
},
|
|
36
36
|
"bin": "./dist/src/main.js",
|
|
37
37
|
"dependencies": {
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"globals": "^15.11.0",
|
|
51
51
|
"graphql": "^16.9.0",
|
|
52
52
|
"isomorphic-git": "^1.27.1",
|
|
53
|
+
"js-yaml": "^4.1.0",
|
|
53
54
|
"mock-fs": "^5.3.0",
|
|
54
55
|
"reflect-metadata": "^0.2.2",
|
|
55
56
|
"rxjs": "^7.8.1",
|
|
@@ -83,6 +84,7 @@
|
|
|
83
84
|
"ts-jest": "^29.2.5",
|
|
84
85
|
"ts-node": "^10.9.2",
|
|
85
86
|
"tsconfig-paths": "4.2.0",
|
|
86
|
-
"typescript": "^5.6.3"
|
|
87
|
+
"typescript": "^5.6.3",
|
|
88
|
+
"@types/js-yaml": "^4.0.9"
|
|
87
89
|
}
|
|
88
90
|
}
|
package/src/app.module.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
2
1
|
import { Module } from '@nestjs/common';
|
|
3
2
|
import { GraphQLModule } from '@nestjs/graphql';
|
|
4
3
|
import { ApolloDriver } from '@nestjs/apollo';
|
|
5
4
|
import { join } from 'path';
|
|
6
5
|
import FilesModule from './files/files.module.js';
|
|
6
|
+
import { ConfigModule } from './config/config.module.js';
|
|
7
|
+
import { CONFIG_SERVICE, IConfig } from './config/config.interface.js';
|
|
7
8
|
|
|
8
9
|
@Module({
|
|
9
10
|
imports: [
|
|
10
|
-
ConfigModule
|
|
11
|
-
isGlobal: true,
|
|
12
|
-
}),
|
|
11
|
+
ConfigModule,
|
|
13
12
|
GraphQLModule.forRootAsync({
|
|
14
13
|
driver: ApolloDriver,
|
|
15
|
-
useFactory: (configService:
|
|
14
|
+
useFactory: (configService: IConfig) => ({
|
|
16
15
|
autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
|
|
17
|
-
path: configService.
|
|
16
|
+
path: configService.getApolloPath(),
|
|
18
17
|
}),
|
|
19
|
-
inject: [
|
|
18
|
+
inject: [CONFIG_SERVICE],
|
|
20
19
|
}),
|
|
21
20
|
FilesModule,
|
|
22
21
|
],
|
package/src/bootstrap.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NestFactory } from '@nestjs/core';
|
|
2
|
-
import { ConfigService } from '@nestjs/config';
|
|
3
|
-
import * as dotenv from 'dotenv';
|
|
4
2
|
import AppModule from './app.module.js';
|
|
5
3
|
import cloudCMD from './cloudcmd/cloudcmd.js';
|
|
4
|
+
import { Logger } from '@nestjs/common';
|
|
5
|
+
import { CONFIG_SERVICE, IConfig } from './config/config.interface.js';
|
|
6
6
|
|
|
7
7
|
type BootstrapOptions = {
|
|
8
8
|
config?: string;
|
|
@@ -11,30 +11,23 @@ type BootstrapOptions = {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export default async function bootstrap(options?: BootstrapOptions) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (configFile.error && process.env.LOCAL_PATH === undefined) {
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
|
-
console.error(configFile.error);
|
|
21
|
-
if (options.runHelp) {
|
|
22
|
-
options.runHelp();
|
|
23
|
-
} else {
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
14
|
+
const logger = new Logger(bootstrap.name);
|
|
15
|
+
|
|
16
|
+
if (process.env.LIBMS_CONFIG_PATH == null)
|
|
17
|
+
process.env.LIBMS_CONFIG_PATH = options.config ?? 'libms.yaml';
|
|
27
18
|
|
|
28
19
|
const app = await NestFactory.create(AppModule);
|
|
29
|
-
const configService = app.get(
|
|
30
|
-
const port = configService.
|
|
31
|
-
const localPath = configService.
|
|
32
|
-
const mode = configService.
|
|
20
|
+
const configService = app.get(CONFIG_SERVICE) as IConfig;
|
|
21
|
+
const port = configService.getPort();
|
|
22
|
+
const localPath = configService.getLocalPath();
|
|
23
|
+
const mode = configService.getMode();
|
|
33
24
|
|
|
34
|
-
|
|
25
|
+
logger.log(
|
|
26
|
+
`\x1b[32mStarting libms in \x1b[33m${mode} \x1b[32mmode, serving files from \x1b[34m${localPath} \x1b[32mon port \x1b[35m${port}\x1b[0m`,
|
|
27
|
+
);
|
|
35
28
|
|
|
36
29
|
if (options.httpServer) {
|
|
37
|
-
cloudCMD(app, options.httpServer, configService.
|
|
30
|
+
cloudCMD(app, options.httpServer, configService.getLocalPath());
|
|
38
31
|
}
|
|
39
32
|
|
|
40
33
|
await app.listen(port);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GitRepo } from './config.model';
|
|
2
|
+
|
|
3
|
+
export const CONFIG_SERVICE = 'CONFIG_SERVICE';
|
|
4
|
+
|
|
5
|
+
export interface IConfig {
|
|
6
|
+
loadConfig(configPath: string): Promise<void>;
|
|
7
|
+
getLocalPath(): string;
|
|
8
|
+
getApolloPath(): string;
|
|
9
|
+
getMode(): string;
|
|
10
|
+
getPort(): number;
|
|
11
|
+
getLogLevel(): string;
|
|
12
|
+
getGraphqlPlayground(): string;
|
|
13
|
+
getGitRepos(): { [key: string]: GitRepo }[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ConfigValues = {
|
|
2
|
+
port: number;
|
|
3
|
+
'local-path': string;
|
|
4
|
+
mode: string;
|
|
5
|
+
'log-level': string;
|
|
6
|
+
'apollo-path': string;
|
|
7
|
+
'graphql-playground': string;
|
|
8
|
+
'git-repos': { [key: string]: GitRepo }[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type GitRepo = {
|
|
12
|
+
'repo-url': string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Global, Module } from '@nestjs/common';
|
|
2
|
+
import * as nestConfig from '@nestjs/config';
|
|
3
|
+
import Config from './config.service.js';
|
|
4
|
+
import { CONFIG_SERVICE } from './config.interface.js';
|
|
5
|
+
|
|
6
|
+
@Global()
|
|
7
|
+
@Module({
|
|
8
|
+
imports: [nestConfig.ConfigModule.forRoot({ isGlobal: true })],
|
|
9
|
+
providers: [
|
|
10
|
+
{
|
|
11
|
+
provide: CONFIG_SERVICE,
|
|
12
|
+
useFactory: async (envConfigservice: nestConfig.ConfigService) => {
|
|
13
|
+
const confPath = envConfigservice.get<string>('LIBMS_CONFIG_PATH');
|
|
14
|
+
const config = new Config();
|
|
15
|
+
await config.loadConfig(confPath);
|
|
16
|
+
return config;
|
|
17
|
+
},
|
|
18
|
+
inject: [nestConfig.ConfigService],
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
exports: [CONFIG_SERVICE],
|
|
22
|
+
})
|
|
23
|
+
export class ConfigModule {}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import * as yaml from 'js-yaml';
|
|
3
|
+
import { Injectable, Logger } from '@nestjs/common';
|
|
4
|
+
import { ConfigValues, GitRepo } from './config.model.js';
|
|
5
|
+
import resolveFile from './util.js';
|
|
6
|
+
import { IConfig } from './config.interface.js';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export default class Config implements IConfig {
|
|
10
|
+
private configValues: ConfigValues;
|
|
11
|
+
private logger: Logger;
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
this.logger = new Logger(Config.name);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async loadConfig(configPath: string): Promise<void> {
|
|
18
|
+
if (configPath !== undefined) {
|
|
19
|
+
try {
|
|
20
|
+
const configFile = readFileSync(resolveFile(configPath), 'utf8');
|
|
21
|
+
this.configValues = yaml.load(configFile) as ConfigValues;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
this.logger.error('Error loading config file', e);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
this.logger.log('Config loaded', this.configValues);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getLocalPath(): string {
|
|
31
|
+
return this.configValues['local-path'];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getApolloPath(): string {
|
|
35
|
+
return this.configValues['apollo-path'];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getMode(): string {
|
|
39
|
+
return this.configValues['mode'];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getPort(): number {
|
|
43
|
+
return this.configValues['port'];
|
|
44
|
+
}
|
|
45
|
+
getLogLevel(): string {
|
|
46
|
+
return this.configValues['log-level'];
|
|
47
|
+
}
|
|
48
|
+
getGraphqlPlayground(): string {
|
|
49
|
+
return this.configValues['graphql-playground'];
|
|
50
|
+
}
|
|
51
|
+
getGitRepos(): { [key: string]: GitRepo }[] {
|
|
52
|
+
return this.configValues['git-repos'];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { ConfigService } from '@nestjs/config';
|
|
3
2
|
import { IFilesService } from './interfaces/files.service.interface.js';
|
|
3
|
+
import { IConfig } from 'src/config/config.interface.js';
|
|
4
4
|
|
|
5
5
|
@Injectable()
|
|
6
6
|
export default class FilesServiceFactory {
|
|
7
7
|
static create(
|
|
8
|
-
configService:
|
|
8
|
+
configService: IConfig,
|
|
9
9
|
fileServices: IFilesService[],
|
|
10
10
|
): IFilesService {
|
|
11
|
-
const mode = configService.
|
|
11
|
+
const mode = configService.getMode();
|
|
12
12
|
const service = fileServices.find((s) => s.getMode() == mode);
|
|
13
13
|
|
|
14
14
|
if (service == undefined) {
|
|
15
15
|
throw new Error(`Invalid MODE: ${mode}`);
|
|
16
|
+
} else {
|
|
17
|
+
service.init();
|
|
16
18
|
}
|
|
17
19
|
return service;
|
|
18
20
|
}
|
|
@@ -6,7 +6,7 @@ import LocalFilesService from './local/local-files.service.js';
|
|
|
6
6
|
import GitFilesService from './git/git-files.service.js';
|
|
7
7
|
import { FILE_SERVICE } from './interfaces/files.service.interface.js';
|
|
8
8
|
import FilesServiceFactory from './files-service.factory.js';
|
|
9
|
-
import {
|
|
9
|
+
import { CONFIG_SERVICE, IConfig } from '../config/config.interface.js';
|
|
10
10
|
|
|
11
11
|
@Module({
|
|
12
12
|
imports: [LocalFilesModule, GitFilesModule],
|
|
@@ -15,14 +15,14 @@ import { ConfigService } from '@nestjs/config';
|
|
|
15
15
|
{
|
|
16
16
|
provide: FILE_SERVICE,
|
|
17
17
|
useFactory: (
|
|
18
|
-
configService:
|
|
18
|
+
configService: IConfig,
|
|
19
19
|
localFilesService: LocalFilesService,
|
|
20
20
|
gitFilesService: GitFilesService,
|
|
21
21
|
) => {
|
|
22
22
|
const fileServices = [localFilesService, gitFilesService];
|
|
23
23
|
return FilesServiceFactory.create(configService, fileServices);
|
|
24
24
|
},
|
|
25
|
-
inject: [
|
|
25
|
+
inject: [CONFIG_SERVICE, LocalFilesService, GitFilesService],
|
|
26
26
|
},
|
|
27
27
|
],
|
|
28
28
|
})
|
|
@@ -1,46 +1,54 @@
|
|
|
1
|
-
import { Inject, Injectable } from '@nestjs/common';
|
|
1
|
+
import { Inject, Injectable, Logger } from '@nestjs/common';
|
|
2
2
|
import { Project } from 'src/types.js';
|
|
3
3
|
import { IFilesService } from '../interfaces/files.service.interface.js';
|
|
4
4
|
import { CONFIG_MODE } from '../../enums/config-mode.enum.js';
|
|
5
|
-
import { ConfigService } from '@nestjs/config';
|
|
6
5
|
import * as git from 'isomorphic-git';
|
|
7
6
|
import * as fs from 'fs';
|
|
8
7
|
import * as http from 'isomorphic-git/http/node/index.cjs';
|
|
9
8
|
import LocalFilesService from '../local/local-files.service.js';
|
|
9
|
+
import Config from '../../config/config.service.js';
|
|
10
|
+
import { CONFIG_SERVICE } from '../../config/config.interface.js';
|
|
11
|
+
import path from 'path';
|
|
10
12
|
|
|
11
13
|
@Injectable()
|
|
12
14
|
export default class GitFilesService implements IFilesService {
|
|
13
15
|
private readonly dataPath: string;
|
|
16
|
+
private readonly logger: Logger;
|
|
14
17
|
@Inject(LocalFilesService) private localFilesService: LocalFilesService;
|
|
15
18
|
|
|
16
|
-
constructor(private configService:
|
|
17
|
-
this.dataPath = this.configService.
|
|
18
|
-
this.
|
|
19
|
+
constructor(@Inject(CONFIG_SERVICE) private configService: Config) {
|
|
20
|
+
this.dataPath = this.configService.getLocalPath();
|
|
21
|
+
this.logger = new Logger(GitFilesService.name);
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
init(): Promise<any> {
|
|
25
|
+
return this.cloneRepositories();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private cloneRepositories(): Promise<void[]> {
|
|
29
|
+
const userRepoConfigs = this.configService.getGitRepos();
|
|
30
|
+
|
|
31
|
+
if (!userRepoConfigs || userRepoConfigs.length === 0) {
|
|
32
|
+
throw new Error('No git repos found in config');
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
const clonePromises = userRepoConfigs.map((repoConf) => {
|
|
36
|
+
const user = Object.keys(repoConf)[0];
|
|
37
|
+
const repoUrl = repoConf[user]['repo-url'];
|
|
38
|
+
|
|
39
|
+
return git
|
|
34
40
|
.clone({
|
|
35
41
|
fs,
|
|
36
42
|
http,
|
|
37
|
-
dir: this.dataPath +
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
dir: this.dataPath + `/${user}`,
|
|
44
|
+
gitdir: path.join(this.dataPath, 'gitdir', user, '.git'),
|
|
45
|
+
url: repoUrl.includes('.git') ? repoUrl : repoUrl + '.git',
|
|
40
46
|
singleBranch: true,
|
|
47
|
+
depth: 1,
|
|
41
48
|
})
|
|
42
|
-
.then(() =>
|
|
49
|
+
.then(() => this.logger.log('done cloning ' + repoUrl));
|
|
43
50
|
});
|
|
51
|
+
return Promise.all(clonePromises);
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
getMode(): CONFIG_MODE {
|
|
@@ -48,7 +56,6 @@ export default class GitFilesService implements IFilesService {
|
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
listDirectory(path: string): Promise<Project> {
|
|
51
|
-
console.log('listDirectory', path);
|
|
52
59
|
return this.localFilesService.listDirectory(path);
|
|
53
60
|
}
|
|
54
61
|
|
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Inject,
|
|
3
|
+
Injectable,
|
|
4
|
+
InternalServerErrorException,
|
|
5
|
+
} from '@nestjs/common';
|
|
2
6
|
import * as fs from 'fs';
|
|
3
7
|
import { join } from 'path';
|
|
4
|
-
import { ConfigService } from '@nestjs/config';
|
|
5
8
|
import { Project } from 'src/types.js';
|
|
6
9
|
import { IFilesService } from '../interfaces/files.service.interface.js';
|
|
7
10
|
import { CONFIG_MODE } from '../../enums/config-mode.enum.js';
|
|
11
|
+
import Config from '../../config/config.service.js';
|
|
12
|
+
import { CONFIG_SERVICE } from '../../config/config.interface.js';
|
|
8
13
|
|
|
9
14
|
@Injectable()
|
|
10
15
|
export default class LocalFilesService implements IFilesService {
|
|
11
16
|
private readonly dataPath: string;
|
|
12
17
|
|
|
13
|
-
constructor(private configService:
|
|
14
|
-
this.dataPath = this.configService.
|
|
18
|
+
constructor(@Inject(CONFIG_SERVICE) private configService: Config) {
|
|
19
|
+
this.dataPath = this.configService.getLocalPath();
|
|
20
|
+
}
|
|
15
21
|
|
|
22
|
+
init(): Promise<any> {
|
|
23
|
+
return Promise.resolve();
|
|
16
24
|
}
|
|
25
|
+
|
|
17
26
|
getMode(): CONFIG_MODE {
|
|
18
27
|
return CONFIG_MODE.LOCAL;
|
|
19
28
|
}
|
package/src/main.ts
CHANGED
|
@@ -7,9 +7,9 @@ describe('cloudcmd test for the application', () => {
|
|
|
7
7
|
config();
|
|
8
8
|
|
|
9
9
|
await writeFile(`${process.env.LOCAL_PATH}/test.txt`, 'content12345');
|
|
10
|
-
|
|
11
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
12
|
-
},
|
|
10
|
+
|
|
11
|
+
await new Promise((resolve) => setTimeout(resolve, 50000)); // This is problematic.
|
|
12
|
+
}, 55000);
|
|
13
13
|
|
|
14
14
|
afterAll(async () => {
|
|
15
15
|
await unlink(`${process.env.LOCAL_PATH}/test.txt`);
|
|
@@ -30,7 +30,7 @@ describe('cloudcmd test for the application', () => {
|
|
|
30
30
|
expect(fileNames).toContain('user2');
|
|
31
31
|
}, 10000);
|
|
32
32
|
|
|
33
|
-
it('should return the content of a file that is uplaoded to cloudcmd
|
|
33
|
+
it('should return the content of a file that is uplaoded to cloudcmd', async () => {
|
|
34
34
|
const response = await axios.get(
|
|
35
35
|
`http://localhost:${process.env.PORT}${process.env.APOLLO_PATH}/files/api/v1/fs/test.txt`,
|
|
36
36
|
);
|