oxc-configs 0.0.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.
Files changed (3) hide show
  1. package/README.md +25 -0
  2. package/index.ts +110 -0
  3. package/package.json +36 -0
package/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # oxc-configs
2
+
3
+ OXC toolset pre-made configs + fetch CLI.
4
+
5
+ ## Prerequisites
6
+
7
+ - Bun
8
+ - GitHub CLI
9
+
10
+ ## CLI Usage
11
+
12
+ Navigate to the project directory, then run:
13
+
14
+ ```sh
15
+ bunx oxc-configs # you will be prompted with template selection
16
+ # OR
17
+ bunx oxc-configs TEMPLATE # download files from specific template for the project in the current directory
18
+ ```
19
+
20
+ ## Development
21
+
22
+ ```sh
23
+ bun install
24
+ bun link
25
+ ```
package/index.ts ADDED
@@ -0,0 +1,110 @@
1
+ #! /usr/bin/env bun
2
+
3
+ import { cancel, intro, isCancel, log, outro, select, spinner } from '@clack/prompts';
4
+ import { $ } from 'bun';
5
+ import { bold, green, red, yellow } from 'picocolors';
6
+
7
+ enum Template {
8
+ ReactTypeScript = 'react-typescript',
9
+ TypeScript = 'typescript',
10
+ JavaScript = 'javascript',
11
+ }
12
+
13
+ async function main() {
14
+ const argv = process.argv.slice(2);
15
+ let template: string | symbol | undefined = argv[0];
16
+
17
+ intro(yellow(`@simek/oxc-configs`));
18
+
19
+ await checkGHCLIAvailability();
20
+
21
+ if (!template) {
22
+ template = await select({
23
+ message: 'Select OXC toolset configs template to download:',
24
+ options: [
25
+ {
26
+ value: Template.ReactTypeScript,
27
+ label: 'React + TypeScript',
28
+ },
29
+ {
30
+ value: Template.TypeScript,
31
+ label: 'TypeScript',
32
+ },
33
+ {
34
+ value: Template.JavaScript,
35
+ label: 'JavaScript',
36
+ },
37
+ ],
38
+ });
39
+
40
+ if (isCancel(template)) {
41
+ cancel('No template has been selected.');
42
+ process.exit(0);
43
+ }
44
+ }
45
+
46
+ if (!Object.values(Template).includes(template as Template)) {
47
+ log.error(`Unknown template: ${bold(template)}\n`);
48
+ process.exit(1);
49
+ }
50
+
51
+ await fetchConfigsFromRepo(template, '.oxfmtrc.json');
52
+ await fetchConfigsFromRepo(template, '.oxlintrc.json');
53
+
54
+ outro(green('All done!'));
55
+ }
56
+
57
+ export async function checkGHCLIAvailability() {
58
+ try {
59
+ await $`gh auth status`.quiet();
60
+ } catch (error) {
61
+ if (error instanceof $.ShellError) {
62
+ const message = error.stderr.toString();
63
+ if (message.includes('You are not logged')) {
64
+ log.error(red(message));
65
+ } else {
66
+ log.error(red('GitHub CLI need to be installed on your system, see: https://cli.github.com/.'));
67
+ }
68
+ }
69
+ process.exit(1);
70
+ }
71
+ }
72
+
73
+ export async function fetchConfigsFromRepo(template: string, fileName: string) {
74
+ let replaceFile: 'yes' | 'no' | symbol = 'yes';
75
+
76
+ if (await Bun.file(fileName).exists()) {
77
+ replaceFile = await select({
78
+ message: `${bold(fileName)} already exists. Do you want to replace its content with the template?`,
79
+ options: [
80
+ { value: 'no', label: 'No' },
81
+ { value: 'yes', label: 'Yes' },
82
+ ],
83
+ });
84
+
85
+ if (isCancel(replaceFile)) {
86
+ cancel('Replacement cancelled.');
87
+ process.exit(0);
88
+ }
89
+ }
90
+
91
+ if (replaceFile === 'no') {
92
+ log.info(`Ignoring ${bold(fileName)} config file.`);
93
+ } else {
94
+ const progress = spinner();
95
+ progress.start(`Fetching ${bold(fileName)} config file...`);
96
+
97
+ const configContent = await $`gh api repos/simek/oxc-configs/contents/${template}/.oxfmtrc.json -q .content`.text();
98
+
99
+ const config = JSON.parse(atob(configContent));
100
+
101
+ await Bun.write(fileName, JSON.stringify(config, null, 2));
102
+
103
+ progress.stop(`${bold(fileName)} fetched and written`);
104
+ }
105
+ }
106
+
107
+ main().catch(err => {
108
+ log.error(err);
109
+ process.exit(1);
110
+ });
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "oxc-configs",
3
+ "description": "OXC toolset pre-made configs.",
4
+ "version": "0.0.1",
5
+ "bugs": {
6
+ "url": "https://github.com/simek/oxc-configs/issues"
7
+ },
8
+ "license": "MIT",
9
+ "repository": "github:simek/oxc-configs",
10
+ "bin": {
11
+ "oxc-configs": "index.ts"
12
+ },
13
+ "files": [
14
+ "index.ts"
15
+ ],
16
+ "type": "module",
17
+ "module": "index.ts",
18
+ "scripts": {
19
+ "lint": "oxlint --type-aware && oxfmt --check",
20
+ "lint:fix": "oxlint --type-aware --fix && oxfmt"
21
+ },
22
+ "dependencies": {
23
+ "@clack/prompts": "^0.11.0",
24
+ "picocolors": "^1.1.1"
25
+ },
26
+ "devDependencies": {
27
+ "@types/bun": "^1.3.6",
28
+ "oxfmt": "^0.26.0",
29
+ "oxlint": "^1.41.0",
30
+ "oxlint-tsgolint": "^0.11.1",
31
+ "typescript": "^5.9.3"
32
+ },
33
+ "engines": {
34
+ "bun": ">=1.3"
35
+ }
36
+ }