diff --git a/package.json b/package.json index 2837018a..f2ba2a6b 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,7 @@ "type": "git", "url": "git+https://github.com/ieedan/ts-blocks" }, - "keywords": [ - "changelog", - "date" - ], + "keywords": ["changelog", "date"], "author": "Aidan Bleser", "license": "MIT", "bugs": { diff --git a/src/commands/add.ts b/src/commands/add.ts index a87d635f..90ce0b5a 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -119,7 +119,7 @@ const _add = async (blockNames: string[], options: Options) => { index = project.createSourceFile(indexPath); } - if (config.imports === undefined || config.imports === 'node') { + if (config.imports === 'node') { index.addExportDeclaration({ moduleSpecifier: `./${blockName}`, isTypeOnly: false, diff --git a/src/config/index.ts b/src/config/index.ts index 59c8e53c..0c15d8a6 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,18 +1,7 @@ import fs from 'node:fs'; import color from 'chalk'; import { program } from 'commander'; -import { - type InferInput, - boolean, - literal, - minLength, - object, - optional, - parse, - pipe, - string, - union, -} from 'valibot'; +import { boolean, literal, minLength, object, optional, parse, pipe, string, union } from 'valibot'; const CONFIG_NAME = 'blocks.json'; @@ -25,20 +14,37 @@ const schema = object({ imports: optional(union([literal('deno'), literal('node')])), }); -type Config = InferInput; +type Config = { + $schema: string; + addByCategory: boolean; + includeIndexFile: boolean; + includeTests: boolean; + path: string; + imports: 'deno' | 'node'; +}; -const getConfig = () => { +const getConfig = (): Config => { if (!fs.existsSync(CONFIG_NAME)) { program.error( color.red( - `Could not find your configuration file! Please run ${color.bold(`'ts-blocks init'`)}.` + `Could not find your configuration file! Please run ${color.bold( + `'ts-blocks init'` + )}.` ) ); } - return parse(schema, JSON.parse(fs.readFileSync(CONFIG_NAME).toString()), { + const config = parse(schema, JSON.parse(fs.readFileSync(CONFIG_NAME).toString()), { message: color.red('Invalid config file!'), }); + + // set defaults here + + if (config.imports === undefined) { + config.imports = 'node'; + } + + return config as Config; }; -export { getConfig, type Config, schema, CONFIG_NAME }; +export { type Config, CONFIG_NAME, getConfig, schema };