@f-o-t/config 0.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.
package/README.md ADDED
@@ -0,0 +1,179 @@
1
+ # @f-o-t/config
2
+
3
+ Standardized configuration for F-O-T libraries. Provides a type-safe configuration system with validation, plugins, and config file generators.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @f-o-t/config
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Usage
14
+
15
+ The simplest way to use `@f-o-t/config` is to call `defineFotConfig()` with no arguments to get default configuration:
16
+
17
+ ```typescript
18
+ import { defineFotConfig } from "@f-o-t/config";
19
+
20
+ const config = defineFotConfig();
21
+ // Returns default config with ESM format, TypeScript declarations, and Biome enabled
22
+ ```
23
+
24
+ ### With Custom Options
25
+
26
+ Customize the configuration by passing options:
27
+
28
+ ```typescript
29
+ import { defineFotConfig } from "@f-o-t/config";
30
+
31
+ const config = defineFotConfig({
32
+ formats: ["esm", "cjs"],
33
+ external: ["react", "react-dom"],
34
+ typescript: {
35
+ declaration: true,
36
+ },
37
+ biome: {
38
+ enabled: true,
39
+ },
40
+ });
41
+ ```
42
+
43
+ ### With Plugins
44
+
45
+ Enable and configure plugins:
46
+
47
+ ```typescript
48
+ import { defineFotConfig } from "@f-o-t/config";
49
+
50
+ const config = defineFotConfig({
51
+ plugins: [
52
+ { name: "datetime", enabled: true },
53
+ { name: "pdf", enabled: false },
54
+ ],
55
+ });
56
+ ```
57
+
58
+ ## Generate Config Files
59
+
60
+ The library provides generators to create standard configuration files for your FOT library:
61
+
62
+ ```typescript
63
+ import {
64
+ generatePackageJson,
65
+ generateTsConfig,
66
+ generateBiomeConfig
67
+ } from "@f-o-t/config";
68
+
69
+ // Generate package.json
70
+ const packageJson = generatePackageJson({
71
+ name: "@f-o-t/my-library",
72
+ version: "1.0.0",
73
+ description: "My FOT library",
74
+ });
75
+
76
+ // Generate tsconfig.json
77
+ const tsconfig = generateTsConfig();
78
+
79
+ // Generate biome.json
80
+ const biomeConfig = generateBiomeConfig();
81
+ ```
82
+
83
+ ## API Reference
84
+
85
+ ### `defineFotConfig(config?: FotConfig): ResolvedFotConfig`
86
+
87
+ Main factory function to define and validate a FOT library configuration.
88
+
89
+ **Parameters:**
90
+ - `config` (optional): Configuration object
91
+
92
+ **Returns:** Validated configuration with all defaults applied
93
+
94
+ **Throws:** Error if configuration is invalid
95
+
96
+ ### Types
97
+
98
+ #### `FotConfig`
99
+
100
+ User-provided configuration:
101
+
102
+ ```typescript
103
+ interface FotConfig {
104
+ formats?: BuildFormat[]; // Build output formats (default: ["esm"])
105
+ external?: string[]; // External dependencies (default: [])
106
+ typescript?: TypeScriptOptions; // TypeScript options
107
+ biome?: BiomeOptions; // Biome options
108
+ plugins?: PluginConfig[]; // Plugin configurations (default: [])
109
+ }
110
+ ```
111
+
112
+ #### `ResolvedFotConfig`
113
+
114
+ Fully resolved configuration with all defaults applied:
115
+
116
+ ```typescript
117
+ interface ResolvedFotConfig {
118
+ formats: BuildFormat[];
119
+ external: string[];
120
+ typescript: Required<TypeScriptOptions>;
121
+ biome: Required<BiomeOptions>;
122
+ plugins: PluginConfig[];
123
+ }
124
+ ```
125
+
126
+ #### `BuildFormat`
127
+
128
+ ```typescript
129
+ type BuildFormat = "esm" | "cjs";
130
+ ```
131
+
132
+ #### `TypeScriptOptions`
133
+
134
+ ```typescript
135
+ interface TypeScriptOptions {
136
+ declaration?: boolean; // Generate .d.ts files (default: true)
137
+ }
138
+ ```
139
+
140
+ #### `BiomeOptions`
141
+
142
+ ```typescript
143
+ interface BiomeOptions {
144
+ enabled?: boolean; // Enable Biome (default: true)
145
+ }
146
+ ```
147
+
148
+ #### `PluginConfig`
149
+
150
+ ```typescript
151
+ interface PluginConfig {
152
+ name: string; // Plugin name
153
+ enabled?: boolean; // Enable plugin (default: true)
154
+ }
155
+ ```
156
+
157
+ ## Generators
158
+
159
+ ### `generatePackageJson(options)`
160
+
161
+ Generates a standard package.json configuration for FOT libraries.
162
+
163
+ **Parameters:**
164
+ - `name`: Package name
165
+ - `version`: Package version
166
+ - `description`: Package description
167
+ - Additional package.json fields as needed
168
+
169
+ ### `generateTsConfig()`
170
+
171
+ Generates a standard TypeScript configuration optimized for FOT libraries.
172
+
173
+ ### `generateBiomeConfig()`
174
+
175
+ Generates a standard Biome configuration for linting and formatting.
176
+
177
+ ## License
178
+
179
+ MIT
@@ -0,0 +1,283 @@
1
+ /**
2
+ * Build output formats
3
+ */
4
+ type BuildFormat = "esm" | "cjs";
5
+ /**
6
+ * TypeScript compiler options for the build
7
+ */
8
+ interface TypeScriptOptions {
9
+ /**
10
+ * Generate .d.ts declaration files
11
+ * @default true
12
+ */
13
+ declaration?: boolean;
14
+ }
15
+ /**
16
+ * Biome configuration options
17
+ */
18
+ interface BiomeOptions {
19
+ /**
20
+ * Enable Biome for linting/formatting
21
+ * @default true
22
+ */
23
+ enabled?: boolean;
24
+ }
25
+ /**
26
+ * Plugin configuration
27
+ */
28
+ interface PluginConfig {
29
+ /**
30
+ * Name of the plugin
31
+ */
32
+ name: string;
33
+ /**
34
+ * Whether the plugin is enabled
35
+ * @default true
36
+ */
37
+ enabled?: boolean;
38
+ }
39
+ /**
40
+ * User-provided configuration for FOT libraries
41
+ */
42
+ interface FotConfig {
43
+ /**
44
+ * Build output formats
45
+ * @default ["esm"]
46
+ */
47
+ formats?: BuildFormat[];
48
+ /**
49
+ * External dependencies that should not be bundled
50
+ * @default []
51
+ */
52
+ external?: string[];
53
+ /**
54
+ * TypeScript options
55
+ */
56
+ typescript?: TypeScriptOptions;
57
+ /**
58
+ * Biome options
59
+ */
60
+ biome?: BiomeOptions;
61
+ /**
62
+ * Plugins to load - can be plugin names as strings or config objects
63
+ * @default []
64
+ */
65
+ plugins?: (string | PluginConfig)[];
66
+ }
67
+ /**
68
+ * Resolved configuration with all defaults applied
69
+ */
70
+ interface ResolvedFotConfig {
71
+ /**
72
+ * Build output formats
73
+ */
74
+ formats: BuildFormat[];
75
+ /**
76
+ * External dependencies that should not be bundled
77
+ */
78
+ external: string[];
79
+ /**
80
+ * TypeScript options
81
+ */
82
+ typescript: Required<TypeScriptOptions>;
83
+ /**
84
+ * Biome options
85
+ */
86
+ biome: Required<BiomeOptions>;
87
+ /**
88
+ * Plugins to load (normalized to config objects)
89
+ */
90
+ plugins: PluginConfig[];
91
+ }
92
+ /**
93
+ * Factory function to define a FOT library configuration
94
+ * Validates the config against the schema and applies defaults
95
+ *
96
+ * @param config - The library configuration
97
+ * @returns The validated and normalized configuration with defaults applied
98
+ * @throws {Error} If the configuration is invalid
99
+ */
100
+ declare function defineFotConfig(config?: FotConfig): ResolvedFotConfig;
101
+ /**
102
+ * Biome configuration structure
103
+ */
104
+ interface BiomeConfig {
105
+ $schema: string;
106
+ vcs: {
107
+ enabled: boolean;
108
+ clientKind: string;
109
+ useIgnoreFile: boolean;
110
+ defaultBranch: string;
111
+ };
112
+ files: {
113
+ ignoreUnknown: boolean;
114
+ ignore: string[];
115
+ };
116
+ formatter: {
117
+ enabled: boolean;
118
+ indentStyle: string;
119
+ indentWidth: number;
120
+ lineWidth: number;
121
+ };
122
+ organizeImports: {
123
+ enabled: boolean;
124
+ };
125
+ linter: {
126
+ enabled: boolean;
127
+ rules: {
128
+ recommended: boolean;
129
+ };
130
+ };
131
+ javascript: {
132
+ formatter: {
133
+ quoteStyle: string;
134
+ semicolons: string;
135
+ trailingCommas: string;
136
+ };
137
+ };
138
+ }
139
+ /**
140
+ * Generate a biome.json file from a resolved FOT configuration
141
+ *
142
+ * @param config - The resolved FOT configuration
143
+ * @returns The generated biome.json object
144
+ */
145
+ declare function generateBiomeConfig(config: ResolvedFotConfig): BiomeConfig;
146
+ /**
147
+ * Package.json configuration
148
+ */
149
+ interface PackageExport {
150
+ types: string;
151
+ default: string;
152
+ }
153
+ /**
154
+ * Package.json structure
155
+ */
156
+ interface PackageJson {
157
+ name: string;
158
+ version: string;
159
+ type: "module";
160
+ main: string;
161
+ types: string;
162
+ exports: Record<string, PackageExport>;
163
+ scripts: Record<string, string>;
164
+ dependencies?: Record<string, string>;
165
+ devDependencies: Record<string, string>;
166
+ repository: {
167
+ type: "git";
168
+ url: string;
169
+ directory: string;
170
+ };
171
+ }
172
+ /**
173
+ * Generate a package.json file from a resolved FOT configuration
174
+ *
175
+ * @param libraryName - The name of the library (without @f-o-t/ prefix)
176
+ * @param version - The version of the library
177
+ * @param config - The resolved FOT configuration
178
+ * @param customDependencies - Optional custom dependencies to include
179
+ * @returns The generated package.json object
180
+ */
181
+ declare function generatePackageJson(libraryName: string, version: string, config: ResolvedFotConfig, customDependencies?: Record<string, string>): PackageJson;
182
+ /**
183
+ * TypeScript configuration structure
184
+ */
185
+ interface TSConfig {
186
+ compilerOptions: {
187
+ allowImportingTsExtensions: boolean;
188
+ declaration: boolean;
189
+ isolatedDeclarations: boolean;
190
+ module: string;
191
+ moduleDetection: string;
192
+ moduleResolution: string;
193
+ noEmit: boolean;
194
+ noFallthroughCasesInSwitch: boolean;
195
+ noImplicitOverride: boolean;
196
+ noPropertyAccessFromIndexSignature: boolean;
197
+ noUncheckedIndexedAccess: boolean;
198
+ noUnusedLocals: boolean;
199
+ noUnusedParameters: boolean;
200
+ skipLibCheck: boolean;
201
+ strict: boolean;
202
+ target: string;
203
+ verbatimModuleSyntax: boolean;
204
+ };
205
+ exclude: string[];
206
+ include: string[];
207
+ }
208
+ /**
209
+ * Generate a tsconfig.json file from a resolved FOT configuration
210
+ *
211
+ * @param config - The resolved FOT configuration
212
+ * @returns The generated tsconfig.json object
213
+ */
214
+ declare function generateTSConfig(config: ResolvedFotConfig): TSConfig;
215
+ import { z } from "zod";
216
+ /**
217
+ * Schema for build output formats
218
+ */
219
+ declare const buildFormatSchema: z.ZodEnum<{
220
+ esm: "esm";
221
+ cjs: "cjs";
222
+ }>;
223
+ /**
224
+ * Schema for plugin configuration
225
+ * Accepts either a string (plugin name) or a config object
226
+ */
227
+ declare const pluginConfigSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
228
+ name: z.ZodString;
229
+ enabled: z.ZodDefault<z.ZodBoolean>;
230
+ }, z.core.$strip>]>, z.ZodTransform<{
231
+ name: string;
232
+ enabled: boolean;
233
+ }, string | {
234
+ name: string;
235
+ enabled: boolean;
236
+ }>>;
237
+ /**
238
+ * Schema for TypeScript compiler options
239
+ */
240
+ declare const typeScriptOptionsSchema: z.ZodDefault<z.ZodObject<{
241
+ declaration: z.ZodDefault<z.ZodBoolean>;
242
+ }, z.core.$strip>>;
243
+ /**
244
+ * Schema for Biome configuration options
245
+ */
246
+ declare const biomeOptionsSchema: z.ZodDefault<z.ZodObject<{
247
+ enabled: z.ZodDefault<z.ZodBoolean>;
248
+ }, z.core.$strip>>;
249
+ /**
250
+ * Schema for FOT configuration
251
+ */
252
+ declare const fotConfigSchema: z.ZodObject<{
253
+ formats: z.ZodDefault<z.ZodArray<z.ZodEnum<{
254
+ esm: "esm";
255
+ cjs: "cjs";
256
+ }>>>;
257
+ external: z.ZodDefault<z.ZodArray<z.ZodString>>;
258
+ typescript: z.ZodDefault<z.ZodObject<{
259
+ declaration: z.ZodDefault<z.ZodBoolean>;
260
+ }, z.core.$strip>>;
261
+ biome: z.ZodDefault<z.ZodObject<{
262
+ enabled: z.ZodDefault<z.ZodBoolean>;
263
+ }, z.core.$strip>>;
264
+ plugins: z.ZodDefault<z.ZodArray<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
265
+ name: z.ZodString;
266
+ enabled: z.ZodDefault<z.ZodBoolean>;
267
+ }, z.core.$strip>]>, z.ZodTransform<{
268
+ name: string;
269
+ enabled: boolean;
270
+ }, string | {
271
+ name: string;
272
+ enabled: boolean;
273
+ }>>>>;
274
+ }, z.core.$strip>;
275
+ /**
276
+ * Type for input configuration (before validation and defaults)
277
+ */
278
+ type FotConfigInput = z.input<typeof fotConfigSchema>;
279
+ /**
280
+ * Type for output configuration (after validation and defaults)
281
+ */
282
+ type FotConfigOutput = z.output<typeof fotConfigSchema>;
283
+ export { typeScriptOptionsSchema, pluginConfigSchema, generateTSConfig, generatePackageJson, generateBiomeConfig, fotConfigSchema, defineFotConfig, buildFormatSchema, biomeOptionsSchema, TypeScriptOptions, TSConfig, ResolvedFotConfig, PluginConfig, PackageJson, PackageExport, FotConfigOutput, FotConfigInput, FotConfig, BuildFormat, BiomeOptions, BiomeConfig };
package/dist/index.js ADDED
@@ -0,0 +1,160 @@
1
+ // src/schemas.ts
2
+ import { z } from "zod";
3
+ var packageNameRegex = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
4
+ var buildFormatSchema = z.enum(["esm", "cjs"]);
5
+ var pluginConfigSchema = z.union([
6
+ z.string(),
7
+ z.object({
8
+ name: z.string(),
9
+ enabled: z.boolean().default(true)
10
+ })
11
+ ]).transform((val) => {
12
+ if (typeof val === "string") {
13
+ return { name: val, enabled: true };
14
+ }
15
+ return { name: val.name, enabled: val.enabled ?? true };
16
+ });
17
+ var typeScriptOptionsSchema = z.object({
18
+ declaration: z.boolean().default(true)
19
+ }).default({ declaration: true });
20
+ var biomeOptionsSchema = z.object({
21
+ enabled: z.boolean().default(true)
22
+ }).default({ enabled: true });
23
+ var fotConfigSchema = z.object({
24
+ formats: z.array(buildFormatSchema).default(["esm"]),
25
+ external: z.array(z.string().regex(packageNameRegex, {
26
+ message: "Invalid package name format"
27
+ })).default([]),
28
+ typescript: typeScriptOptionsSchema,
29
+ biome: biomeOptionsSchema,
30
+ plugins: z.array(pluginConfigSchema).default([])
31
+ });
32
+
33
+ // src/factory.ts
34
+ function defineFotConfig(config = {}) {
35
+ const result = fotConfigSchema.safeParse(config);
36
+ if (!result.success) {
37
+ const errors = result.error.issues.map((err) => `${err.path.join(".")}: ${err.message}`).join(", ");
38
+ throw new Error(`Invalid FOT configuration: ${errors}`);
39
+ }
40
+ return result.data;
41
+ }
42
+ // src/generators/biome.ts
43
+ function generateBiomeConfig(config) {
44
+ return {
45
+ $schema: "https://biomejs.dev/schemas/1.9.4/schema.json",
46
+ vcs: {
47
+ enabled: true,
48
+ clientKind: "git",
49
+ useIgnoreFile: true,
50
+ defaultBranch: "main"
51
+ },
52
+ files: {
53
+ ignoreUnknown: false,
54
+ ignore: ["node_modules", "dist", "*.config.ts"]
55
+ },
56
+ formatter: {
57
+ enabled: config.biome.enabled,
58
+ indentStyle: "tab",
59
+ indentWidth: 2,
60
+ lineWidth: 80
61
+ },
62
+ organizeImports: {
63
+ enabled: true
64
+ },
65
+ linter: {
66
+ enabled: config.biome.enabled,
67
+ rules: {
68
+ recommended: true
69
+ }
70
+ },
71
+ javascript: {
72
+ formatter: {
73
+ quoteStyle: "double",
74
+ semicolons: "always",
75
+ trailingCommas: "all"
76
+ }
77
+ }
78
+ };
79
+ }
80
+ // src/generators/package-json.ts
81
+ function generatePackageJson(libraryName, version, config, customDependencies) {
82
+ const exports = {
83
+ ".": {
84
+ types: "./dist/index.d.ts",
85
+ default: "./dist/index.js"
86
+ }
87
+ };
88
+ for (const plugin of config.plugins) {
89
+ if (plugin.enabled !== false) {
90
+ exports[`./plugins/${plugin.name}`] = {
91
+ types: `./dist/plugins/${plugin.name}/index.d.ts`,
92
+ default: `./dist/plugins/${plugin.name}/index.js`
93
+ };
94
+ }
95
+ }
96
+ const pkg = {
97
+ name: `@f-o-t/${libraryName}`,
98
+ version,
99
+ type: "module",
100
+ main: "./dist/index.js",
101
+ types: "./dist/index.d.ts",
102
+ exports,
103
+ scripts: {
104
+ build: "fot build",
105
+ test: "fot test",
106
+ lint: "fot lint",
107
+ format: "fot format"
108
+ },
109
+ devDependencies: {
110
+ "@f-o-t/cli": "workspace:*",
111
+ "@f-o-t/config": "workspace:*"
112
+ },
113
+ repository: {
114
+ type: "git",
115
+ url: "https://github.com/F-O-T/libraries.git",
116
+ directory: `libraries/${libraryName}`
117
+ }
118
+ };
119
+ if (customDependencies && Object.keys(customDependencies).length > 0) {
120
+ pkg.dependencies = customDependencies;
121
+ }
122
+ return pkg;
123
+ }
124
+ // src/generators/tsconfig.ts
125
+ function generateTSConfig(config) {
126
+ return {
127
+ compilerOptions: {
128
+ allowImportingTsExtensions: true,
129
+ declaration: config.typescript.declaration,
130
+ isolatedDeclarations: false,
131
+ module: "Preserve",
132
+ moduleDetection: "force",
133
+ moduleResolution: "bundler",
134
+ noEmit: true,
135
+ noFallthroughCasesInSwitch: true,
136
+ noImplicitOverride: true,
137
+ noPropertyAccessFromIndexSignature: false,
138
+ noUncheckedIndexedAccess: true,
139
+ noUnusedLocals: false,
140
+ noUnusedParameters: false,
141
+ skipLibCheck: true,
142
+ strict: true,
143
+ target: "ES2023",
144
+ verbatimModuleSyntax: true
145
+ },
146
+ exclude: ["node_modules", "dist", "bunup.config.ts"],
147
+ include: ["src/**/*"]
148
+ };
149
+ }
150
+ export {
151
+ typeScriptOptionsSchema,
152
+ pluginConfigSchema,
153
+ generateTSConfig,
154
+ generatePackageJson,
155
+ generateBiomeConfig,
156
+ fotConfigSchema,
157
+ defineFotConfig,
158
+ buildFormatSchema,
159
+ biomeOptionsSchema
160
+ };
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@f-o-t/config",
3
+ "version": "0.1.0",
4
+ "description": "Standardized configuration for F-O-T libraries",
5
+ "type": "module",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "bun": "./src/index.ts",
11
+ "import": {
12
+ "default": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "types": "./src/index.ts"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "bunup",
24
+ "check": "biome check --write .",
25
+ "dev": "bunup --watch",
26
+ "release": "bumpp --commit --push --tag",
27
+ "test": "bun test",
28
+ "test:coverage": "bun test --coverage",
29
+ "test:watch": "bun test --watch",
30
+ "typecheck": "tsc"
31
+ },
32
+ "dependencies": {
33
+ "zod": "4.3.6"
34
+ },
35
+ "devDependencies": {
36
+ "@biomejs/biome": "2.3.12",
37
+ "@types/bun": "1.3.6",
38
+ "bumpp": "10.4.0",
39
+ "bunup": "0.16.20",
40
+ "typescript": "5.9.3"
41
+ },
42
+ "peerDependencies": {
43
+ "typescript": ">=4.5.0"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "typescript": {
47
+ "optional": true
48
+ }
49
+ },
50
+ "private": false,
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "https://github.com/F-O-T/libraries.git"
57
+ },
58
+ "bugs": {
59
+ "url": "https://github.com/F-O-T/libraries/issues"
60
+ },
61
+ "homepage": "https://github.com/F-O-T/libraries/blob/master/libraries/config",
62
+ "license": "MIT"
63
+ }