@wp-operations/wp-ide 0.2.0 → 0.3.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/LICENSE +339 -339
- package/README.md +35 -42
- package/cli.js +56 -0
- package/dist/index.js +680 -1
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,62 +1,55 @@
|
|
|
1
1
|
# @wp-operations/wp-ide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Platform repository tooling for [wp-operations](https://github.com/wordpress-operations/wordpress-operations): a library that knows the platform repository layout (the same contract the wp-operations theme reads), plus a local browser editor. Zero runtime dependencies.
|
|
4
4
|
|
|
5
|
-
## The
|
|
5
|
+
## The editor
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @wp-operations/wp-ide
|
|
9
|
+
cd my-platform
|
|
10
|
+
wp-ide serve --preview=http://localhost:8080
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
It opens on `http://127.0.0.1:4500/#token=…`. In the editor you get:
|
|
6
14
|
|
|
7
|
-
|
|
15
|
+
- a sidebar of apps grouped by kind, plus your plugins and the full repository;
|
|
16
|
+
- a file tree and editor (Ctrl/Cmd+S saves) with the git branch and a list of changes;
|
|
17
|
+
- a live preview of the selected app from a running `wp-ops sandbox` (`--preview`).
|
|
18
|
+
|
|
19
|
+
It listens on 127.0.0.1 only, checks the Host header, and every API call needs the token from the printed URL. It never reads or writes `.git/`, `vendor/`, `node_modules/` or `.local/`, refuses paths outside the repository (including through links), and limits files to 400 KB.
|
|
20
|
+
|
|
21
|
+
## The platform repository contract
|
|
8
22
|
|
|
9
23
|
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
platform.json the platform's own config (copied from the theme)
|
|
25
|
+
.github/platform.json { platform, packages, apps: { <kind>: { label, folder, manifest } } }
|
|
26
|
+
.github/<kind>.json { "<slug>": { "server", "app_path", "theme_slug" } }
|
|
27
|
+
.github/workflows/composer.yml
|
|
28
|
+
packages/<vendor>/<name>/ plugins: composer.json "type": "psr4-plugin"
|
|
29
|
+
<kind folder>/<slug>/ apps: composer.json "type": "wp-app"
|
|
14
30
|
```
|
|
15
31
|
|
|
32
|
+
In `.github/platform.json`, `folder` defaults to the kind's key and `manifest` defaults to `.github/<key>.json`. Names are normalized exactly as the theme does it.
|
|
33
|
+
|
|
16
34
|
## API
|
|
17
35
|
|
|
18
36
|
```js
|
|
19
37
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
38
|
+
readLayout, hasLayout, layoutJson, findKind, // .github/platform.json
|
|
39
|
+
readManifest, writeManifest, // .github/<kind>.json
|
|
40
|
+
listApps, listPlugins, // apps and plugins, with warnings
|
|
41
|
+
editComposer, encodeJson, relativePath, // byte-identical to the theme's composer.json edits
|
|
42
|
+
slug, folder, // the theme's name normalization
|
|
43
|
+
startEditor, safePath, // the editor server
|
|
44
|
+
resolveProject, useLocalData, appServerOptions, runBlueprint, // .local convention, wp-app helpers
|
|
25
45
|
} from '@wp-operations/wp-ide';
|
|
26
46
|
```
|
|
27
47
|
|
|
28
|
-
|
|
48
|
+
`editComposer(data, 'add' | 'remove', appPath, plugins, constraint)` does the same edit the theme commits. `add` requires the plugin and inserts a path repository `../../packages/<vendor>/*` (with `symlink: false`) after the existing path repositories. `remove` drops the requirement.
|
|
29
49
|
|
|
30
|
-
|
|
31
|
-
import { startServer } from '@wp-operations/wp-app';
|
|
32
|
-
import { appServerOptions, runBlueprint } from '@wp-operations/wp-ide';
|
|
33
|
-
|
|
34
|
-
const options = appServerOptions('./apps/my-theme', { wp: 'classicpress' });
|
|
35
|
-
const { php, url } = await startServer(options);
|
|
36
|
-
|
|
37
|
-
await runBlueprint(php, {
|
|
38
|
-
steps: [
|
|
39
|
-
{ step: 'defineWpConfigConsts', consts: { WP_DEBUG: true } },
|
|
40
|
-
{ step: 'login', username: 'admin', password: 'password' },
|
|
41
|
-
],
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
Supported blueprint steps: `defineWpConfigConsts`, `login`, `activatePlugin`, `activateTheme`, `runPHP`, `writeFile`. Unknown steps are reported as skipped, never fatal.
|
|
46
|
-
|
|
47
|
-
## wp-operations.json
|
|
48
|
-
|
|
49
|
-
Optional repo-root config consumed by `resolveProject` / `appServerOptions`:
|
|
50
|
+
## The `.local` convention
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
"php": "8.0",
|
|
54
|
-
"wp": "classicpress",
|
|
55
|
-
"apps": {
|
|
56
|
-
"my-theme": "apps/my-theme"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
```
|
|
52
|
+
All runtime data for a repository (core cache, per-app sites, SQLite databases) lives in one gitignored `.local/` folder at the repo root. `useLocalData(root)` points wp-app there through `WP_APP_HOME`.
|
|
60
53
|
|
|
61
54
|
## License
|
|
62
55
|
|
package/cli.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { startEditor } from './dist/index.js';
|
|
6
|
+
|
|
7
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const { version } = JSON.parse(fs.readFileSync(path.join(here, 'package.json'), 'utf8'));
|
|
9
|
+
|
|
10
|
+
const HELP = `wp-ide v${version}
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
wp-ide serve [dir] [--port=4500] [--preview=<sandbox url>]
|
|
14
|
+
|
|
15
|
+
Opens a local editor for the platform repository that contains [dir]
|
|
16
|
+
(default: the current folder). It only listens on 127.0.0.1 and every
|
|
17
|
+
request needs the token from the printed URL.
|
|
18
|
+
|
|
19
|
+
--preview Base URL of a running sandbox (wp-ops sandbox), e.g.
|
|
20
|
+
http://localhost:8080. Apps preview at /{kind}/{slug}/.`;
|
|
21
|
+
|
|
22
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
23
|
+
const flags = Object.fromEntries(
|
|
24
|
+
rest
|
|
25
|
+
.filter((arg) => arg.startsWith('--'))
|
|
26
|
+
.map((arg) => {
|
|
27
|
+
const [key, ...value] = arg.slice(2).split('=');
|
|
28
|
+
return [key, value.join('=')];
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
const positional = rest.filter((arg) => !arg.startsWith('--'));
|
|
32
|
+
|
|
33
|
+
if (command === '--version' || command === '-v') {
|
|
34
|
+
console.log(version);
|
|
35
|
+
} else if (command === 'serve') {
|
|
36
|
+
const port = flags.port ? Number(flags.port) : 4500;
|
|
37
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
38
|
+
console.error(`wp-ide: invalid --port "${flags.port}"`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const editor = await startEditor({
|
|
43
|
+
root: path.resolve(positional[0] ?? process.cwd()),
|
|
44
|
+
port,
|
|
45
|
+
preview: flags.preview ?? '',
|
|
46
|
+
});
|
|
47
|
+
console.log(`wp-ide editing ${editor.root}`);
|
|
48
|
+
console.log(`Open: ${editor.url}`);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(`wp-ide: ${error.code === 'EADDRINUSE' ? `port ${port} is in use, pass --port=<n>` : error.message}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
console.log(HELP);
|
|
55
|
+
process.exit(command === undefined || command === 'help' || command === '--help' || command === '-h' ? 0 : 1);
|
|
56
|
+
}
|