@wp-operations/wp-ops 0.5.5 → 0.7.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 CHANGED
@@ -1,3 +1,5 @@
1
+ <p align="center"><img src="../../theme/assets/brand/icon.svg" alt="wp-operations" width="120"></p>
2
+
1
3
  # @wp-operations/wp-ops
2
4
 
3
5
  The wp-operations tool. One install gives you all four commands:
@@ -31,7 +33,8 @@ wp-ops doctor
31
33
 
32
34
  | Command | What it does |
33
35
  |---|---|
34
- | `init [dir]` | Creates the platform repository: the platform theme in `wp-operations/`, `platform.json`, `.github/platform.json`, the app manifests, `packages/`, the app folders, `.github/workflows/composer.yml` and `.gitignore`, then runs `git init`. Never overwrites a file. |
36
+ | `init [dir]` | Asks for each section of the project's `platform.json` (name, author, website, languages and default language, content types and their fields, taxonomies, modules, brand color, app categories) and writes it. Start from the default content types or from empty. Then creates the platform theme in `wp-operations/`, `.github/platform.json`, the app manifests, `packages/`, the app folders, the workflows and `.gitignore`, and runs `git init`. `--yes` takes the default `platform.json`; `--template=empty` starts with no content types. Never overwrites a file. |
37
+ | `github <owner/name>` | Creates the GitHub repository if it does not exist (private unless `--public`), sets it as `origin`, commits and pushes `main`. `init` asks for it at the end (or `--github=owner/name`). Uses `GITHUB_TOKEN`, or the token git already uses for github.com. |
35
38
  | `start` | Runs the platform (`wp-operations/`) locally. Site data stays in `.local/` (gitignored). `wp-ops start <dir>` runs one app instead. |
36
39
  | `update` | Replaces `wp-operations/` with the platform shipped in your wp-ops version. Update wp-ops first (`npm install -g @wp-operations/wp-ops`), then run it and commit. |
37
40
  | `new app <kind> <slug>` | Creates the app (composer type `wp-app`) and adds it to the kind's manifest. |
@@ -58,6 +61,7 @@ Repository secrets:
58
61
  |---|---|
59
62
  | `SSH_PRIVATE_KEY` | The deploy key. |
60
63
  | `SERVERS` | `label:ip:user label2:ip2:user2`, where each label is a `server` value in the manifests. |
64
+ | `PLATFORM_GITHUB_TOKEN` | The token the platform uses for this repository. `deploy-platform.yml` writes it into the server's `wp-config.php` and sets the platform's repository and branch (Settings → Operations) to this repository, so they are never filled in by hand. |
61
65
 
62
66
  ## Sandbox
63
67
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-operations/wp-ops",
3
- "version": "0.5.5",
3
+ "version": "0.7.0",
4
4
  "description": "The wp-operations tool. One install gives the platform and wp-ops, wp-app, wp-ide and wp-code.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -0,0 +1,74 @@
1
+ import { execFileSync, spawnSync } from 'child_process';
2
+ import pc from 'picocolors';
3
+ import { UsageError } from '../args.js';
4
+
5
+ const API = 'https://api.github.com';
6
+
7
+ export function parseRepo(value) {
8
+ const match = String(value || '').trim().replace(/\.git$/, '').match(/(?:github\.com[/:])?([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/);
9
+ return match ? { owner: match[1], name: match[2] } : null;
10
+ }
11
+
12
+ /**
13
+ * GITHUB_TOKEN / GH_TOKEN, else the token git already uses for github.com.
14
+ */
15
+ export function findToken() {
16
+ const env = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
17
+ if (env) return env.trim();
18
+ const result = spawnSync('git', ['credential', 'fill'], { input: 'protocol=https\nhost=github.com\n\n', encoding: 'utf8', env: { ...process.env, GIT_TERMINAL_PROMPT: '0' } });
19
+ return (result.stdout || '').match(/^password=(.+)$/m)?.[1]?.trim() || '';
20
+ }
21
+
22
+ async function api(token, method, path, body) {
23
+ const response = await fetch(API + path, {
24
+ method,
25
+ headers: { Authorization: `Bearer ${token}`, Accept: 'application/vnd.github+json', 'User-Agent': 'wp-ops', ...(body ? { 'Content-Type': 'application/json' } : {}) },
26
+ body: body ? JSON.stringify(body) : undefined,
27
+ });
28
+ const data = await response.json().catch(() => ({}));
29
+ return { status: response.status, data };
30
+ }
31
+
32
+ /**
33
+ * Creates the GitHub repository when it does not exist, sets it as origin,
34
+ * commits everything and pushes main.
35
+ */
36
+ export async function connectGithub({ root, repo, isPrivate = true, token = findToken(), log = console.log }) {
37
+ const target = parseRepo(repo);
38
+ if (!target) throw new UsageError(`"${repo}" is not a GitHub repository. Use owner/name.`);
39
+ if (!token) throw new UsageError('No GitHub token found. Sign in to GitHub with git once, or set GITHUB_TOKEN, then run: wp-ops github owner/name');
40
+
41
+ const user = await api(token, 'GET', '/user');
42
+ if (user.status !== 200) throw new UsageError(`GitHub did not accept the token (${user.status}).`);
43
+
44
+ const existing = await api(token, 'GET', `/repos/${target.owner}/${target.name}`);
45
+ if (existing.status === 200) {
46
+ log(` ${pc.green('✓')} github.com/${target.owner}/${target.name} exists`);
47
+ } else {
48
+ const path = user.data.login?.toLowerCase() === target.owner.toLowerCase() ? '/user/repos' : `/orgs/${target.owner}/repos`;
49
+ const created = await api(token, 'POST', path, { name: target.name, private: isPrivate, auto_init: false });
50
+ if (created.status !== 201) throw new UsageError(`Could not create ${target.owner}/${target.name}: ${created.data.message || created.status}`);
51
+ log(` ${pc.green('+')} github.com/${target.owner}/${target.name} (${isPrivate ? 'private' : 'public'})`);
52
+ }
53
+
54
+ const url = `https://github.com/${target.owner}/${target.name}.git`;
55
+ const git = (...args) => execFileSync('git', args, { cwd: root, stdio: 'pipe', encoding: 'utf8' });
56
+ const remote = spawnSync('git', ['remote', 'get-url', 'origin'], { cwd: root, encoding: 'utf8' });
57
+ if (remote.status !== 0) git('remote', 'add', 'origin', url);
58
+ else if (remote.stdout.trim() !== url) git('remote', 'set-url', 'origin', url);
59
+
60
+ git('add', '-A');
61
+ if (spawnSync('git', ['diff', '--cached', '--quiet'], { cwd: root }).status !== 0) {
62
+ git('commit', '-m', 'Platform repository (wp-ops init)');
63
+ }
64
+ const push = spawnSync('git', ['push', '-u', 'origin', 'main'], { cwd: root, encoding: 'utf8' });
65
+ if (push.status !== 0) throw new UsageError(`git push failed:\n${push.stderr}`);
66
+ log(` ${pc.green('✓')} pushed main to origin`);
67
+ log(`\n Add these secrets once (Settings → Secrets and variables → Actions):`);
68
+ log(` ${pc.bold(`https://github.com/${target.owner}/${target.name}/settings/secrets/actions`)}`);
69
+ log(' SSH_PRIVATE_KEY the deploy key');
70
+ log(' SERVERS label:ip:user label2:ip2:user2');
71
+ log(' PLATFORM_GITHUB_TOKEN the token the platform uses for this repository');
72
+ log(pc.dim(' The deploy sets the platform\'s GitHub settings (repository, branch, token) itself.'));
73
+ return target;
74
+ }
@@ -4,6 +4,7 @@ import { execFileSync, spawnSync } from 'child_process';
4
4
  import { fileURLToPath } from 'url';
5
5
  import pc from 'picocolors';
6
6
  import { ide } from '../deps.js';
7
+ import { buildPlatformJson } from './setup.js';
7
8
  import { UsageError } from '../args.js';
8
9
  import {
9
10
  APP_FUNCTIONS,
@@ -48,7 +49,7 @@ export async function platformRoot(startDir = process.cwd()) {
48
49
  }
49
50
  }
50
51
 
51
- export async function init({ dir = process.cwd(), platform, version, log = console.log }) {
52
+ export async function init({ dir = process.cwd(), platform, version, answers = null, log = console.log }) {
52
53
  const { DEFAULT_KINDS, LAYOUT_FILE, encodeJson, layoutJson } = await ide();
53
54
  const root = path.resolve(dir);
54
55
  fs.mkdirSync(root, { recursive: true });
@@ -85,8 +86,9 @@ export async function init({ dir = process.cwd(), platform, version, log = conso
85
86
  if (!fs.existsSync(file)) {
86
87
  throw new UsageError(`--platform: ${file} does not exist.`);
87
88
  }
88
- JSON.parse(fs.readFileSync(file, 'utf8').replace(/^/, ''));
89
- writeNew(path.join(root, 'platform.json'), fs.readFileSync(file), created);
89
+ const base = JSON.parse(fs.readFileSync(file, 'utf8').replace(/^/, ''));
90
+ const config = answers ? encodeJson(buildPlatformJson(base, answers)) : fs.readFileSync(file);
91
+ if (writeNew(path.join(root, 'platform.json'), config, created)) syncPlatformJson(root);
90
92
  }
91
93
 
92
94
  let gitInit = false;
@@ -119,6 +121,18 @@ export function bundledPlatform() {
119
121
 
120
122
  export const PLATFORM_DIR = 'wp-operations';
121
123
 
124
+ /**
125
+ * The repository's platform.json is the one the platform runs with: it is
126
+ * copied into wp-operations/ (deploy-platform.yml does the same on deploy).
127
+ */
128
+ function syncPlatformJson(root) {
129
+ const source = path.join(root, 'platform.json');
130
+ const theme = path.join(root, PLATFORM_DIR);
131
+ if (fs.existsSync(source) && fs.existsSync(path.join(theme, 'style.css'))) {
132
+ fs.copyFileSync(source, path.join(theme, 'platform.json'));
133
+ }
134
+ }
135
+
122
136
  function writeWorkflows(root, version, created) {
123
137
  const dir = path.join(root, '.github', 'workflows');
124
138
  writeNew(path.join(dir, 'composer.yml'), composerWorkflow(version), created);
@@ -161,6 +175,7 @@ export async function update({ root, version, log = console.log }) {
161
175
  }
162
176
  fs.rmSync(target, { recursive: true, force: true });
163
177
  copyTheme(source, target);
178
+ syncPlatformJson(root);
164
179
  log(` ${pc.green('✓')} Platform ${from || '(none)'} → ${to}. Review with git diff, then commit.`);
165
180
  return { from, to, changed: true };
166
181
  }
@@ -0,0 +1,163 @@
1
+ import * as p from '@clack/prompts';
2
+
3
+ export const LANGUAGES = [
4
+ ['en', 'English'], ['fr', 'French'], ['ar', 'Arabic'], ['de', 'German'], ['es', 'Spanish'], ['it', 'Italian'],
5
+ ['pt', 'Portuguese'], ['nl', 'Dutch'], ['ru', 'Russian'], ['tr', 'Turkish'], ['hi', 'Hindi'], ['ml', 'Malayalam'],
6
+ ['ta', 'Tamil'], ['ur', 'Urdu'], ['zh', 'Chinese'], ['ja', 'Japanese'],
7
+ ];
8
+
9
+ export const FIELD_TYPES = ['text', 'textarea', 'html', 'number', 'checkbox', 'url', 'email', 'select', 'image', 'files', 'video', 'audio', 'lines'];
10
+ const KINDS = { media: 'All Contents', interactive: 'Questionnaires', document: 'Doc Templates' };
11
+ const MENU_FOR_KIND = { media: 'contents', interactive: 'questionnaires', document: 'templates' };
12
+
13
+ const clone = (value) => JSON.parse(JSON.stringify(value));
14
+ const key = (value) => String(value).toLowerCase().trim().replace(/[^a-z0-9_-]+/g, '_').replace(/^_+|_+$/g, '');
15
+
16
+ class Cancelled extends Error {}
17
+ function check(value) {
18
+ if (p.isCancel(value)) throw new Cancelled('Cancelled.');
19
+ return value;
20
+ }
21
+
22
+ /**
23
+ * "title, level:select(beginner|advanced), cover:image" → field definitions.
24
+ */
25
+ export function parseFields(text) {
26
+ return String(text || '')
27
+ .split(',')
28
+ .map((part) => part.trim())
29
+ .filter(Boolean)
30
+ .map((part) => {
31
+ const match = part.match(/^([^:]+?)(?::\s*([a-z]+)(?:\(([^)]*)\))?)?$/i);
32
+ const label = (match?.[1] || part).trim();
33
+ const type = FIELD_TYPES.includes(String(match?.[2] || '').toLowerCase()) ? match[2].toLowerCase() : 'text';
34
+ const field = { key: key(label), type, label: label.charAt(0).toUpperCase() + label.slice(1) };
35
+ if (type === 'select') {
36
+ const options = String(match?.[3] || '').split('|').map((o) => o.trim()).filter(Boolean);
37
+ field.options = Object.fromEntries(options.map((o) => [key(o), o]));
38
+ }
39
+ return field;
40
+ });
41
+ }
42
+
43
+ export function contentType({ label, singular, kind = 'media', fields = [] }) {
44
+ const slug = key(label);
45
+ return {
46
+ key: slug,
47
+ label,
48
+ singular: singular || label,
49
+ kind,
50
+ icon: 'dashicons-admin-post',
51
+ supports: ['title', 'editor', 'excerpt', 'thumbnail'],
52
+ translate: true,
53
+ folder: slug,
54
+ fields,
55
+ };
56
+ }
57
+
58
+ /**
59
+ * Builds a project's platform.json from the platform's default one and the
60
+ * answers. Sections that are not answered keep the default values.
61
+ */
62
+ export function buildPlatformJson(base, answers = {}) {
63
+ const config = clone(base);
64
+ const a = answers;
65
+
66
+ config.platform = { ...config.platform, name: a.name ?? config.platform?.name ?? '', author: a.author ?? config.platform?.author ?? '', url: a.url ?? config.platform?.url ?? '' };
67
+
68
+ if (Array.isArray(a.languages) && a.languages.length) {
69
+ config.languages = a.languages.map((code) => ({ code, name: (LANGUAGES.find(([c]) => c === code) || [code, code])[1] }));
70
+ config.default_language = a.languages.includes(a.defaultLanguage) ? a.defaultLanguage : a.languages[0];
71
+ }
72
+
73
+ if (a.template === 'empty') {
74
+ config.content = { ...config.content, placeholders: [], types: [], taxonomies: [] };
75
+ }
76
+ if (Array.isArray(a.types)) config.content.types.push(...a.types);
77
+ if (Array.isArray(a.taxonomies)) config.content.taxonomies.push(...a.taxonomies);
78
+
79
+ const kinds = new Set(config.content.types.map((type) => type.kind));
80
+ if (config.app?.cms?.menu) {
81
+ config.app.cms.menu = config.app.cms.menu.filter((item) => !item.kinds || item.kinds.some((kind) => kinds.has(kind)));
82
+ }
83
+
84
+ if (Array.isArray(a.modules)) {
85
+ config.modules = Object.fromEntries(Object.entries(config.modules || {}).filter(([name]) => a.modules.includes(name)));
86
+ }
87
+
88
+ if (config.app) {
89
+ if (a.name) config.app.name = a.name;
90
+ if (a.brandColor) config.app.theme = { ...config.app.theme, colors: { ...config.app.theme?.colors, brand: a.brandColor, ring: a.brandColor } };
91
+ if (Array.isArray(a.categories) && a.categories.length) config.app.apps = { ...config.app.apps, categories: a.categories };
92
+ }
93
+
94
+ return config;
95
+ }
96
+
97
+ /**
98
+ * Asks for each section of platform.json, in order. Enter keeps the default.
99
+ */
100
+ export async function askPlatform(base, { name: suggested = '' } = {}) {
101
+ try {
102
+ const answers = {};
103
+ p.log.step('platform');
104
+ answers.name = check(await p.text({ message: 'Platform name', initialValue: suggested, placeholder: suggested }));
105
+ answers.author = check(await p.text({ message: 'Author (optional)', defaultValue: '', placeholder: '' }));
106
+ answers.url = check(await p.text({ message: 'Website (optional)', defaultValue: '', placeholder: 'https://' }));
107
+
108
+ p.log.step('languages');
109
+ const defaults = (base.languages || []).map((l) => l.code);
110
+ answers.languages = check(await p.multiselect({
111
+ message: 'Languages',
112
+ options: LANGUAGES.map(([code, label]) => ({ value: code, label: `${label} (${code})` })),
113
+ initialValues: defaults.filter((code) => LANGUAGES.some(([c]) => c === code)),
114
+ required: true,
115
+ }));
116
+ answers.defaultLanguage = answers.languages.length > 1
117
+ ? check(await p.select({ message: 'Default language', options: answers.languages.map((code) => ({ value: code, label: code })), initialValue: answers.languages.includes(base.default_language) ? base.default_language : answers.languages[0] }))
118
+ : answers.languages[0];
119
+
120
+ p.log.step('content');
121
+ answers.template = check(await p.select({
122
+ message: 'Content types',
123
+ options: [
124
+ { value: 'default', label: 'Start from the default set', hint: (base.content?.types || []).map((t) => t.label).join(', ') },
125
+ { value: 'empty', label: 'Start empty' },
126
+ ],
127
+ }));
128
+ answers.types = [];
129
+ while (check(await p.confirm({ message: answers.types.length ? 'Add another content type?' : 'Add a content type?', initialValue: answers.template === 'empty' && !answers.types.length }))) {
130
+ const label = check(await p.text({ message: 'Name (plural)', placeholder: 'Products', validate: (v) => (key(v) ? undefined : 'Enter a name') }));
131
+ const singular = check(await p.text({ message: 'Singular', initialValue: label.replace(/s$/i, '') }));
132
+ const kind = check(await p.select({ message: 'Shown in the CMS under', options: Object.entries(KINDS).map(([value, label]) => ({ value, label })) }));
133
+ const fields = check(await p.text({ message: `Fields (name:type, comma separated). Types: ${FIELD_TYPES.join(', ')}`, placeholder: 'price:number, color:select(red|blue), gallery:files', defaultValue: '' }));
134
+ answers.types.push(contentType({ label, singular, kind, fields: parseFields(fields) }));
135
+ }
136
+ answers.taxonomies = [];
137
+ const typeKeys = [...(answers.template === 'empty' ? [] : (base.content?.types || []).map((t) => t.key)), ...answers.types.map((t) => t.key)];
138
+ while (typeKeys.length && check(await p.confirm({ message: answers.taxonomies.length ? 'Add another taxonomy?' : 'Add a taxonomy (categories, tags)?', initialValue: false }))) {
139
+ const label = check(await p.text({ message: 'Name (plural)', placeholder: 'Categories', validate: (v) => (key(v) ? undefined : 'Enter a name') }));
140
+ const hierarchical = check(await p.confirm({ message: 'Nested (like categories)?', initialValue: true }));
141
+ const types = check(await p.multiselect({ message: 'For which content types?', options: typeKeys.map((value) => ({ value, label: value })), required: true }));
142
+ answers.taxonomies.push({ key: key(label), label, singular: label.replace(/ies$/i, 'y').replace(/s$/i, ''), hierarchical, types, translate: true });
143
+ }
144
+
145
+ p.log.step('modules');
146
+ answers.modules = check(await p.multiselect({
147
+ message: 'Modules',
148
+ options: Object.entries(base.modules || {}).map(([value, module]) => ({ value, label: module.label || value })),
149
+ initialValues: Object.keys(base.modules || {}),
150
+ required: false,
151
+ }));
152
+
153
+ p.log.step('app');
154
+ answers.brandColor = check(await p.text({ message: 'Brand color', initialValue: base.app?.theme?.colors?.brand || '#8b7cf6', validate: (v) => (/^#[0-9a-f]{3,8}$/i.test(v) ? undefined : 'Use a hex color, e.g. #8b7cf6') }));
155
+ const categories = check(await p.text({ message: 'App categories (comma separated)', initialValue: (base.app?.apps?.categories || []).join(', ') }));
156
+ answers.categories = categories.split(',').map((c) => c.trim()).filter(Boolean);
157
+
158
+ return answers;
159
+ } catch (error) {
160
+ if (error instanceof Cancelled) return null;
161
+ throw error;
162
+ }
163
+ }
package/src/main.js CHANGED
@@ -6,7 +6,10 @@ import { parseArgs, UsageError } from './args.js';
6
6
  import { startApp } from './commands/start.js';
7
7
  import { buildAll } from './commands/build.js';
8
8
  import { doctor } from './commands/doctor.js';
9
- import { PLATFORM_DIR, apps, composer, init, newApp, newPlugin, platformRoot, plugins, update } from './commands/platform.js';
9
+ import * as p from '@clack/prompts';
10
+ import { PLATFORM_DIR, apps, bundledPlatform, composer, init, newApp, newPlugin, platformRoot, plugins, update } from './commands/platform.js';
11
+ import { askPlatform } from './commands/setup.js';
12
+ import { connectGithub } from './commands/github.js';
10
13
  import { sandbox } from './commands/sandbox.js';
11
14
  import { tui } from './tui.js';
12
15
 
@@ -19,7 +22,12 @@ Usage:
19
22
  wp-ops interactive menu
20
23
 
21
24
  Platform repository:
22
- wp-ops init [dir] create a platform repository: the platform (wp-operations/), layout, workflows, git
25
+ wp-ops init [dir] create a platform repository: asks for each section of platform.json
26
+ (name, languages, content types, taxonomies, modules, app), then
27
+ writes the platform (wp-operations/), layout, workflows and git
28
+ [--yes: default platform.json] [--template=empty] [--github=owner/name] [--public]
29
+ wp-ops github <owner/name> [--public]
30
+ create the GitHub repository (if needed), set it as origin, commit and push main
23
31
  wp-ops start [--port=] run the platform locally (admin / password)
24
32
  wp-ops update update wp-operations/ to the platform shipped with this wp-ops
25
33
  wp-ops apps list apps (<kind>/<slug>) and their deploy targets
@@ -70,7 +78,44 @@ async function run() {
70
78
  await doctor();
71
79
  return;
72
80
  case 'init':
73
- await init({ dir: positional[0] ?? process.cwd(), platform: options.platform, version: pkg.version });
81
+ {
82
+ const dir = path.resolve(positional[0] ?? process.cwd());
83
+ const source = options.platform ? path.resolve(options.platform) : bundledPlatform();
84
+ const baseFile = source && fs.existsSync(source) && fs.statSync(source).isDirectory() ? path.join(source, 'platform.json') : source;
85
+ let answers = options.template === 'empty' ? { template: 'empty', name: path.basename(dir) } : null;
86
+ if (!answers && options.yes !== true && process.stdin.isTTY && baseFile && fs.existsSync(baseFile) && !fs.existsSync(path.join(dir, 'platform.json'))) {
87
+ p.intro(`wp-ops init ${path.basename(dir)}`);
88
+ answers = await askPlatform(JSON.parse(fs.readFileSync(baseFile, 'utf8')), { name: path.basename(dir) });
89
+ if (!answers) {
90
+ p.cancel('Nothing created.');
91
+ return;
92
+ }
93
+ p.log.step('github');
94
+ const repo = await p.text({ message: 'GitHub repository to create and push to (owner/name, empty to skip)', placeholder: `your-account/${path.basename(dir)}`, defaultValue: '' });
95
+ if (p.isCancel(repo)) {
96
+ p.cancel('Nothing created.');
97
+ return;
98
+ }
99
+ if (repo.trim()) {
100
+ const isPrivate = await p.confirm({ message: 'Private repository?', initialValue: true });
101
+ if (p.isCancel(isPrivate)) {
102
+ p.cancel('Nothing created.');
103
+ return;
104
+ }
105
+ options.github = repo.trim();
106
+ options.public = !isPrivate;
107
+ }
108
+ p.outro('Creating the platform repository');
109
+ }
110
+ await init({ dir, platform: options.platform, version: pkg.version, answers });
111
+ if (options.github && options.github !== true) {
112
+ console.log('');
113
+ await connectGithub({ root: dir, repo: options.github, isPrivate: options.public !== true });
114
+ }
115
+ }
116
+ return;
117
+ case 'github':
118
+ await connectGithub({ root: await platformRoot(), repo: positional[0], isPrivate: options.public !== true });
74
119
  return;
75
120
  case 'apps':
76
121
  await apps({ root: await platformRoot() });
package/src/templates.js CHANGED
@@ -278,6 +278,41 @@ ${SERVER_LOOKUP}
278
278
  wp theme activate \${{ steps.target.outputs.theme_slug }} --allow-root && \\
279
279
  wp cache flush --allow-root && \\
280
280
  (curl -X PURGE http://127.0.0.1/ || true)"
281
+
282
+ # The platform's GitHub settings come from here: this repository, this
283
+ # branch, and the PLATFORM_GITHUB_TOKEN secret. Nobody fills them in.
284
+ - name: Connect the platform to this repository
285
+ if: steps.target.outputs.skip != 'true'
286
+ env:
287
+ TARGET: \${{ steps.target.outputs.target }}
288
+ APP_PATH: \${{ steps.target.outputs.app_path }}
289
+ PLATFORM_GITHUB_TOKEN: \${{ secrets.PLATFORM_GITHUB_TOKEN }}
290
+ run: |
291
+ if [ -n "$PLATFORM_GITHUB_TOKEN" ]; then
292
+ printf '%s\\n' "$PLATFORM_GITHUB_TOKEN" | ssh -i ~/.ssh/id_ed25519 "$TARGET" \\
293
+ "cd $APP_PATH && read -r T && wp config set PLATFORM_GITHUB_TOKEN \\"\\$T\\" --type=constant --allow-root --quiet"
294
+ else
295
+ echo "::notice::Add the PLATFORM_GITHUB_TOKEN secret so the platform can reach this repository."
296
+ fi
297
+ cat > connect.php <<'PHP'
298
+ <?php
299
+ if ( ! class_exists( 'Platform\\App\\Ops' ) ) {
300
+ WP_CLI::error( 'The wp-operations platform is not the active theme.' );
301
+ }
302
+ $saved = Platform\\App\\Ops::save( [ 'url' => 'https://github.com/' . getenv( 'PLATFORM_REPO' ), 'branch' => getenv( 'PLATFORM_BRANCH' ) ] );
303
+ if ( is_wp_error( $saved ) ) {
304
+ WP_CLI::error( $saved->get_error_message() );
305
+ }
306
+ if ( defined( 'PLATFORM_GITHUB_TOKEN' ) && '' !== PLATFORM_GITHUB_TOKEN ) {
307
+ $imported = Platform\\App\\Ops::import();
308
+ if ( is_wp_error( $imported ) ) {
309
+ WP_CLI::warning( $imported->get_error_message() );
310
+ }
311
+ }
312
+ WP_CLI::success( 'Platform connected to ' . getenv( 'PLATFORM_REPO' ) . ' (' . getenv( 'PLATFORM_BRANCH' ) . ').' );
313
+ PHP
314
+ ssh -i ~/.ssh/id_ed25519 "$TARGET" \\
315
+ "cd $APP_PATH && PLATFORM_REPO='\${{ github.repository }}' PLATFORM_BRANCH='\${{ github.ref_name }}' wp eval-file - --allow-root" < connect.php
281
316
  `;
282
317
 
283
318
  export function appStyle(slug) {
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.3
4
+
5
+ - App settings → Details renders every field from `platform.json` (`apps.metadata`) with its type, options and width, using the same fields as the CMS.
6
+ - The AI (Build, Plan, Chat) gets the app's configured details and links, labelled as `platform.json` defines them.
7
+ - Chat ideas and the new-app hint use the platform's own content types instead of fixed examples.
8
+
3
9
  ## 0.1.2
4
10
 
5
11
  - changed logo size from mine to my father's (tried to fool boss)