@gengjiawen/os-init 1.1.1 → 1.2.1

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/bin/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { Command } = require('commander')
4
- const { writeConfig, installDeps } = require('../build')
4
+ const { writeConfig, installDeps, writeCodexConfig, installCodexDeps } = require('../build')
5
5
 
6
6
  const program = new Command()
7
7
 
@@ -24,6 +24,29 @@ program
24
24
  console.error('Failed to complete setup:', err.message)
25
25
  process.exit(1)
26
26
  }
27
+ console.log('use `ccr code` in terminal to start building')
28
+ })
29
+
30
+ program
31
+ .command('set-codex')
32
+ .description('setup codex cli config and auth')
33
+ .argument('<apiKey>', 'API key to set for Codex')
34
+ .action(async (apiKey) => {
35
+ if (!apiKey || String(apiKey).trim().length === 0) {
36
+ console.error('Missing required argument: <apiKey>')
37
+ program.help({ error: true })
38
+ return
39
+ }
40
+ try {
41
+ const { configPath, authPath } = writeCodexConfig(apiKey)
42
+ console.log(`Codex config written to: ${configPath}`)
43
+ console.log(`Codex auth written to: ${authPath}`)
44
+ await installCodexDeps()
45
+ } catch (err) {
46
+ console.error('Failed to setup Codex:', err.message)
47
+ process.exit(1)
48
+ }
49
+ console.log('Codex is ready. use `codex` in terminal to start building')
27
50
  })
28
51
 
29
52
  program.parse(process.argv)
package/build/index.d.ts CHANGED
@@ -1,2 +1,7 @@
1
1
  export declare function writeConfig(apiKey: string): string;
2
2
  export declare function installDeps(): Promise<void>;
3
+ export declare function writeCodexConfig(apiKey: string): {
4
+ configPath: string;
5
+ authPath: string;
6
+ };
7
+ export declare function installCodexDeps(): Promise<void>;
package/build/index.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.writeConfig = writeConfig;
4
4
  exports.installDeps = installDeps;
5
+ exports.writeCodexConfig = writeCodexConfig;
6
+ exports.installCodexDeps = installCodexDeps;
5
7
  const fs = require("fs");
6
8
  const path = require("path");
7
9
  const os = require("os");
@@ -61,3 +63,40 @@ async function installDeps() {
61
63
  }
62
64
  console.log('Dependencies installed successfully.');
63
65
  }
66
+ function getCodexConfigDir() {
67
+ return path.join(os.homedir(), '.codex');
68
+ }
69
+ const CODEX_CONFIG_TOML_TEMPLATE = `model_provider = "jw"
70
+ model = "gpt-5"
71
+ model_reasoning_effort = "high"
72
+ disable_response_storage = true
73
+ preferred_auth_method = "apikey"
74
+
75
+ [model_providers.jw]
76
+ name = "jw"
77
+ base_url = "https://ai.gengjiawen.com/api/openai"
78
+ wire_api = "responses"
79
+ `;
80
+ function writeCodexConfig(apiKey) {
81
+ const configDir = getCodexConfigDir();
82
+ ensureDir(configDir);
83
+ const configPath = path.join(configDir, 'config.toml');
84
+ fs.writeFileSync(configPath, CODEX_CONFIG_TOML_TEMPLATE);
85
+ const authPath = path.join(configDir, 'auth.json');
86
+ const authContent = JSON.stringify({ OPENAI_API_KEY: apiKey }, null, 2);
87
+ fs.writeFileSync(authPath, authContent);
88
+ return { configPath, authPath };
89
+ }
90
+ async function installCodexDeps() {
91
+ const packages = ['@openai/codex'];
92
+ const usePnpm = await commandExists('pnpm');
93
+ if (usePnpm) {
94
+ console.log('pnpm detected. Installing Codex dependency with pnpm...');
95
+ await (0, execa_1.execa)('pnpm', ['add', '-g', ...packages], { stdio: 'inherit' });
96
+ }
97
+ else {
98
+ console.log('pnpm not found. Falling back to npm...');
99
+ await (0, execa_1.execa)('npm', ['install', '-g', ...packages], { stdio: 'inherit' });
100
+ }
101
+ console.log('Codex dependency installed successfully.');
102
+ }
package/libs/index.ts CHANGED
@@ -72,3 +72,51 @@ export async function installDeps(): Promise<void> {
72
72
  }
73
73
 
74
74
 
75
+ /** Return Codex configuration directory path */
76
+ function getCodexConfigDir(): string {
77
+ return path.join(os.homedir(), '.codex')
78
+ }
79
+
80
+ /** Template for Codex config.toml */
81
+ const CODEX_CONFIG_TOML_TEMPLATE = `model_provider = "jw"
82
+ model = "gpt-5"
83
+ model_reasoning_effort = "high"
84
+ disable_response_storage = true
85
+ preferred_auth_method = "apikey"
86
+
87
+ [model_providers.jw]
88
+ name = "jw"
89
+ base_url = "https://ai.gengjiawen.com/api/openai"
90
+ wire_api = "responses"
91
+ `
92
+
93
+ /** Write Codex config.toml and auth.json */
94
+ export function writeCodexConfig(apiKey: string): { configPath: string; authPath: string } {
95
+ const configDir = getCodexConfigDir()
96
+ ensureDir(configDir)
97
+
98
+ const configPath = path.join(configDir, 'config.toml')
99
+ fs.writeFileSync(configPath, CODEX_CONFIG_TOML_TEMPLATE)
100
+
101
+ const authPath = path.join(configDir, 'auth.json')
102
+ const authContent = JSON.stringify({ OPENAI_API_KEY: apiKey }, null, 2)
103
+ fs.writeFileSync(authPath, authContent)
104
+
105
+ return { configPath, authPath }
106
+ }
107
+
108
+ /** Install Codex dependency */
109
+ export async function installCodexDeps(): Promise<void> {
110
+ const packages = ['@openai/codex']
111
+ const usePnpm = await commandExists('pnpm')
112
+
113
+ if (usePnpm) {
114
+ console.log('pnpm detected. Installing Codex dependency with pnpm...')
115
+ await execa('pnpm', ['add', '-g', ...packages], { stdio: 'inherit' })
116
+ } else {
117
+ console.log('pnpm not found. Falling back to npm...')
118
+ await execa('npm', ['install', '-g', ...packages], { stdio: 'inherit' })
119
+ }
120
+ console.log('Codex dependency installed successfully.')
121
+ }
122
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gengjiawen/os-init",
3
3
  "private": false,
4
- "version": "1.1.1",
4
+ "version": "1.2.1",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "bin": {