@wpmoo/toolkit 0.9.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/LICENSE +22 -0
- package/README.md +519 -0
- package/dist/addons-yaml.js +59 -0
- package/dist/args.js +259 -0
- package/dist/cli.js +1039 -0
- package/dist/cockpit/command-palette.js +23 -0
- package/dist/cockpit/command-registry.js +91 -0
- package/dist/cockpit/daily-prompts.js +177 -0
- package/dist/cockpit/menu.js +99 -0
- package/dist/cockpit/safety.js +22 -0
- package/dist/compose-layout.js +118 -0
- package/dist/daily-actions.js +190 -0
- package/dist/doctor.js +519 -0
- package/dist/environment-context.js +10 -0
- package/dist/environment-version.js +5 -0
- package/dist/environment.js +136 -0
- package/dist/external-assets.js +153 -0
- package/dist/external-templates.js +86 -0
- package/dist/git.js +98 -0
- package/dist/github.js +87 -0
- package/dist/help.js +157 -0
- package/dist/menu-navigation.js +67 -0
- package/dist/module-actions.js +114 -0
- package/dist/odoo-versions.js +1 -0
- package/dist/path-validation.js +50 -0
- package/dist/prompt-copy.js +8 -0
- package/dist/prompt-repositories.js +34 -0
- package/dist/prompts/index.js +174 -0
- package/dist/repo-actions.js +158 -0
- package/dist/repo-url.js +27 -0
- package/dist/repository-preflight.js +46 -0
- package/dist/safe-reset.js +217 -0
- package/dist/scaffold.js +161 -0
- package/dist/source-actions.js +65 -0
- package/dist/source-manifest.js +338 -0
- package/dist/status.js +239 -0
- package/dist/templates.js +758 -0
- package/dist/types.js +1 -0
- package/dist/update-check.js +106 -0
- package/dist/version.js +19 -0
- package/docs/assets/patreon-donate.png +0 -0
- package/docs/assets/wpmoo-banner.png +0 -0
- package/docs/external-resources.md +136 -0
- package/docs/generated-environment-verification.md +140 -0
- package/docs/handoff.md +29 -0
- package/package.json +65 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { access } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { markerPath } from './environment.js';
|
|
5
|
+
export const dailyActionCommands = [
|
|
6
|
+
'start',
|
|
7
|
+
'stop',
|
|
8
|
+
'logs',
|
|
9
|
+
'restart',
|
|
10
|
+
'shell',
|
|
11
|
+
'psql',
|
|
12
|
+
'install',
|
|
13
|
+
'update',
|
|
14
|
+
'test',
|
|
15
|
+
'resetdb',
|
|
16
|
+
'snapshot',
|
|
17
|
+
'restore-snapshot',
|
|
18
|
+
'lint',
|
|
19
|
+
'pot',
|
|
20
|
+
];
|
|
21
|
+
const dailyActionCommandSet = new Set(dailyActionCommands);
|
|
22
|
+
export const dailyActionScripts = {
|
|
23
|
+
start: 'up.sh',
|
|
24
|
+
stop: 'down.sh',
|
|
25
|
+
logs: 'logs.sh',
|
|
26
|
+
restart: 'restart.sh',
|
|
27
|
+
shell: 'shell.sh',
|
|
28
|
+
psql: 'psql.sh',
|
|
29
|
+
install: 'install.sh',
|
|
30
|
+
update: 'update.sh',
|
|
31
|
+
test: 'test.sh',
|
|
32
|
+
resetdb: 'resetdb.sh',
|
|
33
|
+
snapshot: 'snapshot.sh',
|
|
34
|
+
'restore-snapshot': 'restore-snapshot.sh',
|
|
35
|
+
lint: 'lint.sh',
|
|
36
|
+
pot: 'pot.sh',
|
|
37
|
+
};
|
|
38
|
+
export function isDailyActionCommand(command) {
|
|
39
|
+
return dailyActionCommandSet.has(command);
|
|
40
|
+
}
|
|
41
|
+
function usage(command) {
|
|
42
|
+
if (command === 'start')
|
|
43
|
+
return 'Usage: wpmoo start';
|
|
44
|
+
if (command === 'stop')
|
|
45
|
+
return 'Usage: wpmoo stop';
|
|
46
|
+
if (command === 'logs')
|
|
47
|
+
return 'Usage: wpmoo logs [service]';
|
|
48
|
+
if (command === 'restart')
|
|
49
|
+
return 'Usage: wpmoo restart';
|
|
50
|
+
if (command === 'shell')
|
|
51
|
+
return 'Usage: wpmoo shell';
|
|
52
|
+
if (command === 'psql')
|
|
53
|
+
return 'Usage: wpmoo psql [db]';
|
|
54
|
+
if (command === 'install')
|
|
55
|
+
return 'Usage: wpmoo install <module[,module]> [db]';
|
|
56
|
+
if (command === 'update')
|
|
57
|
+
return 'Usage: wpmoo update <module[,module]> [db]';
|
|
58
|
+
if (command === 'test')
|
|
59
|
+
return 'Usage: wpmoo test <module[,module]> [--db <db>] [--mode init|update] [--tags <tags>]';
|
|
60
|
+
if (command === 'resetdb')
|
|
61
|
+
return 'Usage: wpmoo resetdb [db] [module[,module]]';
|
|
62
|
+
if (command === 'snapshot')
|
|
63
|
+
return 'Usage: wpmoo snapshot [db] [snapshot-name]';
|
|
64
|
+
if (command === 'restore-snapshot')
|
|
65
|
+
return 'Usage: wpmoo restore-snapshot [--dry-run] <snapshot-name> [db]';
|
|
66
|
+
if (command === 'lint')
|
|
67
|
+
return 'Usage: wpmoo lint';
|
|
68
|
+
return 'Usage: wpmoo pot <module[,module]> [db] [output]';
|
|
69
|
+
}
|
|
70
|
+
function ensureNoArgs(command, argv) {
|
|
71
|
+
if (argv.length > 0)
|
|
72
|
+
throw new Error(usage(command));
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
function optionalSingleArg(command, argv, fallback) {
|
|
76
|
+
if (argv.length > 1)
|
|
77
|
+
throw new Error(usage(command));
|
|
78
|
+
return [argv[0] ?? fallback];
|
|
79
|
+
}
|
|
80
|
+
function moduleArgs(command, argv) {
|
|
81
|
+
const [modules, db, ...rest] = argv;
|
|
82
|
+
if (!modules || modules.startsWith('-') || rest.length > 0)
|
|
83
|
+
throw new Error(usage(command));
|
|
84
|
+
return db ? [modules, db] : [modules];
|
|
85
|
+
}
|
|
86
|
+
function positionalArgs(command, argv, min, max) {
|
|
87
|
+
if (argv.length < min || argv.length > max || argv.some((arg) => arg.startsWith('-'))) {
|
|
88
|
+
throw new Error(usage(command));
|
|
89
|
+
}
|
|
90
|
+
return argv;
|
|
91
|
+
}
|
|
92
|
+
function restoreSnapshotArgs(argv) {
|
|
93
|
+
const args = [...argv];
|
|
94
|
+
const dryRun = args[0] === '--dry-run';
|
|
95
|
+
if (dryRun) {
|
|
96
|
+
args.shift();
|
|
97
|
+
}
|
|
98
|
+
if (args.length < 1 || args.length > 2 || args.some((arg) => arg.startsWith('-'))) {
|
|
99
|
+
throw new Error(usage('restore-snapshot'));
|
|
100
|
+
}
|
|
101
|
+
return dryRun ? ['--dry-run', ...args] : args;
|
|
102
|
+
}
|
|
103
|
+
function testArgs(argv) {
|
|
104
|
+
const [modules, ...rest] = argv;
|
|
105
|
+
if (!modules || modules.startsWith('-'))
|
|
106
|
+
throw new Error(usage('test'));
|
|
107
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
108
|
+
const option = rest[index];
|
|
109
|
+
if (!['--db', '--mode', '--tags'].includes(option))
|
|
110
|
+
throw new Error(`Unknown option for wpmoo test: ${option}`);
|
|
111
|
+
const value = rest[index + 1];
|
|
112
|
+
if (!value || value.startsWith('--'))
|
|
113
|
+
throw new Error(`Missing value for ${option}`);
|
|
114
|
+
if (option === '--mode' && value !== 'init' && value !== 'update') {
|
|
115
|
+
throw new Error('Invalid value for --mode: expected init or update');
|
|
116
|
+
}
|
|
117
|
+
index += 1;
|
|
118
|
+
}
|
|
119
|
+
return argv;
|
|
120
|
+
}
|
|
121
|
+
function scriptArgs(command, argv) {
|
|
122
|
+
if (command === 'start')
|
|
123
|
+
return ensureNoArgs(command, argv);
|
|
124
|
+
if (command === 'stop')
|
|
125
|
+
return ensureNoArgs(command, argv);
|
|
126
|
+
if (command === 'logs')
|
|
127
|
+
return optionalSingleArg(command, argv, 'odoo');
|
|
128
|
+
if (command === 'restart')
|
|
129
|
+
return ensureNoArgs(command, argv);
|
|
130
|
+
if (command === 'shell')
|
|
131
|
+
return ensureNoArgs(command, argv);
|
|
132
|
+
if (command === 'psql')
|
|
133
|
+
return optionalSingleArg(command, argv, 'postgres');
|
|
134
|
+
if (command === 'install' || command === 'update')
|
|
135
|
+
return moduleArgs(command, argv);
|
|
136
|
+
if (command === 'test')
|
|
137
|
+
return testArgs(argv);
|
|
138
|
+
if (command === 'resetdb')
|
|
139
|
+
return positionalArgs(command, argv, 0, 2);
|
|
140
|
+
if (command === 'snapshot')
|
|
141
|
+
return positionalArgs(command, argv, 0, 2);
|
|
142
|
+
if (command === 'restore-snapshot')
|
|
143
|
+
return restoreSnapshotArgs(argv);
|
|
144
|
+
if (command === 'lint')
|
|
145
|
+
return ensureNoArgs(command, argv);
|
|
146
|
+
return positionalArgs(command, argv, 1, 3);
|
|
147
|
+
}
|
|
148
|
+
async function assertEnvironmentRoot(cwd) {
|
|
149
|
+
try {
|
|
150
|
+
await access(join(cwd, markerPath));
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
throw new Error('Daily actions must be run from a WPMoo Toolkit environment root containing .wpmoo/odoo.json.');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async function assertScriptExists(cwd, script) {
|
|
157
|
+
const scriptPath = join(cwd, 'scripts', script);
|
|
158
|
+
try {
|
|
159
|
+
await access(scriptPath);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
throw new Error(`Missing daily action script: scripts/${script}`);
|
|
163
|
+
}
|
|
164
|
+
return scriptPath;
|
|
165
|
+
}
|
|
166
|
+
export async function dailyActionPlan(command, argv, cwd = process.cwd()) {
|
|
167
|
+
await assertEnvironmentRoot(cwd);
|
|
168
|
+
const scriptPath = await assertScriptExists(cwd, dailyActionScripts[command]);
|
|
169
|
+
return {
|
|
170
|
+
cwd,
|
|
171
|
+
scriptPath,
|
|
172
|
+
args: scriptArgs(command, argv),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async function spawnDailyAction(plan) {
|
|
176
|
+
const child = spawn(plan.scriptPath, plan.args, {
|
|
177
|
+
cwd: plan.cwd,
|
|
178
|
+
stdio: 'inherit',
|
|
179
|
+
});
|
|
180
|
+
const exitCode = await new Promise((resolve, reject) => {
|
|
181
|
+
child.on('error', reject);
|
|
182
|
+
child.on('close', resolve);
|
|
183
|
+
});
|
|
184
|
+
if (exitCode !== 0) {
|
|
185
|
+
throw new Error(`Daily action script exited with code ${exitCode ?? 'unknown'}: ${plan.scriptPath}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export async function runDailyAction(command, argv, cwd = process.cwd(), runner = spawnDailyAction) {
|
|
189
|
+
await runner(await dailyActionPlan(command, argv, cwd));
|
|
190
|
+
}
|