@loopress/cli 0.10.0 → 0.11.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 +41 -35
- package/dist/commands/init.js +24 -10
- package/dist/commands/project/config.js +1 -1
- package/dist/commands/project/remove.js +3 -2
- package/dist/commands/project/switch.d.ts +1 -2
- package/dist/commands/project/switch.js +28 -34
- package/dist/commands/project/sync.d.ts +13 -0
- package/dist/commands/project/sync.js +210 -0
- package/dist/commands/snippet/list.d.ts +0 -1
- package/dist/commands/snippet/list.js +4 -7
- package/dist/commands/snippet/pull.d.ts +1 -2
- package/dist/commands/snippet/pull.js +6 -10
- package/dist/commands/snippet/push.d.ts +1 -1
- package/dist/commands/snippet/push.js +37 -16
- package/dist/config/project-config.manager.d.ts +3 -1
- package/dist/config/project-config.manager.js +27 -3
- package/dist/help.js +1 -1
- package/dist/lib/api-client.d.ts +14 -0
- package/dist/lib/api-client.js +46 -0
- package/dist/lib/base.d.ts +0 -1
- package/dist/lib/base.js +0 -5
- package/dist/lib/push-command.js +1 -1
- package/dist/lib/wp-client.d.ts +1 -0
- package/dist/lib/wp-client.js +4 -0
- package/dist/types/global-config.generated.d.ts +8 -0
- package/dist/types/project-config.generated.d.ts +0 -4
- package/dist/types/snippet.d.ts +1 -1
- package/dist/utils/{snippet-plugin.d.ts → snippet-format.d.ts} +3 -19
- package/dist/utils/snippet-format.js +57 -0
- package/oclif.manifest.json +28 -43
- package/package.json +6 -1
- package/schemas/global-config.schema.json +8 -0
- package/schemas/project-config.schema.json +0 -6
- package/dist/utils/snippet-plugin-flag.d.ts +0 -3
- package/dist/utils/snippet-plugin-flag.js +0 -8
- package/dist/utils/snippet-plugin.js +0 -232
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopress/cli",
|
|
3
3
|
"description": "CLI tool for syncing WordPress code snippets, plugins, and Composer dependencies via the REST API",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"author": "jean-smaug",
|
|
6
6
|
"bin": {
|
|
7
7
|
"loopress": "bin/run.js",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"@eslint/compat": "2.1.0",
|
|
27
27
|
"@oclif/prettier-config": "^0.2.1",
|
|
28
28
|
"@oclif/test": "^4.1.20",
|
|
29
|
+
"@stryker-mutator/core": "^9.6.1",
|
|
30
|
+
"@stryker-mutator/vitest-runner": "^9.6.1",
|
|
29
31
|
"@types/node": "26.0.1",
|
|
30
32
|
"@types/write-file-atomic": "^4.0.3",
|
|
31
33
|
"@vitest/coverage-v8": "4.1.9",
|
|
@@ -36,6 +38,7 @@
|
|
|
36
38
|
"oclif": "^4.23.24",
|
|
37
39
|
"prettier": "3.9.4",
|
|
38
40
|
"shx": "^0.4.0",
|
|
41
|
+
"ts-node": "10.9.2",
|
|
39
42
|
"tsx": "4.22.4",
|
|
40
43
|
"typescript": "^6.0.3",
|
|
41
44
|
"vitest": "^4.1.9"
|
|
@@ -111,6 +114,8 @@
|
|
|
111
114
|
"posttest": "pnpm run lint",
|
|
112
115
|
"schema:types": "tsx scripts/generate-config-types.ts",
|
|
113
116
|
"test": "vitest run",
|
|
117
|
+
"pretest:mutation": "pnpm run schema:types",
|
|
118
|
+
"test:mutation": "stryker run",
|
|
114
119
|
"version": "oclif readme && git add README.md",
|
|
115
120
|
"format": "prettier . --write"
|
|
116
121
|
}
|
|
@@ -44,6 +44,10 @@
|
|
|
44
44
|
"type": "string",
|
|
45
45
|
"description": "ISO timestamp of when the project was added."
|
|
46
46
|
},
|
|
47
|
+
"apiProjectId": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "Id of the matching project on the Loopress API, once synced via `lps project sync`."
|
|
50
|
+
},
|
|
47
51
|
"environments": {
|
|
48
52
|
"type": "object",
|
|
49
53
|
"description": "Environments for this project, keyed by environment name.",
|
|
@@ -65,6 +69,10 @@
|
|
|
65
69
|
"type": "string",
|
|
66
70
|
"description": "ISO timestamp of when the environment was added."
|
|
67
71
|
},
|
|
72
|
+
"apiEnvironmentId": {
|
|
73
|
+
"type": "string",
|
|
74
|
+
"description": "Id of the matching environment on the Loopress API, once synced via `lps project sync`."
|
|
75
|
+
},
|
|
68
76
|
"name": {
|
|
69
77
|
"type": "string",
|
|
70
78
|
"description": "Environment name (e.g. \"production\", \"staging\")."
|
|
@@ -23,12 +23,6 @@
|
|
|
23
23
|
"type": "string",
|
|
24
24
|
"description": "Project identifier from the global Loopress config. When set, takes precedence over the currently active project in the global config."
|
|
25
25
|
},
|
|
26
|
-
"snippetPlugin": {
|
|
27
|
-
"type": "string",
|
|
28
|
-
"description": "WordPress snippet plugin to use for pull and push commands.",
|
|
29
|
-
"enum": ["wpcode", "code-snippets"],
|
|
30
|
-
"default": "wpcode"
|
|
31
|
-
},
|
|
32
26
|
"plugins": {
|
|
33
27
|
"type": "object",
|
|
34
28
|
"description": "Pinned plugin versions. Keys are WordPress.org plugin slugs, values are version constraints.",
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
export function parseType(raw) {
|
|
2
|
-
const valid = ['css', 'html', 'js', 'php', 'text'];
|
|
3
|
-
const value = String(raw ?? '').toLowerCase();
|
|
4
|
-
return valid.includes(value) ? value : null;
|
|
5
|
-
}
|
|
6
|
-
const VALID_LOCATIONS = new Set(['admin', 'body', 'everywhere', 'footer', 'frontend', 'header', 'once']);
|
|
7
|
-
export function parseLocation(raw) {
|
|
8
|
-
const value = String(raw ?? '').toLowerCase();
|
|
9
|
-
return VALID_LOCATIONS.has(value) ? value : null;
|
|
10
|
-
}
|
|
11
|
-
export function parseInsertMethod(raw) {
|
|
12
|
-
return raw === 'auto' || raw === 'shortcode' ? raw : null;
|
|
13
|
-
}
|
|
14
|
-
// The sensible default placement for a freshly pushed snippet that doesn't specify a location.
|
|
15
|
-
export function defaultLocationForType(type) {
|
|
16
|
-
switch (type) {
|
|
17
|
-
case 'css': {
|
|
18
|
-
return 'header';
|
|
19
|
-
}
|
|
20
|
-
case 'html':
|
|
21
|
-
case 'js':
|
|
22
|
-
case 'text': {
|
|
23
|
-
return 'footer';
|
|
24
|
-
}
|
|
25
|
-
case 'php': {
|
|
26
|
-
return 'everywhere';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function inferTypeFromCode(code) {
|
|
31
|
-
const firstLine = code.trimStart().split('\n')[0].trimStart();
|
|
32
|
-
if (firstLine.startsWith('<?'))
|
|
33
|
-
return 'php';
|
|
34
|
-
if (firstLine.startsWith('<'))
|
|
35
|
-
return 'html';
|
|
36
|
-
return 'php';
|
|
37
|
-
}
|
|
38
|
-
function resolveType(raw, code) {
|
|
39
|
-
return parseType(raw) ?? inferTypeFromCode(code);
|
|
40
|
-
}
|
|
41
|
-
function resolvePriority(raw) {
|
|
42
|
-
const value = Number(raw);
|
|
43
|
-
return Number.isFinite(value) ? value : 10;
|
|
44
|
-
}
|
|
45
|
-
// Snippet files on disk keep the <?php opening tag so they're valid, syntax-highlighted PHP files.
|
|
46
|
-
// Both plugins store just the executable body, so it's stripped before push and restored on pull
|
|
47
|
-
// (see buildSnippetFile in commands/snippet/pull.ts).
|
|
48
|
-
function stripPhpOpeningTag(code) {
|
|
49
|
-
return code.replace(/^<\?php\s*/i, '');
|
|
50
|
-
}
|
|
51
|
-
// The real Code Snippets plugin has no independent "type" field: its REST API only has `scope`,
|
|
52
|
-
// and the snippet type is derived from it (see WPCode_Snippet::get_type_from_scope() upstream).
|
|
53
|
-
// Sending a `type` key (as this adapter used to) is silently ignored by that plugin.
|
|
54
|
-
const CODE_SNIPPETS_SCOPE_TO_LOCATION = {
|
|
55
|
-
admin: 'admin',
|
|
56
|
-
'admin-css': 'admin',
|
|
57
|
-
content: 'everywhere',
|
|
58
|
-
'footer-content': 'footer',
|
|
59
|
-
'front-end': 'frontend',
|
|
60
|
-
global: 'everywhere',
|
|
61
|
-
'head-content': 'header',
|
|
62
|
-
'single-use': 'once',
|
|
63
|
-
'site-css': 'frontend',
|
|
64
|
-
'site-footer-js': 'footer',
|
|
65
|
-
'site-head-js': 'header',
|
|
66
|
-
};
|
|
67
|
-
function typeFromScope(scope) {
|
|
68
|
-
if (scope.endsWith('-css'))
|
|
69
|
-
return 'css';
|
|
70
|
-
if (scope.endsWith('-js'))
|
|
71
|
-
return 'js';
|
|
72
|
-
if (scope.endsWith('content'))
|
|
73
|
-
return 'html';
|
|
74
|
-
return 'php';
|
|
75
|
-
}
|
|
76
|
-
function scopeFromTypeAndLocation(type, location) {
|
|
77
|
-
switch (type) {
|
|
78
|
-
case 'css': {
|
|
79
|
-
if (location === 'frontend')
|
|
80
|
-
return 'site-css';
|
|
81
|
-
if (location === 'admin')
|
|
82
|
-
return 'admin-css';
|
|
83
|
-
throw new Error(`Code Snippets does not support the "${location}" location for CSS snippets. Use one of: frontend, admin.`);
|
|
84
|
-
}
|
|
85
|
-
case 'html': {
|
|
86
|
-
if (location === 'header')
|
|
87
|
-
return 'head-content';
|
|
88
|
-
if (location === 'footer')
|
|
89
|
-
return 'footer-content';
|
|
90
|
-
if (location === 'everywhere')
|
|
91
|
-
return 'content';
|
|
92
|
-
throw new Error(`Code Snippets does not support the "${location}" location for HTML snippets. Use one of: header, footer, everywhere.`);
|
|
93
|
-
}
|
|
94
|
-
case 'js': {
|
|
95
|
-
if (location === 'header')
|
|
96
|
-
return 'site-head-js';
|
|
97
|
-
if (location === 'footer')
|
|
98
|
-
return 'site-footer-js';
|
|
99
|
-
throw new Error(`Code Snippets does not support the "${location}" location for JS snippets. Use one of: header, footer.`);
|
|
100
|
-
}
|
|
101
|
-
case 'php': {
|
|
102
|
-
if (location === 'everywhere')
|
|
103
|
-
return 'global';
|
|
104
|
-
if (location === 'frontend')
|
|
105
|
-
return 'front-end';
|
|
106
|
-
if (location === 'admin')
|
|
107
|
-
return 'admin';
|
|
108
|
-
if (location === 'once')
|
|
109
|
-
return 'single-use';
|
|
110
|
-
throw new Error(`Code Snippets does not support the "${location}" location for PHP snippets. Use one of: everywhere, frontend, admin, once.`);
|
|
111
|
-
}
|
|
112
|
-
case 'text': {
|
|
113
|
-
throw new Error('Code Snippets has no "text" snippet type. Change the sidecar "type", or push this snippet to "wpcode" instead.');
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
class CodeSnippetsPlugin {
|
|
118
|
-
endpointPath() {
|
|
119
|
-
return 'code-snippets/v1/snippets';
|
|
120
|
-
}
|
|
121
|
-
fromRemote(data) {
|
|
122
|
-
const scope = String(data.scope ?? 'global');
|
|
123
|
-
const type = typeFromScope(scope);
|
|
124
|
-
return {
|
|
125
|
-
active: Boolean(data.active),
|
|
126
|
-
code: String(data.code ?? ''),
|
|
127
|
-
description: String(data.desc ?? ''),
|
|
128
|
-
id: Number(data.id),
|
|
129
|
-
insertMethod: 'auto',
|
|
130
|
-
location: CODE_SNIPPETS_SCOPE_TO_LOCATION[scope] ?? defaultLocationForType(type),
|
|
131
|
-
name: String(data.name ?? ''),
|
|
132
|
-
priority: resolvePriority(data.priority),
|
|
133
|
-
shortcodeAttributes: [],
|
|
134
|
-
tags: Array.isArray(data.tags) ? data.tags : [],
|
|
135
|
-
type,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
toPayload({ active, code, location, name, path, priority, tags, type }) {
|
|
139
|
-
return {
|
|
140
|
-
active,
|
|
141
|
-
code: stripPhpOpeningTag(code),
|
|
142
|
-
desc: `Imported from ${path}`,
|
|
143
|
-
name,
|
|
144
|
-
priority,
|
|
145
|
-
scope: scopeFromTypeAndLocation(type, location),
|
|
146
|
-
tags,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
// WPCode taxonomy term slugs (see wpcode_register_taxonomies() and the auto-insert location
|
|
151
|
-
// classes upstream). 'everywhere' | 'frontend_only' | 'admin_only' | 'on_demand' only apply to
|
|
152
|
-
// PHP snippets; 'site_wide_header' | 'site_wide_body' | 'site_wide_footer' apply to any type.
|
|
153
|
-
const WPCODE_PHP_ONLY_LOCATIONS = {
|
|
154
|
-
admin: 'admin_only',
|
|
155
|
-
everywhere: 'everywhere',
|
|
156
|
-
frontend: 'frontend_only',
|
|
157
|
-
once: 'on_demand',
|
|
158
|
-
};
|
|
159
|
-
const WPCODE_UNIVERSAL_LOCATIONS = {
|
|
160
|
-
body: 'site_wide_body',
|
|
161
|
-
footer: 'site_wide_footer',
|
|
162
|
-
header: 'site_wide_header',
|
|
163
|
-
};
|
|
164
|
-
const WPCODE_LOCATION_TO_CANONICAL = {
|
|
165
|
-
'admin_only': 'admin',
|
|
166
|
-
everywhere: 'everywhere',
|
|
167
|
-
'frontend_only': 'frontend',
|
|
168
|
-
'on_demand': 'once',
|
|
169
|
-
'site_wide_body': 'body',
|
|
170
|
-
'site_wide_footer': 'footer',
|
|
171
|
-
'site_wide_header': 'header',
|
|
172
|
-
};
|
|
173
|
-
function wpcodeLocationTerm(type, location) {
|
|
174
|
-
const universal = WPCODE_UNIVERSAL_LOCATIONS[location];
|
|
175
|
-
if (universal)
|
|
176
|
-
return universal;
|
|
177
|
-
if (type === 'php') {
|
|
178
|
-
const phpOnly = WPCODE_PHP_ONLY_LOCATIONS[location];
|
|
179
|
-
if (phpOnly)
|
|
180
|
-
return phpOnly;
|
|
181
|
-
}
|
|
182
|
-
const allowed = type === 'php' ? 'header, body, footer, everywhere, frontend, admin, once' : 'header, body, footer';
|
|
183
|
-
throw new Error(`WPCode does not support the "${location}" location for ${type} snippets. Use one of: ${allowed}.`);
|
|
184
|
-
}
|
|
185
|
-
class WPCodePlugin {
|
|
186
|
-
endpointPath() {
|
|
187
|
-
return 'loopress/v1/wpcode/snippets';
|
|
188
|
-
}
|
|
189
|
-
fromRemote(data) {
|
|
190
|
-
const type = resolveType(data.type, String(data.code ?? ''));
|
|
191
|
-
return {
|
|
192
|
-
active: Boolean(data.active),
|
|
193
|
-
code: String(data.code ?? ''),
|
|
194
|
-
description: String(data.note ?? ''),
|
|
195
|
-
id: Number(data.id),
|
|
196
|
-
insertMethod: data.insert_method === 'shortcode' ? 'shortcode' : 'auto',
|
|
197
|
-
location: WPCODE_LOCATION_TO_CANONICAL[String(data.location)] ?? defaultLocationForType(type),
|
|
198
|
-
name: String(data.title ?? ''),
|
|
199
|
-
priority: resolvePriority(data.priority),
|
|
200
|
-
shortcodeAttributes: Array.isArray(data.shortcode_attributes) ? data.shortcode_attributes.map(String) : [],
|
|
201
|
-
tags: Array.isArray(data.tags) ? data.tags : [],
|
|
202
|
-
type,
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
toPayload({ active, code, insertMethod, location, name, path, priority, shortcodeAttributes, tags, type, }) {
|
|
206
|
-
const placement = insertMethod === 'shortcode'
|
|
207
|
-
? { 'shortcode_attributes': shortcodeAttributes }
|
|
208
|
-
: { location: wpcodeLocationTerm(type, location) };
|
|
209
|
-
return {
|
|
210
|
-
active,
|
|
211
|
-
code: stripPhpOpeningTag(code),
|
|
212
|
-
note: `Imported from ${path}`,
|
|
213
|
-
priority,
|
|
214
|
-
tags,
|
|
215
|
-
title: name,
|
|
216
|
-
type,
|
|
217
|
-
...placement,
|
|
218
|
-
'insert_method': insertMethod,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
export function getSnippetPlugin(name) {
|
|
223
|
-
switch (name) {
|
|
224
|
-
case 'wpcode': {
|
|
225
|
-
return new WPCodePlugin();
|
|
226
|
-
}
|
|
227
|
-
case 'code-snippets':
|
|
228
|
-
default: {
|
|
229
|
-
return new CodeSnippetsPlugin();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|