@maker-or/opencms 0.1.5 → 0.1.6

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.
Files changed (2) hide show
  1. package/dist/index.js +23 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -211,6 +211,7 @@ var dashboardUrl = process.env.OPENCMS_DASHBOARD_URL ?? hostedUrl;
211
211
  var apiUrl = process.env.OPENCMS_API_URL ?? hostedUrl;
212
212
  var configRoot = process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config");
213
213
  var configPath = join(configRoot, "opencms", "config.json");
214
+ var legacyLocalApiUrl = "http://localhost:3000";
214
215
  async function readConfig() {
215
216
  if (!await fileExists(configPath))
216
217
  return {};
@@ -228,9 +229,16 @@ async function writeConfig(config) {
228
229
  function tokenFor(config) {
229
230
  return process.env.OPENCMS_CLERK_TOKEN ?? config.token ?? null;
230
231
  }
232
+ function apiUrlFor(config) {
233
+ if (process.env.OPENCMS_API_URL)
234
+ return process.env.OPENCMS_API_URL;
235
+ if (config?.apiUrl && config.apiUrl !== legacyLocalApiUrl)
236
+ return config.apiUrl;
237
+ return apiUrl;
238
+ }
231
239
  function sdk(config, projectId) {
232
240
  return createSdk({
233
- baseUrl: process.env.OPENCMS_API_URL ?? config.apiUrl ?? apiUrl,
241
+ baseUrl: apiUrlFor(config),
234
242
  projectId,
235
243
  getToken: () => tokenFor(config)
236
244
  });
@@ -317,7 +325,7 @@ async function ensureToken(config) {
317
325
  if (token)
318
326
  return token;
319
327
  const loggedInToken = await browserLogin();
320
- await writeConfig({ ...config, token: loggedInToken, apiUrl: config.apiUrl ?? apiUrl });
328
+ await writeConfig({ ...config, token: loggedInToken, apiUrl: apiUrlFor(config) });
321
329
  return loggedInToken;
322
330
  }
323
331
  async function reauthenticate(config) {
@@ -326,18 +334,18 @@ async function reauthenticate(config) {
326
334
  }
327
335
  console.log("Your OpenCMS session has expired. Opening browser login…");
328
336
  const loggedInToken = await browserLogin();
329
- await writeConfig({ ...config, token: loggedInToken, apiUrl: config.apiUrl ?? apiUrl });
337
+ await writeConfig({ ...config, token: loggedInToken, apiUrl: apiUrlFor(config) });
330
338
  return loggedInToken;
331
339
  }
332
340
  async function login() {
333
341
  const config = await readConfig();
334
342
  if (process.env.OPENCMS_CLERK_TOKEN) {
335
- await writeConfig({ ...config, token: process.env.OPENCMS_CLERK_TOKEN, apiUrl: config.apiUrl ?? apiUrl });
343
+ await writeConfig({ ...config, token: process.env.OPENCMS_CLERK_TOKEN, apiUrl: apiUrlFor(config) });
336
344
  console.log("Saved OPENCMS_CLERK_TOKEN for local CLI use.");
337
345
  return;
338
346
  }
339
347
  const loggedInToken = await browserLogin();
340
- await writeConfig({ ...config, token: loggedInToken, apiUrl: config.apiUrl ?? apiUrl });
348
+ await writeConfig({ ...config, token: loggedInToken, apiUrl: apiUrlFor(config) });
341
349
  console.log("Logged in to OpenCMS.");
342
350
  }
343
351
  async function logout() {
@@ -435,7 +443,7 @@ async function createProject() {
435
443
  }
436
444
  const destination = resolve(process.cwd(), slugify(project.name));
437
445
  await pullTemplate(destination);
438
- const baseUrl = process.env.OPENCMS_API_URL ?? config.apiUrl ?? apiUrl;
446
+ const baseUrl = apiUrlFor(config);
439
447
  await writeProjectEnv(destination, project, baseUrl);
440
448
  await ensureCmsDirectory(destination, project, baseUrl);
441
449
  await installDependencies(destination);
@@ -463,7 +471,15 @@ async function runDev() {
463
471
  }
464
472
  const manager = await packageManager(process.cwd());
465
473
  const command = manager[0] === "npm" ? ["npm", "run", "dev"] : manager[0] === "pnpm" ? ["pnpm", "dev"] : manager[0] === "yarn" ? ["yarn", "dev"] : ["bun", "run", "dev"];
466
- process.exit(await runCommand(command[0], command.slice(1), { cwd: process.cwd(), env: { ...process.env, OPENCMS_ENVIRONMENT: "development" }, inherit: true }));
474
+ process.exit(await runCommand(command[0], command.slice(1), {
475
+ cwd: process.cwd(),
476
+ env: {
477
+ ...process.env,
478
+ OPENCMS_API_URL: apiUrlFor(await readConfig()),
479
+ OPENCMS_ENVIRONMENT: "development"
480
+ },
481
+ inherit: true
482
+ }));
467
483
  }
468
484
  async function syncLocalSchema(projectId, config) {
469
485
  if (!projectId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maker-or/opencms",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "The developer-first CLI for OpenCMS",
5
5
  "type": "module",
6
6
  "repository": {