connector-wordpress/gulpfile.js

102 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-01-08 14:08:40 +01:00
const { dest, series, src } = require('gulp');
const del = require('del');
const replace = require('gulp-replace');
const webpack = require('webpack-stream');
const PACKAGE = require('./package.json');
const FOLDER_SOURCE = './source'
const FOLDER_BUILD = './build';
let mode = 'development';
function clean(cb) {
del(FOLDER_BUILD);
cb();
}
const eventsLoaderOutputPath = PACKAGE.name + '/front/events-loader';
2021-11-01 20:55:37 +01:00
const blockEventsLoaderOutputPath = PACKAGE.name + '/front/block-events-loader';
2021-01-08 14:08:40 +01:00
const eventsLoaderInputPath = FOLDER_SOURCE + '/' + PACKAGE.name + '/front/events-loader.js';
2021-11-01 20:55:37 +01:00
const blockEventsLoaderInputPath = FOLDER_SOURCE + '/' + PACKAGE.name + '/front/block-events-loader.js';
2021-01-08 14:08:40 +01:00
function bundleFrontend() {
2021-11-01 20:55:37 +01:00
return src([
FOLDER_SOURCE + '/' + PACKAGE.name + '/front/events-loader.js',
FOLDER_SOURCE + '/' + PACKAGE.name + '/front/block-events-loader.js',
])
2021-01-08 14:08:40 +01:00
.pipe(webpack({
mode,
entry: {
[eventsLoaderOutputPath]: eventsLoaderInputPath,
2021-11-01 20:55:37 +01:00
[blockEventsLoaderOutputPath]: blockEventsLoaderInputPath,
2021-01-08 14:08:40 +01:00
},
output: {
filename: '[name].js',
},
2021-11-01 20:55:37 +01:00
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
}
}
]
}
2021-01-08 14:08:40 +01:00
}))
.pipe(dest(FOLDER_BUILD));
2021-04-05 17:53:47 +02:00
}
2021-01-08 14:08:40 +01:00
function copyBackend() {
return src([
FOLDER_SOURCE + '/**/*.php',
FOLDER_SOURCE + '/**/*.txt'
])
.pipe(dest(FOLDER_BUILD));
}
function injectMetadata() {
return src([
FOLDER_BUILD + '/' + eventsLoaderOutputPath + '.js',
2021-11-01 20:55:37 +01:00
FOLDER_BUILD + '/' + blockEventsLoaderOutputPath + '.js',
2021-01-08 14:08:40 +01:00
FOLDER_BUILD + '/' + PACKAGE.name + '/' + PACKAGE.name + '.php',
FOLDER_BUILD + '/' + PACKAGE.name + '/includes/constants.php',
FOLDER_BUILD + '/' + PACKAGE.name + '/readme.txt'
], { base: './' })
.pipe(replace('<wordpress-author-name>', PACKAGE.author.name))
.pipe(replace('<wordpress-author-url>', PACKAGE.author.url))
.pipe(replace('<wordpress-description>', PACKAGE.description))
2021-03-28 22:28:32 +02:00
.pipe(replace('<wordpress-donation-link>', PACKAGE.funding.url))
2021-01-08 14:08:40 +01:00
.pipe(replace('<wordpress-license>', PACKAGE.license))
.pipe(replace('<wordpress-minimum-version>', PACKAGE.additionalDetails.wordpressMinimumVersion))
.pipe(replace('<wordpress-name>', PACKAGE.name))
.pipe(replace('<wordpress-nice-name>', PACKAGE.additionalDetails.niceName))
.pipe(replace('<wordpress-php-minimum-version>', PACKAGE.additionalDetails.phpMinimumVersion))
.pipe(replace('<wordpress-tested-up-to-version>', PACKAGE.additionalDetails.wordpressTestedUpToVersion))
.pipe(replace('<wordpress-version>', PACKAGE.version))
.pipe(dest('.'));
}
exports.front = bundleFrontend;
exports.copy = copyBackend;
exports.inject = injectMetadata;
const build = series(clean, bundleFrontend, copyBackend, injectMetadata);
const buildDev = series((cb) => { mode = 'development'; cb(); }, build);
const buildProd = series((cb) => { mode = 'production'; cb(); }, build);
exports.clean = clean;
exports.dev = buildDev;
exports.default = buildDev;
exports.prod = buildProd;