@wp-operations/wp-ops 0.3.1 → 0.4.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.
- package/README.md +6 -3
- package/package.json +1 -1
- package/src/commands/platform.js +43 -1
- package/src/commands/start.js +2 -2
- package/src/main.js +19 -14
package/README.md
CHANGED
|
@@ -18,8 +18,9 @@ Requires Node.js 20.10 or later and git. Composer is needed for plugins. If you
|
|
|
18
18
|
## Commands
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
wp-ops init my-platform
|
|
21
|
+
wp-ops init my-platform # the platform (wp-operations/), layout, workflows, git
|
|
22
22
|
cd my-platform
|
|
23
|
+
wp-ops start # the platform at http://localhost:8881 (admin / password)
|
|
23
24
|
wp-ops new plugin acme/forms
|
|
24
25
|
wp-ops new app service-apps shop --server=prod-1 --app-path=/var/www/shop
|
|
25
26
|
wp-ops composer add --apps=service-apps/shop --packages="acme/forms"
|
|
@@ -30,14 +31,16 @@ wp-ops doctor
|
|
|
30
31
|
|
|
31
32
|
| Command | What it does |
|
|
32
33
|
|---|---|
|
|
33
|
-
| `init [dir]
|
|
34
|
+
| `init [dir]` | Creates the platform repository: the platform theme in `wp-operations/`, `platform.json`, `.github/platform.json`, the app manifests, `packages/`, the app folders, `.github/workflows/composer.yml` and `.gitignore`, then runs `git init`. Never overwrites a file. |
|
|
35
|
+
| `start` | Runs the platform (`wp-operations/`) locally. Site data stays in `.local/` (gitignored). `wp-ops start <dir>` runs one app instead. |
|
|
36
|
+
| `update` | Replaces `wp-operations/` with the platform shipped in your wp-ops version. Update wp-ops first (`npm install -g @wp-operations/wp-ops`), then run it and commit. |
|
|
34
37
|
| `new app <kind> <slug>` | Creates the app (composer type `wp-app`) and adds it to the kind's manifest. |
|
|
35
38
|
| `new plugin <vendor/name>` | Creates `packages/<vendor>/<name>` (composer type `psr4-plugin`) with `src/Plugin.php`. |
|
|
36
39
|
| `apps`, `plugins` | Lists apps and plugins, which app uses which plugin, and any problems. |
|
|
37
40
|
| `composer <add\|remove\|update> --apps= --packages=` | Edits the apps' composer.json the same way the platform does and refreshes `composer.lock`. This is what `composer.yml` runs. |
|
|
38
41
|
| `sandbox` | Preview runtime for the platform. See below. |
|
|
39
42
|
| `edit` | Opens wp-ide for this repository. |
|
|
40
|
-
| `
|
|
43
|
+
| `dev`, `build` | Runs with file watching; builds packages with a build script. |
|
|
41
44
|
| `doctor` | Checks the environment and the repository. |
|
|
42
45
|
|
|
43
46
|
Running `wp-ops` with no arguments opens a menu.
|
package/package.json
CHANGED
package/src/commands/platform.js
CHANGED
|
@@ -71,6 +71,11 @@ export async function init({ dir = process.cwd(), platform, version, log = conso
|
|
|
71
71
|
writeNew(path.join(root, '.gitignore'), GITIGNORE, created);
|
|
72
72
|
|
|
73
73
|
platform = platform || bundledPlatform();
|
|
74
|
+
const themeDir = path.join(root, PLATFORM_DIR);
|
|
75
|
+
if (platform && fs.statSync(path.resolve(platform)).isDirectory() && !fs.existsSync(themeDir)) {
|
|
76
|
+
copyTheme(path.resolve(platform), themeDir);
|
|
77
|
+
created.push(themeDir);
|
|
78
|
+
}
|
|
74
79
|
if (platform) {
|
|
75
80
|
const source = path.resolve(platform);
|
|
76
81
|
const file = fs.existsSync(source) && fs.statSync(source).isDirectory() ? path.join(source, 'platform.json') : source;
|
|
@@ -93,7 +98,7 @@ export async function init({ dir = process.cwd(), platform, version, log = conso
|
|
|
93
98
|
if (!fs.existsSync(path.join(root, 'platform.json'))) {
|
|
94
99
|
log(pc.yellow(`\n platform.json is missing at the root. Run: wp-ops init --platform=<path to the theme>`));
|
|
95
100
|
}
|
|
96
|
-
log(`\n Next: ${pc.bold(`cd ${path.relative(process.cwd(), root) || '.'}`)}
|
|
101
|
+
log(`\n Next: ${pc.bold(`cd ${path.relative(process.cwd(), root) || '.'}`)} then ${pc.bold('wp-ops start')} to run the platform locally.`);
|
|
97
102
|
return { root, created, gitInit };
|
|
98
103
|
}
|
|
99
104
|
|
|
@@ -109,6 +114,43 @@ export function bundledPlatform() {
|
|
|
109
114
|
return '';
|
|
110
115
|
}
|
|
111
116
|
|
|
117
|
+
export const PLATFORM_DIR = 'wp-operations';
|
|
118
|
+
|
|
119
|
+
function themeVersion(dir) {
|
|
120
|
+
const css = path.join(dir, 'style.css');
|
|
121
|
+
return fs.existsSync(css) ? (fs.readFileSync(css, 'utf8').match(/^Version:\s*(\S+)/m)?.[1] ?? '') : '';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function copyTheme(source, target) {
|
|
125
|
+
fs.cpSync(source, target, {
|
|
126
|
+
recursive: true,
|
|
127
|
+
filter: (file) => {
|
|
128
|
+
const relative = path.relative(source, file).split(path.sep).join('/');
|
|
129
|
+
return relative !== 'ui' && !relative.startsWith('ui/');
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Replaces the repository's platform theme (wp-operations/) with the one
|
|
136
|
+
* shipped in this wp-ops version. Commit the result to deploy it.
|
|
137
|
+
*/
|
|
138
|
+
export async function update({ root, log = console.log }) {
|
|
139
|
+
const source = bundledPlatform();
|
|
140
|
+
if (!source) throw new UsageError('The platform theme is missing from this wp-ops install. Reinstall: npm install -g @wp-operations/wp-ops');
|
|
141
|
+
const target = path.join(root, PLATFORM_DIR);
|
|
142
|
+
const from = themeVersion(target);
|
|
143
|
+
const to = themeVersion(source);
|
|
144
|
+
if (from === to) {
|
|
145
|
+
log(` Platform is up to date (${to}).`);
|
|
146
|
+
return { from, to, changed: false };
|
|
147
|
+
}
|
|
148
|
+
fs.rmSync(target, { recursive: true, force: true });
|
|
149
|
+
copyTheme(source, target);
|
|
150
|
+
log(` ${pc.green('✓')} Platform ${from || '(none)'} → ${to}. Review with git diff, then commit.`);
|
|
151
|
+
return { from, to, changed: true };
|
|
152
|
+
}
|
|
153
|
+
|
|
112
154
|
function composerName(value) {
|
|
113
155
|
return value.toLowerCase().replace(/[^a-z0-9_.-]+/g, '-').replace(/^[-_.]+|[-_.]+$/g, '');
|
|
114
156
|
}
|
package/src/commands/start.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
2
|
import { findRootDir, findWpAppCli } from '../project.js';
|
|
3
3
|
|
|
4
|
-
export function startApp({ appDir, flags = [], dev = false }) {
|
|
4
|
+
export function startApp({ appDir, flags = [], dev = false, env = process.env }) {
|
|
5
5
|
const rootDir = findRootDir(appDir);
|
|
6
6
|
const wpAppCli = findWpAppCli(rootDir);
|
|
7
7
|
if (!wpAppCli) {
|
|
@@ -11,7 +11,7 @@ export function startApp({ appDir, flags = [], dev = false }) {
|
|
|
11
11
|
process.exit(1);
|
|
12
12
|
}
|
|
13
13
|
const args = [wpAppCli, dev ? 'dev' : 'start', `--path=${appDir}`, ...flags];
|
|
14
|
-
const child = spawn(process.execPath, args, { stdio: 'inherit' });
|
|
14
|
+
const child = spawn(process.execPath, args, { stdio: 'inherit', env });
|
|
15
15
|
child.on('exit', (code) => process.exit(code ?? 0));
|
|
16
16
|
return child;
|
|
17
17
|
}
|
package/src/main.js
CHANGED
|
@@ -6,7 +6,7 @@ import { parseArgs, UsageError } from './args.js';
|
|
|
6
6
|
import { startApp } from './commands/start.js';
|
|
7
7
|
import { buildAll } from './commands/build.js';
|
|
8
8
|
import { doctor } from './commands/doctor.js';
|
|
9
|
-
import {
|
|
9
|
+
import { PLATFORM_DIR, apps, composer, init, newApp, newPlugin, platformRoot, plugins, update } from './commands/platform.js';
|
|
10
10
|
import { sandbox } from './commands/sandbox.js';
|
|
11
11
|
import { tui } from './tui.js';
|
|
12
12
|
|
|
@@ -19,9 +19,10 @@ Usage:
|
|
|
19
19
|
wp-ops interactive menu
|
|
20
20
|
|
|
21
21
|
Platform repository:
|
|
22
|
-
wp-ops init [dir]
|
|
23
|
-
wp-ops
|
|
24
|
-
wp-ops
|
|
22
|
+
wp-ops init [dir] create a platform repository: the platform (wp-operations/), layout, workflows, git
|
|
23
|
+
wp-ops start [--port=] run the platform locally (admin / password)
|
|
24
|
+
wp-ops update update wp-operations/ to the platform shipped with this wp-ops
|
|
25
|
+
wp-ops apps list apps (<kind>/<slug>) and their deploy targets
|
|
25
26
|
wp-ops plugins list plugins and the apps that use them
|
|
26
27
|
wp-ops new app <kind> <slug> [--server= --app-path= --theme-slug=]
|
|
27
28
|
wp-ops new plugin <vendor/name> [--description=]
|
|
@@ -34,8 +35,8 @@ Platform repository:
|
|
|
34
35
|
open the local browser editor (wp-ide)
|
|
35
36
|
|
|
36
37
|
Single app:
|
|
37
|
-
wp-ops start
|
|
38
|
-
wp-ops dev [dir] start + watch
|
|
38
|
+
wp-ops start <dir> [--wp=… --php=… --port=…]
|
|
39
|
+
wp-ops dev [dir] start + watch (the platform when no dir is given)
|
|
39
40
|
wp-ops build build all packages/ with a build script
|
|
40
41
|
wp-ops doctor environment and repository checks`;
|
|
41
42
|
|
|
@@ -49,8 +50,18 @@ async function run() {
|
|
|
49
50
|
await tui(pkg.version);
|
|
50
51
|
return;
|
|
51
52
|
case 'start':
|
|
52
|
-
case 'dev':
|
|
53
|
-
|
|
53
|
+
case 'dev': {
|
|
54
|
+
const root = await platformRoot().catch(() => null);
|
|
55
|
+
let appDir = positional[0] ? path.resolve(positional[0]) : process.cwd();
|
|
56
|
+
if (!positional[0] && root && fs.existsSync(path.join(root, PLATFORM_DIR, 'style.css'))) {
|
|
57
|
+
appDir = path.join(root, PLATFORM_DIR);
|
|
58
|
+
}
|
|
59
|
+
const env = root ? { ...process.env, WP_APP_HOME: process.env.WP_APP_HOME || path.join(root, '.local') } : process.env;
|
|
60
|
+
startApp({ appDir, flags, dev: command === 'dev', env });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
case 'update':
|
|
64
|
+
await update({ root: await platformRoot() });
|
|
54
65
|
return;
|
|
55
66
|
case 'build':
|
|
56
67
|
buildAll();
|
|
@@ -61,12 +72,6 @@ async function run() {
|
|
|
61
72
|
case 'init':
|
|
62
73
|
await init({ dir: positional[0] ?? process.cwd(), platform: options.platform, version: pkg.version });
|
|
63
74
|
return;
|
|
64
|
-
case 'platform': {
|
|
65
|
-
const theme = bundledPlatform();
|
|
66
|
-
if (!theme) throw new UsageError('The platform theme is missing from this wp-ops install. Reinstall: npm install -g @wp-operations/wp-ops');
|
|
67
|
-
startApp({ appDir: theme, flags });
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
75
|
case 'apps':
|
|
71
76
|
await apps({ root: await platformRoot() });
|
|
72
77
|
return;
|