forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
59 lines (52 loc) · 1.77 KB
/
Copy pathinit.js
File metadata and controls
59 lines (52 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { spawn } from 'node:child_process';
import { existsSync } from 'node:fs';
import { mkdir, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { CONFIG_FILE } from '../utils/getConfiguration.js';
import { getCLIRoot } from '../utils/getMonorepoRoot.js';
/**
* Performs one-time machine-level configuration tasks such as creating a blank config file.
*/
export async function init() {
// If the config file already exists, print a warning and exit.
if (existsSync(CONFIG_FILE)) {
console.warn('Configuration file already exists. Run `clerk-dev config` to open it.');
return;
}
const cliRoot = getCLIRoot();
/** @type import('../utils/getConfiguration.js').Configuration */
const configuration = {
$schema: join(cliRoot, 'packages', 'dev', 'schema.json'),
root: null,
activeInstance: 'default',
instances: {
default: {
secretKey: 'sk_REPLACE_WITH_SECRET_KEY',
publishableKey: 'pk_REPLACE_WITH_PUBLISHABLE_KEY',
fapiUrl: 'REPLACE_WITH_FAPI_URL',
bapiUrl: 'https://api.clerk.com',
},
},
};
await mkdir(dirname(CONFIG_FILE), { recursive: true });
await writeFile(CONFIG_FILE, JSON.stringify(configuration, null, 2), 'utf-8');
if (process.env.VISUAL) {
spawn(process.env.VISUAL, [CONFIG_FILE], {
stdio: 'inherit',
env: {
...process.env,
},
});
console.log(`Configuration file written to ${CONFIG_FILE}.`);
} else if (process.env.EDITOR) {
spawn(process.env.EDITOR, [CONFIG_FILE], {
stdio: 'inherit',
env: {
...process.env,
},
});
console.log(`Configuration file written to ${CONFIG_FILE}.`);
} else {
console.log(`Configuration file written to ${CONFIG_FILE}. Replace with your values.`);
}
}