@wp-operations/wp-ops 0.1.0 → 0.3.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/src/tui.js CHANGED
@@ -5,13 +5,19 @@ 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';
9
+ import { ide } from './deps.js';
10
+
11
+ async function appChoices(rootDir) {
12
+ const { hasLayout, listApps: listPlatformApps } = await ide();
13
+ if (hasLayout(rootDir)) {
14
+ return listPlatformApps(rootDir).filter((app) => !app.warnings.some((w) => w.includes('missing'))).map((app) => ({ value: app.dir, label: app.path }));
15
+ }
16
+ return listApps(rootDir).map(({ name, dir }) => ({ value: dir, label: name }));
17
+ }
8
18
 
9
19
  async function pickApp(rootDir) {
10
- const apps = listApps(rootDir);
11
- const options = [
12
- ...apps.map(({ name, dir }) => ({ value: dir, label: name })),
13
- { value: '__custom__', label: 'Custom path…' },
14
- ];
20
+ const options = [...(await appChoices(rootDir)), { value: '__custom__', label: 'Custom path…' }];
15
21
  const picked = await p.select({
16
22
  message: 'Which app?',
17
23
  options,
@@ -40,6 +46,8 @@ async function pickEngine() {
40
46
  export async function tui(version) {
41
47
  console.log(banner(version));
42
48
  const rootDir = findRootDir();
49
+ const { hasLayout } = await ide();
50
+ const platform = hasLayout(rootDir);
43
51
  p.intro(pc.inverse(' wp-ops '));
44
52
 
45
53
  for (;;) {
@@ -48,6 +56,12 @@ export async function tui(version) {
48
56
  options: [
49
57
  { value: 'start', label: 'Start an app', hint: 'wp-app start' },
50
58
  { value: 'dev', label: 'Dev an app', hint: 'start + watch' },
59
+ ...(platform
60
+ ? [
61
+ { value: 'apps', label: 'List apps' },
62
+ { value: 'plugins', label: 'List plugins' },
63
+ ]
64
+ : []),
51
65
  { value: 'build', label: 'Build all packages' },
52
66
  { value: 'doctor', label: 'Doctor', hint: 'environment checks' },
53
67
  { value: 'exit', label: 'Exit' },
@@ -57,20 +71,22 @@ export async function tui(version) {
57
71
  p.outro('Done.');
58
72
  return;
59
73
  }
60
- if (action === 'start' || action === 'dev') {
61
- const appDir = await pickApp(rootDir);
62
- if (!appDir) continue;
63
- const flags = await pickEngine();
64
- if (flags === null) continue;
65
- p.outro(`Starting ${appDir}`);
66
- startApp({ appDir, flags, dev: action === 'dev' });
67
- return;
68
- }
69
- if (action === 'build') {
70
- buildAll(rootDir);
71
- }
72
- if (action === 'doctor') {
73
- doctor(rootDir);
74
+ try {
75
+ if (action === 'start' || action === 'dev') {
76
+ const appDir = await pickApp(rootDir);
77
+ if (!appDir) continue;
78
+ const flags = await pickEngine();
79
+ if (flags === null) continue;
80
+ p.outro(`Starting ${appDir}`);
81
+ startApp({ appDir, flags, dev: action === 'dev' });
82
+ return;
83
+ }
84
+ if (action === 'apps') await apps({ root: rootDir });
85
+ if (action === 'plugins') await plugins({ root: rootDir });
86
+ if (action === 'build') buildAll(rootDir);
87
+ if (action === 'doctor') await doctor(rootDir);
88
+ } catch (error) {
89
+ p.log.error(error.message);
74
90
  }
75
91
  }
76
92
  }