@bootmap/wpep-cli 1.0.0 → 1.0.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/bin/wpep.js +1 -1
- package/package.json +1 -1
- package/src/commands/deploy.js +34 -2
- package/src/commands/init.js +14 -1
package/bin/wpep.js
CHANGED
|
@@ -26,7 +26,7 @@ program
|
|
|
26
26
|
program
|
|
27
27
|
.command('deploy')
|
|
28
28
|
.description('Build and deploy your Next.js project to WordPress')
|
|
29
|
-
.option('-d, --dir <dir>', 'The export directory to deploy'
|
|
29
|
+
.option('-d, --dir <dir>', 'The export directory to deploy')
|
|
30
30
|
.option('-u, --url <url>', 'WordPress site URL (overrides .wpeprc)')
|
|
31
31
|
.option('-k, --key <key>', 'WPEP API Key (overrides .wpeprc)')
|
|
32
32
|
.option('--no-build', 'Skip running the build step')
|
package/package.json
CHANGED
package/src/commands/deploy.js
CHANGED
|
@@ -4,6 +4,7 @@ import crypto from 'crypto';
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import ora from 'ora';
|
|
6
6
|
import { execSync } from 'child_process';
|
|
7
|
+
import inquirer from 'inquirer';
|
|
7
8
|
|
|
8
9
|
function getFiles(dir, files = []) {
|
|
9
10
|
if (!fs.existsSync(dir)) return files;
|
|
@@ -30,6 +31,7 @@ export default async function deployCommand(options) {
|
|
|
30
31
|
const config = JSON.parse(fs.readFileSync(rcPath, 'utf8'));
|
|
31
32
|
url = url || config.url;
|
|
32
33
|
key = key || config.key;
|
|
34
|
+
options.dir = options.dir || config.dir;
|
|
33
35
|
} catch (e) {
|
|
34
36
|
throw new Error('Could not read .wpeprc.json. Run "wpep init" first.');
|
|
35
37
|
}
|
|
@@ -54,9 +56,39 @@ export default async function deployCommand(options) {
|
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
let outputDir = options.dir;
|
|
60
|
+
|
|
61
|
+
if (!outputDir) {
|
|
62
|
+
const possibleDirs = ['out', 'dist', 'build'];
|
|
63
|
+
const existingDirs = possibleDirs.filter(d => fs.existsSync(path.join(process.cwd(), d)));
|
|
64
|
+
|
|
65
|
+
if (existingDirs.length === 1) {
|
|
66
|
+
outputDir = existingDirs[0];
|
|
67
|
+
console.log(chalk.gray(`Auto-detected export directory: ${outputDir}`));
|
|
68
|
+
} else if (existingDirs.length > 1) {
|
|
69
|
+
const answers = await inquirer.prompt([
|
|
70
|
+
{
|
|
71
|
+
type: 'list',
|
|
72
|
+
name: 'dir',
|
|
73
|
+
message: 'Multiple export directories found. Which one do you want to deploy?',
|
|
74
|
+
choices: existingDirs
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
outputDir = answers.dir;
|
|
78
|
+
} else {
|
|
79
|
+
outputDir = 'out'; // fallback
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (outputDir === '.next') {
|
|
84
|
+
console.log(chalk.yellow.bold('\n⚠️ WARNING: You are trying to deploy the ".next" directory.'));
|
|
85
|
+
console.log(chalk.yellow('This contains Node.js server files, not static HTML.'));
|
|
86
|
+
console.log(chalk.yellow('WPEP only hosts static HTML. Please add { output: "export" } to your next.config.ts/js to generate an "out" directory instead.\n'));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const outDir = path.join(process.cwd(), outputDir);
|
|
58
90
|
if (!fs.existsSync(outDir)) {
|
|
59
|
-
throw new Error(`Export directory "${
|
|
91
|
+
throw new Error(`Export directory "${outputDir}" does not exist. Did the build succeed?`);
|
|
60
92
|
}
|
|
61
93
|
|
|
62
94
|
const spinner = ora('Preparing files for upload...').start();
|
package/src/commands/init.js
CHANGED
|
@@ -41,6 +41,18 @@ export default async function initCommand() {
|
|
|
41
41
|
}
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: 'input',
|
|
47
|
+
name: 'dir',
|
|
48
|
+
message: 'What is your export directory? (default: out)',
|
|
49
|
+
default: existingConfig.dir || 'out',
|
|
50
|
+
validate: (input) => {
|
|
51
|
+
if (input.trim() === '') {
|
|
52
|
+
return 'Directory is required';
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
44
56
|
}
|
|
45
57
|
]);
|
|
46
58
|
|
|
@@ -49,7 +61,8 @@ export default async function initCommand() {
|
|
|
49
61
|
|
|
50
62
|
const config = {
|
|
51
63
|
url: cleanUrl,
|
|
52
|
-
key: answers.key.trim()
|
|
64
|
+
key: answers.key.trim(),
|
|
65
|
+
dir: answers.dir.trim()
|
|
53
66
|
};
|
|
54
67
|
|
|
55
68
|
fs.writeFileSync(rcPath, JSON.stringify(config, null, 2));
|