Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevoss committed Jul 24, 2024
1 parent a34f3eb commit f78c892
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
13 changes: 6 additions & 7 deletions dist/setup-wp-env/create-wp-env-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ async function main() {
"active-theme": {
type: "string",
default: "",
validate: (value) => typeof value === "string" && /^[a-z0-9-]+$/.test(value)
validate: (value) => typeof value === "string" && /^[a-z0-9-]+$/.test(value) || value === ""
},
mappings: { type: "string", default: "" },
dir: { type: "string", default: "./" },
config1: { type: "string", default: "" },
config2: { type: "string", default: "" }
config: { type: "string", default: "" }
});
console.log(config);
const content = {
core: wp ? `WordPress/Wordpress#${wp}` : null,
phpVersion: php ? php : null,
themes: parseAsArray(themes),
mappings: mappingsFromString(mappings),
mappings: mapFromString(mappings),
plugins: parseAsArray(plugins),
config: mapFromString(config),
lifecycleScripts: {
afterStart: prepareCommands(
["cli", "tests-cli"],
Expand Down Expand Up @@ -61,12 +60,12 @@ function getOptions(args) {
});
return options;
}
function mappingsFromString(mappings) {
function mapFromString(mappings) {
const config = parseAsArray(mappings).map((mapping) => mapping.split(":")).filter(([from, to]) => from && to);
return Object.fromEntries(config);
}
function parseAsArray(array) {
return array.split(",").map((item) => item.trim()).filter(Boolean);
return array.split(/[,\r\n]/).map((item) => item.trim()).filter(Boolean);
}
function prepareCommands(envs, commands) {
const mergedCommands = commands.filter(Boolean).join(" && ");
Expand Down
15 changes: 7 additions & 8 deletions src/setup-wp-env/create-wp-env-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ async function main() {
type: 'string',
default: '',
validate: (value) =>
typeof value === 'string' && /^[a-z0-9-]+$/.test(value),
(typeof value === 'string' && /^[a-z0-9-]+$/.test(value)) ||
value === '',
},
mappings: { type: 'string', default: '' },
dir: { type: 'string', default: './' },
config1: { type: 'string', default: '' },
config2: { type: 'string', default: '' },
config: { type: 'string', default: '' },
});

console.log(config);

const content = {
core: wp ? `WordPress/Wordpress#${wp}` : null,
phpVersion: php ? php : null,
themes: parseAsArray(themes),
mappings: mappingsFromString(mappings),
mappings: mapFromString(mappings),
plugins: parseAsArray(plugins),
config: mapFromString(config),
lifecycleScripts: {
afterStart: prepareCommands(
['cli', 'tests-cli'],
Expand Down Expand Up @@ -84,7 +83,7 @@ function getOptions(
return options;
}

function mappingsFromString(mappings: string) {
function mapFromString(mappings: string) {
const config = parseAsArray(mappings)
.map((mapping) => mapping.split(':'))
.filter(([from, to]) => from && to);
Expand All @@ -94,7 +93,7 @@ function mappingsFromString(mappings: string) {

function parseAsArray(array: string) {
return array
.split(',')
.split(/[,\r\n]/)
.map((item) => item.trim())
.filter(Boolean);
}
Expand Down

0 comments on commit f78c892

Please sign in to comment.