@bootmap/wpep-cli 1.0.5 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bootmap/wpep-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "description": "CLI tool for deploying Next.js static exports to WordPress via WP Elementor Publisher",
5
5
  "main": "bin/wpep.js",
6
6
  "type": "module",
@@ -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 move/copy to wpep-build
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) {
@@ -78,7 +120,7 @@ export default async function deployCommand(options) {
78
120
 
79
121
  outputDir = 'wpep-build';
80
122
  const outDir = path.join(process.cwd(), outputDir);
81
-
123
+
82
124
  if (!fs.existsSync(outDir)) {
83
125
  throw new Error(`Export directory "${outputDir}" does not exist. Did the build succeed?`);
84
126
  }