-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
95 lines (84 loc) · 2.62 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* global async:true */
/**
* Functions & Basic Needs.
* @type {string}
*/
const $easy_gulp_tasker = '1.6';
/**
* Required Imports.
*/
const { handler } = require( './handler' );
const $gulp = require( 'gulp' );
const { get_config, processarg } = require( './functions' );
const $config = get_config();
const fancyLog = require( 'fancy-log' );
async function processFiles( array, src = null ) {
for( let $id in array ) {
if( array.hasOwnProperty( $id ) ) {
if( array[ $id ] instanceof Array ) {
await processFiles( array[ $id ], $id );
} else {
let $_src = ( null === src ) ? $id : src;
let $handler = new handler( $_src, array[ $id ], $config.config );
await $handler.init();
}
}
}
}
$gulp.task( 'watch', ( callback ) => {
async function processData( $id, $config, $global ) {
let $handler = new handler( $id, $config, $global );
await $handler.init();
}
async function watchArray( array, src = null ) {
for( let $id in array ) {
if( array.hasOwnProperty( $id ) ) {
if( array[ $id ] instanceof Array ) {
for( let $_c in array[ $id ] ) {
if( array[ $id ].hasOwnProperty( $_c ) ) {
let $watch = ( true === array[ $id ][ $_c ].watch ) ? $id : array[ $id ][ $_c ].watch;
if( typeof $watch !== 'undefined' ) {
$gulp.watch( $watch, { queue: true }, ( cb ) => {
processData( $id, array[ $id ][ $_c ], $config.config ).then( () => cb() );
} );
}
}
}
} else {
let $watch = ( true === array[ $id ].watch ) ? $id : array[ $id ].watch;
if( typeof $watch !== 'undefined' ) {
$gulp.watch( $watch, { queue: true }, ( cb ) => {
processData( $id, array[ $id ], $config.config ).then( () => cb() );
} );
}
}
}
}
}
if( typeof $config.files !== 'undefined' ) {
watchArray( $config.files ).then( () => {
callback();
} );
}
} );
$gulp.task( 'compile', ( callback ) => {
if( typeof $config.files !== 'undefined' ) {
processFiles( $config.files ).then( () => {
callback();
} );
}
} );
$gulp.task( 'single', ( callback ) => {
let $current = processarg();
let $_config = $config.files[ $current.file ];
if( typeof $_config !== 'undefined' ) {
let $arg = {};
$arg[ $current.file ] = $_config;
processFiles( $arg ).then( () => {
callback();
} );
} else {
fancyLog.error( $current.file + ' Not Found. Please check if you have passed file path. Eg : gulp single --file "your-file-path" ' );
callback();
}
} );