-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
104 lines (90 loc) · 3.45 KB
/
Copy pathgulpfile.mjs
File metadata and controls
104 lines (90 loc) · 3.45 KB
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
96
97
98
99
100
101
102
103
104
import chalk from 'chalk';
import { spawn } from 'child_process';
import { existsSync, readdirSync } from 'fs';
import { dest, parallel, series, src } from 'gulp';
import zip from 'gulp-zip';
import os from 'os';
import path from 'path';
const PLUGIN_SLUG = 'allfeedback';
const BUILD_DIR = `build/${PLUGIN_SLUG}`;
function resolveLocalWpPhpBin() {
const base = path.join(os.homedir(), 'Library', 'Application Support', 'Local', 'lightning-services');
if (!existsSync(base)) return null;
const bin = readdirSync(base)
.filter((d) => /^php-8\.[2-9]/.test(d))
.sort()
.reverse()
.map((d) => path.join(base, d, 'bin', 'darwin-arm64', 'bin'))
.find((b) => existsSync(path.join(b, 'php')));
return bin ?? null;
}
const localWpPhpBin = resolveLocalWpPhpBin();
const spawnEnv = localWpPhpBin
? { ...process.env, PATH: `${localWpPhpBin}:${process.env.PATH}` }
: process.env;
if (localWpPhpBin) {
console.log(chalk.dim(`Using LocalWP PHP: ${localWpPhpBin}`));
}
function exec(command, env = spawnEnv) {
console.log(chalk.cyan(`▶ ${command}`));
return new Promise((resolve, reject) => {
const [cmd, ...args] = command.split(' ');
const child = spawn(cmd, args, { shell: true, stdio: 'pipe', env });
child.stdout.on('data', (d) => console.log(chalk.green(d.toString().trim())));
child.stderr.on('data', (d) => console.error(chalk.red(d.toString().trim())));
child.on('close', (code) => {
if (code === 0) {
console.log(chalk.green(`✓ ${command}`));
resolve();
} else {
console.error(chalk.red(`✗ Exit ${code}: ${command}`));
reject(new Error(`Command failed: ${command}`));
}
});
child.on('error', (err) => {
console.error(chalk.red(`✗ Failed to start: ${command}`));
reject(err);
});
});
}
const FILES = {
'src/**/*': `${BUILD_DIR}/src`,
'config/**/*': `${BUILD_DIR}/config`,
'database/**/*': `${BUILD_DIR}/database`,
'languages/**/*': `${BUILD_DIR}/languages`,
'resources/scripts/blocks/**/block.json': `${BUILD_DIR}/resources/scripts/blocks`,
[`${PLUGIN_SLUG}.php`]: BUILD_DIR,
'uninstall.php': BUILD_DIR,
'readme.txt': BUILD_DIR,
'composer.json': BUILD_DIR,
'composer.lock': BUILD_DIR,
};
const copyTasks = Object.entries(FILES).map(([source, destination]) => {
const taskName = `copy:${path.basename(source.replace('/**/*', ''))}`;
const task = () => src(source, { encoding: false }).pipe(dest(destination));
task.displayName = taskName;
return task;
});
export const release = series(
function clean() { return exec('rm -rf build/ release/'); },
function build() {
return exec('pnpm build', {
...spawnEnv,
OUTPUT_PATH: `${BUILD_DIR}/resources/build`,
});
},
function makePot() { return exec('pnpm make-pot'); },
parallel(...copyTasks),
function composer() {
return exec(`cd ${BUILD_DIR} && composer install --no-dev --optimize-autoloader`);
},
function compress() {
return src(
['./build/**/*', '!./build/**/*.map', '!./build/**/composer.lock', '!./build/**/*.sh'],
{ encoding: false },
)
.pipe(zip(`${PLUGIN_SLUG}.zip`))
.pipe(dest('./release/'));
},
function cleanup() { return exec('rm -rf build/'); },
);