Skip to content

Commit 067f781

Browse files
committed
Add basic init command
1 parent ac1f8cc commit 067f781

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ Ultracite is a robust linting configuration for modern TypeScript apps, built on
1111

1212
## Installation
1313

14+
### Automatic Installation
15+
16+
Run the command below to install and initialize Ultracite in the current directory:
17+
18+
```sh
19+
npx ultracite init
20+
```
21+
22+
### Manual Installation
23+
1424
Run the command below to install Ultracite:
1525

1626
```sh

scripts/run.mjs

+76
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,82 @@ program
99
.name('Ultracite')
1010
.description('Strict, opinionated linting config for modern TypeScript apps.');
1111

12+
program
13+
.command('init')
14+
.description('Initialize Ultracite in the current directory')
15+
.action(() => {
16+
try {
17+
// Create biome.json config
18+
const biomeConfig = {
19+
$schema: 'https://biomejs.dev/schemas/1.9.4/schema.json',
20+
extends: ['ultracite'],
21+
};
22+
23+
// Create .vscode/settings.json
24+
const vsCodeSettings = {
25+
'typescript.tsdk': 'node_modules/typescript/lib',
26+
'editor.defaultFormatter': 'biomejs.biome',
27+
'editor.formatOnSave': true,
28+
'editor.formatOnPaste': true,
29+
'emmet.showExpandedAbbreviation': 'never',
30+
'editor.codeActionsOnSave': {
31+
'quickfix.biome': 'explicit',
32+
'source.organizeImports.biome': 'explicit',
33+
},
34+
'[typescript]': {
35+
'editor.defaultFormatter': 'biomejs.biome',
36+
},
37+
'[json]': {
38+
'editor.defaultFormatter': 'biomejs.biome',
39+
},
40+
'[javascript]': {
41+
'editor.defaultFormatter': 'biomejs.biome',
42+
},
43+
'[jsonc]': {
44+
'editor.defaultFormatter': 'biomejs.biome',
45+
},
46+
'[typescriptreact]': {
47+
'editor.defaultFormatter': 'biomejs.biome',
48+
},
49+
};
50+
// Create or merge tsconfig.json
51+
let tsConfig = {
52+
compilerOptions: {
53+
strictNullChecks: true,
54+
},
55+
};
56+
57+
try {
58+
const existingTsConfig = JSON.parse(execSync('cat tsconfig.json', { encoding: 'utf-8' }));
59+
tsConfig = {
60+
...existingTsConfig,
61+
compilerOptions: {
62+
...existingTsConfig.compilerOptions,
63+
...tsConfig.compilerOptions,
64+
},
65+
};
66+
} catch (e) {
67+
// tsconfig.json doesn't exist, use default config
68+
}
69+
70+
// Install dependencies
71+
execSync('pnpm add -D --save-exact ultracite @biomejs/biome');
72+
73+
// Write the config files
74+
execSync('mkdir -p .vscode');
75+
execSync(`echo '${JSON.stringify(biomeConfig, null, 2)}' > biome.json`);
76+
execSync(
77+
`echo '${JSON.stringify(vsCodeSettings, null, 2)}' > .vscode/settings.json`
78+
);
79+
execSync(`echo '${JSON.stringify(tsConfig, null, 2)}' > tsconfig.json`);
80+
81+
console.log('Successfully initialized Ultracite configuration!');
82+
} catch (error) {
83+
console.error('Failed to run Ultracite:', error.message);
84+
process.exit(1);
85+
}
86+
});
87+
1288
program
1389
.command('lint')
1490
.description('Run Biome linter without fixing files')

0 commit comments

Comments
 (0)