@wp-operations/wp-ide 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +52 -35
  2. package/package.json +1 -5
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ var CONFIG_FILENAME = "wp-operations.json";
4
4
  var ROOT_MARKERS = [CONFIG_FILENAME, ".git"];
5
5
 
6
6
  // src/resolve-project.ts
7
- import fs from "fs-extra";
7
+ import fs from "fs";
8
8
  import path from "path";
9
9
  function findRootDir(startDir = process.cwd()) {
10
10
  let current = path.resolve(startDir);
@@ -26,35 +26,41 @@ function resolveProject(startDir = process.cwd()) {
26
26
  const configPath = path.join(rootDir, CONFIG_FILENAME);
27
27
  let config = {};
28
28
  if (fs.existsSync(configPath)) {
29
- const parsed = fs.readJsonSync(configPath, { throws: false });
30
- if (parsed && typeof parsed === "object") {
31
- config = parsed;
29
+ try {
30
+ const parsed = JSON.parse(fs.readFileSync(configPath, "utf8"));
31
+ if (parsed && typeof parsed === "object") {
32
+ config = parsed;
33
+ }
34
+ } catch {
32
35
  }
33
36
  }
34
37
  return { rootDir, config };
35
38
  }
36
39
 
37
40
  // src/local-path.ts
38
- import fs2 from "fs-extra";
41
+ import fs2 from "fs";
39
42
  import path2 from "path";
40
43
  function localPath(rootDir, ...segments) {
41
44
  return path2.join(rootDir, LOCAL_DIR, ...segments);
42
45
  }
43
46
  function ensureLocalDir(rootDir, ...segments) {
44
47
  const target = localPath(rootDir, ...segments);
45
- fs2.ensureDirSync(target);
48
+ fs2.mkdirSync(target, { recursive: true });
46
49
  return target;
47
50
  }
51
+ function useLocalData(rootDir) {
52
+ const home = ensureLocalDir(rootDir, "wp-app");
53
+ process.env["WP_APP_HOME"] = home;
54
+ return home;
55
+ }
48
56
 
49
57
  // src/app-server-options.ts
50
58
  import path3 from "path";
51
59
  function appServerOptions(appDir, overrides = {}) {
52
60
  const { rootDir, config } = resolveProject(appDir);
53
- const appName = path3.basename(path3.resolve(appDir));
54
- const wpContentPath = ensureLocalDir(rootDir, "wp-content", appName);
61
+ useLocalData(rootDir);
55
62
  const options = {
56
- projectPath: path3.resolve(appDir),
57
- wpContentPath
63
+ projectPath: path3.resolve(appDir)
58
64
  };
59
65
  const php = overrides.php ?? config.php;
60
66
  const wp = overrides.wp ?? config.wp;
@@ -66,41 +72,51 @@ function appServerOptions(appDir, overrides = {}) {
66
72
  }
67
73
 
68
74
  // src/run-blueprint.ts
69
- import {
70
- activatePlugin,
71
- activateTheme,
72
- defineWpConfigConsts,
73
- login
74
- } from "@wp-playground/blueprints";
75
+ var DOCROOT = "/wordpress";
76
+ function phpString(value) {
77
+ return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
78
+ }
79
+ async function runWordPressCode(php, code) {
80
+ const response = await php.run({
81
+ code: `<?php
82
+ require ${phpString(`${DOCROOT}/wp-load.php`)};
83
+ require_once ${phpString(`${DOCROOT}/wp-admin/includes/plugin.php`)};
84
+ ${code}
85
+ `
86
+ });
87
+ if (response.exitCode !== 0) {
88
+ throw new Error(`Blueprint PHP step failed: ${response.errors}`);
89
+ }
90
+ }
75
91
  async function runBlueprint(php, blueprint) {
76
92
  const executed = [];
77
93
  const skipped = [];
78
94
  for (const step of blueprint.steps ?? []) {
79
95
  switch (step.step) {
80
- case "defineWpConfigConsts":
81
- await defineWpConfigConsts(php, {
82
- consts: step.consts ?? {},
83
- virtualize: true
84
- });
85
- executed.push(step.step);
86
- break;
87
- case "login":
88
- await login(php, {
89
- username: step.username ?? "admin",
90
- password: step.password ?? "password"
91
- });
96
+ case "defineWpConfigConsts": {
97
+ const consts = step.consts ?? {};
98
+ for (const key in consts) {
99
+ php.defineConstant(key, consts[key]);
100
+ }
92
101
  executed.push(step.step);
93
102
  break;
103
+ }
94
104
  case "activatePlugin":
95
- await activatePlugin(php, {
96
- pluginPath: step.pluginPath
97
- });
105
+ await runWordPressCode(
106
+ php,
107
+ `activate_plugin(${phpString(
108
+ String(step.pluginPath)
109
+ )});`
110
+ );
98
111
  executed.push(step.step);
99
112
  break;
100
113
  case "activateTheme":
101
- await activateTheme(php, {
102
- themeFolderName: step.themeFolderName
103
- });
114
+ await runWordPressCode(
115
+ php,
116
+ `switch_theme(${phpString(
117
+ String(step.themeFolderName)
118
+ )});`
119
+ );
104
120
  executed.push(step.step);
105
121
  break;
106
122
  case "runPHP":
@@ -126,5 +142,6 @@ export {
126
142
  findRootDir,
127
143
  localPath,
128
144
  resolveProject,
129
- runBlueprint
145
+ runBlueprint,
146
+ useLocalData
130
147
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-operations/wp-ide",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Project and monorepo tooling for wp-operations: .local data convention, project resolution, blueprint runner.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,10 +28,6 @@
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "dependencies": {
32
- "@wp-playground/blueprints": "0.6.16",
33
- "fs-extra": "11.1.1"
34
- },
35
31
  "devDependencies": {
36
32
  "esbuild": "^0.25.0"
37
33
  },