@wp-operations/wp-ops 0.5.1 → 0.5.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-operations/wp-ops",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
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",
@@ -3,24 +3,41 @@ import path from 'path';
3
3
  import { execSync } from 'child_process';
4
4
  import { findRootDir, listPackages } from '../project.js';
5
5
 
6
+ function subdirs(dir) {
7
+ return fs.existsSync(dir)
8
+ ? fs.readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => path.join(dir, entry.name))
9
+ : [];
10
+ }
11
+
12
+ /**
13
+ * In a platform repository: every plugin (packages/<vendor>/<name>) and every
14
+ * app (<kind folder>/<slug>). Otherwise: packages/<name>.
15
+ */
16
+ function buildDirs(rootDir) {
17
+ const layoutFile = path.join(rootDir, '.github', 'platform.json');
18
+ if (!fs.existsSync(layoutFile)) {
19
+ return listPackages(rootDir);
20
+ }
21
+ const layout = JSON.parse(fs.readFileSync(layoutFile, 'utf8'));
22
+ const plugins = subdirs(path.join(rootDir, layout.packages || 'packages')).flatMap(subdirs);
23
+ const apps = Object.entries(layout.apps || {}).flatMap(([key, kind]) => subdirs(path.join(rootDir, kind?.folder || key)));
24
+ return [...plugins, ...apps];
25
+ }
26
+
6
27
  export function buildAll(startDir = process.cwd()) {
7
28
  const rootDir = findRootDir(startDir);
8
- const packages = listPackages(rootDir);
9
- if (packages.length === 0) {
10
- console.log('No packages/ directory with packages found.');
11
- return;
12
- }
13
29
  let built = 0;
14
- for (const dir of packages) {
15
- const pkg = JSON.parse(
16
- fs.readFileSync(path.join(dir, 'package.json'), 'utf8')
17
- );
18
- if (!pkg.scripts?.build) {
19
- continue;
30
+ for (const dir of buildDirs(rootDir)) {
31
+ const file = path.join(dir, 'package.json');
32
+ if (!fs.existsSync(file)) continue;
33
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf8'));
34
+ if (!pkg.scripts?.build) continue;
35
+ console.log(`\n[wp-ops] build: ${path.relative(rootDir, dir).split(path.sep).join('/')}`);
36
+ if (!fs.existsSync(path.join(dir, 'node_modules')) && fs.existsSync(path.join(dir, 'package-lock.json'))) {
37
+ execSync('npm ci', { cwd: dir, stdio: 'inherit', shell: true });
20
38
  }
21
- console.log(`\n[wp-ops] build: ${pkg.name}`);
22
- execSync(pkg.scripts.build, { cwd: dir, stdio: 'inherit', shell: true });
39
+ execSync('npm run build', { cwd: dir, stdio: 'inherit', shell: true });
23
40
  built++;
24
41
  }
25
- console.log(`\n[wp-ops] built ${built} package(s).`);
42
+ console.log(built ? `\n[wp-ops] built ${built}.` : '[wp-ops] nothing to build: no package.json with a "build" script in the apps or plugins.');
26
43
  }
@@ -56,12 +56,15 @@ async function platformChecks(rootDir) {
56
56
  return;
57
57
  }
58
58
  check('.github/platform.json', layout.kinds.length > 0, `${layout.kinds.length} kinds, plugins in ${layout.packages}/`);
59
- check('platform.json', fs.existsSync(path.join(rootDir, 'platform.json')), fs.existsSync(path.join(rootDir, 'platform.json')) ? 'present' : "missing; copy the theme's platform.json to the root");
59
+ check('platform.json', fs.existsSync(path.join(rootDir, 'platform.json')), fs.existsSync(path.join(rootDir, 'platform.json')) ? 'present' : 'missing; run "wp-ops update"');
60
+ const themeCss = path.join(rootDir, 'wp-operations', 'style.css');
61
+ const themeVersion = fs.existsSync(themeCss) ? (fs.readFileSync(themeCss, 'utf8').match(/^Version:\s*(\S+)/m)?.[1] ?? '?') : '';
62
+ check('platform (wp-operations/)', Boolean(themeVersion), themeVersion ? `version ${themeVersion}` : 'missing; run "wp-ops update"');
60
63
  const workflows = path.join(rootDir, '.github', 'workflows');
61
64
  for (const name of ['composer.yml', 'deploy-apps.yml', 'deploy-platform.yml']) {
62
65
  const present = fs.existsSync(path.join(workflows, name));
63
66
  if (name === 'composer.yml') check(`workflow ${name}`, present, present ? '' : 'missing; "wp-ops init" adds it');
64
- else if (!present) warn(`workflow ${name}`, 'not found; the theme dispatches it for deploys (the name is set in Settings → Operations)');
67
+ else if (!present) warn(`workflow ${name}`, 'missing; run "wp-ops update"');
65
68
  else check(`workflow ${name}`, true);
66
69
  }
67
70
  try {
@@ -98,5 +101,6 @@ export async function doctor(startDir = process.cwd()) {
98
101
  await platformChecks(rootDir);
99
102
 
100
103
  console.log(pc.dim(`\n root: ${rootDir}`));
101
- console.log(pc.dim(` home data: ${process.env.WP_APP_HOME || path.join(os.homedir(), '.wp-app')}\n`));
104
+ const repoData = fs.existsSync(path.join(rootDir, '.github', 'platform.json')) ? path.join(rootDir, '.local') : '';
105
+ console.log(pc.dim(` site data: ${process.env.WP_APP_HOME || repoData || path.join(os.homedir(), '.wp-app')}\n`));
102
106
  }
@@ -1,6 +1,33 @@
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
1
4
  import { spawn } from 'child_process';
2
5
  import { findRootDir, findWpAppCli } from '../project.js';
3
6
 
7
+ /**
8
+ * Downloads (WordPress, ClassicPress, SQLite) are shared between data folders:
9
+ * whatever one folder has cached, the other gets, so a new repository never
10
+ * downloads WordPress again.
11
+ */
12
+ function shareCache(home) {
13
+ const shared = path.join(os.homedir(), '.wp-app', 'cache');
14
+ const local = path.join(home, 'cache');
15
+ if (path.resolve(shared) === path.resolve(local)) return;
16
+ for (const [from, to] of [[shared, local], [local, shared]]) {
17
+ if (!fs.existsSync(from)) continue;
18
+ fs.mkdirSync(to, { recursive: true });
19
+ for (const name of fs.readdirSync(from)) {
20
+ const source = path.join(from, name);
21
+ const target = path.join(to, name);
22
+ if (!fs.existsSync(target) && fs.statSync(source).isFile()) {
23
+ try {
24
+ fs.copyFileSync(source, target);
25
+ } catch {}
26
+ }
27
+ }
28
+ }
29
+ }
30
+
4
31
  export function startApp({ appDir, flags = [], dev = false, env = process.env }) {
5
32
  const rootDir = findRootDir(appDir);
6
33
  const wpAppCli = findWpAppCli(rootDir);
@@ -10,8 +37,12 @@ export function startApp({ appDir, flags = [], dev = false, env = process.env })
10
37
  );
11
38
  process.exit(1);
12
39
  }
40
+ if (env.WP_APP_HOME) shareCache(env.WP_APP_HOME);
13
41
  const args = [wpAppCli, dev ? 'dev' : 'start', `--path=${appDir}`, ...flags];
14
42
  const child = spawn(process.execPath, args, { stdio: 'inherit', env });
15
- child.on('exit', (code) => process.exit(code ?? 0));
43
+ child.on('exit', (code) => {
44
+ if (env.WP_APP_HOME) shareCache(env.WP_APP_HOME);
45
+ process.exit(code ?? 0);
46
+ });
16
47
  return child;
17
48
  }
package/src/tui.js CHANGED
@@ -5,7 +5,9 @@ import { findRootDir, listApps } from './project.js';
5
5
  import { startApp } from './commands/start.js';
6
6
  import { buildAll } from './commands/build.js';
7
7
  import { doctor } from './commands/doctor.js';
8
- import { apps, plugins } from './commands/platform.js';
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import { PLATFORM_DIR, apps, newApp, newPlugin, plugins, update } from './commands/platform.js';
9
11
  import { ide } from './deps.js';
10
12
 
11
13
  async function appChoices(rootDir) {
@@ -48,18 +50,24 @@ export async function tui(version) {
48
50
  const rootDir = findRootDir();
49
51
  const { hasLayout } = await ide();
50
52
  const platform = hasLayout(rootDir);
53
+ const platformTheme = path.join(rootDir, PLATFORM_DIR);
54
+ const hasPlatform = platform && fs.existsSync(path.join(platformTheme, 'style.css'));
51
55
  p.intro(pc.inverse(' wp-ops '));
52
56
 
53
57
  for (;;) {
54
58
  const action = await p.select({
55
59
  message: 'What do you want to do?',
56
60
  options: [
61
+ ...(hasPlatform ? [{ value: 'platform', label: 'Start the platform', hint: 'admin / password' }] : []),
57
62
  { value: 'start', label: 'Start an app', hint: 'wp-app start' },
58
63
  { value: 'dev', label: 'Dev an app', hint: 'start + watch' },
59
64
  ...(platform
60
65
  ? [
66
+ { value: 'new-app', label: 'New app' },
67
+ { value: 'new-plugin', label: 'New plugin' },
61
68
  { value: 'apps', label: 'List apps' },
62
69
  { value: 'plugins', label: 'List plugins' },
70
+ { value: 'update', label: 'Update the platform', hint: 'wp-operations/' },
63
71
  ]
64
72
  : []),
65
73
  { value: 'build', label: 'Build all packages' },
@@ -72,6 +80,29 @@ export async function tui(version) {
72
80
  return;
73
81
  }
74
82
  try {
83
+ if (action === 'platform') {
84
+ p.outro('Starting the platform');
85
+ startApp({ appDir: platformTheme, env: { ...process.env, WP_APP_HOME: process.env.WP_APP_HOME || path.join(rootDir, '.local') } });
86
+ return;
87
+ }
88
+ if (action === 'new-app') {
89
+ const kind = await p.text({ message: 'Kind (folder):', initialValue: 'service-apps' });
90
+ if (p.isCancel(kind)) continue;
91
+ const slug = await p.text({ message: 'App name:' });
92
+ if (p.isCancel(slug)) continue;
93
+ await newApp({ root: rootDir, kind, slug, server: '', appPath: '' });
94
+ continue;
95
+ }
96
+ if (action === 'new-plugin') {
97
+ const name = await p.text({ message: 'Plugin (vendor/name):' });
98
+ if (p.isCancel(name)) continue;
99
+ await newPlugin({ root: rootDir, name, description: '' });
100
+ continue;
101
+ }
102
+ if (action === 'update') {
103
+ await update({ root: rootDir, version });
104
+ continue;
105
+ }
75
106
  if (action === 'start' || action === 'dev') {
76
107
  const appDir = await pickApp(rootDir);
77
108
  if (!appDir) continue;
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1
4
+
5
+ - Sign-in screen shows the platform logo again (your Site Logo when set) and no longer scrolls.
6
+
3
7
  ## 0.1.0
4
8
 
5
9
  - The theme now lives in the wp-operations repository and updates itself from its releases, with this changelog in Dashboard → Updates.
@@ -6,7 +6,7 @@
6
6
  html,body{height:100%}
7
7
  body.platform-gate,body.login{margin:0;background:var(--bg);color:var(--text);font:14px/1.5 Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;-webkit-font-smoothing:antialiased}
8
8
 
9
- .gate{min-height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:48px 20px;position:relative;overflow:hidden}
9
+ .gate{box-sizing:border-box;min-height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:48px 20px;position:relative;overflow:hidden}
10
10
  .gate__glow{position:absolute;inset:-40% -20% auto;height:90%;background:radial-gradient(50% 50% at 50% 40%,rgba(255,255,255,.07),transparent 70%);pointer-events:none}
11
11
  .gate__card{position:relative;width:100%;max-width:380px;background:linear-gradient(180deg,rgba(255,255,255,.035),rgba(255,255,255,.01));border:1px solid var(--line);border-radius:20px;padding:36px 32px 28px;box-shadow:0 30px 80px -20px rgba(0,0,0,.7)}
12
12
  .gate__mark{display:block;width:56px;height:56px;object-fit:contain;margin:0 auto 20px}
@@ -121,9 +121,7 @@ final class App {
121
121
  <body class="platform-gate">
122
122
  <main class="gate">
123
123
  <section class="gate__card">
124
- <?php if ( '' !== $brand['logo'] ) : ?>
125
- <img class="gate__mark" src="<?php echo esc_url( $brand['logo'] ); ?>" alt="">
126
- <?php endif; ?>
124
+ <img class="gate__mark" src="<?php echo esc_url( $brand['logo'] ?: $brand['mark'] ); ?>" alt="">
127
125
  <?php if ( 'login' === $view ) : ?>
128
126
  <h1>Sign in to <?php echo esc_html( $brand['name'] ); ?></h1>
129
127
  <?php
@@ -3,7 +3,7 @@ Theme Name: wp-operations
3
3
  Theme URI: https://github.com/wordpress-operations/wordpress-operations
4
4
  Author: wp-operations
5
5
  Description: The wp-operations platform: content engine (platform.json), CMS, app builder and operations for one platform repository.
6
- Version: 0.1.0
6
+ Version: 0.1.1
7
7
  Requires at least: 6.4
8
8
  Requires PHP: 8.0
9
9
  License: GPL-2.0-or-later