-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
120 lines (107 loc) · 3.46 KB
/
Copy pathgulpfile.mjs
File metadata and controls
120 lines (107 loc) · 3.46 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import chalk from 'chalk';
import { spawn } from 'child_process';
import { rm } from 'fs/promises';
import { dest, parallel, series, src } from 'gulp';
import _zip from 'gulp-zip';
import path from 'path';
async function removeDir(dir) {
try {
await rm(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 500 });
console.log(chalk.green(`✓ Removed: ${dir}`));
} catch (err) {
console.warn(chalk.yellow(`⚠ Could not fully remove ${dir}: ${err.message}`));
}
}
function exec(command) {
console.log(`Executing: ${command}`);
return new Promise((resolve, reject) => {
const parts = command.split(' ');
const cmd = parts[0];
const args = parts.slice(1);
const process = spawn(cmd, args, {
shell: true,
stdio: 'pipe',
});
process.stdout.on('data', (data) => {
console.log(chalk.green(data.toString().trim()));
});
process.stderr.on('data', (data) => {
console.error(chalk.red(data.toString().trim()));
});
process.on('close', (code) => {
if (code === 0) {
console.log(chalk.green(`✓ Command completed successfully: ${command}`));
resolve();
} else {
console.error(chalk.red(`✗ Command failed with exit code ${code}: ${command}`));
reject(new Error(`Command failed with exit code ${code}`));
}
});
process.on('error', (err) => {
console.error(chalk.red(`✗ Failed to start command: ${command}`));
console.error(chalk.red(err));
reject(err);
});
});
}
const FILES = {
'readme.txt': 'build/themegrill-demo-importer',
'themegrill-demo-importer.php': 'build/themegrill-demo-importer',
'composer.json': 'build/themegrill-demo-importer',
'license.txt': 'build/themegrill-demo-importer',
'package.json': 'build/themegrill-demo-importer',
'includes/**/*': 'build/themegrill-demo-importer/includes',
'src/**/*': 'build/themegrill-demo-importer/src',
'languages/**/*': 'build/themegrill-demo-importer/languages',
};
// Special handling for images to prevent corruption
const copyDist = function () {
return src(['dist/**/*'], { encoding: false }).pipe(dest('build/themegrill-demo-importer/dist'));
};
copyDist.displayName = 'copy:dist';
const copyDotOrgImages = function () {
return src(['.wordpress-org/**/*'], { encoding: false }).pipe(
dest('build/themegrill-demo-importer/.wordpress-org'),
);
};
copyDotOrgImages.displayName = 'copy:dotorgimages';
// Handle other files (non-dist)
const copyTasks = Object.entries(FILES)
.filter(([source]) => !source.startsWith('dist/'))
.map(([source, destination]) => {
const taskName = `copy:${path.basename(source.replace('/**/*', ''))}`;
const copyTask = function () {
return src(source).pipe(dest(destination));
};
copyTask.displayName = taskName;
return copyTask;
});
// Add the special image and dist tasks to the copy tasks
copyTasks.unshift(copyDotOrgImages, copyDist);
const copy = parallel(...copyTasks);
const release = series(
function clean() {
return Promise.all([removeDir('release'), removeDir('build')]);
},
function build() {
return exec(`pnpm build`);
},
copy,
function composer() {
return exec(
`cd build/themegrill-demo-importer && composer install --no-dev --optimize-autoloader`,
);
},
function zip() {
return src(['./build/**/*', '!./build/**/composer.json', '!./build/**/composer.lock', '!./build/**/vendor/composer/tmp-*.zip'], {
encoding: false,
dot: true,
})
.pipe(_zip('themegrill-demo-importer.zip'))
.pipe(dest('release'));
},
function cleanBuild() {
return removeDir('build');
},
);
export { release };