@loopress/cli 0.33.0 → 0.34.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 +174 -161
- package/dist/commands/app/push.js +2 -1
- package/dist/commands/block/push.js +9 -4
- package/dist/commands/dev.d.ts +2 -2
- package/dist/commands/dev.js +10 -16
- package/dist/commands/diff.d.ts +6 -4
- package/dist/commands/diff.js +49 -29
- package/dist/commands/doctor.js +12 -2
- package/dist/commands/option/push.js +1 -0
- package/dist/commands/page/push.js +1 -0
- package/dist/commands/plugin/add.d.ts +1 -0
- package/dist/commands/plugin/add.js +50 -9
- package/dist/commands/plugin/push.js +39 -4
- package/dist/commands/project/config.js +0 -1
- package/dist/commands/promote.d.ts +1 -0
- package/dist/commands/promote.js +8 -4
- package/dist/commands/pull.d.ts +5 -0
- package/dist/commands/pull.js +26 -1
- package/dist/commands/push.d.ts +9 -0
- package/dist/commands/push.js +104 -39
- package/dist/commands/theme/style/diff.js +1 -1
- package/dist/commands/theme/style/push.js +1 -1
- package/dist/commands/theme/style/rollback.js +1 -1
- package/dist/commands/theme/template/push.d.ts +2 -0
- package/dist/commands/theme/template/push.js +42 -13
- package/dist/commands/validate.js +3 -0
- package/dist/lib/base.d.ts +6 -0
- package/dist/lib/base.js +33 -1
- package/dist/lib/declared-plugins.d.ts +9 -0
- package/dist/lib/declared-plugins.js +21 -0
- package/dist/lib/declared-type-command.js +3 -0
- package/dist/lib/dev-watch.d.ts +1 -1
- package/dist/lib/dev-watch.js +11 -13
- package/dist/lib/diff-command.d.ts +17 -0
- package/dist/lib/diff-command.js +125 -9
- package/dist/lib/environment-urls.d.ts +6 -0
- package/dist/lib/environment-urls.js +59 -0
- package/dist/lib/exclude.d.ts +16 -0
- package/dist/lib/exclude.js +102 -0
- package/dist/lib/load-snippets.js +2 -1
- package/dist/lib/php-files-command.js +5 -3
- package/dist/lib/push-command.d.ts +4 -0
- package/dist/lib/push-command.js +38 -2
- package/dist/lib/readdir-tolerant.js +6 -3
- package/dist/lib/resource-selection.d.ts +9 -0
- package/dist/lib/resource-selection.js +49 -0
- package/dist/lib/resource-state.d.ts +2 -0
- package/dist/lib/resource-state.js +25 -4
- package/dist/lib/rollback-command.js +1 -1
- package/dist/lib/rollback-materialize.js +1 -1
- package/dist/lib/validate-local.d.ts +1 -0
- package/dist/lib/validate-local.js +67 -8
- package/dist/lib/wp-client.d.ts +1 -0
- package/dist/lib/wp-client.js +6 -0
- package/dist/types/project-config.generated.d.ts +15 -4
- package/dist/utils/block-format.d.ts +2 -0
- package/dist/utils/block-format.js +18 -2
- package/dist/utils/page-format.js +2 -1
- package/dist/utils/resource-dirs.js +4 -4
- package/oclif.manifest.json +2275 -1394
- package/package.json +7 -7
- package/schemas/project-config.schema.json +21 -4
package/dist/commands/push.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { LoopressCommand } from '../lib/base.js';
|
|
|
2
2
|
type PushTargetResult = {
|
|
3
3
|
error?: string;
|
|
4
4
|
label: string;
|
|
5
|
+
reason?: string;
|
|
5
6
|
result?: unknown;
|
|
6
7
|
status: 'failed' | 'pushed' | 'skipped';
|
|
7
8
|
};
|
|
@@ -14,16 +15,24 @@ export default class Push extends LoopressCommand {
|
|
|
14
15
|
static examples: string[];
|
|
15
16
|
static flags: {
|
|
16
17
|
overwrite: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
'skip-unsupported': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
|
+
only: ReturnType<typeof import("@oclif/core/flags").string>;
|
|
20
|
+
skip: ReturnType<typeof import("@oclif/core/flags").string>;
|
|
17
21
|
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
22
|
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
23
|
};
|
|
24
|
+
private skipUnsupported;
|
|
25
|
+
private readonly unsupported;
|
|
20
26
|
run(): Promise<PushResult>;
|
|
21
27
|
private applySiteSteps;
|
|
22
28
|
private buildArgv;
|
|
23
29
|
private composerJsonPath;
|
|
24
30
|
private declaredPlugins;
|
|
31
|
+
private doneMessage;
|
|
25
32
|
private globalStylesSkipNote;
|
|
26
33
|
private guardProductionPush;
|
|
27
34
|
private skippedTargets;
|
|
35
|
+
private unsupportedLine;
|
|
36
|
+
private warnUnsupported;
|
|
28
37
|
}
|
|
29
38
|
export {};
|
package/dist/commands/push.js
CHANGED
|
@@ -7,7 +7,9 @@ import { guardProductionPush } from '../lib/guard-production-push.js';
|
|
|
7
7
|
import { stdoutToStderr } from '../lib/json-delegation.js';
|
|
8
8
|
import { errorMessage } from '../lib/narrow.js';
|
|
9
9
|
import { PushCommand } from '../lib/push-command.js';
|
|
10
|
+
import { parseSelectionFlag, selectionFlags, selectResources } from '../lib/resource-selection.js';
|
|
10
11
|
import { isLocalEnvironment } from '../lib/wp-client.js';
|
|
12
|
+
import { pinActive } from '../types/plugin.js';
|
|
11
13
|
import { parseComposerJson, wpackagistRequire } from '../utils/composer.js';
|
|
12
14
|
import { projectHasChildThemeFiles, projectUses, resolveResourceDir } from '../utils/resource-dirs.js';
|
|
13
15
|
import { globalStylesSkipNote } from '../utils/theme-styles-format.js';
|
|
@@ -16,55 +18,68 @@ import { globalStylesSkipNote } from '../utils/theme-styles-format.js';
|
|
|
16
18
|
// site's 409 or the missing directory.
|
|
17
19
|
const PLUGIN_BACKED = { 'acf:push': 'acf', 'form:push': 'form', 'snippet:push': 'snippets' };
|
|
18
20
|
// Features of Loopress Full only: on Light, skipped while the project doesn't use them, refused
|
|
19
|
-
// upfront when it does.
|
|
21
|
+
// upfront when it does. Like every other resource, skipped when the project doesn't use them.
|
|
20
22
|
const FULL_ONLY = { 'api:push': 'api', 'block:push': 'block', 'hook:push': 'hooks', 'page:push': 'page', 'pattern:push': 'pattern' };
|
|
23
|
+
// Always available on the site: nothing to refuse, but a project without the resource's
|
|
24
|
+
// directory has nothing to push, so the step is skipped instead of running on an empty directory.
|
|
25
|
+
const CORE_BACKED = { 'cpt:push': 'cpt', 'menu:push': 'menu', 'meta:push': 'meta', 'option:push': 'options', 'role:push': 'role', 'taxonomy:push': 'taxonomy' };
|
|
21
26
|
// Dependency-ish order: code first (plugins, composer), then the ACF definitions content
|
|
22
27
|
// relies on, then content itself.
|
|
23
28
|
const PUSH_TARGETS = [
|
|
24
|
-
{ commandId: 'plugin:push', label: 'plugins' },
|
|
25
|
-
{ commandId: 'composer:push', label: 'composer' },
|
|
29
|
+
{ commandId: 'plugin:push', id: 'plugin', label: 'plugins' },
|
|
30
|
+
{ commandId: 'composer:push', id: 'composer', label: 'composer' },
|
|
26
31
|
// Before ACF: a field group's location rule can target a Loopress post type or taxonomy.
|
|
27
|
-
{ commandId: 'cpt:push', label: 'post types' },
|
|
28
|
-
{ commandId: 'taxonomy:push', label: 'taxonomies' },
|
|
29
|
-
{ commandId: 'meta:push', label: 'post meta' },
|
|
30
|
-
{ commandId: 'role:push', label: 'roles' },
|
|
31
|
-
{ commandId: 'acf:push', label: 'ACF' },
|
|
32
|
-
{ commandId: 'api:push', label: 'API routes' },
|
|
33
|
-
{ commandId: 'hook:push', label: 'hooks' },
|
|
32
|
+
{ commandId: 'cpt:push', id: 'cpt', label: 'post types' },
|
|
33
|
+
{ commandId: 'taxonomy:push', id: 'taxonomy', label: 'taxonomies' },
|
|
34
|
+
{ commandId: 'meta:push', id: 'meta', label: 'post meta' },
|
|
35
|
+
{ commandId: 'role:push', id: 'role', label: 'roles' },
|
|
36
|
+
{ commandId: 'acf:push', id: 'acf', label: 'ACF' },
|
|
37
|
+
{ commandId: 'api:push', id: 'api', label: 'API routes' },
|
|
38
|
+
{ commandId: 'hook:push', id: 'hook', label: 'hooks' },
|
|
34
39
|
// Before templates and pages, which place them (`wp:loopress/<slug>`).
|
|
35
|
-
{ commandId: 'block:push', label: 'dynamic blocks' },
|
|
36
|
-
{ commandId: 'form:push', label: 'forms' },
|
|
40
|
+
{ commandId: 'block:push', id: 'block', label: 'dynamic blocks' },
|
|
41
|
+
{ commandId: 'form:push', id: 'form', label: 'forms' },
|
|
37
42
|
// Before templates and pages, which can reference them (`wp:pattern`).
|
|
38
|
-
{ commandId: 'pattern:push', label: 'patterns' },
|
|
43
|
+
{ commandId: 'pattern:push', id: 'pattern', label: 'patterns' },
|
|
39
44
|
// Before pages: WordPress refuses a page whose `template` it doesn't know yet.
|
|
40
|
-
{ commandId: 'theme:template:push', label: 'templates and parts' },
|
|
45
|
+
{ commandId: 'theme:template:push', id: 'template', label: 'templates and parts' },
|
|
41
46
|
// Belong to whichever theme is active, so right after its templates. Theme versions stay out:
|
|
42
47
|
// installing or removing themes is `lps theme push`'s call.
|
|
43
|
-
{ commandId: 'theme:style:push', label: 'Global Styles' },
|
|
44
|
-
{ commandId: 'page:push', label: 'pages' },
|
|
45
|
-
{ commandId: 'menu:push', label: 'menus' },
|
|
46
|
-
{ commandId: 'option:push', label: 'options' },
|
|
47
|
-
{ commandId: 'snippet:push', label: 'snippets' },
|
|
48
|
+
{ commandId: 'theme:style:push', id: 'theme-style', label: 'Global Styles' },
|
|
49
|
+
{ commandId: 'page:push', id: 'page', label: 'pages' },
|
|
50
|
+
{ commandId: 'menu:push', id: 'menu', label: 'menus' },
|
|
51
|
+
{ commandId: 'option:push', id: 'option', label: 'options' },
|
|
52
|
+
{ commandId: 'snippet:push', id: 'snippet', label: 'snippets' },
|
|
48
53
|
];
|
|
54
|
+
const PUSH_IDS = PUSH_TARGETS.map((target) => target.id);
|
|
49
55
|
export default class Push extends LoopressCommand {
|
|
50
56
|
static description = 'Push every local resource to WordPress in one run: plugins, composer dependencies, post types, taxonomies, post meta, roles, ACF, API routes, hooks, dynamic blocks, forms, patterns, templates and parts, Global Styles, pages, menus, options, and snippets';
|
|
51
57
|
static enableJsonFlag = true;
|
|
52
|
-
static examples = ['$ lps push', '$ lps push --env staging', '$ lps push --dry-run'];
|
|
58
|
+
static examples = ['$ lps push', '$ lps push --env staging', '$ lps push --dry-run', '$ lps push --only acf,page', '$ lps push --skip plugin --skip composer'];
|
|
53
59
|
static flags = {
|
|
54
60
|
...LoopressCommand.dryRunFlag,
|
|
55
61
|
...LoopressCommand.yesFlag,
|
|
62
|
+
...selectionFlags('push', PUSH_IDS),
|
|
63
|
+
...LoopressCommand.skipUnsupportedFlag,
|
|
56
64
|
overwrite: PushCommand.baseFlags.overwrite,
|
|
57
65
|
};
|
|
66
|
+
skipUnsupported = false;
|
|
67
|
+
// What --skip-unsupported held back, for the final warning.
|
|
68
|
+
unsupported = [];
|
|
58
69
|
async run() {
|
|
59
70
|
await this.guardProductionPush();
|
|
71
|
+
const { flags } = await this.parse(Push);
|
|
72
|
+
this.skipUnsupported = flags['skip-unsupported'];
|
|
73
|
+
const skipFlag = parseSelectionFlag(flags.skip, 'skip', PUSH_IDS, (message) => this.error(message));
|
|
74
|
+
const selected = new Set(selectResources(PUSH_IDS, parseSelectionFlag(flags.only, 'only', PUSH_IDS, (message) => this.error(message)), skipFlag));
|
|
60
75
|
const argv = this.buildArgv();
|
|
61
76
|
const results = [];
|
|
62
|
-
const skips = await this.skippedTargets();
|
|
77
|
+
const skips = await this.skippedTargets(selected, skipFlag.includes('composer'));
|
|
63
78
|
for (const target of PUSH_TARGETS) {
|
|
64
79
|
const skip = skips.get(target.commandId);
|
|
65
80
|
if (skip) {
|
|
66
81
|
this.log(`\n→ ${target.label}: ${skip.note}`);
|
|
67
|
-
results.push({ label: target.label, status: skip.status });
|
|
82
|
+
results.push({ label: target.label, ...(skip.reason && { reason: skip.reason }), status: skip.status });
|
|
68
83
|
continue;
|
|
69
84
|
}
|
|
70
85
|
this.log(`\n→ Pushing ${target.label}...`);
|
|
@@ -79,12 +94,16 @@ export default class Push extends LoopressCommand {
|
|
|
79
94
|
results.push({ error: message, label: target.label, status: 'failed' });
|
|
80
95
|
// Stop here: later targets depend on earlier ones (hooks use what composer installs,
|
|
81
96
|
// pages need their templates), so pushing them anyway can ship a silently broken site.
|
|
82
|
-
const skipped = PUSH_TARGETS.slice(PUSH_TARGETS.indexOf(target) + 1)
|
|
97
|
+
const skipped = PUSH_TARGETS.slice(PUSH_TARGETS.indexOf(target) + 1)
|
|
98
|
+
.filter((next) => !skips.has(next.commandId))
|
|
99
|
+
.map((next) => next.label);
|
|
83
100
|
const skippedNote = skipped.length > 0 ? ` Not attempted: ${skipped.join(', ')}.` : '';
|
|
101
|
+
this.warnUnsupported();
|
|
84
102
|
this.error(`${target.label} failed to push: ${message}.${skippedNote}`);
|
|
85
103
|
}
|
|
86
104
|
}
|
|
87
|
-
this.log(this.
|
|
105
|
+
this.log(this.doneMessage(selected.size < PUSH_IDS.length));
|
|
106
|
+
this.warnUnsupported();
|
|
88
107
|
return { results };
|
|
89
108
|
}
|
|
90
109
|
// A step the project uses on a site that can't hold it would only fail at its turn, after
|
|
@@ -94,10 +113,13 @@ export default class Push extends LoopressCommand {
|
|
|
94
113
|
const blockers = [];
|
|
95
114
|
for (const { commandId, missing, skipUnused, used } of steps) {
|
|
96
115
|
if (used && missing) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
const line = this.unsupportedLine(commandId, missing, declared);
|
|
117
|
+
if (this.skipUnsupported) {
|
|
118
|
+
skips.set(commandId, { note: `${missing.reason}, skipped (--skip-unsupported)`, reason: `${missing.reason} on ${this.siteConfig.name}`, status: 'skipped' });
|
|
119
|
+
this.unsupported.push(line);
|
|
120
|
+
}
|
|
121
|
+
else
|
|
122
|
+
blockers.push(line);
|
|
101
123
|
}
|
|
102
124
|
else if (!used && missing?.needsFull) {
|
|
103
125
|
skips.set(commandId, { note: `${missing.reason}, skipped`, status: 'skipped' });
|
|
@@ -137,6 +159,13 @@ export default class Push extends LoopressCommand {
|
|
|
137
159
|
return [];
|
|
138
160
|
}
|
|
139
161
|
}
|
|
162
|
+
// A run narrowed by --only / --skip must not read as a full push. Unused resources skipped
|
|
163
|
+
// on a plain run don't count: that run still pushes everything the project has.
|
|
164
|
+
doneMessage(narrowed) {
|
|
165
|
+
if (narrowed)
|
|
166
|
+
return this.dryRun ? '\nEvery selected resource would push, the others are skipped.' : '\nSelected resources pushed, the others are skipped.';
|
|
167
|
+
return this.dryRun ? '\nEvery resource would push.' : '\nAll resources pushed.';
|
|
168
|
+
}
|
|
140
169
|
// The site unreachable or the theme list refused: let the step run and report it itself.
|
|
141
170
|
async globalStylesSkipNote() {
|
|
142
171
|
try {
|
|
@@ -158,14 +187,20 @@ export default class Push extends LoopressCommand {
|
|
|
158
187
|
}
|
|
159
188
|
// Unconfigured is not a failure: a project that doesn't manage plugins or composer through
|
|
160
189
|
// Loopress must not stop the run before anything else gets pushed.
|
|
161
|
-
|
|
190
|
+
// `composerSkipped`: `composer` was named in --skip, as opposed to just left out of --only.
|
|
191
|
+
async skippedTargets(selected, composerSkipped) {
|
|
162
192
|
const skips = new Map();
|
|
193
|
+
const isSelected = (commandId) => selected.has(PUSH_TARGETS.find((target) => target.commandId === commandId)?.id ?? '');
|
|
163
194
|
const notConfigured = { note: 'not configured, skipped', status: 'skipped' };
|
|
164
195
|
const hasComposerJson = existsSync(this.composerJsonPath());
|
|
165
196
|
const declaredPlugins = await this.declaredPlugins(hasComposerJson);
|
|
166
197
|
// A composer.json that declares plugins is pushed whole by `plugin:push` (with its activation
|
|
167
198
|
// safety), so `composer:push` would only run Composer on the server a second time.
|
|
168
|
-
const composerPushedByPlugins = hasComposerJson && declaredPlugins.length > 0;
|
|
199
|
+
const composerPushedByPlugins = hasComposerJson && declaredPlugins.length > 0 && isSelected('plugin:push');
|
|
200
|
+
// That push runs Composer on the server, so a run told to skip Composer can't push plugins.
|
|
201
|
+
if (composerPushedByPlugins && composerSkipped) {
|
|
202
|
+
this.error('--skip composer conflicts with pushing plugins: composer.json declares them, so plugin push runs Composer on the server. Skip plugin too, or drop --skip composer.');
|
|
203
|
+
}
|
|
169
204
|
if (composerPushedByPlugins)
|
|
170
205
|
skips.set('composer:push', { note: 'already pushed whole by plugins', status: 'pushed' });
|
|
171
206
|
else if (!hasComposerJson)
|
|
@@ -174,28 +209,58 @@ export default class Push extends LoopressCommand {
|
|
|
174
209
|
if (declaredPlugins.length === 0)
|
|
175
210
|
skips.set('plugin:push', notConfigured);
|
|
176
211
|
const capabilities = await this.capabilities();
|
|
212
|
+
// Installed and activated by this run's first step, before the steps that need them: a fresh
|
|
213
|
+
// site (CI, a new staging) gets ACF from loopress.json and its field groups in one push.
|
|
214
|
+
// composer.json records no active state, so its plugins stay inactive until --activate.
|
|
215
|
+
const activatedByPush = hasComposerJson || !isSelected('plugin:push') ? [] : declaredPlugins.filter((slug) => pinActive(this.localConfig.plugins?.[slug]));
|
|
177
216
|
const missingDependencies = missingModule('dependencies', 'plugins and Composer', capabilities);
|
|
178
|
-
|
|
217
|
+
// A target left out by --only / --skip is reported skipped and never reaches the site checks,
|
|
218
|
+
// so it can't block the run.
|
|
219
|
+
const allSteps = [
|
|
179
220
|
...['plugin:push', 'composer:push'].map((commandId) => ({ commandId, missing: missingDependencies, skipUnused: false, used: !skips.has(commandId) })),
|
|
180
|
-
...Object.entries(PLUGIN_BACKED).map(([commandId, kind]) =>
|
|
181
|
-
|
|
182
|
-
missing
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
221
|
+
...Object.entries(PLUGIN_BACKED).map(([commandId, kind]) => {
|
|
222
|
+
const missing = missingIntegration(kind, capabilities);
|
|
223
|
+
// Not missing when one of the plugins that would provide it is activated earlier in the run.
|
|
224
|
+
const activated = missing?.plugins?.some((slug) => activatedByPush.includes(slug)) ?? false;
|
|
225
|
+
// A dry run activates nothing, so the site can't preview this step yet.
|
|
226
|
+
if (activated && this.dryRun)
|
|
227
|
+
skips.set(commandId, { note: `${missing?.reason} until this push activates it, skipped`, status: 'skipped' });
|
|
228
|
+
return { commandId, missing: activated ? undefined : missing, skipUnused: true, used: projectUses(kind, this.localConfig) };
|
|
229
|
+
}),
|
|
186
230
|
...Object.entries(FULL_ONLY).map(([commandId, kind]) => ({
|
|
187
231
|
commandId,
|
|
188
232
|
missing: missingIntegration(kind, capabilities),
|
|
189
|
-
skipUnused:
|
|
233
|
+
skipUnused: true,
|
|
190
234
|
used: projectUses(kind, this.localConfig),
|
|
191
235
|
})),
|
|
236
|
+
...Object.entries(CORE_BACKED).map(([commandId, kind]) => ({ commandId, missing: undefined, skipUnused: true, used: projectUses(kind, this.localConfig) })),
|
|
192
237
|
// Without templates, parts or CSS, the step would only write an empty child theme.
|
|
193
238
|
{ commandId: 'theme:template:push', missing: missingIntegration('template', capabilities), skipUnused: true, used: projectHasChildThemeFiles(this.localConfig) },
|
|
194
239
|
];
|
|
240
|
+
const steps = allSteps.filter((step) => isSelected(step.commandId));
|
|
195
241
|
this.applySiteSteps(steps, skips, { fromComposer: hasComposerJson, plugins: declaredPlugins });
|
|
196
|
-
const stylesNote = await this.globalStylesSkipNote();
|
|
242
|
+
const stylesNote = isSelected('theme:style:push') ? await this.globalStylesSkipNote() : undefined;
|
|
197
243
|
if (stylesNote)
|
|
198
244
|
skips.set('theme:style:push', { note: stylesNote, status: 'skipped' });
|
|
245
|
+
for (const target of PUSH_TARGETS) {
|
|
246
|
+
// Composer left out of --only still runs when plugin push syncs composer.json: say so.
|
|
247
|
+
if (composerPushedByPlugins && target.commandId === 'composer:push')
|
|
248
|
+
continue;
|
|
249
|
+
if (!selected.has(target.id))
|
|
250
|
+
skips.set(target.commandId, { note: 'not selected, skipped', status: 'skipped' });
|
|
251
|
+
}
|
|
199
252
|
return skips;
|
|
200
253
|
}
|
|
254
|
+
// "<resources>: <why> on <site>. <fix>", for the refusal and for the --skip-unsupported warning.
|
|
255
|
+
unsupportedLine(commandId, missing, declared) {
|
|
256
|
+
const label = PUSH_TARGETS.find((target) => target.commandId === commandId)?.label;
|
|
257
|
+
const fix = integrationFix(missing, declared);
|
|
258
|
+
const fixSentence = fix ? ` ${fix}.` : '';
|
|
259
|
+
return `${label}: ${missing.reason} on ${this.siteConfig.name}.${fixSentence}`;
|
|
260
|
+
}
|
|
261
|
+
warnUnsupported() {
|
|
262
|
+
if (this.unsupported.length > 0) {
|
|
263
|
+
this.warn(`Skipped with --skip-unsupported, this site can't hold them:\n ${this.unsupported.join('\n ')}\nResources that depend on them (a page placing a block, code calling a hook) may not work until they are pushed.`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
201
266
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resourceDiffCommand } from '../../../lib/diff-command.js';
|
|
2
|
-
export default resourceDiffCommand('theme-
|
|
2
|
+
export default resourceDiffCommand('theme-style', {
|
|
3
3
|
description: "Show what differs in the active block theme's Global Styles (Site Editor > Styles) between your local file and a WordPress environment, or between two environments",
|
|
4
4
|
command: 'theme style',
|
|
5
5
|
pathNoun: 'theme styles directory',
|
|
@@ -34,7 +34,7 @@ export default class Push extends PushCommand {
|
|
|
34
34
|
throw error;
|
|
35
35
|
}
|
|
36
36
|
// Only the active theme's file is pushed, whatever else the directory holds.
|
|
37
|
-
const provider = getResourceStateProvider('theme-
|
|
37
|
+
const provider = getResourceStateProvider('theme-style');
|
|
38
38
|
const beforeState = await this.captureBeforePushState(provider, dir, (name) => name === stylesheet);
|
|
39
39
|
if (this.dryRun)
|
|
40
40
|
return { changes: this.previewChanges, file, status: 'dry-run' };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resourceRollbackCommand } from '../../../lib/rollback-command.js';
|
|
2
|
-
export default resourceRollbackCommand('theme-
|
|
2
|
+
export default resourceRollbackCommand('theme-style', {
|
|
3
3
|
description: "Restore the active theme's Global Styles to a snapshot taken automatically before an earlier `lps theme style push`",
|
|
4
4
|
command: 'theme style',
|
|
5
5
|
pathNoun: 'theme styles directory',
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
+
import { join } from 'node:path';
|
|
2
3
|
import { activateTheme } from '../../../lib/capabilities.js';
|
|
3
4
|
import {} from '../../../lib/diff-state.js';
|
|
5
|
+
import { hasExclusions, isExcluded } from '../../../lib/exclude.js';
|
|
4
6
|
import { errorMessage } from '../../../lib/narrow.js';
|
|
5
7
|
import { logChanges, pushChanges, PushCommand } from '../../../lib/push-command.js';
|
|
6
8
|
import { formatPageProblems } from '../../../utils/page-format.js';
|
|
@@ -39,8 +41,15 @@ export default class Push extends PushCommand {
|
|
|
39
41
|
};
|
|
40
42
|
this.log(`Found ${pluralize(templates.length, 'template')}, ${pluralize(parts.length, 'part')}, ` +
|
|
41
43
|
`${css.style ? 'a global stylesheet' : 'no global stylesheet'} and ${pluralize(css.blocks.length, 'block stylesheet')}`);
|
|
44
|
+
this.warnEnvironmentUrls([
|
|
45
|
+
...templates.map((template) => ({ id: `templates/${template.slug}`, value: template.html })),
|
|
46
|
+
...parts.map((part) => ({ id: `parts/${part.slug}`, value: part.html })),
|
|
47
|
+
]);
|
|
48
|
+
// The PUT replaces every file of the child theme: what the site has under a path this
|
|
49
|
+
// environment excludes (loopress.json) is sent back as it is, so it is left alone.
|
|
50
|
+
const kept = await this.keptFromSite(templatesPath, partsPath, templates, parts);
|
|
42
51
|
if (this.dryRun) {
|
|
43
|
-
const changes = await this.previewChildTheme(templates, parts, css);
|
|
52
|
+
const changes = await this.previewChildTheme(templates, parts, css, kept);
|
|
44
53
|
logChanges((message) => { this.log(message); }, changes.templates, 'templates/');
|
|
45
54
|
logChanges((message) => { this.log(message); }, changes.parts, 'parts/');
|
|
46
55
|
logChanges((message) => { this.log(message); }, changes.css, 'css/');
|
|
@@ -51,7 +60,7 @@ export default class Push extends PushCommand {
|
|
|
51
60
|
}
|
|
52
61
|
return { ...names, changes, status: 'dry-run' };
|
|
53
62
|
}
|
|
54
|
-
const child = await this.wp.put(CHILD_THEME_ENDPOINT, { ...css, parts, templates });
|
|
63
|
+
const child = await this.wp.put(CHILD_THEME_ENDPOINT, { ...css, parts: [...parts, ...kept.parts], templates: [...templates, ...kept.templates] });
|
|
55
64
|
await this.recordSuccess();
|
|
56
65
|
this.log(`Child theme ${child.stylesheet} written.`);
|
|
57
66
|
// Activated only when the project asks for it: a theme switch changes every per-theme setting.
|
|
@@ -83,15 +92,23 @@ export default class Push extends PushCommand {
|
|
|
83
92
|
unknownBlocks,
|
|
84
93
|
};
|
|
85
94
|
}
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
// The site's templates and parts under an excluded path the project doesn't push. Refuses when
|
|
96
|
+
// the site can't be read: pushing blind would remove them.
|
|
97
|
+
async keptFromSite(templatesPath, partsPath, templates, parts) {
|
|
98
|
+
if (!hasExclusions())
|
|
99
|
+
return { parts: [], templates: [] };
|
|
100
|
+
const child = await this.readChildTheme();
|
|
101
|
+
const localTemplates = new Set(templates.map((template) => template.slug));
|
|
102
|
+
const localParts = new Set(parts.map((part) => part.slug));
|
|
103
|
+
return {
|
|
104
|
+
parts: child.parts.filter((part) => !localParts.has(part.slug) && isExcluded(join(partsPath, `${part.slug}.html`))),
|
|
105
|
+
templates: child.templates.filter((template) => !localTemplates.has(template.slug) && isExcluded(join(templatesPath, `${template.slug}.html`))),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Same read and same refusal as previewRemote, one GET for templates, parts and CSS. Kept
|
|
109
|
+
// files are held back, they are neither changes nor removals.
|
|
110
|
+
async previewChildTheme(templates, parts, css, kept) {
|
|
111
|
+
const child = await this.readChildTheme();
|
|
95
112
|
const localCss = new Map(css.blocks.map((block) => [`blocks/${block.name}.css`, sha256(block.css)]));
|
|
96
113
|
if (css.style !== '')
|
|
97
114
|
localCss.set('style.css', sha256(css.style));
|
|
@@ -100,14 +117,26 @@ export default class Push extends PushCommand {
|
|
|
100
117
|
: [...localCss.keys()].toSorted((a, b) => a.localeCompare(b)).map((id) => ({ id, status: 'unknown' }));
|
|
101
118
|
return {
|
|
102
119
|
css: cssChanges,
|
|
103
|
-
parts: pushChanges(bySlug(parts), bySlug(child.parts), { mirror: true }),
|
|
104
|
-
templates: pushChanges(bySlug(templates), bySlug(child.templates), { mirror: true }),
|
|
120
|
+
parts: withoutKept(pushChanges(bySlug([...parts, ...kept.parts]), bySlug(child.parts), { mirror: true }), kept.parts),
|
|
121
|
+
templates: withoutKept(pushChanges(bySlug([...templates, ...kept.templates]), bySlug(child.templates), { mirror: true }), kept.templates),
|
|
105
122
|
};
|
|
106
123
|
}
|
|
124
|
+
async readChildTheme() {
|
|
125
|
+
try {
|
|
126
|
+
return await this.wp.get(CHILD_THEME_ENDPOINT);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
this.error(`The site would refuse this push: ${errorMessage(error)}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
107
132
|
}
|
|
108
133
|
function bySlug(files) {
|
|
109
134
|
return new Map(files.map(({ slug, ...rest }) => [slug, rest]));
|
|
110
135
|
}
|
|
136
|
+
function withoutKept(changes, kept) {
|
|
137
|
+
const slugs = new Set(kept.map((file) => file.slug));
|
|
138
|
+
return changes.filter((change) => !slugs.has(change.id));
|
|
139
|
+
}
|
|
111
140
|
function sha256(text) {
|
|
112
141
|
return createHash('sha256').update(text, 'utf8').digest('hex');
|
|
113
142
|
}
|
|
@@ -11,6 +11,9 @@ export default class Validate extends Command {
|
|
|
11
11
|
for (const problem of result.problems) {
|
|
12
12
|
this.log(` ✗ ${problem.file}: ${problem.message}`);
|
|
13
13
|
}
|
|
14
|
+
for (const warning of result.warnings) {
|
|
15
|
+
this.log(` ! ${warning.file}: ${warning.message}`);
|
|
16
|
+
}
|
|
14
17
|
this.log('');
|
|
15
18
|
this.log(result.valid
|
|
16
19
|
? `${result.checked} file(s) checked, no problems found.`
|
package/dist/lib/base.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type EnvironmentConfig } from '../types/config.js';
|
|
|
3
3
|
import { type LoopressLocalConfig } from '../utils/loopress-config.js';
|
|
4
4
|
import { type SiteCapabilities } from './capabilities.js';
|
|
5
5
|
import { WpClient } from './wp-client.js';
|
|
6
|
+
export declare function listrRenderer(silent: boolean): 'default' | 'silent' | 'simple';
|
|
6
7
|
export declare abstract class LoopressCommand extends Command {
|
|
7
8
|
static baseFlags: {
|
|
8
9
|
env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -10,6 +11,10 @@ export declare abstract class LoopressCommand extends Command {
|
|
|
10
11
|
static dryRunFlag: {
|
|
11
12
|
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
13
|
};
|
|
14
|
+
static honorsExclude: boolean;
|
|
15
|
+
static skipUnsupportedFlag: {
|
|
16
|
+
'skip-unsupported': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
};
|
|
13
18
|
static yesFlag: {
|
|
14
19
|
yes: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
15
20
|
};
|
|
@@ -17,6 +22,7 @@ export declare abstract class LoopressCommand extends Command {
|
|
|
17
22
|
protected localConfig: LoopressLocalConfig;
|
|
18
23
|
protected overwrite: boolean;
|
|
19
24
|
protected productionConfirmed: boolean;
|
|
25
|
+
protected projectEnvironments: EnvironmentConfig[];
|
|
20
26
|
protected projectId: string;
|
|
21
27
|
protected siteConfig: EnvironmentConfig;
|
|
22
28
|
protected yes: boolean;
|
package/dist/lib/base.js
CHANGED
|
@@ -9,10 +9,19 @@ import { readLocalConfig } from '../utils/loopress-config.js';
|
|
|
9
9
|
import { pluralize } from '../utils/pluralize.js';
|
|
10
10
|
import { resolveResourceDir } from '../utils/resource-dirs.js';
|
|
11
11
|
import { getCapabilities } from './capabilities.js';
|
|
12
|
+
import { activateExclusions } from './exclude.js';
|
|
12
13
|
import { isInteractive } from './interactive.js';
|
|
13
14
|
import { isAppPasswordStale, rotateAppPassword } from './rotate-app-password.js';
|
|
14
15
|
import { withoutSpinner } from './spinner.js';
|
|
15
16
|
import { WpClient } from './wp-client.js';
|
|
17
|
+
// Listr's default renderer wraps every label to the terminal width, so a terminal reporting no
|
|
18
|
+
// width (columns 0 or undefined, e.g. `script` without a size) renders one letter per line. The
|
|
19
|
+
// simple renderer prints plain lines and does not wrap.
|
|
20
|
+
export function listrRenderer(silent) {
|
|
21
|
+
if (silent)
|
|
22
|
+
return 'silent';
|
|
23
|
+
return process.stdout.columns > 0 ? 'default' : 'simple';
|
|
24
|
+
}
|
|
16
25
|
export class LoopressCommand extends Command {
|
|
17
26
|
// On every subclass without opt-in. Without it, commands target the "local" environment, so
|
|
18
27
|
// reaching a remote site is always spelled out in the command itself.
|
|
@@ -24,6 +33,16 @@ export class LoopressCommand extends Command {
|
|
|
24
33
|
static dryRunFlag = {
|
|
25
34
|
'dry-run': Flags.boolean({ char: 'd', description: 'Show what would change without making changes' }),
|
|
26
35
|
};
|
|
36
|
+
// Whether the environment's `exclude` globs in loopress.json apply (lib/exclude.ts): push and
|
|
37
|
+
// diff commands only, never pull.
|
|
38
|
+
static honorsExclude = false;
|
|
39
|
+
// Opt-in on push, pull, diff and promote: a resource the project uses but the site can't hold
|
|
40
|
+
// (see lib/capabilities.ts) is reported skipped, with a final warning, instead of failing the run.
|
|
41
|
+
static skipUnsupportedFlag = {
|
|
42
|
+
'skip-unsupported': Flags.boolean({
|
|
43
|
+
description: "Skip the resources the project uses but this site can't hold (a missing plugin, a Full feature on Light) instead of failing, and warn about each",
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
27
46
|
static yesFlag = {
|
|
28
47
|
yes: Flags.boolean({ char: 'y', description: 'Answer yes to confirmation prompts' }),
|
|
29
48
|
};
|
|
@@ -33,6 +52,8 @@ export class LoopressCommand extends Command {
|
|
|
33
52
|
overwrite = false;
|
|
34
53
|
// Set by PushCommand's hidden --production-confirmed, see there.
|
|
35
54
|
productionConfirmed = false;
|
|
55
|
+
// Every environment of the project, the target included (see environment-urls.ts).
|
|
56
|
+
projectEnvironments = [];
|
|
36
57
|
projectId;
|
|
37
58
|
siteConfig;
|
|
38
59
|
yes = false;
|
|
@@ -75,6 +96,13 @@ export class LoopressCommand extends Command {
|
|
|
75
96
|
const resolved = this.resolveEnvironment(flags.env);
|
|
76
97
|
this.siteConfig = resolved.env;
|
|
77
98
|
this.projectId = resolved.projectId;
|
|
99
|
+
activateExclusions({
|
|
100
|
+
config: this.localConfig,
|
|
101
|
+
cwd: process.cwd(),
|
|
102
|
+
envName: this.siteConfig.name,
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- see above
|
|
104
|
+
honors: this.ctor.honorsExclude,
|
|
105
|
+
});
|
|
78
106
|
await this.maybeAutoRotate();
|
|
79
107
|
}
|
|
80
108
|
// Silent, best-effort: a stale app password still works, so a failed rotation attempt
|
|
@@ -128,7 +156,10 @@ export class LoopressCommand extends Command {
|
|
|
128
156
|
task.output = `Pulled: ${options.title(item)}`;
|
|
129
157
|
},
|
|
130
158
|
title: `Pull ${options.title(item)}`,
|
|
131
|
-
})),
|
|
159
|
+
})),
|
|
160
|
+
// Listr types the task wrapper per renderer, a union of renderer names does not fit it.
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- Listr ties the task wrapper type to one renderer
|
|
162
|
+
{ renderer: listrRenderer(this.jsonEnabled()) }).run();
|
|
132
163
|
});
|
|
133
164
|
await this.removeOrphanedFiles(dir, orphans, options.orphanReason);
|
|
134
165
|
this.log(options.pulledMessage);
|
|
@@ -204,6 +235,7 @@ export class LoopressCommand extends Command {
|
|
|
204
235
|
if (!project) {
|
|
205
236
|
this.error(`Project "${projectId}" (from loopress.json) not found. Run \`lps project config\` to configure it.`);
|
|
206
237
|
}
|
|
238
|
+
this.projectEnvironments = Object.values(project.environments);
|
|
207
239
|
const envNames = Object.keys(project.environments);
|
|
208
240
|
if (envNames.length === 0) {
|
|
209
241
|
this.error(`Project "${project.name}" has no environments configured. Run \`lps project config\` to add one.`);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type LoopressLocalConfig } from '../utils/loopress-config.js';
|
|
2
|
+
export declare function declaredPlugins(options: {
|
|
3
|
+
localConfig: LoopressLocalConfig;
|
|
4
|
+
rootDir: string;
|
|
5
|
+
siteName: string;
|
|
6
|
+
}): Promise<{
|
|
7
|
+
fromComposer: boolean;
|
|
8
|
+
plugins: string[];
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { parseComposerJson, wpackagistRequire } from '../utils/composer.js';
|
|
5
|
+
import {} from '../utils/loopress-config.js';
|
|
6
|
+
import { isLocalEnvironment } from './wp-client.js';
|
|
7
|
+
// The wordpress.org plugins the project declares: composer.json's wpackagist plugins when it
|
|
8
|
+
// exists, loopress.json's otherwise. Unreadable or invalid composer.json: none, the commands
|
|
9
|
+
// report it.
|
|
10
|
+
export async function declaredPlugins(options) {
|
|
11
|
+
const path = resolve(process.cwd(), options.rootDir, 'composer.json');
|
|
12
|
+
if (!existsSync(path))
|
|
13
|
+
return { fromComposer: false, plugins: Object.keys(options.localConfig.plugins ?? {}) };
|
|
14
|
+
try {
|
|
15
|
+
const composerJson = parseComposerJson(await readFile(path, 'utf8'));
|
|
16
|
+
return { fromComposer: true, plugins: Object.keys(wpackagistRequire(composerJson, 'plugin', isLocalEnvironment(options.siteName))) };
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return { fromComposer: true, plugins: [] };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -46,6 +46,9 @@ export function declaredPushCommand(spec, description) {
|
|
|
46
46
|
parse: (raw, filePath) => parseDeclaredFile(spec, filePath, raw),
|
|
47
47
|
});
|
|
48
48
|
this.log(`Found ${pluralize(items.length, spec.noun, spec.plural)} to push`);
|
|
49
|
+
// Patterns carry block markup, the other declared types only registration arguments.
|
|
50
|
+
if (spec.cliName === 'pattern')
|
|
51
|
+
this.warnEnvironmentUrls(items.map((item) => ({ id: `${spec.plural}/${item.slug}`, value: item.args })));
|
|
49
52
|
const pushed = [];
|
|
50
53
|
await this.runPushTasks(items, (item) => item.slug, async (item, task) => {
|
|
51
54
|
await this.pushItem(item, task);
|
package/dist/lib/dev-watch.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type LoopressLocalConfig } from '../utils/loopress-config.js';
|
|
2
|
-
export type ResourceType = 'api' | '
|
|
2
|
+
export type ResourceType = 'api' | 'block' | 'css' | 'hook' | 'page' | 'part' | 'plugin' | 'snippet' | 'template';
|
|
3
3
|
export declare const RESOURCE_TYPES: ResourceType[];
|
|
4
4
|
export type WatchTarget = {
|
|
5
5
|
commandId: string;
|
package/dist/lib/dev-watch.js
CHANGED
|
@@ -2,12 +2,10 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { join, sep } from 'node:path';
|
|
3
3
|
import {} from '../utils/loopress-config.js';
|
|
4
4
|
import { resolveResourceDir } from '../utils/resource-dirs.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// precedence a combined `--only=a,b --skip=b` reads as: watch a, b, then drop b.
|
|
5
|
+
import { selectResources } from './resource-selection.js';
|
|
6
|
+
export const RESOURCE_TYPES = ['snippet', 'template', 'part', 'css', 'block', 'page', 'api', 'hook', 'plugin'];
|
|
8
7
|
export function resolveResourceTypes(only, skip = []) {
|
|
9
|
-
|
|
10
|
-
return base.filter((type) => !skip.includes(type));
|
|
8
|
+
return selectResources(RESOURCE_TYPES, only, skip);
|
|
11
9
|
}
|
|
12
10
|
// One target per requested type that actually has something to watch: a missing directory (no
|
|
13
11
|
// `api/` folder yet) or an empty plugin manifest is left out silently, matching `push`'s own
|
|
@@ -17,19 +15,19 @@ export function buildWatchTargets(types, localConfig, cwd) {
|
|
|
17
15
|
const candidates = {
|
|
18
16
|
api: { commandId: 'api:push', path: join(cwd, resolveResourceDir('api', localConfig)), type: 'api' },
|
|
19
17
|
// The theme CSS is bundled into the child theme with the templates, by the same push.
|
|
20
|
-
|
|
18
|
+
block: { commandId: 'theme:template:push', path: join(cwd, resolveResourceDir('blockCss', localConfig)), type: 'block' },
|
|
21
19
|
css: { commandId: 'theme:template:push', path: join(cwd, resolveResourceDir('css', localConfig)), type: 'css' },
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
hook: { commandId: 'hook:push', path: join(cwd, resolveResourceDir('hooks', localConfig)), type: 'hook' },
|
|
21
|
+
page: { commandId: 'page:push', path: join(cwd, resolveResourceDir('page', localConfig)), type: 'page' },
|
|
22
|
+
plugin: { commandId: 'plugin:push', path: join(cwd, 'loopress.json'), type: 'plugin' },
|
|
23
|
+
part: { commandId: 'theme:template:push', path: join(cwd, resolveResourceDir('part', localConfig)), type: 'part' },
|
|
24
|
+
template: { commandId: 'theme:template:push', path: join(cwd, resolveResourceDir('template', localConfig)), type: 'template' },
|
|
25
|
+
snippet: { commandId: 'snippet:push', path: join(cwd, resolveResourceDir('snippets', localConfig)), type: 'snippet' },
|
|
28
26
|
};
|
|
29
27
|
return types
|
|
30
28
|
.map((type) => candidates[type])
|
|
31
29
|
.filter((target) => {
|
|
32
|
-
if (target.type === '
|
|
30
|
+
if (target.type === 'plugin')
|
|
33
31
|
return Object.keys(localConfig.plugins ?? {}).length > 0;
|
|
34
32
|
return existsSync(target.path);
|
|
35
33
|
});
|