-
Notifications
You must be signed in to change notification settings - Fork 2
/
verify-theme.ts
44 lines (37 loc) 路 1.28 KB
/
verify-theme.ts
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
import * as path from 'node:path';
import fs from 'fs-extra';
import SemanticReleaseError from '@semantic-release/error';
import getError from './get-error.js';
import { PluginConfig } from '../classes/plugin-config.class.js';
export async function verifyTheme(config: PluginConfig): Promise<void> {
const themePath = config.path
? path.resolve(config.path, config.slug)
: path.resolve('./');
const errors: SemanticReleaseError[] = [];
if (
!(await fs.pathExists(path.resolve(themePath, 'style.css'))) ||
!(await fs.pathExists(path.resolve(themePath, 'functions.php')))
) {
throw new AggregateError([
getError('ETHEMEFILENOTFOUND', 'style.css, functions.php'),
]);
}
try {
const styleSheet = await fs.readFile(
path.resolve(themePath, 'style.css'),
'utf-8',
);
if (!styleSheet.includes('Theme Name:')) {
errors.push(getError('ETHEMEFILEINVALID', 'style.css'));
}
const version = styleSheet.match(/Version:\s*(\d+\.\d+\.\d+)/);
if (version !== null && version[1] !== '0.0.0') {
errors.push(getError('ETHEMEFILEVERSION', version[1]));
}
} catch (err) {
if (err instanceof Error) {
errors.push(new SemanticReleaseError(err.message, 'EINVALIDTHEME', ''));
}
throw new AggregateError(errors);
}
}