@bootmap/wpep-cli 1.0.7 → 1.0.8
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 +43 -15
package/package.json
CHANGED
package/src/commands/deploy.js
CHANGED
|
@@ -47,20 +47,62 @@ export default async function deployCommand(options) {
|
|
|
47
47
|
|
|
48
48
|
console.log(chalk.blue.bold(`\nDeploying to ${url} ...\n`));
|
|
49
49
|
|
|
50
|
+
// ── Auto-detect framework and patch config before building ──────────────
|
|
51
|
+
let nextConfigPath = null;
|
|
52
|
+
let nextConfigBackup = null;
|
|
53
|
+
|
|
54
|
+
const configCandidates = ['next.config.ts', 'next.config.mjs', 'next.config.js'];
|
|
55
|
+
for (const c of configCandidates) {
|
|
56
|
+
const p = path.join(process.cwd(), c);
|
|
57
|
+
if (fs.existsSync(p)) {
|
|
58
|
+
nextConfigPath = p;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// If it's a Next.js project, inject output: "export" automatically
|
|
64
|
+
if (nextConfigPath) {
|
|
65
|
+
const originalContent = fs.readFileSync(nextConfigPath, 'utf8');
|
|
66
|
+
|
|
67
|
+
if (!originalContent.includes('output:') && !originalContent.includes("output :")) {
|
|
68
|
+
nextConfigBackup = originalContent;
|
|
69
|
+
console.log(chalk.yellow('⚡ Detected Next.js project without static export configured.'));
|
|
70
|
+
console.log(chalk.yellow(' Auto-injecting { output: "export" } for this deployment...\n'));
|
|
71
|
+
|
|
72
|
+
// Inject output: "export" right after the opening brace of the config object
|
|
73
|
+
const patched = originalContent.replace(
|
|
74
|
+
/(\bconst\s+\w+\s*(?::\s*\w+)?\s*=\s*\{)/,
|
|
75
|
+
'$1\n output: "export",'
|
|
76
|
+
);
|
|
77
|
+
fs.writeFileSync(nextConfigPath, patched, 'utf8');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
50
81
|
if (options.build !== false) {
|
|
51
82
|
console.log(chalk.gray('Running npm run build...'));
|
|
52
83
|
try {
|
|
53
84
|
execSync('npm run build', { stdio: 'inherit' });
|
|
54
85
|
} catch (e) {
|
|
86
|
+
// Restore original config before throwing
|
|
87
|
+
if (nextConfigBackup && nextConfigPath) {
|
|
88
|
+
fs.writeFileSync(nextConfigPath, nextConfigBackup, 'utf8');
|
|
89
|
+
console.log(chalk.gray('Restored original next.config after failed build.'));
|
|
90
|
+
}
|
|
55
91
|
throw new Error('Build failed. See output above.');
|
|
56
92
|
}
|
|
57
93
|
}
|
|
58
94
|
|
|
95
|
+
// Restore the original next.config so git stays clean
|
|
96
|
+
if (nextConfigBackup && nextConfigPath) {
|
|
97
|
+
fs.writeFileSync(nextConfigPath, nextConfigBackup, 'utf8');
|
|
98
|
+
console.log(chalk.gray('Restored original next.config after build.\n'));
|
|
99
|
+
}
|
|
100
|
+
|
|
59
101
|
let outputDir = options.dir || 'wpep-build';
|
|
60
102
|
const targetDir = path.join(process.cwd(), 'wpep-build');
|
|
61
103
|
|
|
62
104
|
if (!fs.existsSync(targetDir)) {
|
|
63
|
-
// Try to auto-detect and
|
|
105
|
+
// Try to auto-detect and copy to wpep-build
|
|
64
106
|
const possibleDirs = ['out', 'dist', 'build'];
|
|
65
107
|
let foundDir = null;
|
|
66
108
|
for (const d of possibleDirs) {
|
|
@@ -73,20 +115,6 @@ export default async function deployCommand(options) {
|
|
|
73
115
|
if (foundDir) {
|
|
74
116
|
console.log(chalk.gray(`Auto-detected build in "${foundDir}". Copying to "wpep-build"...`));
|
|
75
117
|
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
118
|
}
|
|
91
119
|
}
|
|
92
120
|
|