@gengjiawen/os-init 1.1.0

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.
@@ -0,0 +1,23 @@
1
+ name: Node CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ${{ matrix.operating-system }}
8
+ strategy:
9
+ matrix:
10
+ operating-system: [ubuntu-latest, windows-latest, macOS-latest]
11
+
12
+ steps:
13
+ - uses: actions/checkout@v1
14
+ - name: Envinfo
15
+ run: npx envinfo
16
+ - name: npm install, build, and test
17
+ run: |
18
+ yarn
19
+ yarn build
20
+ yarn format-check
21
+ yarn test
22
+ env:
23
+ CI: true
@@ -0,0 +1 @@
1
+ build/
package/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "semi": false,
3
+ "singleQuote": true,
4
+ "trailingComma": "es5"
5
+ }
package/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c)
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ ## Setup
2
+
3
+ My OS setup and mostly used script.
4
+
5
+ ```
6
+ npm install
7
+ npm start
8
+ ```
9
+
10
+ Project generated by [gengjiawen/ts-scaffold](https://github.com/gengjiawen/ts-scaffold)
package/bin/bin.js ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { Command } = require('commander')
4
+ const { writeConfig, installDeps } = require('../build')
5
+
6
+ const program = new Command()
7
+
8
+ program
9
+ .command('set-cc')
10
+ .description('setup claude-code-router')
11
+ .argument('<apiKey>', 'API key to set')
12
+ .action(async (apiKey) => {
13
+ // Ensure apiKey is provided
14
+ if (!apiKey || String(apiKey).trim().length === 0) {
15
+ console.error('Missing required argument: <apiKey>')
16
+ program.help({ error: true })
17
+ return
18
+ }
19
+ try {
20
+ const configPath = writeConfig(apiKey)
21
+ console.log(`Config written to: ${configPath}`)
22
+ await installDeps()
23
+ } catch (err) {
24
+ console.error('Failed to complete setup:', err.message)
25
+ process.exit(1)
26
+ }
27
+ })
28
+
29
+ program.parse(process.argv)
@@ -0,0 +1,4 @@
1
+ ## Setup
2
+
3
+ - https://chrome.google.com/webstore/detail/gitpod-always-ready-to-co/dodmmooeoklaejobgleioelladacbeki
4
+ - https://chrome.google.com/webstore/detail/sourcegraph/dgjhfomjieaadpoljlnidmbgkdffpack
@@ -0,0 +1,5 @@
1
+ test('add more test', async () => {
2
+ const a = 1
3
+ const b = 1
4
+ expect(a + b).toBe(2)
5
+ })
package/libs/index.ts ADDED
@@ -0,0 +1,74 @@
1
+ import * as fs from 'fs'
2
+ import * as path from 'path'
3
+ import * as os from 'os'
4
+ import { execa } from 'execa'
5
+
6
+ /** Return default configuration directory path */
7
+ function getDefaultConfigDir(): string {
8
+ return path.join(os.homedir(), '.claude-code-router')
9
+ }
10
+
11
+ /** Ensure directory exists */
12
+ function ensureDir(dirPath: string): void {
13
+ fs.mkdirSync(dirPath, { recursive: true })
14
+ }
15
+
16
+ /** Template string used for simple string replacement */
17
+ const DEFAULT_TEMPLATE = `{
18
+ "Providers": [
19
+ {
20
+ "name": "jw",
21
+ "api_base_url": "https://ai.gengjiawen.com/api/openai/v1/chat/completions",
22
+ "api_key": "API_KEY_PLACEHOLDER",
23
+ "models": ["code", "free", "free-thinking"],
24
+ "transformer": {
25
+ "use": ["openrouter"]
26
+ }
27
+ }
28
+ ],
29
+ "Router": {
30
+ "default": "jw,code",
31
+ "background": "jw,code",
32
+ "think": "jw,code",
33
+ "longContext": "jw,code"
34
+ }
35
+ }`
36
+
37
+ /** Write config by simple string replacement */
38
+ export function writeConfig(apiKey: string): string {
39
+ const configDir = getDefaultConfigDir()
40
+ const configPath = path.join(configDir, 'config.json')
41
+ ensureDir(configDir)
42
+ const content = DEFAULT_TEMPLATE.replace('API_KEY_PLACEHOLDER', apiKey)
43
+ fs.writeFileSync(configPath, content)
44
+ return configPath
45
+ }
46
+
47
+ /** Check if a command exists */
48
+ async function commandExists(command: string): Promise<boolean> {
49
+ try {
50
+ // execa with reject: false will not throw on non-zero exit codes.
51
+ const { failed } = await execa(command, ['--version'], { stdio: 'ignore', reject: false })
52
+ return !failed
53
+ } catch (error) {
54
+ // Catch errors for commands that don't support --version or other issues
55
+ return false
56
+ }
57
+ }
58
+
59
+ /** Install global dependencies */
60
+ export async function installDeps(): Promise<void> {
61
+ const packages = ['@anthropic-ai/claude-code', '@musistudio/claude-code-router']
62
+ const usePnpm = await commandExists('pnpm')
63
+
64
+ if (usePnpm) {
65
+ console.log('pnpm detected. Installing dependencies with pnpm...')
66
+ await execa('pnpm', ['add', '-g', ...packages], { stdio: 'inherit' })
67
+ } else {
68
+ console.log('pnpm not found. Falling back to npm...')
69
+ await execa('npm', ['install', '-g', ...packages], { stdio: 'inherit' })
70
+ }
71
+ console.log('Dependencies installed successfully.')
72
+ }
73
+
74
+
package/macOS-init.md ADDED
@@ -0,0 +1,59 @@
1
+ macOS init script
2
+
3
+ ## For developer
4
+
5
+ ```
6
+ sudo spctl --master-disable
7
+ sudo /usr/sbin/DevToolsSecurity -enable
8
+ ```
9
+
10
+ ## Basic software
11
+
12
+ ```bash
13
+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
14
+ brew install git
15
+ brew install node
16
+ brew install fish
17
+ brew install go
18
+ brew install rustup-init
19
+ brew install visual-studio-code
20
+ brew install google-chrome
21
+ brew install jetbrains-toolbox
22
+ brew install omnidisksweeper
23
+ brew install git-lfs
24
+ brew install jordanbaird-ice
25
+ sudo git lfs install --system
26
+ ```
27
+
28
+
29
+ Fish config
30
+ ```
31
+ egrep "^export " ~/.bashrc | while read e
32
+ set var (echo $e | sed -E "s/^export ([A-Za-z_0-9]+)=(.*)\$/\1/")
33
+ set value (echo $e | sed -E "s/^export ([A-Za-z_0-9]+)=(.*)\$/\2/")
34
+
35
+ # remove surrounding quotes if existing
36
+ set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/")
37
+
38
+ if test $var = "PATH"
39
+ # replace ":" by spaces. this is how PATH looks for Fish
40
+ set value (echo $value | sed -E "s/:/ /g")
41
+
42
+ # use eval because we need to expand the value
43
+ eval set -xg $var $value
44
+
45
+ continue
46
+ end
47
+
48
+ # evaluate variables. we can use eval because we most likely just used "$var"
49
+ set value (eval echo $value)
50
+
51
+ #echo "set -xg '$var' '$value' (via '$e')"
52
+ set -xg $var $value
53
+ end
54
+ ```
55
+
56
+ make homebrew path first
57
+ ```bash
58
+ fish_add_path /opt/homebrew/opt
59
+ ```
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@gengjiawen/os-init",
3
+ "private": false,
4
+ "version": "1.1.0",
5
+ "description": "",
6
+ "main": "index.js",
7
+ "bin": {
8
+ "os-init": "bin/bin.js"
9
+ },
10
+ "scripts": {
11
+ "start": "tsc -w",
12
+ "server": "nodemon --exec ts-node libs/index.ts",
13
+ "prepare": "husky install",
14
+ "clean": "rimraf build",
15
+ "format": "prettier --write \"{examples,libs,script,bin}/**/*.{js,ts}\" \"**/*.yml\"",
16
+ "format:check": "prettier --list-different \"{examples,libs,script,bin}/**/*.{js,ts}\" \"**/*.yml\"",
17
+ "test": "jest",
18
+ "build": "npm run clean && tsc -p ./tsconfig.json",
19
+ "postbuild": "cpy '**/*' '!**/*.ts' ../build/ --cwd=libs --parents"
20
+ },
21
+ "dependencies": {
22
+ "commander": "^12.1.0",
23
+ "execa": "^8.0.1"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "devDependencies": {
29
+ "@types/jest": "29.5.12",
30
+ "@types/node": "24.1.0",
31
+ "cpy-cli": "^4.2.0",
32
+ "husky": "9.1.6",
33
+ "jest": "29.7.0",
34
+ "lint-staged": "^15.2.2",
35
+ "nodemon": "3.1.4",
36
+ "prettier": "3.5.3",
37
+ "rimraf": "5.0.5",
38
+ "ts-jest": "29.2.4",
39
+ "ts-node": "^10.9.1",
40
+ "typescript": "5.6.3"
41
+ },
42
+ "husky": {
43
+ "hooks": {
44
+ "pre-commit": "lint-staged"
45
+ }
46
+ },
47
+ "lint-staged": {
48
+ "*.{js,ts,tsx,md,css,html,yml}": [
49
+ "prettier --write"
50
+ ]
51
+ },
52
+ "jest": {
53
+ "testEnvironment": "node",
54
+ "transform": {
55
+ "^.+\\.tsx?$": "ts-jest"
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) gengjiawen <technicalcute@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ ### Setup
2
+
3
+ ```
4
+ npm install
5
+ npm start
6
+ ```
7
+
8
+ Project generated by [gengjiawen/ts-scaffold](https://github.com/gengjiawen/ts-scaffold)
@@ -0,0 +1,5 @@
1
+ import { list } from '../libs'
2
+
3
+ test('packages', () => {
4
+ expect(() => list()).not.toThrow()
5
+ })
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env node
2
+
3
+ const program = require('commander')
4
+
5
+ const { init, list } = require('../build')
6
+
7
+ program
8
+ .version(require('../package.json').version)
9
+ .command('init')
10
+ .action(() => {
11
+ init()
12
+ })
13
+
14
+ program
15
+ .version(require('../package.json').version)
16
+ .command('list')
17
+ .action(() => {
18
+ list()
19
+ })
20
+
21
+ program.parse(process.argv)
@@ -0,0 +1,15 @@
1
+ import { packages } from './packages'
2
+ import * as execa from 'execa'
3
+
4
+ export const psPolicy = `Set-ExecutionPolicy -ExecutionPolicy ByPass`
5
+
6
+ export async function init() {
7
+ const cmd = `Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))`
8
+ console.log(`need to ${psPolicy} if you are not`)
9
+ console.log(cmd)
10
+ await execa.command(cmd, { shell: 'powershell', stdio: 'inherit' })
11
+ }
12
+
13
+ export function list() {
14
+ console.log(packages.join('\n'))
15
+ }
@@ -0,0 +1,8 @@
1
+ export const packages = [
2
+ 'git',
3
+ 'nodejs',
4
+ 'jdk8',
5
+ 'vscode',
6
+ 'visualstudio2022enterprise',
7
+ 'jetbrainstoolbox',
8
+ ]
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@gengjiawen/win",
3
+ "version": "0.0.4",
4
+ "description": "my groovy project",
5
+ "author": "gengjiawen <technicalcute@gmail.com>",
6
+ "bin": {
7
+ "init": "bin/init.js"
8
+ },
9
+ "scripts": {
10
+ "start": "tsc -w",
11
+ "clean": "rimraf build",
12
+ "test": "jest",
13
+ "build": "npm run clean && tsc -p ./tsconfig.json"
14
+ },
15
+ "dependencies": {
16
+ "commander": "^8.2.0",
17
+ "execa": "^5.1.1"
18
+ },
19
+ "devDependencies": {
20
+ "@types/jest": "27.0.2",
21
+ "jest": "27.3.0",
22
+ "ts-jest": "27.0.7"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "jest": {
28
+ "testEnvironment": "node",
29
+ "transform": {
30
+ "^.+\\.tsx?$": "ts-jest"
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./build"
5
+ },
6
+ "exclude": [
7
+ "build",
8
+ "__tests__",
9
+ "test"
10
+ ]
11
+ }