@bostonuniversity/buwp-local 0.1.0 ā 0.2.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/USAGE.md +15 -1
- package/bin/buwp-local.js +9 -4
- package/bostonuniversity-buwp-local-0.2.0.tgz +0 -0
- package/lib/commands/shell.js +71 -0
- package/lib/commands/wp.js +57 -0
- package/package.json +1 -1
package/USAGE.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
### 1. Install in your project
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install --save-dev buwp-local
|
|
8
|
+
npm install --save-dev @bostonuniversity/buwp-local
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
### 2. Initialize configuration
|
|
@@ -14,6 +14,12 @@ npm install --save-dev buwp-local
|
|
|
14
14
|
npx buwp-local config --init
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
```bash
|
|
18
|
+
buwp-local config --init --plugin # For plugins
|
|
19
|
+
buwp-local config --init --mu-plugin # For mu-plugins
|
|
20
|
+
buwp-local config --init --theme # For themes
|
|
21
|
+
```
|
|
22
|
+
|
|
17
23
|
This creates `.buwp-local.json` in your project directory.
|
|
18
24
|
|
|
19
25
|
### 3. Edit configuration
|
|
@@ -250,6 +256,14 @@ See the resolved configuration (with masked secrets):
|
|
|
250
256
|
npx buwp-local config --show
|
|
251
257
|
```
|
|
252
258
|
|
|
259
|
+
## WP-CLI Command
|
|
260
|
+
```bash
|
|
261
|
+
buwp-local wp user list
|
|
262
|
+
buwp-local wp post list --format=json
|
|
263
|
+
buwp-local wp plugin activate akismet
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
|
|
253
267
|
## Next Steps
|
|
254
268
|
|
|
255
269
|
- [ ] Phase 2: WP-CLI proxy command
|
package/bin/buwp-local.js
CHANGED
|
@@ -14,6 +14,8 @@ const startCommand = require('../lib/commands/start');
|
|
|
14
14
|
const stopCommand = require('../lib/commands/stop');
|
|
15
15
|
const destroyCommand = require('../lib/commands/destroy');
|
|
16
16
|
const logsCommand = require('../lib/commands/logs');
|
|
17
|
+
const wpCommand = require('../lib/commands/wp');
|
|
18
|
+
const shellCommand = require('../lib/commands/shell');
|
|
17
19
|
const configCommand = require('../lib/commands/config');
|
|
18
20
|
|
|
19
21
|
const program = new Command();
|
|
@@ -70,10 +72,13 @@ program
|
|
|
70
72
|
.command('wp <args...>')
|
|
71
73
|
.description('Run WP-CLI commands in the WordPress container')
|
|
72
74
|
.allowUnknownOption()
|
|
73
|
-
.action(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
.action(wpCommand);
|
|
76
|
+
|
|
77
|
+
// Shell command
|
|
78
|
+
program
|
|
79
|
+
.command('shell')
|
|
80
|
+
.description('Open an interactive bash shell in the WordPress container')
|
|
81
|
+
.action(shellCommand);
|
|
77
82
|
|
|
78
83
|
// Error handling
|
|
79
84
|
program.exitOverride();
|
|
Binary file
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell command - Open an interactive bash shell in the WordPress container
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const { spawnSync } = require('child_process');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const { loadConfig } = require('../config');
|
|
10
|
+
|
|
11
|
+
async function shellCommand(options) {
|
|
12
|
+
console.log(chalk.blue('š Opening interactive shell...\n'));
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const projectPath = process.cwd();
|
|
16
|
+
const composePath = path.join(projectPath, '.buwp-local', 'docker-compose.yml');
|
|
17
|
+
|
|
18
|
+
// Check if docker-compose.yml exists
|
|
19
|
+
if (!fs.existsSync(composePath)) {
|
|
20
|
+
console.log(chalk.yellow('ā ļø No running environment found.'));
|
|
21
|
+
console.log(chalk.gray('Run "buwp-local start" to create an environment.\n'));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Load config to get project name
|
|
26
|
+
const config = loadConfig(projectPath);
|
|
27
|
+
const projectName = config.projectName || 'buwp-local';
|
|
28
|
+
|
|
29
|
+
// Check if Docker is running
|
|
30
|
+
try {
|
|
31
|
+
spawnSync('docker', ['info'], { stdio: 'ignore' });
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error(chalk.red('ā Docker is not running.'));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Build docker compose exec command for interactive shell
|
|
38
|
+
const composeDir = path.dirname(composePath);
|
|
39
|
+
|
|
40
|
+
// Use spawnSync instead of execSync for proper TTY handling
|
|
41
|
+
const result = spawnSync(
|
|
42
|
+
'docker',
|
|
43
|
+
[
|
|
44
|
+
'compose',
|
|
45
|
+
'-p', projectName,
|
|
46
|
+
'-f', composePath,
|
|
47
|
+
'exec',
|
|
48
|
+
'wordpress',
|
|
49
|
+
'/bin/bash'
|
|
50
|
+
],
|
|
51
|
+
{
|
|
52
|
+
cwd: composeDir,
|
|
53
|
+
stdio: 'inherit',
|
|
54
|
+
shell: false
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Only show exit message if shell exited with error
|
|
59
|
+
if (result.status !== 0 && result.status !== null) {
|
|
60
|
+
console.log(chalk.yellow(`\nā ļø Shell exited with code ${result.status}\n`));
|
|
61
|
+
} else {
|
|
62
|
+
console.log(chalk.gray('\nš Shell closed.\n'));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
} catch (err) {
|
|
66
|
+
console.error(chalk.red('\nā Error:'), err.message);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = shellCommand;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WP-CLI proxy command - Execute WP-CLI commands in the WordPress container
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const { execSync } = require('child_process');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const { loadConfig } = require('../config');
|
|
10
|
+
|
|
11
|
+
async function wpCommand(args, options) {
|
|
12
|
+
try {
|
|
13
|
+
const projectPath = process.cwd();
|
|
14
|
+
const composePath = path.join(projectPath, '.buwp-local', 'docker-compose.yml');
|
|
15
|
+
|
|
16
|
+
// Check if docker-compose.yml exists
|
|
17
|
+
if (!fs.existsSync(composePath)) {
|
|
18
|
+
console.log(chalk.yellow('ā ļø No running environment found.'));
|
|
19
|
+
console.log(chalk.gray('Run "buwp-local start" to create an environment.\n'));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Load config to get project name
|
|
24
|
+
const config = loadConfig(projectPath);
|
|
25
|
+
const projectName = config.projectName || 'buwp-local';
|
|
26
|
+
|
|
27
|
+
// Check if Docker is running
|
|
28
|
+
try {
|
|
29
|
+
execSync('docker info', { stdio: 'ignore' });
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error(chalk.red('ā Docker is not running.'));
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Build docker compose exec command for WP-CLI
|
|
36
|
+
const composeDir = path.dirname(composePath);
|
|
37
|
+
const wpArgs = args.join(' ');
|
|
38
|
+
const command = `docker compose -p ${projectName} -f ${composePath} exec wordpress wp ${wpArgs}`;
|
|
39
|
+
|
|
40
|
+
// Execute WP-CLI command
|
|
41
|
+
try {
|
|
42
|
+
execSync(command, {
|
|
43
|
+
cwd: composeDir,
|
|
44
|
+
stdio: 'inherit'
|
|
45
|
+
});
|
|
46
|
+
} catch (err) {
|
|
47
|
+
// WP-CLI may exit with error codes (e.g., failed import), don't exit harshly
|
|
48
|
+
// The error output is already shown via stdio: 'inherit'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
} catch (err) {
|
|
52
|
+
console.error(chalk.red('\nā Error:'), err.message);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = wpCommand;
|