@clerk/dev-cli 0.0.6 → 0.0.7-canary.v2f37bd2

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@clerk/dev-cli",
3
3
  "description": "CLI tool designed to simplify the process of iterating on packages within the clerk/javascript repository",
4
- "version": "0.0.6",
4
+ "version": "0.0.7-canary.v2f37bd2",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "author": "Clerk",
package/src/cli.js CHANGED
@@ -66,5 +66,8 @@ export default function cli() {
66
66
  await watch({ js });
67
67
  });
68
68
 
69
- program.parseAsync();
69
+ program.parseAsync().catch(err => {
70
+ console.error(err.message);
71
+ process.exit(1);
72
+ });
70
73
  }
@@ -1,4 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { existsSync } from 'node:fs';
2
3
  import { mkdir, writeFile } from 'node:fs/promises';
3
4
  import { dirname, join } from 'node:path';
4
5
 
@@ -9,6 +10,12 @@ import { getCLIRoot } from '../utils/getMonorepoRoot.js';
9
10
  * Performs one-time machine-level configuration tasks such as creating a blank config file.
10
11
  */
11
12
  export async function init() {
13
+ // If the config file already exists, print a warning and exit.
14
+ if (existsSync(CONFIG_FILE)) {
15
+ console.warn('Configuration file already exists. Run `clerk-dev config` to open it.');
16
+ return;
17
+ }
18
+
12
19
  const cliRoot = getCLIRoot();
13
20
 
14
21
  /** @type import('../utils/getConfiguration.js').Configuration */
@@ -6,6 +6,7 @@ import { join } from 'node:path';
6
6
  import { parse } from 'dotenv';
7
7
 
8
8
  import { applyCodemod } from '../codemods/index.js';
9
+ import { INVALID_INSTANCE_KEYS_ERROR } from '../utils/errors.js';
9
10
  import { getClerkPackages } from '../utils/getClerkPackages.js';
10
11
  import { getConfiguration } from '../utils/getConfiguration.js';
11
12
  import { getDependencies } from '../utils/getDependencies.js';
@@ -64,7 +65,11 @@ async function detectFramework() {
64
65
  */
65
66
  async function getInstanceConfiguration(configuration) {
66
67
  const { activeInstance, instances } = configuration;
67
- return instances[activeInstance];
68
+ const activeInstanceConfig = instances[activeInstance];
69
+ if (!activeInstanceConfig.publishableKey.startsWith('pk_') || !activeInstanceConfig.secretKey.startsWith('sk_')) {
70
+ throw new Error(INVALID_INSTANCE_KEYS_ERROR);
71
+ }
72
+ return activeInstanceConfig;
68
73
  }
69
74
 
70
75
  /**
@@ -2,6 +2,7 @@ import { join } from 'node:path';
2
2
 
3
3
  import concurrently from 'concurrently';
4
4
 
5
+ import { NULL_ROOT_ERROR } from '../utils/errors.js';
5
6
  import { getClerkPackages } from '../utils/getClerkPackages.js';
6
7
  import { getDependencies } from '../utils/getDependencies.js';
7
8
  import { getMonorepoRoot } from '../utils/getMonorepoRoot.js';
@@ -24,6 +25,9 @@ export async function watch({ js }) {
24
25
  const args = ['watch', 'build', ...filterArgs];
25
26
 
26
27
  const cwd = await getMonorepoRoot();
28
+ if (!cwd) {
29
+ throw new Error(NULL_ROOT_ERROR);
30
+ }
27
31
 
28
32
  /** @type {import('concurrently').ConcurrentlyCommandInput} */
29
33
  const clerkJsCommand = {
@@ -0,0 +1,5 @@
1
+ export const NULL_ROOT_ERROR =
2
+ 'The `root` property of your configuration file is null. Run `clerk-dev set-root` in your local checkout of clerk/javascript to set it.';
3
+
4
+ export const INVALID_INSTANCE_KEYS_ERROR =
5
+ 'The publishableKey and secretKey fields of your config are invalid. publishableKey should start with `pk_` and secretKey should start with `sk_`.';
@@ -3,6 +3,7 @@ import { dirname, posix } from 'node:path';
3
3
 
4
4
  import { globby } from 'globby';
5
5
 
6
+ import { NULL_ROOT_ERROR } from './errors.js';
6
7
  import { getMonorepoRoot } from './getMonorepoRoot.js';
7
8
 
8
9
  /**
@@ -11,6 +12,9 @@ import { getMonorepoRoot } from './getMonorepoRoot.js';
11
12
  */
12
13
  export async function getClerkPackages() {
13
14
  const monorepoRoot = await getMonorepoRoot();
15
+ if (!monorepoRoot) {
16
+ throw new Error(NULL_ROOT_ERROR);
17
+ }
14
18
  /** @type {Record<string, string>} */
15
19
  const packages = {};
16
20
  const clerkPackages = await globby([posix.join(monorepoRoot, 'packages', '*', 'package.json'), '!*node_modules*']);
@@ -7,15 +7,10 @@ export function getCLIRoot() {
7
7
  }
8
8
 
9
9
  /**
10
- * Gets the `root` property of the clerk-dev configuration file, falling back to the folder containing the source
11
- * for the running instance of clerk-dev.
12
- * @returns {Promise<string>}
10
+ * Gets the `root` property of the clerk-dev configuration file.
11
+ * @returns {Promise<string | null>}
13
12
  */
14
13
  export async function getMonorepoRoot() {
15
14
  const config = await getConfiguration();
16
- if (config.root) {
17
- return config.root;
18
- }
19
-
20
- return getCLIRoot();
15
+ return config.root;
21
16
  }