@bootmap/wpep-cli 1.0.3 → 1.0.5
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 +23 -31
package/package.json
CHANGED
package/src/commands/deploy.js
CHANGED
|
@@ -56,37 +56,29 @@ 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
|
+
}
|
|
87
77
|
}
|
|
88
78
|
|
|
79
|
+
outputDir = 'wpep-build';
|
|
89
80
|
const outDir = path.join(process.cwd(), outputDir);
|
|
81
|
+
|
|
90
82
|
if (!fs.existsSync(outDir)) {
|
|
91
83
|
throw new Error(`Export directory "${outputDir}" does not exist. Did the build succeed?`);
|
|
92
84
|
}
|
|
@@ -100,7 +92,7 @@ export default async function deployCommand(options) {
|
|
|
100
92
|
const data = fs.readFileSync(file);
|
|
101
93
|
filesList[relativePath] = crypto.createHash('sha256').update(data).digest('hex');
|
|
102
94
|
}
|
|
103
|
-
|
|
95
|
+
|
|
104
96
|
spinner.text = `Creating deployment session for ${allFiles.length} files...`;
|
|
105
97
|
|
|
106
98
|
let deployId;
|
|
@@ -110,14 +102,14 @@ export default async function deployCommand(options) {
|
|
|
110
102
|
headers: { 'Content-Type': 'application/json', 'x-wpep-api-key': key },
|
|
111
103
|
body: JSON.stringify({ files: filesList })
|
|
112
104
|
});
|
|
113
|
-
|
|
105
|
+
|
|
114
106
|
if (!createRes.ok) {
|
|
115
107
|
throw new Error(`Server returned ${createRes.status} ${createRes.statusText}`);
|
|
116
108
|
}
|
|
117
|
-
|
|
109
|
+
|
|
118
110
|
const createData = await createRes.json();
|
|
119
111
|
if (!createData.deployment_id) {
|
|
120
|
-
|
|
112
|
+
throw new Error(`Invalid response from server: ${JSON.stringify(createData)}`);
|
|
121
113
|
}
|
|
122
114
|
deployId = createData.deployment_id;
|
|
123
115
|
} catch (e) {
|
|
@@ -136,7 +128,7 @@ export default async function deployCommand(options) {
|
|
|
136
128
|
const hash = filesList[relativePath];
|
|
137
129
|
|
|
138
130
|
const uploadSpinner = ora(`Uploading ${relativePath}...`).start();
|
|
139
|
-
|
|
131
|
+
|
|
140
132
|
try {
|
|
141
133
|
const uploadRes = await fetch(`${url}/wp-json/wpep/v1/deployments/${deployId}/upload`, {
|
|
142
134
|
method: 'POST',
|
|
@@ -161,7 +153,7 @@ export default async function deployCommand(options) {
|
|
|
161
153
|
headers: { 'Content-Type': 'application/json', 'x-wpep-api-key': key }
|
|
162
154
|
});
|
|
163
155
|
if (!activateRes.ok) {
|
|
164
|
-
|
|
156
|
+
throw new Error(`Activation failed: ${activateRes.statusText}`);
|
|
165
157
|
}
|
|
166
158
|
activateSpinner.succeed('Deployment activated successfully!');
|
|
167
159
|
} catch (e) {
|