Skip to content

Commit

Permalink
wp-now: read and parse blueprint on config
Browse files Browse the repository at this point in the history
  • Loading branch information
sejas committed Jun 19, 2023
1 parent 124f62d commit 3d2b4a6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/wp-now/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import {
SupportedPHPVersionsList,
} from '@php-wasm/universal';
import crypto from 'crypto';
import fs from 'fs-extra';
import path from 'path';
import { Blueprint } from '@wp-playground/blueprints';
import { getCodeSpaceURL, isGitHubCodespace } from './github-codespaces';
import { inferMode } from './wp-now';
import { portFinder } from './port-finder';
import { isValidWordPressVersion } from './wp-playground-wordpress';
import getWpNowPath from './get-wp-now-path';

import path from 'path';

import { DEFAULT_PHP_VERSION, DEFAULT_WORDPRESS_VERSION } from './constants';

export interface CliOptions {
php?: string;
path?: string;
wp?: string;
port?: number;
blueprint?: string;
}

export const enum WPNowMode {
Expand All @@ -41,6 +42,7 @@ export interface WPNowOptions {
wpContentPath?: string;
wordPressVersion?: string;
numberOfPhpInstances?: number;
blueprintObject?: Blueprint;
}

export const DEFAULT_OPTIONS: WPNowOptions = {
Expand Down Expand Up @@ -135,5 +137,17 @@ export default async function getWpNowConfig(
}. Supported versions: ${SupportedPHPVersionsList.join(', ')}`
);
}
if (args.blueprint) {
const blueprintPath = path.resolve(args.blueprint);
if (!fs.existsSync(blueprintPath)) {
throw new Error(`Blueprint file not found: ${blueprintPath}`);
}
const blueprintObject = JSON.parse(
fs.readFileSync(blueprintPath, 'utf8')
);
// TODO: blueprint schema validation

options.blueprintObject = blueprintObject;
}
return options;
}

0 comments on commit 3d2b4a6

Please sign in to comment.