પ્લેગ્રાઉન્ડ CLI નો પ્રોગ્રામેટિક ઉપયોગ
runCLI ફંક્શનનો ઉપયોગ કરીને તમારા JavaScript/TypeScript કોડમાંથી પ્લેગ્રાઉન્ડ CLI ને પ્રોગ્રામેટિક રીતે પણ નિયંત્રિત કરી શકાય છે. આથી તમારા કોડની અંદર CLI ની તમામ સુવિધાઓનો સીધો ઉપયોગ કરી શકાય છે, જે ખાસ કરીને end-to-end ટેસ્ટને ઓટોમેટ કરવા માટે ઉપયોગી છે. તમે runCLI ને આપો છો તે વિકલ્પો સીધા જ CLI flags સાથે મેળ ખાય છે.
ચોક્કસ વર્ઝન સાથે WordPress ઇન્સ્ટન્સ ચલાવવું
runCLI ફંક્શનનો ઉપયોગ કરીને તમે PHP અને WordPress વર્ઝન જેવા વિકલ્પો નિર્દિષ્ટ કરી શકો છો. નીચેના ઉદાહરણમાં, આપણે PHP 8.3, WordPress નું નવીનતમ વર્ઝન અને આપમેળે લૉગિન થવાની સુવિધા પસંદ કરીએ છીએ. સપોર્ટેડ તમામ આર્ગ્યુમેન્ટ ્સ RunCLIArgs ટાઇપમાં વ્યાખ્યાયિત છે.
import { runCLI } from "@wp-playground/cli";
const cliServer = await runCLI({
command: 'server',
php: '8.3',
wp: 'latest',
login: true,
});
ઉપરનો કોડ તમારા પસંદગીના TypeScript runtime દ્વારા ચલાવો, ઉદાહરણ તરીકે tsx:
npx tsx my-script.ts
Blueprint સેટ કરવું
તમે Blueprint બે રીતે આપી શકો છો: blueprint પ્રોપર્ટીમાં સીધો object literal આપીને અથવા બહારની .json ફાઇલનો પાથ ધરાવતી string આપીને.
import { runCLI, RunCLIServer } from "@wp-playground/cli";
const cliServer: RunCLIServer = await runCLI({
command: 'server',
wp: 'latest',
blueprint: {
steps: [
{
"step": "setSiteOptions",
"options": {
"blogname": "Blueprint Title",
"blogdescription": "A great blog description"
}
}
],
},
});
તમારા Blueprint object ને સંપૂર્ણ type-safety સાથે વ્યાખ્યાયિત કરવા માટે, @wp-playground/blueprints પેકેજમાંથી BlueprintDeclaration ટાઇપ import કરીને તેનો ઉપયોગ કરી શકો છો:
import type { BlueprintDeclaration } from '@wp-playground/blueprints';
const myBlueprint: BlueprintDeclaration = {
landingPage: "/wp-admin/",
steps: [
{
"step": "installTheme",
"themeData": {
"resource": "wordpress.org/themes",
"slug": "twentytwentyone"
},
"options": {
"activate": true
}
}
]
};