@wp-operations/wp-ide 0.2.0 → 0.3.1
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 +11 -51
- package/cli.js +56 -0
- package/dist/index.js +680 -1
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,62 +1,22 @@
|
|
|
1
1
|
# @wp-operations/wp-ide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A simple WordPress-first editor in your browser, with a live preview. It comes with [wp-ops](../wp-ops):
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
<repo>/.local/
|
|
11
|
-
└── wp-content/
|
|
12
|
-
├── my-theme/ wp-content + SQLite db for the my-theme app
|
|
13
|
-
└── my-plugin/
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## API
|
|
17
|
-
|
|
18
|
-
```js
|
|
19
|
-
import {
|
|
20
|
-
resolveProject, // walk up to repo root, read wp-operations.json
|
|
21
|
-
localPath, // localPath(root, 'wp-content', 'my-app')
|
|
22
|
-
ensureLocalDir, // same, but creates it
|
|
23
|
-
appServerOptions, // build wp-app startServer options with .local wpContentPath
|
|
24
|
-
runBlueprint, // run blueprint steps against a running wp-app php instance
|
|
25
|
-
} from '@wp-operations/wp-ide';
|
|
5
|
+
```bash
|
|
6
|
+
npm install -g @wp-operations/wp-ops
|
|
7
|
+
cd my-platform
|
|
8
|
+
wp-ide serve --preview=http://localhost:8080
|
|
26
9
|
```
|
|
27
10
|
|
|
28
|
-
|
|
11
|
+
It opens on `http://127.0.0.1:4500/#token=…` with:
|
|
29
12
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
- your apps, plugins and the whole repository in the sidebar;
|
|
14
|
+
- a file tree and editor (Ctrl/Cmd+S saves), the git branch and the list of changes;
|
|
15
|
+
- a live preview of the selected app from `wp-ops sandbox` (`--preview`).
|
|
33
16
|
|
|
34
|
-
|
|
35
|
-
const { php, url } = await startServer(options);
|
|
17
|
+
It listens on 127.0.0.1 only, and every request needs the token from the printed URL. It never touches `.git/`, `vendor/`, `node_modules/` or `.local/`, stays inside the repository, and limits files to 400 KB.
|
|
36
18
|
|
|
37
|
-
|
|
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
|
-
|
|
51
|
-
```json
|
|
52
|
-
{
|
|
53
|
-
"php": "8.0",
|
|
54
|
-
"wp": "classicpress",
|
|
55
|
-
"apps": {
|
|
56
|
-
"my-theme": "apps/my-theme"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
```
|
|
19
|
+
wp-ops and wp-code also use it as a library: it reads the platform repository (`.github/platform.json`, the app manifests, apps and plugins) and makes the same composer.json edits the platform makes.
|
|
60
20
|
|
|
61
21
|
## License
|
|
62
22
|
|
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
|
+
}
|