@maker-or/opencms 0.1.1 → 0.1.2
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/dist/index.js +19 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -207,6 +207,12 @@ async function ensureToken(config) {
|
|
|
207
207
|
await writeConfig({ ...config, token: loggedInToken, apiUrl: config.apiUrl ?? apiUrl });
|
|
208
208
|
return loggedInToken;
|
|
209
209
|
}
|
|
210
|
+
async function reauthenticate(config) {
|
|
211
|
+
console.log("Your OpenCMS session has expired. Opening browser login…");
|
|
212
|
+
const loggedInToken = await browserLogin();
|
|
213
|
+
await writeConfig({ ...config, token: loggedInToken, apiUrl: config.apiUrl ?? apiUrl });
|
|
214
|
+
return loggedInToken;
|
|
215
|
+
}
|
|
210
216
|
async function login() {
|
|
211
217
|
const config = await readConfig();
|
|
212
218
|
if (process.env.OPENCMS_CLERK_TOKEN) {
|
|
@@ -292,8 +298,19 @@ async function createProject() {
|
|
|
292
298
|
const name = await ask("Project name: ");
|
|
293
299
|
if (!name)
|
|
294
300
|
throw new Error("A project name is required.");
|
|
295
|
-
|
|
296
|
-
|
|
301
|
+
let currentConfig = await readConfig();
|
|
302
|
+
let client = sdk(currentConfig);
|
|
303
|
+
let project;
|
|
304
|
+
try {
|
|
305
|
+
project = await client.projects.create({ name });
|
|
306
|
+
} catch (error) {
|
|
307
|
+
if (!(error instanceof OpenCmsApiError) || error.status !== 401)
|
|
308
|
+
throw error;
|
|
309
|
+
await reauthenticate(currentConfig);
|
|
310
|
+
currentConfig = await readConfig();
|
|
311
|
+
client = sdk(currentConfig);
|
|
312
|
+
project = await client.projects.create({ name });
|
|
313
|
+
}
|
|
297
314
|
const destination = resolve(process.cwd(), slugify(project.name));
|
|
298
315
|
await pullTemplate(destination);
|
|
299
316
|
const baseUrl = process.env.OPENCMS_API_URL ?? config.apiUrl ?? apiUrl;
|