mirror of
https://github.com/LamGC/wp-asciiplayer.git
synced 2026-10-12 23:33:55 +00:00
Refresh player with native block editor preview and local assets
Preserve shortcode rendering, normalize options, bundle the player locally, and add reproducible packaging and WordPress integration tests.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { cp, mkdir, mkdtemp, readdir, readFile, rm, stat, utimes } from 'node:fs/promises';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
|
||||
const root = path.resolve(import.meta.dirname, '..');
|
||||
const required = ['build/block.json', 'build/index.js', 'build/index.asset.php', 'build/view.js', 'build/view.asset.php', 'build/player.js', 'build/player.css'];
|
||||
for (const file of required) await stat(path.join(root, file));
|
||||
const pkg = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'));
|
||||
const php = await readFile(path.join(root, 'asciicast-player.php'), 'utf8');
|
||||
const readme = await readFile(path.join(root, 'readme.txt'), 'utf8');
|
||||
if (!php.includes(`Version: ${pkg.version}`) || !readme.includes(`Stable tag: ${pkg.version}`)) throw new Error('Version headers disagree.');
|
||||
const temp = await mkdtemp(path.join(os.tmpdir(), 'wp-asciiplayer-package-'));
|
||||
const target = path.join(temp, 'wp-asciiplayer');
|
||||
const inputs = ['asciicast-player.php', 'includes', 'build', 'LICENSE', 'licenses', 'THIRD-PARTY-NOTICES.md', 'README.md', 'README-zh.md', 'readme.txt', 'SOURCE.md', 'src', 'block.json', 'package.json', 'package-lock.json', 'webpack.config.cjs', 'babel.config.json', 'scripts'];
|
||||
try {
|
||||
await mkdir(target);
|
||||
for (const file of inputs) await cp(path.join(root, file), path.join(target, file), { recursive: true });
|
||||
const files = [];
|
||||
async function walk(dir) {
|
||||
for (const entry of (await readdir(dir, { withFileTypes: true })).sort((a,b) => a.name.localeCompare(b.name, 'en'))) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) await walk(full);
|
||||
else if (entry.isFile()) {
|
||||
await utimes(full, new Date('2026-01-01T00:00:00Z'), new Date('2026-01-01T00:00:00Z'));
|
||||
files.push(path.relative(temp, full));
|
||||
} else throw new Error(`Unexpected non-regular archive entry: ${full}`);
|
||||
}
|
||||
}
|
||||
await walk(target);
|
||||
await mkdir(path.join(root, 'dist'), { recursive: true });
|
||||
const zip = path.join(root, 'dist/wp-asciiplayer.zip');
|
||||
await rm(zip, { force: true });
|
||||
execFileSync('zip', ['-X', '-q', zip, ...files], { cwd: temp, env: { ...process.env, TZ: 'UTC' } });
|
||||
console.log(`Created ${zip} (${files.length} files), version ${pkg.version}.`);
|
||||
} finally {
|
||||
await rm(temp, { recursive: true, force: true });
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { copyFile, mkdir, readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
const root = path.resolve(import.meta.dirname, '..');
|
||||
const pkg = JSON.parse(await readFile(path.join(root, 'node_modules/asciinema-player/package.json'), 'utf8'));
|
||||
if (pkg.version !== '3.17.0') throw new Error(`Unexpected player version: ${pkg.version}`);
|
||||
await mkdir(path.join(root, 'build'), { recursive: true });
|
||||
for (const [source, destination] of [
|
||||
['dist/bundle/asciinema-player.min.js', 'player.js'],
|
||||
['dist/bundle/asciinema-player.css', 'player.css'],
|
||||
]) {
|
||||
await copyFile(path.join(root, 'node_modules/asciinema-player', source), path.join(root, 'build', destination));
|
||||
}
|
||||
await copyFile(path.join(root, 'block.json'), path.join(root, 'build/block.json'));
|
||||
console.log(`Bundled local asciinema-player ${pkg.version}; no CDN is used.`);
|
||||
@@ -0,0 +1,17 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { createHash } from 'node:crypto';
|
||||
const hash = (data) => createHash('sha256').update(data).digest('hex');
|
||||
const asset = await readFile('build/index.asset.php', 'utf8');
|
||||
if (asset.includes('react-jsx-runtime')) throw new Error('Automatic JSX runtime would break the WordPress 6.3 baseline.');
|
||||
for (const dependency of ['wp-blocks', 'wp-block-editor', 'wp-element', 'wp-compose']) {
|
||||
if (!asset.includes(`'${dependency}'`)) throw new Error(`Missing editor dependency: ${dependency}`);
|
||||
}
|
||||
for (const [destination, original] of [
|
||||
['build/player.js', 'node_modules/asciinema-player/dist/bundle/asciinema-player.min.js'],
|
||||
['build/player.css', 'node_modules/asciinema-player/dist/bundle/asciinema-player.css'],
|
||||
]) {
|
||||
if (hash(await readFile(destination)) !== hash(await readFile(original))) throw new Error(`Vendor file mismatch: ${destination}`);
|
||||
}
|
||||
const metadata = JSON.parse(await readFile('build/block.json', 'utf8'));
|
||||
if (metadata.apiVersion !== 3 || metadata.name !== 'lamgc/asciiplayer') throw new Error('Unexpected block metadata.');
|
||||
console.log('Verified WordPress 6.3-compatible JSX dependencies, block metadata, and exact local vendor files.');
|
||||
Reference in New Issue
Block a user