File tree Expand file tree Collapse file tree 2 files changed +76
-0
lines changed Expand file tree Collapse file tree 2 files changed +76
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments