@wp-operations/wp-ops 0.3.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.
Files changed (117) hide show
  1. package/package.json +6 -2
  2. package/src/commands/platform.js +16 -2
  3. package/src/main.js +9 -3
  4. package/wp-operations/CHANGELOG.md +14 -0
  5. package/wp-operations/README.md +39 -0
  6. package/wp-operations/agents/builder/AGENT.md +15 -0
  7. package/wp-operations/assets/admin.css +631 -0
  8. package/wp-operations/assets/admin.js +614 -0
  9. package/wp-operations/assets/app/app.css +1 -0
  10. package/wp-operations/assets/app/app.js +70 -0
  11. package/wp-operations/assets/app/fonts/inter-medium.woff +0 -0
  12. package/wp-operations/assets/app/fonts/inter-regular.woff +0 -0
  13. package/wp-operations/assets/app/fonts/inter-semibold.woff +0 -0
  14. package/wp-operations/assets/app/login.css +42 -0
  15. package/wp-operations/assets/brand/icon.svg +20 -0
  16. package/wp-operations/assets/brand/mark.svg +19 -0
  17. package/wp-operations/assets/editors/audiobook.css +311 -0
  18. package/wp-operations/assets/editors/audiofile.css +286 -0
  19. package/wp-operations/assets/editors/course.css +701 -0
  20. package/wp-operations/assets/editors/course.js +698 -0
  21. package/wp-operations/assets/editors/faq.css +258 -0
  22. package/wp-operations/assets/editors/faq.js +196 -0
  23. package/wp-operations/assets/editors/interactive.css +220 -0
  24. package/wp-operations/assets/editors/interactive.js +378 -0
  25. package/wp-operations/assets/editors/media-sources.css +3 -0
  26. package/wp-operations/assets/editors/media-sources.js +40 -0
  27. package/wp-operations/assets/editors/open-media.css +114 -0
  28. package/wp-operations/assets/editors/open-media.js +182 -0
  29. package/wp-operations/assets/editors/thumbnails.css +335 -0
  30. package/wp-operations/assets/editors/thumbnails.js +447 -0
  31. package/wp-operations/assets/editors/translator.css +818 -0
  32. package/wp-operations/functions.php +24 -0
  33. package/wp-operations/index.php +14 -0
  34. package/wp-operations/platform.json +1836 -0
  35. package/wp-operations/skills/ai-development-guardrails/SKILL.md +49 -0
  36. package/wp-operations/skills/gutenberg-reference/SKILL.md +45 -0
  37. package/wp-operations/skills/js-tooling-for-themes/SKILL.md +51 -0
  38. package/wp-operations/skills/tailwind-for-wp/SKILL.md +62 -0
  39. package/wp-operations/skills/wp-clean-classic-themes/SKILL.md +112 -0
  40. package/wp-operations/skills/wp-psr4-plugins/SKILL.md +2043 -0
  41. package/wp-operations/skills/wp-security/SKILL.md +90 -0
  42. package/wp-operations/src/Admin.php +78 -0
  43. package/wp-operations/src/App/Access.php +57 -0
  44. package/wp-operations/src/App/Admin.php +442 -0
  45. package/wp-operations/src/App/App.php +157 -0
  46. package/wp-operations/src/App/Apps.php +379 -0
  47. package/wp-operations/src/App/Bundle.php +111 -0
  48. package/wp-operations/src/App/Contents.php +676 -0
  49. package/wp-operations/src/App/Engine.php +554 -0
  50. package/wp-operations/src/App/Github.php +308 -0
  51. package/wp-operations/src/App/Module.php +23 -0
  52. package/wp-operations/src/App/Ops.php +470 -0
  53. package/wp-operations/src/App/Packages.php +289 -0
  54. package/wp-operations/src/App/Rest.php +539 -0
  55. package/wp-operations/src/App/Sandboxes.php +206 -0
  56. package/wp-operations/src/App/Store.php +104 -0
  57. package/wp-operations/src/App/Usage.php +268 -0
  58. package/wp-operations/src/Config.php +249 -0
  59. package/wp-operations/src/Content/Editor.php +223 -0
  60. package/wp-operations/src/Content/Fields.php +681 -0
  61. package/wp-operations/src/Content/Scoring.php +253 -0
  62. package/wp-operations/src/Content/Structure.php +293 -0
  63. package/wp-operations/src/Content/Types.php +150 -0
  64. package/wp-operations/src/Content/Uploads.php +50 -0
  65. package/wp-operations/src/Editors/AudiobookAuthor.php +61 -0
  66. package/wp-operations/src/Editors/AudiobookChapters.php +632 -0
  67. package/wp-operations/src/Editors/AudiobookCover.php +235 -0
  68. package/wp-operations/src/Editors/Audiofile.php +462 -0
  69. package/wp-operations/src/Editors/Course.php +784 -0
  70. package/wp-operations/src/Editors/Ebook.php +242 -0
  71. package/wp-operations/src/Editors/Editors.php +44 -0
  72. package/wp-operations/src/Editors/Faq.php +237 -0
  73. package/wp-operations/src/Editors/Files.php +139 -0
  74. package/wp-operations/src/Editors/Interactive/Builder.php +103 -0
  75. package/wp-operations/src/Editors/Interactive/Card.php +76 -0
  76. package/wp-operations/src/Editors/Interactive/Editor.php +42 -0
  77. package/wp-operations/src/Editors/Interactive/Field.php +272 -0
  78. package/wp-operations/src/Editors/Interactive/Map.php +84 -0
  79. package/wp-operations/src/Editors/Interactive/Models.php +227 -0
  80. package/wp-operations/src/Editors/Interactive/Report.php +59 -0
  81. package/wp-operations/src/Editors/Interactive/Save.php +323 -0
  82. package/wp-operations/src/Editors/Interactive/Scoring.php +244 -0
  83. package/wp-operations/src/Editors/Interactive/Structure.php +195 -0
  84. package/wp-operations/src/Editors/Legal.php +235 -0
  85. package/wp-operations/src/Editors/OpenMedia.php +140 -0
  86. package/wp-operations/src/Editors/OriginalTitle.php +112 -0
  87. package/wp-operations/src/Editors/Sources.php +28 -0
  88. package/wp-operations/src/Editors/Thumbnails/Admin.php +306 -0
  89. package/wp-operations/src/Editors/Thumbnails/Ajax.php +163 -0
  90. package/wp-operations/src/Editors/Thumbnails/Box.php +188 -0
  91. package/wp-operations/src/Editors/Thumbnails/Storage.php +228 -0
  92. package/wp-operations/src/Editors/Translator/Admin.php +913 -0
  93. package/wp-operations/src/Editors/Translator/Api.php +63 -0
  94. package/wp-operations/src/Editors/Translator/Bar.php +83 -0
  95. package/wp-operations/src/Editors/Translator/Fields.php +273 -0
  96. package/wp-operations/src/Editors/Translator/Storage.php +131 -0
  97. package/wp-operations/src/Editors/Translator/Thumbnail.php +215 -0
  98. package/wp-operations/src/Identity.php +104 -0
  99. package/wp-operations/src/Languages.php +45 -0
  100. package/wp-operations/src/Lockdown.php +85 -0
  101. package/wp-operations/src/Modules/Apps/Admin.php +472 -0
  102. package/wp-operations/src/Modules/Apps/Api.php +193 -0
  103. package/wp-operations/src/Modules/Apps/Apps.php +279 -0
  104. package/wp-operations/src/Modules/Apps/Formatters.php +478 -0
  105. package/wp-operations/src/Modules/Apps/Schemes.php +248 -0
  106. package/wp-operations/src/Modules/Apps/Table.php +101 -0
  107. package/wp-operations/src/Modules/Thumbnails.php +68 -0
  108. package/wp-operations/src/Modules/Translations.php +133 -0
  109. package/wp-operations/src/Platform.php +59 -0
  110. package/wp-operations/src/Setup.php +273 -0
  111. package/wp-operations/src/Status.php +99 -0
  112. package/wp-operations/src/Storage/Client.php +168 -0
  113. package/wp-operations/src/Storage/Offload.php +120 -0
  114. package/wp-operations/src/Storage/Settings.php +166 -0
  115. package/wp-operations/src/Storage/Storage.php +35 -0
  116. package/wp-operations/src/Updates.php +151 -0
  117. package/wp-operations/style.css +11 -0
@@ -0,0 +1,289 @@
1
+ <?php
2
+ namespace Platform\App;
3
+
4
+ use Platform\Modules\Apps\Apps as Registry;
5
+
6
+ defined( 'ABSPATH' ) || exit;
7
+
8
+ final class Packages {
9
+
10
+ const TYPE = 'psr4-plugin';
11
+ const APP_TYPE = 'wp-app';
12
+ const ACTIONS = [ 'add', 'remove', 'update', 'delete' ];
13
+
14
+ public static function scan( bool $fresh = false ) {
15
+ $settings = Ops::settings();
16
+ $result = [ 'connected' => '' !== $settings['repo'], 'ready' => Github::ready(), 'branch' => $settings['branch'], 'folder' => $settings['packages'], 'packages' => [], 'apps' => [], 'error' => '' ];
17
+
18
+ if ( ! $result['ready'] ) {
19
+ return $result;
20
+ }
21
+
22
+ $tree = Github::tree();
23
+
24
+ if ( is_wp_error( $tree ) ) {
25
+ $result['error'] = $tree->get_error_message();
26
+
27
+ return $result;
28
+ }
29
+
30
+ $key = 'platform_ops_packages_' . md5( $tree['sha'] . wp_json_encode( $settings['kinds'] ) . $settings['packages'] );
31
+ $cached = $fresh ? false : get_transient( $key );
32
+
33
+ if ( is_array( $cached ) ) {
34
+ return $cached;
35
+ }
36
+
37
+ $result['branch'] = $tree['branch'];
38
+ $files = [];
39
+
40
+ foreach ( $tree['files'] as $file ) {
41
+ $files[ $file['path'] ] = $file;
42
+ }
43
+
44
+ $prefix = $settings['packages'] . '/';
45
+
46
+ foreach ( $files as $path => $file ) {
47
+ if ( 0 !== strpos( $path, $prefix ) || 'composer.json' !== basename( $path ) ) {
48
+ continue;
49
+ }
50
+
51
+ $depth = substr_count( substr( $path, strlen( $prefix ) ), '/' );
52
+
53
+ if ( $depth < 1 || $depth > 2 || false !== strpos( $path, '/vendor/' ) || false !== strpos( $path, '/node_modules/' ) ) {
54
+ continue;
55
+ }
56
+
57
+ $data = Github::json( $path, [ $file ] );
58
+
59
+ if ( ! is_array( $data ) || '' === (string) ( $data['name'] ?? '' ) ) {
60
+ continue;
61
+ }
62
+
63
+ $type = (string) ( $data['type'] ?? 'library' );
64
+ $warnings = self::TYPE === $type ? [] : [ sprintf( 'type is "%s", expected "%s"', $type, self::TYPE ) ];
65
+
66
+ $result['packages'][ (string) $data['name'] ] = [
67
+ 'name' => (string) $data['name'],
68
+ 'version' => (string) ( $data['version'] ?? '' ),
69
+ 'description' => (string) ( $data['description'] ?? '' ),
70
+ 'type' => $type,
71
+ 'path' => dirname( $path ),
72
+ 'namespace' => (string) ( array_keys( (array) ( $data['autoload']['psr-4'] ?? [] ) )[0] ?? '' ),
73
+ 'php' => (string) ( $data['require']['php'] ?? '' ),
74
+ 'warnings' => $warnings,
75
+ 'apps' => [],
76
+ ];
77
+ }
78
+
79
+ $apps = [];
80
+
81
+ foreach ( Registry::all() as $app ) {
82
+ $apps[ Ops::app_path( $app ) ] = $app;
83
+ }
84
+
85
+ foreach ( $settings['kinds'] as $kind ) {
86
+ $kprefix = $kind['folder'] . '/';
87
+
88
+ foreach ( $files as $path => $file ) {
89
+ if ( 0 !== strpos( $path, $kprefix ) || 1 !== substr_count( substr( $path, strlen( $kprefix ) ), '/' ) || 'composer.json' !== basename( $path ) ) {
90
+ continue;
91
+ }
92
+
93
+ $data = Github::json( $path, [ $file ] );
94
+
95
+ if ( ! is_array( $data ) ) {
96
+ continue;
97
+ }
98
+
99
+ $dir = dirname( $path );
100
+ $lock = isset( $files[ $dir . '/composer.lock' ] ) ? Github::json( $dir . '/composer.lock', [ $files[ $dir . '/composer.lock' ] ] ) : null;
101
+ $installed = [];
102
+
103
+ foreach ( (array) ( is_array( $lock ) ? ( $lock['packages'] ?? [] ) : [] ) as $package ) {
104
+ $installed[ (string) ( $package['name'] ?? '' ) ] = (string) ( $package['version'] ?? '' );
105
+ }
106
+
107
+ $registered = $apps[ $dir ] ?? null;
108
+ $type = (string) ( $data['type'] ?? '' );
109
+
110
+ $result['apps'][ $dir ] = [
111
+ 'path' => $dir,
112
+ 'slug' => basename( $dir ),
113
+ 'kind' => $kind['key'],
114
+ 'label' => $kind['label'],
115
+ 'type' => $type,
116
+ 'app_id' => $registered ? (int) $registered['id'] : 0,
117
+ 'name' => $registered ? (string) $registered['name'] : basename( $dir ),
118
+ 'locked' => is_array( $lock ),
119
+ 'warnings' => self::APP_TYPE === $type ? [] : [ sprintf( 'type is "%s", expected "%s"', $type ?: 'none', self::APP_TYPE ) ],
120
+ ];
121
+
122
+ foreach ( (array) ( $data['require'] ?? [] ) as $name => $constraint ) {
123
+ if ( isset( $result['packages'][ $name ] ) ) {
124
+ $result['packages'][ $name ]['apps'][] = [ 'path' => $dir, 'constraint' => (string) $constraint, 'installed' => (string) ( $installed[ $name ] ?? '' ) ];
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ $result['packages'] = array_values( $result['packages'] );
131
+ $result['apps'] = array_values( $result['apps'] );
132
+
133
+ usort( $result['packages'], static fn( array $a, array $b ): int => strcmp( $a['name'], $b['name'] ) );
134
+ usort( $result['apps'], static fn( array $a, array $b ): int => strcmp( $a['path'], $b['path'] ) );
135
+
136
+ set_transient( $key, $result, 10 * MINUTE_IN_SECONDS );
137
+
138
+ return $result;
139
+ }
140
+
141
+ private static function relative( string $from, string $to ): string {
142
+ $from = explode( '/', trim( $from, '/' ) );
143
+ $to = explode( '/', trim( $to, '/' ) );
144
+
145
+ while ( $from && $to && $from[0] === $to[0] ) {
146
+ array_shift( $from );
147
+ array_shift( $to );
148
+ }
149
+
150
+ return str_repeat( '../', count( $from ) ) . implode( '/', $to );
151
+ }
152
+
153
+ private static function encode( array $data ): string {
154
+ return str_replace( '\/', '/', (string) wp_json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ) . "\n";
155
+ }
156
+
157
+ public static function run( string $action, array $names, array $paths, string $constraint = '*' ) {
158
+ $action = sanitize_key( $action );
159
+ $names = array_values( array_unique( array_filter( array_map( 'strval', $names ), static fn( string $n ): bool => (bool) preg_match( '#^[a-z0-9_.-]+/[a-z0-9_.-]+$#', $n ) ) ) );
160
+ $paths = array_values( array_unique( array_filter( array_map( [ Ops::class, 'folder' ], array_map( 'strval', $paths ) ), 'strlen' ) ) );
161
+ $constraint = preg_replace( '/[^A-Za-z0-9.*@^~|<>=, -]/', '', $constraint ) ?: '*';
162
+
163
+ if ( ! in_array( $action, self::ACTIONS, true ) ) {
164
+ return new \WP_Error( 'action', 'Unknown action.', [ 'status' => 400 ] );
165
+ }
166
+
167
+ if ( ! $names ) {
168
+ return new \WP_Error( 'packages', 'Select at least one plugin.', [ 'status' => 400 ] );
169
+ }
170
+
171
+ $scan = self::scan( true );
172
+
173
+ if ( ! $scan['ready'] ) {
174
+ return new \WP_Error( 'repo', 'Connect the platform repository in Settings → Operations first.', [ 'status' => 409 ] );
175
+ }
176
+
177
+ if ( '' !== $scan['error'] ) {
178
+ return new \WP_Error( 'repo', $scan['error'], [ 'status' => 502 ] );
179
+ }
180
+
181
+ $packages = array_column( $scan['packages'], null, 'name' );
182
+ $apps = array_column( $scan['apps'], null, 'path' );
183
+
184
+ foreach ( $names as $name ) {
185
+ if ( ! isset( $packages[ $name ] ) ) {
186
+ return new \WP_Error( 'packages', sprintf( '%s is not in %s/.', $name, $scan['folder'] ), [ 'status' => 404 ] );
187
+ }
188
+ }
189
+
190
+ if ( 'delete' === $action ) {
191
+ $changes = [];
192
+ $tree = Github::tree();
193
+
194
+ foreach ( $names as $name ) {
195
+ if ( $packages[ $name ]['apps'] ) {
196
+ return new \WP_Error( 'in_use', sprintf( '%s is still installed in %d apps. Uninstall it from them first.', $name, count( $packages[ $name ]['apps'] ) ), [ 'status' => 409 ] );
197
+ }
198
+
199
+ foreach ( $tree['files'] as $file ) {
200
+ if ( 0 === strpos( $file['path'], $packages[ $name ]['path'] . '/' ) ) {
201
+ $changes[ $file['path'] ] = null;
202
+ }
203
+ }
204
+ }
205
+
206
+ $commit = Github::commit( sprintf( 'plugins: delete %s', implode( ', ', $names ) ), $changes );
207
+
208
+ return is_wp_error( $commit ) ? $commit : [ 'commit' => $commit, 'workflow' => null ];
209
+ }
210
+
211
+ if ( 'update' === $action && ! $paths ) {
212
+ foreach ( $names as $name ) {
213
+ $paths = array_merge( $paths, array_column( $packages[ $name ]['apps'], 'path' ) );
214
+ }
215
+
216
+ $paths = array_values( array_unique( $paths ) );
217
+ }
218
+
219
+ if ( ! $paths ) {
220
+ return new \WP_Error( 'apps', 'Select at least one app.', [ 'status' => 400 ] );
221
+ }
222
+
223
+ foreach ( $paths as $path ) {
224
+ if ( ! isset( $apps[ $path ] ) ) {
225
+ return new \WP_Error( 'apps', sprintf( '%s has no composer.json.', $path ), [ 'status' => 404 ] );
226
+ }
227
+ }
228
+
229
+ $commit = null;
230
+
231
+ if ( 'update' !== $action ) {
232
+ $changes = [];
233
+
234
+ foreach ( $paths as $path ) {
235
+ $file = Github::read( $path . '/composer.json' );
236
+
237
+ if ( is_wp_error( $file ) ) {
238
+ return $file;
239
+ }
240
+
241
+ $data = json_decode( $file['content'], true );
242
+
243
+ if ( ! is_array( $data ) ) {
244
+ return new \WP_Error( 'json', sprintf( '%s/composer.json is not valid JSON.', $path ), [ 'status' => 422 ] );
245
+ }
246
+
247
+ $before = $data;
248
+
249
+ foreach ( $names as $name ) {
250
+ if ( 'add' === $action ) {
251
+ $data['require'] = (array) ( $data['require'] ?? [] );
252
+ $data['require'][ $name ] = $constraint;
253
+ $repository = self::relative( $path, dirname( $packages[ $name ]['path'] ) ) . '/*';
254
+ $urls = array_column( array_filter( (array) ( $data['repositories'] ?? [] ), 'is_array' ), 'url' );
255
+
256
+ if ( ! in_array( $repository, $urls, true ) ) {
257
+ $data['repositories'] = array_values( (array) ( $data['repositories'] ?? [] ) );
258
+ $position = count( array_filter( $data['repositories'], static fn( $r ): bool => is_array( $r ) && 'path' === ( $r['type'] ?? '' ) ) );
259
+ array_splice( $data['repositories'], $position, 0, [ [ 'type' => 'path', 'url' => $repository, 'options' => [ 'symlink' => false ] ] ] );
260
+ }
261
+ } else {
262
+ unset( $data['require'][ $name ] );
263
+ }
264
+ }
265
+
266
+ if ( $data !== $before ) {
267
+ $changes[ $path . '/composer.json' ] = self::encode( $data );
268
+ }
269
+ }
270
+
271
+ if ( ! $changes ) {
272
+ return new \WP_Error( 'nothing', 'Nothing to change: the selected apps already match.', [ 'status' => 409 ] );
273
+ }
274
+
275
+ $commit = Github::commit( sprintf( 'plugins: %s %s %s %d app%s', $action, implode( ', ', $names ), 'add' === $action ? 'to' : 'from', count( $changes ), 1 === count( $changes ) ? '' : 's' ), $changes );
276
+
277
+ if ( is_wp_error( $commit ) ) {
278
+ return $commit;
279
+ }
280
+ }
281
+
282
+ $workflow = Github::dispatch( Ops::settings()['workflows']['composer'], [ 'action' => $action, 'apps' => implode( ',', $paths ), 'packages' => implode( ' ', $names ) ] );
283
+
284
+ return [
285
+ 'commit' => $commit,
286
+ 'workflow' => is_wp_error( $workflow ) ? [ 'error' => $workflow->get_error_message() ] : $workflow,
287
+ ];
288
+ }
289
+ }