From 0350859cbc58eef224d51ebf0ec06d4a3972f47c Mon Sep 17 00:00:00 2001 From: BART! Date: Sun, 5 Jan 2025 15:02:23 +0100 Subject: [PATCH] feat(config): handle missing config --- index.ts | 12 ++++++++---- package.json | 6 +++--- src/helpers/config.ts | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/index.ts b/index.ts index fd0b5ea..c16bf37 100644 --- a/index.ts +++ b/index.ts @@ -68,14 +68,14 @@ if (args.help || args.version === '' || args.version === true) { log(' --debug Debug mode'); log(' '); process.exit(args.help ? 0 : 1); -} else if (!config.domain && !args.domain) { +} else if (!config?.domain && !args.domain) { console.log( `⚠ svelte-sitemap: --domain argument is required.\n\nSee instructions: ${REPO_URL}\n\nExample:\n\n svelte-sitemap --domain https://mydomain.com\n` ); process.exit(0); } else if ( // (config.domain || args.domain) && - !config.domain?.includes('http') && + !config?.domain?.includes('http') && !args.domain?.includes('http') ) { console.log( @@ -87,7 +87,11 @@ if (args.help || args.version === '' || args.version === true) { } else { const domain: string = args.domain ? args.domain : undefined; const debug: boolean = args.debug === '' || args.debug === true ? true : false; - const additional = Array.isArray(args['additional']) ? args['additional'] : args.additional ? [args.additional] : []; + const additional = Array.isArray(args['additional']) + ? args['additional'] + : args.additional + ? [args.additional] + : []; const resetTime: boolean = args['reset-time'] === '' || args['reset-time'] === true ? true : false; const trailingSlashes: boolean = @@ -107,7 +111,7 @@ if (args.help || args.version === '' || args.version === true) { attribution, ignore, trailingSlashes, - additional, + additional }; // Config file is preferred diff --git a/package.json b/package.json index 971d302..b7c3411 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-sitemap", - "version": "2.7.0", + "version": "3.0.0-next.8", "description": "Small helper which scans your Svelte routes folder and generates static sitemap.xml", "main": "./dist/index.js", "author": "BART! ", @@ -22,8 +22,8 @@ "test:coverage": "vitest run --coverage", "postinstall": "cp -r ./src/build/ ./build", "postversion": "git push && git push --follow-tags", - "publish:next": "yarn && yarn build && yarn test && cd dist && npm publish --tag next", - "publish:beta": "yarn && yarn build && yarn test && cd dist && npm publish --tag beta", + "publish:next": "yarn && yarn build && yarn test run && cd dist && npm publish --tag next", + "publish:beta": "yarn && yarn build && yarn test run && cd dist && npm publish --tag beta", "release:beta": "npm version prerelease -m \"chore(update): prelease %s β\"", "release:patch": "git checkout master && npm version patch -m \"chore(update): patch release %s 🐛 \"", "release:minor": "git checkout master && npm version minor -m \"chore(update): release %s 🚀\"", diff --git a/src/helpers/config.ts b/src/helpers/config.ts index ee1eb95..5562f4b 100644 --- a/src/helpers/config.ts +++ b/src/helpers/config.ts @@ -2,7 +2,7 @@ import { OptionsSvelteSitemap } from '../interfaces/global.interface'; import { OUT_DIR } from './../vars'; import { loadFile } from './file'; -export const loadConfig = (path: string): OptionsSvelteSitemap => { +export const loadConfig = (path: string): OptionsSvelteSitemap | undefined => { const baseConfig = loadFile(path); return baseConfig!; };