@loopress/cli 0.7.0 → 0.8.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 +45 -45
- package/dist/commands/composer/pull.js +4 -14
- package/dist/commands/composer/push.js +7 -16
- package/dist/commands/login.js +1 -1
- package/dist/commands/logout.js +1 -1
- package/dist/commands/plugin/add.js +9 -9
- package/dist/commands/plugin/pull.js +7 -18
- package/dist/commands/plugin/push.d.ts +1 -0
- package/dist/commands/plugin/push.js +20 -45
- package/dist/commands/snippet/list.d.ts +1 -1
- package/dist/commands/snippet/list.js +23 -38
- package/dist/commands/snippet/pull.d.ts +1 -1
- package/dist/commands/snippet/pull.js +41 -50
- package/dist/commands/snippet/push.d.ts +1 -1
- package/dist/commands/snippet/push.js +82 -70
- package/dist/config/auth.manager.d.ts +0 -2
- package/dist/config/auth.manager.js +5 -25
- package/dist/config/json-file.d.ts +2 -0
- package/dist/config/json-file.js +21 -0
- package/dist/config/project-config.manager.d.ts +1 -3
- package/dist/config/project-config.manager.js +7 -23
- package/dist/lib/base.d.ts +14 -4
- package/dist/lib/base.js +63 -33
- package/dist/lib/push-command.d.ts +0 -1
- package/dist/lib/push-command.js +0 -1
- package/dist/lib/wp-client.d.ts +15 -0
- package/dist/lib/wp-client.js +53 -0
- package/dist/types/snippet.d.ts +7 -1
- package/dist/utils/loopress-config.js +5 -2
- package/dist/utils/snippet-plugin-flag.d.ts +3 -0
- package/dist/utils/snippet-plugin-flag.js +8 -0
- package/dist/utils/snippet-plugin.d.ts +23 -2
- package/dist/utils/snippet-plugin.js +168 -13
- package/oclif.manifest.json +165 -125
- package/package.json +5 -3
- package/dist/types/menu.d.ts +0 -7
- package/dist/types/menu.js +0 -1
- /package/dist/{config/types.d.ts → types/config.d.ts} +0 -0
- /package/dist/{config/types.js → types/config.js} +0 -0
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ $ npm install -g @loopress/cli
|
|
|
20
20
|
$ lps COMMAND
|
|
21
21
|
running command...
|
|
22
22
|
$ lps (--version)
|
|
23
|
-
@loopress/cli/0.
|
|
23
|
+
@loopress/cli/0.8.0 linux-x64 node-v24.18.0
|
|
24
24
|
$ lps --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ lps COMMAND
|
|
@@ -58,12 +58,12 @@ USAGE
|
|
|
58
58
|
$ lps composer pull [--password <value>] [--url <value>] [--user <value>] [-d]
|
|
59
59
|
|
|
60
60
|
FLAGS
|
|
61
|
-
-d, --dry-run Show what would
|
|
61
|
+
-d, --dry-run Show what would change without making changes
|
|
62
62
|
|
|
63
63
|
GLOBAL FLAGS
|
|
64
|
-
--password=<value> WordPress application password (
|
|
65
|
-
--url=<value> WordPress URL (
|
|
66
|
-
--user=<value> WordPress username (
|
|
64
|
+
--password=<value> WordPress application password (overrides project config, requires --user)
|
|
65
|
+
--url=<value> WordPress URL (overrides project config)
|
|
66
|
+
--user=<value> WordPress username (overrides project config, requires --password)
|
|
67
67
|
|
|
68
68
|
DESCRIPTION
|
|
69
69
|
Pull composer.lock from WordPress
|
|
@@ -74,7 +74,7 @@ EXAMPLES
|
|
|
74
74
|
$ lps composer pull --dry-run
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
_See code: [src/commands/composer/pull.ts](https://github.com/loopress/loopress/blob/v0.
|
|
77
|
+
_See code: [src/commands/composer/pull.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/composer/pull.ts)_
|
|
78
78
|
|
|
79
79
|
## `lps composer push`
|
|
80
80
|
|
|
@@ -88,9 +88,9 @@ FLAGS
|
|
|
88
88
|
-d, --dry-run Show what would change without making changes
|
|
89
89
|
|
|
90
90
|
GLOBAL FLAGS
|
|
91
|
-
--password=<value> WordPress application password (
|
|
92
|
-
--url=<value> WordPress URL (
|
|
93
|
-
--user=<value> WordPress username (
|
|
91
|
+
--password=<value> WordPress application password (overrides project config, requires --user)
|
|
92
|
+
--url=<value> WordPress URL (overrides project config)
|
|
93
|
+
--user=<value> WordPress username (overrides project config, requires --password)
|
|
94
94
|
|
|
95
95
|
DESCRIPTION
|
|
96
96
|
Push composer.json and composer.lock to WordPress and run composer install
|
|
@@ -101,7 +101,7 @@ EXAMPLES
|
|
|
101
101
|
$ lps composer push --dry-run
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
_See code: [src/commands/composer/push.ts](https://github.com/loopress/loopress/blob/v0.
|
|
104
|
+
_See code: [src/commands/composer/push.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/composer/push.ts)_
|
|
105
105
|
|
|
106
106
|
## `lps help [COMMAND]`
|
|
107
107
|
|
|
@@ -138,7 +138,7 @@ EXAMPLES
|
|
|
138
138
|
$ lps init
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
_See code: [src/commands/init.ts](https://github.com/loopress/loopress/blob/v0.
|
|
141
|
+
_See code: [src/commands/init.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/init.ts)_
|
|
142
142
|
|
|
143
143
|
## `lps login`
|
|
144
144
|
|
|
@@ -155,7 +155,7 @@ EXAMPLES
|
|
|
155
155
|
$ lps login
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
_See code: [src/commands/login.ts](https://github.com/loopress/loopress/blob/v0.
|
|
158
|
+
_See code: [src/commands/login.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/login.ts)_
|
|
159
159
|
|
|
160
160
|
## `lps logout`
|
|
161
161
|
|
|
@@ -172,7 +172,7 @@ EXAMPLES
|
|
|
172
172
|
$ lps logout
|
|
173
173
|
```
|
|
174
174
|
|
|
175
|
-
_See code: [src/commands/logout.ts](https://github.com/loopress/loopress/blob/v0.
|
|
175
|
+
_See code: [src/commands/logout.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/logout.ts)_
|
|
176
176
|
|
|
177
177
|
## `lps plugin add SLUG [VERSION]`
|
|
178
178
|
|
|
@@ -187,12 +187,12 @@ ARGUMENTS
|
|
|
187
187
|
[VERSION] Version to pin (default: latest)
|
|
188
188
|
|
|
189
189
|
FLAGS
|
|
190
|
-
-d, --dry-run Show what would
|
|
190
|
+
-d, --dry-run Show what would change without making changes
|
|
191
191
|
|
|
192
192
|
GLOBAL FLAGS
|
|
193
|
-
--password=<value> WordPress application password (
|
|
194
|
-
--url=<value> WordPress URL (
|
|
195
|
-
--user=<value> WordPress username (
|
|
193
|
+
--password=<value> WordPress application password (overrides project config, requires --user)
|
|
194
|
+
--url=<value> WordPress URL (overrides project config)
|
|
195
|
+
--user=<value> WordPress username (overrides project config, requires --password)
|
|
196
196
|
|
|
197
197
|
DESCRIPTION
|
|
198
198
|
Add a WordPress.org plugin to loopress.json
|
|
@@ -205,7 +205,7 @@ EXAMPLES
|
|
|
205
205
|
$ lps plugin add contact-form-7 --dry-run
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
-
_See code: [src/commands/plugin/add.ts](https://github.com/loopress/loopress/blob/v0.
|
|
208
|
+
_See code: [src/commands/plugin/add.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/plugin/add.ts)_
|
|
209
209
|
|
|
210
210
|
## `lps plugin pull`
|
|
211
211
|
|
|
@@ -216,12 +216,12 @@ USAGE
|
|
|
216
216
|
$ lps plugin pull [--password <value>] [--url <value>] [--user <value>] [-d]
|
|
217
217
|
|
|
218
218
|
FLAGS
|
|
219
|
-
-d, --dry-run Show what would
|
|
219
|
+
-d, --dry-run Show what would change without making changes
|
|
220
220
|
|
|
221
221
|
GLOBAL FLAGS
|
|
222
|
-
--password=<value> WordPress application password (
|
|
223
|
-
--url=<value> WordPress URL (
|
|
224
|
-
--user=<value> WordPress username (
|
|
222
|
+
--password=<value> WordPress application password (overrides project config, requires --user)
|
|
223
|
+
--url=<value> WordPress URL (overrides project config)
|
|
224
|
+
--user=<value> WordPress username (overrides project config, requires --password)
|
|
225
225
|
|
|
226
226
|
DESCRIPTION
|
|
227
227
|
Pull installed plugins from WordPress into loopress.json
|
|
@@ -232,7 +232,7 @@ EXAMPLES
|
|
|
232
232
|
$ lps plugin pull --dry-run
|
|
233
233
|
```
|
|
234
234
|
|
|
235
|
-
_See code: [src/commands/plugin/pull.ts](https://github.com/loopress/loopress/blob/v0.
|
|
235
|
+
_See code: [src/commands/plugin/pull.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/plugin/pull.ts)_
|
|
236
236
|
|
|
237
237
|
## `lps plugin push`
|
|
238
238
|
|
|
@@ -246,9 +246,9 @@ FLAGS
|
|
|
246
246
|
-d, --dry-run Show what would change without making changes
|
|
247
247
|
|
|
248
248
|
GLOBAL FLAGS
|
|
249
|
-
--password=<value> WordPress application password (
|
|
250
|
-
--url=<value> WordPress URL (
|
|
251
|
-
--user=<value> WordPress username (
|
|
249
|
+
--password=<value> WordPress application password (overrides project config, requires --user)
|
|
250
|
+
--url=<value> WordPress URL (overrides project config)
|
|
251
|
+
--user=<value> WordPress username (overrides project config, requires --password)
|
|
252
252
|
|
|
253
253
|
DESCRIPTION
|
|
254
254
|
Push plugins to WordPress to match loopress.json
|
|
@@ -259,7 +259,7 @@ EXAMPLES
|
|
|
259
259
|
$ lps plugin push --dry-run
|
|
260
260
|
```
|
|
261
261
|
|
|
262
|
-
_See code: [src/commands/plugin/push.ts](https://github.com/loopress/loopress/blob/v0.
|
|
262
|
+
_See code: [src/commands/plugin/push.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/plugin/push.ts)_
|
|
263
263
|
|
|
264
264
|
## `lps project config`
|
|
265
265
|
|
|
@@ -276,7 +276,7 @@ EXAMPLES
|
|
|
276
276
|
$ lps project config
|
|
277
277
|
```
|
|
278
278
|
|
|
279
|
-
_See code: [src/commands/project/config.ts](https://github.com/loopress/loopress/blob/v0.
|
|
279
|
+
_See code: [src/commands/project/config.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/project/config.ts)_
|
|
280
280
|
|
|
281
281
|
## `lps project list`
|
|
282
282
|
|
|
@@ -293,7 +293,7 @@ EXAMPLES
|
|
|
293
293
|
$ lps project list
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
-
_See code: [src/commands/project/list.ts](https://github.com/loopress/loopress/blob/v0.
|
|
296
|
+
_See code: [src/commands/project/list.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/project/list.ts)_
|
|
297
297
|
|
|
298
298
|
## `lps project remove`
|
|
299
299
|
|
|
@@ -310,7 +310,7 @@ EXAMPLES
|
|
|
310
310
|
$ lps project remove
|
|
311
311
|
```
|
|
312
312
|
|
|
313
|
-
_See code: [src/commands/project/remove.ts](https://github.com/loopress/loopress/blob/v0.
|
|
313
|
+
_See code: [src/commands/project/remove.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/project/remove.ts)_
|
|
314
314
|
|
|
315
315
|
## `lps project switch`
|
|
316
316
|
|
|
@@ -327,7 +327,7 @@ EXAMPLES
|
|
|
327
327
|
$ lps project switch
|
|
328
328
|
```
|
|
329
329
|
|
|
330
|
-
_See code: [src/commands/project/switch.ts](https://github.com/loopress/loopress/blob/v0.
|
|
330
|
+
_See code: [src/commands/project/switch.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/project/switch.ts)_
|
|
331
331
|
|
|
332
332
|
## `lps snippet list`
|
|
333
333
|
|
|
@@ -343,9 +343,9 @@ FLAGS
|
|
|
343
343
|
<options: code-snippets|wpcode>
|
|
344
344
|
|
|
345
345
|
GLOBAL FLAGS
|
|
346
|
-
--password=<value> WordPress application password (
|
|
347
|
-
--url=<value> WordPress URL (
|
|
348
|
-
--user=<value> WordPress username (
|
|
346
|
+
--password=<value> WordPress application password (overrides project config, requires --user)
|
|
347
|
+
--url=<value> WordPress URL (overrides project config)
|
|
348
|
+
--user=<value> WordPress username (overrides project config, requires --password)
|
|
349
349
|
|
|
350
350
|
DESCRIPTION
|
|
351
351
|
List snippets from WordPress
|
|
@@ -358,7 +358,7 @@ EXAMPLES
|
|
|
358
358
|
$ lps snippet list --plugin wpcode
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
-
_See code: [src/commands/snippet/list.ts](https://github.com/loopress/loopress/blob/v0.
|
|
361
|
+
_See code: [src/commands/snippet/list.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/snippet/list.ts)_
|
|
362
362
|
|
|
363
363
|
## `lps snippet pull [PATH]`
|
|
364
364
|
|
|
@@ -372,14 +372,14 @@ ARGUMENTS
|
|
|
372
372
|
[PATH] Path to snippets directory (overrides project config)
|
|
373
373
|
|
|
374
374
|
FLAGS
|
|
375
|
-
-d, --dry-run Show what would
|
|
375
|
+
-d, --dry-run Show what would change without making changes
|
|
376
376
|
-p, --plugin=<option> WordPress snippet plugin to target (overrides loopress.json)
|
|
377
377
|
<options: code-snippets|wpcode>
|
|
378
378
|
|
|
379
379
|
GLOBAL FLAGS
|
|
380
|
-
--password=<value> WordPress application password (
|
|
381
|
-
--url=<value> WordPress URL (
|
|
382
|
-
--user=<value> WordPress username (
|
|
380
|
+
--password=<value> WordPress application password (overrides project config, requires --user)
|
|
381
|
+
--url=<value> WordPress URL (overrides project config)
|
|
382
|
+
--user=<value> WordPress username (overrides project config, requires --password)
|
|
383
383
|
|
|
384
384
|
DESCRIPTION
|
|
385
385
|
Pull snippets from WordPress
|
|
@@ -394,7 +394,7 @@ EXAMPLES
|
|
|
394
394
|
$ lps snippet pull --plugin wpcode
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
-
_See code: [src/commands/snippet/pull.ts](https://github.com/loopress/loopress/blob/v0.
|
|
397
|
+
_See code: [src/commands/snippet/pull.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/snippet/pull.ts)_
|
|
398
398
|
|
|
399
399
|
## `lps snippet push [PATH]`
|
|
400
400
|
|
|
@@ -413,9 +413,9 @@ FLAGS
|
|
|
413
413
|
<options: code-snippets|wpcode>
|
|
414
414
|
|
|
415
415
|
GLOBAL FLAGS
|
|
416
|
-
--password=<value> WordPress application password (
|
|
417
|
-
--url=<value> WordPress URL (
|
|
418
|
-
--user=<value> WordPress username (
|
|
416
|
+
--password=<value> WordPress application password (overrides project config, requires --user)
|
|
417
|
+
--url=<value> WordPress URL (overrides project config)
|
|
418
|
+
--user=<value> WordPress username (overrides project config, requires --password)
|
|
419
419
|
|
|
420
420
|
DESCRIPTION
|
|
421
421
|
Push snippets to WordPress. Local snippet files created or updated remotely are renamed on disk to the `<id>-<slug>`
|
|
@@ -431,7 +431,7 @@ EXAMPLES
|
|
|
431
431
|
$ lps snippet push --plugin wpcode
|
|
432
432
|
```
|
|
433
433
|
|
|
434
|
-
_See code: [src/commands/snippet/push.ts](https://github.com/loopress/loopress/blob/v0.
|
|
434
|
+
_See code: [src/commands/snippet/push.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/snippet/push.ts)_
|
|
435
435
|
|
|
436
436
|
## `lps status`
|
|
437
437
|
|
|
@@ -448,5 +448,5 @@ EXAMPLES
|
|
|
448
448
|
$ lps status
|
|
449
449
|
```
|
|
450
450
|
|
|
451
|
-
_See code: [src/commands/status.ts](https://github.com/loopress/loopress/blob/v0.
|
|
451
|
+
_See code: [src/commands/status.ts](https://github.com/loopress/loopress/blob/v0.8.0/src/commands/status.ts)_
|
|
452
452
|
<!-- commandsstop -->
|
|
@@ -1,32 +1,22 @@
|
|
|
1
|
-
import { Flags } from '@oclif/core';
|
|
2
|
-
import got from 'got';
|
|
3
1
|
import { writeFile } from 'node:fs/promises';
|
|
4
2
|
import { join } from 'node:path';
|
|
5
3
|
import { LoopressCommand } from '../../lib/base.js';
|
|
6
|
-
import { readLocalConfig } from '../../utils/loopress-config.js';
|
|
7
4
|
export default class ComposerPull extends LoopressCommand {
|
|
8
5
|
static description = 'Pull composer.lock from WordPress';
|
|
9
6
|
static examples = ['$ lps composer pull', '$ lps composer pull --dry-run'];
|
|
10
7
|
static flags = {
|
|
11
8
|
...LoopressCommand.baseFlags,
|
|
12
|
-
|
|
9
|
+
...LoopressCommand.dryRunFlag,
|
|
13
10
|
};
|
|
14
11
|
async run() {
|
|
15
|
-
const { flags } = await this.parse(ComposerPull);
|
|
16
|
-
const dryRun = flags['dry-run'];
|
|
17
12
|
const { url } = this.siteConfig;
|
|
18
13
|
this.log(`Pulling composer.lock from ${url}`);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
.get(`${url}/wp-json/loopress/v1/composer/lock`, { headers })
|
|
22
|
-
.json();
|
|
23
|
-
if (dryRun) {
|
|
14
|
+
const { composerLock } = await this.wp.get('loopress/v1/composer/lock');
|
|
15
|
+
if (this.dryRun) {
|
|
24
16
|
this.log('[dry-run] Would write composer.lock');
|
|
25
17
|
return;
|
|
26
18
|
}
|
|
27
|
-
const
|
|
28
|
-
const rootDir = localConfig.rootDir ?? '.';
|
|
29
|
-
const lockPath = join(process.cwd(), rootDir, 'composer.lock');
|
|
19
|
+
const lockPath = join(process.cwd(), this.rootDir, 'composer.lock');
|
|
30
20
|
await writeFile(lockPath, composerLock, 'utf8');
|
|
31
21
|
this.log(`Wrote composer.lock`);
|
|
32
22
|
}
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
import { Flags } from '@oclif/core';
|
|
2
|
-
import got from 'got';
|
|
3
1
|
import { existsSync } from 'node:fs';
|
|
4
2
|
import { readFile } from 'node:fs/promises';
|
|
5
3
|
import { join } from 'node:path';
|
|
6
4
|
import { PushCommand } from '../../lib/push-command.js';
|
|
7
|
-
import { readLocalConfig } from '../../utils/loopress-config.js';
|
|
8
5
|
export default class ComposerPush extends PushCommand {
|
|
9
6
|
static description = 'Push composer.json and composer.lock to WordPress and run composer install';
|
|
10
7
|
static examples = ['$ lps composer push', '$ lps composer push --dry-run'];
|
|
11
8
|
static flags = {
|
|
12
9
|
...PushCommand.baseFlags,
|
|
13
|
-
|
|
10
|
+
...PushCommand.dryRunFlag,
|
|
14
11
|
};
|
|
15
12
|
async run() {
|
|
16
|
-
const { flags } = await this.parse(ComposerPush);
|
|
17
|
-
const dryRun = flags['dry-run'];
|
|
18
|
-
this.dryRun = dryRun;
|
|
19
13
|
const { url } = this.siteConfig;
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const composerJsonPath = join(process.cwd(), rootDir, 'composer.json');
|
|
23
|
-
const composerLockPath = join(process.cwd(), rootDir, 'composer.lock');
|
|
14
|
+
const composerJsonPath = join(process.cwd(), this.rootDir, 'composer.json');
|
|
15
|
+
const composerLockPath = join(process.cwd(), this.rootDir, 'composer.lock');
|
|
24
16
|
if (!existsSync(composerJsonPath)) {
|
|
25
17
|
this.error(`No composer.json found at ${composerJsonPath}`);
|
|
26
18
|
}
|
|
@@ -36,12 +28,11 @@ export default class ComposerPush extends PushCommand {
|
|
|
36
28
|
else {
|
|
37
29
|
this.warn('No composer.lock found. The server will resolve versions freely.');
|
|
38
30
|
}
|
|
39
|
-
if (dryRun)
|
|
31
|
+
if (this.dryRun)
|
|
40
32
|
return;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
json: { composerJson: composerJsonRaw, composerLock: composerLockRaw },
|
|
33
|
+
await this.wp.post('loopress/v1/composer/sync', {
|
|
34
|
+
composerJson: composerJsonRaw,
|
|
35
|
+
composerLock: composerLockRaw,
|
|
45
36
|
});
|
|
46
37
|
this.log('composer install completed on the server.');
|
|
47
38
|
await this.recordSuccess();
|
package/dist/commands/login.js
CHANGED
|
@@ -10,7 +10,7 @@ export default class Login extends Command {
|
|
|
10
10
|
async run() {
|
|
11
11
|
const { email, token } = await this.waitForCallback();
|
|
12
12
|
authManager.setAuth({ email, savedAt: new Date().toISOString(), token });
|
|
13
|
-
this.log(`\
|
|
13
|
+
this.log(`\nLogged in${email ? ` as ${email}` : ''}. You're all set!`);
|
|
14
14
|
}
|
|
15
15
|
openBrowser(url) {
|
|
16
16
|
const cmds = {
|
package/dist/commands/logout.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Args
|
|
1
|
+
import { Args } from '@oclif/core';
|
|
2
2
|
import got from 'got';
|
|
3
3
|
import { LoopressCommand } from '../../lib/base.js';
|
|
4
|
-
import {
|
|
4
|
+
import { writeLocalConfig } from '../../utils/loopress-config.js';
|
|
5
5
|
const WP_ORG_API = 'https://api.wordpress.org/plugins/info/1.2/';
|
|
6
|
+
const WP_ORG_TIMEOUT_MS = 10_000;
|
|
6
7
|
export async function resolvePluginVersion(slug, version) {
|
|
7
8
|
if (version !== 'latest')
|
|
8
9
|
return version;
|
|
@@ -14,6 +15,7 @@ export async function resolvePluginVersion(slug, version) {
|
|
|
14
15
|
action: 'plugin_information',
|
|
15
16
|
'request[slug]': slug,
|
|
16
17
|
},
|
|
18
|
+
timeout: { request: WP_ORG_TIMEOUT_MS },
|
|
17
19
|
})
|
|
18
20
|
.json();
|
|
19
21
|
}
|
|
@@ -37,11 +39,10 @@ export default class Add extends LoopressCommand {
|
|
|
37
39
|
];
|
|
38
40
|
static flags = {
|
|
39
41
|
...LoopressCommand.baseFlags,
|
|
40
|
-
|
|
42
|
+
...LoopressCommand.dryRunFlag,
|
|
41
43
|
};
|
|
42
44
|
async run() {
|
|
43
|
-
const { args
|
|
44
|
-
const dryRun = flags['dry-run'];
|
|
45
|
+
const { args } = await this.parse(Add);
|
|
45
46
|
const { slug } = args;
|
|
46
47
|
const requestedVersion = args.version ?? 'latest';
|
|
47
48
|
this.log(`Resolving ${slug}@${requestedVersion}...`);
|
|
@@ -53,20 +54,19 @@ export default class Add extends LoopressCommand {
|
|
|
53
54
|
this.error(error.message);
|
|
54
55
|
}
|
|
55
56
|
this.log(`Resolved: ${slug}@${resolvedVersion}`);
|
|
56
|
-
const
|
|
57
|
-
const existing = localConfig.plugins ?? {};
|
|
57
|
+
const existing = this.localConfig.plugins ?? {};
|
|
58
58
|
if (existing[slug] === resolvedVersion) {
|
|
59
59
|
this.log(`${slug}@${resolvedVersion} is already in loopress.json, nothing to do.`);
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
const updated = existing[slug] !== undefined;
|
|
63
63
|
const label = updated ? `${existing[slug]} → ${resolvedVersion}` : resolvedVersion;
|
|
64
|
-
if (dryRun) {
|
|
64
|
+
if (this.dryRun) {
|
|
65
65
|
this.log(`[dry-run] Would ${updated ? 'update' : 'add'} ${slug}: ${label}`);
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
await writeLocalConfig({
|
|
69
|
-
...localConfig,
|
|
69
|
+
...this.localConfig,
|
|
70
70
|
plugins: { ...existing, [slug]: resolvedVersion },
|
|
71
71
|
});
|
|
72
72
|
this.log(`${updated ? 'Updated' : 'Added'} ${slug}: ${label}`);
|
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
import { Flags } from '@oclif/core';
|
|
2
|
-
import got from 'got';
|
|
3
1
|
import { LoopressCommand } from '../../lib/base.js';
|
|
4
2
|
import { getComposerManagedSlugs, readComposerJson } from '../../utils/composer.js';
|
|
5
|
-
import {
|
|
3
|
+
import { writeLocalConfig } from '../../utils/loopress-config.js';
|
|
6
4
|
import { mergePluginManifest } from '../../utils/plugins.js';
|
|
7
5
|
export default class Pull extends LoopressCommand {
|
|
8
6
|
static description = 'Pull installed plugins from WordPress into loopress.json';
|
|
9
7
|
static examples = ['$ lps plugin pull', '$ lps plugin pull --dry-run'];
|
|
10
8
|
static flags = {
|
|
11
9
|
...LoopressCommand.baseFlags,
|
|
12
|
-
|
|
10
|
+
...LoopressCommand.dryRunFlag,
|
|
13
11
|
};
|
|
14
12
|
async run() {
|
|
15
|
-
const { flags } = await this.parse(Pull);
|
|
16
|
-
const dryRun = flags['dry-run'];
|
|
17
13
|
const { url } = this.siteConfig;
|
|
18
14
|
this.log(`Pulling plugins from ${url}`);
|
|
19
|
-
const
|
|
20
|
-
const installed = await got.get(`${url}/wp-json/loopress/v1/plugins`, { headers }).json();
|
|
15
|
+
const installed = await this.wp.get('loopress/v1/plugins');
|
|
21
16
|
const composerJson = await readComposerJson();
|
|
22
17
|
const composerSlugs = composerJson ? getComposerManagedSlugs(composerJson) : [];
|
|
23
18
|
const incoming = Object.fromEntries(installed.filter((p) => !composerSlugs.includes(p.slug)).map((p) => [p.slug, p.version]));
|
|
@@ -27,9 +22,8 @@ export default class Pull extends LoopressCommand {
|
|
|
27
22
|
this.log(`Skipping ${found.length} Composer-managed ${found.length === 1 ? 'plugin' : 'plugins'}: ${found.join(', ')}`);
|
|
28
23
|
}
|
|
29
24
|
}
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
if (dryRun) {
|
|
25
|
+
const { added, merged, updated } = mergePluginManifest(this.localConfig.plugins ?? {}, incoming);
|
|
26
|
+
if (this.dryRun) {
|
|
33
27
|
this.log(`[dry-run] Would write ${Object.keys(merged).length} plugins to loopress.json`);
|
|
34
28
|
if (added.length > 0)
|
|
35
29
|
this.log(` + ${added.join(', ')}`);
|
|
@@ -39,19 +33,14 @@ export default class Pull extends LoopressCommand {
|
|
|
39
33
|
}
|
|
40
34
|
return;
|
|
41
35
|
}
|
|
42
|
-
await writeLocalConfig({ ...localConfig, plugins: merged });
|
|
36
|
+
await writeLocalConfig({ ...this.localConfig, plugins: merged });
|
|
43
37
|
this.log(`Wrote ${Object.keys(merged).length} plugins to loopress.json`);
|
|
44
38
|
if (added.length > 0)
|
|
45
39
|
this.log(` + Added: ${added.join(', ')}`);
|
|
46
40
|
for (const u of updated)
|
|
47
41
|
this.log(` ~ Updated: ${u.slug} ${u.from} → ${u.to}`);
|
|
48
42
|
if (Object.keys(merged).length > 0) {
|
|
49
|
-
await
|
|
50
|
-
.post(`${url}/wp-json/loopress/v1/plugins/auto-updates/disable`, {
|
|
51
|
-
headers,
|
|
52
|
-
json: { slugs: Object.keys(merged) },
|
|
53
|
-
})
|
|
54
|
-
.json();
|
|
43
|
+
await this.wp.post('loopress/v1/plugins/auto-updates/disable', { slugs: Object.keys(merged) });
|
|
55
44
|
}
|
|
56
45
|
}
|
|
57
46
|
}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import { confirm } from '@inquirer/prompts';
|
|
2
|
-
import { Flags } from '@oclif/core';
|
|
3
|
-
import got from 'got';
|
|
4
2
|
import { PushCommand } from '../../lib/push-command.js';
|
|
5
3
|
import { getComposerManagedSlugs, readComposerJson } from '../../utils/composer.js';
|
|
6
|
-
import { readLocalConfig } from '../../utils/loopress-config.js';
|
|
7
4
|
import { diffPlugins } from '../../utils/plugins.js';
|
|
8
5
|
export default class Push extends PushCommand {
|
|
9
6
|
static description = 'Push plugins to WordPress to match loopress.json';
|
|
10
7
|
static examples = ['$ lps plugin push', '$ lps plugin push --dry-run'];
|
|
11
8
|
static flags = {
|
|
12
9
|
...PushCommand.baseFlags,
|
|
13
|
-
|
|
10
|
+
...PushCommand.dryRunFlag,
|
|
14
11
|
};
|
|
15
12
|
async run() {
|
|
16
|
-
const { flags } = await this.parse(Push);
|
|
17
|
-
const dryRun = flags['dry-run'];
|
|
18
|
-
this.dryRun = dryRun;
|
|
19
13
|
const { url } = this.siteConfig;
|
|
20
|
-
const
|
|
21
|
-
const manifest = localConfig.plugins;
|
|
14
|
+
const manifest = this.localConfig.plugins;
|
|
22
15
|
if (!manifest || Object.keys(manifest).length === 0) {
|
|
23
16
|
this.error('No plugins found in loopress.json. Run `lps plugin pull` first.');
|
|
24
17
|
}
|
|
@@ -31,8 +24,7 @@ export default class Push extends PushCommand {
|
|
|
31
24
|
this.log('Run `lps composer push` to deploy them.');
|
|
32
25
|
}
|
|
33
26
|
this.log(`Pushing plugins to ${url}`);
|
|
34
|
-
const
|
|
35
|
-
const installed = await got.get(`${url}/wp-json/loopress/v1/plugins`, { headers }).json();
|
|
27
|
+
const installed = await this.wp.get('loopress/v1/plugins');
|
|
36
28
|
const { drifted, toActivate, toInstall } = diffPlugins(filteredManifest, installed);
|
|
37
29
|
if (toInstall.length === 0 && toActivate.length === 0 && drifted.length === 0) {
|
|
38
30
|
this.log('Everything is already in sync.');
|
|
@@ -54,30 +46,17 @@ export default class Push extends PushCommand {
|
|
|
54
46
|
this.log(` ~ ${a.slug}: site has ${a.currentVersion}, manifest wants ${a.targetVersion}`);
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
|
-
if (dryRun)
|
|
49
|
+
if (this.dryRun)
|
|
58
50
|
return;
|
|
59
51
|
// Install missing plugins and activate them.
|
|
60
52
|
for (const action of toInstall) {
|
|
61
53
|
this.log(`\nInstalling ${action.slug} @ ${action.targetVersion}...`);
|
|
62
|
-
|
|
63
|
-
const result = await got
|
|
64
|
-
.post(`${url}/wp-json/loopress/v1/plugins/install`, {
|
|
65
|
-
headers,
|
|
66
|
-
json: { slug: action.slug, version: action.targetVersion },
|
|
67
|
-
})
|
|
68
|
-
.json();
|
|
69
|
-
this.log(` ✓ ${result.message}`);
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
this.warn(` Failed to install ${action.slug}: ${error.message}`);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
await this.activatePlugin(url, headers, action.slug);
|
|
54
|
+
await this.installAndActivate(action.slug, action.targetVersion);
|
|
76
55
|
}
|
|
77
56
|
// Activate installed-but-inactive plugins without prompting.
|
|
78
57
|
for (const action of toActivate) {
|
|
79
58
|
this.log(`\nActivating ${action.slug}...`);
|
|
80
|
-
await this.activatePlugin(
|
|
59
|
+
await this.activatePlugin(action.slug);
|
|
81
60
|
}
|
|
82
61
|
// Prompt per drifted plugin before syncing.
|
|
83
62
|
for (const action of drifted) {
|
|
@@ -91,32 +70,28 @@ export default class Push extends PushCommand {
|
|
|
91
70
|
continue;
|
|
92
71
|
}
|
|
93
72
|
this.log(` Syncing ${action.slug} to ${action.targetVersion}...`);
|
|
94
|
-
|
|
95
|
-
const result = await got
|
|
96
|
-
.post(`${url}/wp-json/loopress/v1/plugins/install`, {
|
|
97
|
-
headers,
|
|
98
|
-
json: { slug: action.slug, version: action.targetVersion },
|
|
99
|
-
})
|
|
100
|
-
.json();
|
|
101
|
-
this.log(` ✓ ${result.message}`);
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
this.warn(` Failed to sync ${action.slug}: ${error.message}`);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
await this.activatePlugin(url, headers, action.slug);
|
|
73
|
+
await this.installAndActivate(action.slug, action.targetVersion);
|
|
108
74
|
}
|
|
109
75
|
await this.recordSuccess();
|
|
110
76
|
}
|
|
111
|
-
async activatePlugin(
|
|
77
|
+
async activatePlugin(slug) {
|
|
112
78
|
try {
|
|
113
|
-
const result = await
|
|
114
|
-
.post(`${url}/wp-json/loopress/v1/plugins/activate`, { headers, json: { slug } })
|
|
115
|
-
.json();
|
|
79
|
+
const result = await this.wp.post('loopress/v1/plugins/activate', { slug });
|
|
116
80
|
this.log(` ✓ ${result.message}`);
|
|
117
81
|
}
|
|
118
82
|
catch (error) {
|
|
119
83
|
this.warn(` Failed to activate ${slug}: ${error.message}`);
|
|
120
84
|
}
|
|
121
85
|
}
|
|
86
|
+
async installAndActivate(slug, version) {
|
|
87
|
+
try {
|
|
88
|
+
const result = await this.wp.post('loopress/v1/plugins/install', { slug, version });
|
|
89
|
+
this.log(` ✓ ${result.message}`);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
this.warn(` Failed to install ${slug}: ${error.message}`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
await this.activatePlugin(slug);
|
|
96
|
+
}
|
|
122
97
|
}
|
|
@@ -3,8 +3,8 @@ export default class List extends LoopressCommand {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
-
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
7
6
|
plugin: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
8
|
password: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
9
|
url: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
10
|
user: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|