-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
73 lines (60 loc) · 1.64 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
/**
* Gulp WP.
*/
// Load .env file.
const env = require( 'dotenv' ).config();
if ( process.env.NOTIFY === 'false' ) {
process.env.DISABLE_NOTIFIER = true;
}
// Node
const { resolve } = require( 'path' );
// Internal
const GulpWPRegistry = require( './lib/registry' );
const {
c,
getPluginFile,
isTheme,
loadConfig,
loadTasks,
log,
} = require( './util' );
function init( gulp, config = {} ) {
const localConfig = loadConfig();
config = Object.assign( {}, localConfig, config );
// Add env explicitly so that it can't be set via config.
config.env = {
DEV_URL: 'http://localhost',
...env.parsed,
};
// If `plugin` not specified in config, check for style.css and then for a plugin entry point.
if ( ! config.plugin ) {
if ( ! isTheme() ) {
config.plugin = getPluginFile();
}
}
// Load local tasks first so we can ignore tasks meant to be overridden.
const localTaskFolder = config.taskFolder || 'gulp-wp';
log.debug( 'Loading local tasks from', c.blue( localTaskFolder ) );
const localTasks = loadTasks( localTaskFolder );
log.debug(
'Loaded local tasks:',
c.cyan( Object.keys( localTasks ).join( ' ' ) )
);
// Load Gulp WP core tasks.
const gulpWPTasks = loadTasks(
resolve( __dirname, 'tasks' ),
Object.keys( localTasks )
);
log.debug(
'Loaded Gulp WP tasks:',
c.cyan( Object.keys( gulpWPTasks ).join( ' ' ) )
);
const tasks = Object.assign( {}, gulpWPTasks, localTasks );
// Register our custom registry.
const gulpWP = new GulpWPRegistry( gulp, tasks, config );
gulp.registry( gulpWP );
return gulpWP;
}
// Expose GulpWPRegistry for advanced use.
init.GulpWPRegistry = GulpWPRegistry;
module.exports = init;