@bootmap/wpep-cli 1.0.3 → 1.0.7
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 +1 -1
- package/src/commands/deploy.js +37 -31
package/package.json
CHANGED
package/src/commands/deploy.js
CHANGED
|
@@ -56,37 +56,43 @@ export default async function deployCommand(options) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
let outputDir = options.dir;
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
let outputDir = options.dir || 'wpep-build';
|
|
60
|
+
const targetDir = path.join(process.cwd(), 'wpep-build');
|
|
61
|
+
|
|
62
|
+
if (!fs.existsSync(targetDir)) {
|
|
63
|
+
// Try to auto-detect and move/copy to wpep-build
|
|
62
64
|
const possibleDirs = ['out', 'dist', 'build'];
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
|
65
|
+
let foundDir = null;
|
|
66
|
+
for (const d of possibleDirs) {
|
|
67
|
+
if (fs.existsSync(path.join(process.cwd(), d))) {
|
|
68
|
+
foundDir = d;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
80
71
|
}
|
|
81
|
-
}
|
|
82
72
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
if (foundDir) {
|
|
74
|
+
console.log(chalk.gray(`Auto-detected build in "${foundDir}". Copying to "wpep-build"...`));
|
|
75
|
+
fs.cpSync(path.join(process.cwd(), foundDir), targetDir, { recursive: true });
|
|
76
|
+
} else if (fs.existsSync(path.join(process.cwd(), '.next'))) {
|
|
77
|
+
console.log(chalk.red.bold('\n⚠️ ERROR: No static export directory found, but a ".next" directory exists.'));
|
|
78
|
+
console.log(chalk.red('Next.js is currently building a Node.js server app, which cannot be hosted on WordPress.\n'));
|
|
79
|
+
|
|
80
|
+
console.log(chalk.yellow.bold('--- How to fix your Next.js App ---'));
|
|
81
|
+
console.log(chalk.yellow('To actually make your deployment work, you MUST configure Next.js to export static HTML.'));
|
|
82
|
+
console.log(chalk.yellow('Open your next.config.ts (or .js) and add `output: "export"` inside your config object:\n'));
|
|
83
|
+
|
|
84
|
+
console.log(chalk.cyan('const nextConfig: NextConfig = {'));
|
|
85
|
+
console.log(chalk.green(' output: "export",'));
|
|
86
|
+
console.log(chalk.cyan(' // ... rest of your config'));
|
|
87
|
+
console.log(chalk.cyan('};\n'));
|
|
88
|
+
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
87
91
|
}
|
|
88
92
|
|
|
93
|
+
outputDir = 'wpep-build';
|
|
89
94
|
const outDir = path.join(process.cwd(), outputDir);
|
|
95
|
+
|
|
90
96
|
if (!fs.existsSync(outDir)) {
|
|
91
97
|
throw new Error(`Export directory "${outputDir}" does not exist. Did the build succeed?`);
|
|
92
98
|
}
|
|
@@ -100,7 +106,7 @@ export default async function deployCommand(options) {
|
|
|
100
106
|
const data = fs.readFileSync(file);
|
|
101
107
|
filesList[relativePath] = crypto.createHash('sha256').update(data).digest('hex');
|
|
102
108
|
}
|
|
103
|
-
|
|
109
|
+
|
|
104
110
|
spinner.text = `Creating deployment session for ${allFiles.length} files...`;
|
|
105
111
|
|
|
106
112
|
let deployId;
|
|
@@ -110,14 +116,14 @@ export default async function deployCommand(options) {
|
|
|
110
116
|
headers: { 'Content-Type': 'application/json', 'x-wpep-api-key': key },
|
|
111
117
|
body: JSON.stringify({ files: filesList })
|
|
112
118
|
});
|
|
113
|
-
|
|
119
|
+
|
|
114
120
|
if (!createRes.ok) {
|
|
115
121
|
throw new Error(`Server returned ${createRes.status} ${createRes.statusText}`);
|
|
116
122
|
}
|
|
117
|
-
|
|
123
|
+
|
|
118
124
|
const createData = await createRes.json();
|
|
119
125
|
if (!createData.deployment_id) {
|
|
120
|
-
|
|
126
|
+
throw new Error(`Invalid response from server: ${JSON.stringify(createData)}`);
|
|
121
127
|
}
|
|
122
128
|
deployId = createData.deployment_id;
|
|
123
129
|
} catch (e) {
|
|
@@ -136,7 +142,7 @@ export default async function deployCommand(options) {
|
|
|
136
142
|
const hash = filesList[relativePath];
|
|
137
143
|
|
|
138
144
|
const uploadSpinner = ora(`Uploading ${relativePath}...`).start();
|
|
139
|
-
|
|
145
|
+
|
|
140
146
|
try {
|
|
141
147
|
const uploadRes = await fetch(`${url}/wp-json/wpep/v1/deployments/${deployId}/upload`, {
|
|
142
148
|
method: 'POST',
|
|
@@ -161,7 +167,7 @@ export default async function deployCommand(options) {
|
|
|
161
167
|
headers: { 'Content-Type': 'application/json', 'x-wpep-api-key': key }
|
|
162
168
|
});
|
|
163
169
|
if (!activateRes.ok) {
|
|
164
|
-
|
|
170
|
+
throw new Error(`Activation failed: ${activateRes.statusText}`);
|
|
165
171
|
}
|
|
166
172
|
activateSpinner.succeed('Deployment activated successfully!');
|
|
167
173
|
} catch (e) {
|