Skip to content

Commit 0cf30a6

Browse files
author
Ovidiu Barabula
committed
feat(core): add paths provider for plugins
1 parent d9630fc commit 0cf30a6

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/plugin-manager/paths.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { assert, expect } from 'chai';
2+
import 'mocha';
3+
import PathsProvider from './paths';
4+
5+
6+
describe('PathsProvider', () => {
7+
it('returns an object', () => {
8+
expect(PathsProvider()).to.be.an('object');
9+
});
10+
11+
12+
it('returns an object with current working directory (cwd) property', () => {
13+
expect(PathsProvider()).to.contain.keys('cwd');
14+
});
15+
16+
17+
it('doesn\'t provide source directory path if core configuration is not passed', () => {
18+
expect(PathsProvider()).to.not.contain.keys('sourceDir');
19+
});
20+
21+
22+
it('doesn\'t provide build directory path if core configuration is not passed', () => {
23+
expect(PathsProvider()).to.not.contain.keys('buildDir');
24+
});
25+
26+
27+
it('provides source directory path', () => {
28+
expect(PathsProvider({ sourceDir: 'source' })).to.contain.keys('sourceDir');
29+
});
30+
31+
32+
it('provides build directory path', () => {
33+
expect(PathsProvider({ buildDir: 'build' })).to.contain.keys('buildDir');
34+
});
35+
});

src/plugin-manager/paths.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Name: paths.ts
3+
* Description: Paths plugin provider
4+
* Author: Ovidiu Barabula <lectii2008@gmail.com>
5+
* @since 0.1.0
6+
*/
7+
8+
import * as path from 'path';
9+
import { Config } from '../config-manager';
10+
11+
12+
export interface WorkingPaths {
13+
cwd: string;
14+
buildDir?: string;
15+
sourceDir?: string;
16+
}
17+
18+
19+
/**
20+
* Create an object with working paths
21+
* @param coreConfig Core configuration object
22+
*/
23+
function PathsProvider(coreConfig: Config = {}): WorkingPaths {
24+
// Get current working path
25+
const cwd: string = process.cwd();
26+
let paths: WorkingPaths = {
27+
cwd,
28+
};
29+
30+
for (const option of ['sourceDir', 'buildDir']) {
31+
if (Object.keys(coreConfig).includes(option)) {
32+
paths = { ...paths,
33+
[option]: coreConfig[option],
34+
};
35+
}
36+
}
37+
38+
return Object.freeze(paths);
39+
}
40+
41+
export default PathsProvider;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy