cr0ybot / gulp-wp

A reusable, extendable, updatable Gulp workflow for WordPress themes & plugins

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom build Task is not run

mikastamm opened this issue · comments

Hey,

im trying to enable the use of Blade Templates, by adding an extra build task. This task lives in my /gulp-wp folder, in blade.js.
With this content, based on the readme.

The problem is that no .php files are generated from my .blade.php files. Debugging the task, I find that the task: ( gulp, config, registry ) function gets called, but the function it returns never is. I have no custom neither gulpfile nor a gulp-wp.config.js.

gulp-wp/blade.js:

 var blade = require('gulp-blade');

module.exports = {
	
	task: ( gulp, config, registry ) => {
 
		const { src, dest } = config;
		return function() {
			return gulp.src(src)
                         .pipe(blade())
                         .pipe(gulp.dest(dest))
		}


	},
	config: {
		src: '*views/*.blade.php',
		dest: 'views',
	},
	dependencies: [ 'clean', 'scripts', 'styles'],
};

This is my Folder structure

├── composer.json
├── composer.lock
├── package-lock.json
├── package.json
├── plugin.php
├── gulp-wp
│   └── blade.js
├── languages
│   └── translations.pot
└── src
    ├── app
    │   └── example.php
    ├── scripts
    │   └── index.ts
    ├── styles
    │   └── style.scss
    └── views
        └── example.blade.php

Here's what appears in my dist folder

├── dist
│   ├── css
│   │   ├── style.asset.php
│   │   ├── style.css
│   │   └── style.css.map
│   └── js
│       ├── index.asset.php
│       ├── index.js
│       └── index.js.map

Heres the build scripts output

> gulp-wp build

No entry file discovered in the "src" directory.
[09:16:17] 

 ┏━━┓      ┏┓ ┏┳━┓   ┏
 ┃┏━╋┳┳┓┏━┓┃┣━┫┃╻┃ ███
 ┃┗┓┃╹┃┗┫╹┃┃╹┃╹┃┏┛ ▐█▌
 ┗━━┻━┻━┫┏┛┗━┻━┻┛  ▝▀▘ v0.6.1
        ┗┛

[09:16:17] Using gulpfile ~/Documents/code/wordpress-plugin-base/node_modules/gulp-wp/lib/gulpfile.js
[09:16:17] Starting 'build'...
[09:16:17] Starting 'clean'...
[09:16:17] cleaned: /Users/mika/Documents/code/wordpress-plugin-base/dist/css
[09:16:17] cleaned: /Users/mika/Documents/code/wordpress-plugin-base/dist/js
[09:16:17] Finished 'clean' after 5.11 ms
[09:16:17] Starting 'styles'...
[09:16:17] Starting 'scripts'...
[09:16:17] Starting 'blocks'...
[09:16:17] blocks entry: 0 items
[09:16:17] webpack-stream - No files given; aborting compilation
[09:16:17] blocks copy: 0 items
[09:16:17] Finished 'blocks' after 27 ms
[09:16:17] scripts entry: src/scripts/index.ts
[09:16:17] scripts entry: 1 item
[09:16:17] styles entry: src/styles/style.css
[09:16:17] styles entry: 1 item
[09:16:17] Finished 'styles' after 209 ms
[09:16:18] asset index.js 250 bytes [emitted] (name: index) 1 related asset
asset index.asset.php 95 bytes [emitted] (name: index)
Entrypoint index 345 bytes (235 bytes) = index.js 250 bytes index.asset.php 95 bytes 1 auxiliary asset
webpack 5.69.1 compiled successfully
[09:16:18] Finished 'scripts' after 378 ms
[09:16:18] Starting 'translate'...
[09:16:18] Starting 'version'...
[09:16:18] Copying version 1.0.0 from package.json to ./plugin.php
[09:16:18] Finished 'version' after 1.31 ms
[09:16:18] Plugin Name not found.
[09:16:18] Text Domain not found, all text domains will be included.
[09:16:18] Finished 'translate' after 3.89 ms
[09:16:18] Finished 'build' after 388 ms
[09:16:19] error

Also, I love this project. It's exactly what ive been looking for and haven't found anything else that suits my purpuse like it. Thanks a lot for making this!

@mikastamm Apologies that I didn't see this until just now!

First thing is that, even though gulp-wp detects your custom task, it doesn't know where to run it. You can have tasks that are just meant to be run directly via your package.son scripts, such as "gulp-wp my-custom-task". If you want this task to be run during the build task, the build task's config needs to be altered.

You can do that with a gulp-wp.config.js file like so:

module.exports = {
	tasks: {
		build: {
			build: [ 'blade' ], // currently gulp-wp combines array with the default build config, this might change
		},
		watch: {
			tasks: [
				{
					task: 'blade',
					mirrorDeletion: [ '.php' ],
				},
			],
		},
		clean: {
			cleanDest: [ 'blade' ], // same thing here about combining with the default array
		},
	},
};

The part that alters the watch task is a bit cumbersome too but it need to know what dist filetype to delete if you delete a src file. You have a custom dest in your task that is read by the watch task so it should work (but remember this is still prerelease!).

I'm open to suggestions about how to make this more intuitive.

Also, you should probably be able to remove the dependencies array, since it doesn't look like your task is dependent on any of those.

Hi @mikastamm, unless you're having further issues with this I'm closing this issue. Feel free to reply here if it's still not working!