svelte-sitemap 3.0.0-next.8 → 3.0.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/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/cli.js ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env node
2
+ import { APP_NAME, CONFIG_FILES, REPO_URL } from "./const.js";
3
+ import { version as version$1 } from "./package.js";
4
+ import { cliColors, errorMsgGeneration } from "./helpers/vars.helper.js";
5
+ import { createSitemap } from "./index.js";
6
+ import { defaultConfig, loadConfig, withDefaultConfig } from "./helpers/config.js";
7
+ import minimist from "minimist";
8
+
9
+ //#region src/cli.ts
10
+ const version = version$1;
11
+ const main = async () => {
12
+ console.log(cliColors.cyanAndBold, `> Using ${APP_NAME}`);
13
+ let stop = false;
14
+ const config = await loadConfig(CONFIG_FILES);
15
+ const args = minimist(process.argv.slice(2), {
16
+ string: [
17
+ "domain",
18
+ "out-dir",
19
+ "ignore",
20
+ "change-freq",
21
+ "additional"
22
+ ],
23
+ boolean: [
24
+ "attribution",
25
+ "reset-time",
26
+ "trailing-slashes",
27
+ "debug",
28
+ "version"
29
+ ],
30
+ default: {
31
+ attribution: true,
32
+ "trailing-slashes": false,
33
+ default: false
34
+ },
35
+ alias: {
36
+ d: "domain",
37
+ D: "domain",
38
+ h: "help",
39
+ H: "help",
40
+ v: "version",
41
+ V: "version",
42
+ O: "out-dir",
43
+ o: "out-dir",
44
+ r: "reset-time",
45
+ R: "reset-time",
46
+ c: "change-freq",
47
+ C: "change-freq",
48
+ i: "ignore",
49
+ I: "ignore",
50
+ t: "trailing-slashes",
51
+ T: "trailing-slashes",
52
+ a: "additional",
53
+ A: "additional"
54
+ },
55
+ unknown: (err) => {
56
+ if (config && Object.keys(config).length > 0) return false;
57
+ console.log(cliColors.yellow, " ⚠ This argument is not supported:", err);
58
+ stop = true;
59
+ return false;
60
+ }
61
+ });
62
+ if (args.help || args.version === "" || args.version === true) {
63
+ const log = args.help ? console.log : console.error;
64
+ log("Svelte `sitemap.xml` generator");
65
+ log("");
66
+ log(`svelte-sitemap ${version} (check updates: ${REPO_URL})`);
67
+ log("");
68
+ log("Options:");
69
+ log("");
70
+ log(" -d, --domain Use your domain (eg. https://example.com)");
71
+ log(" -o, --out-dir Custom output dir");
72
+ log(" -i, --ignore Exclude some pages or folders");
73
+ log(" -a, --additional Additional pages outside of SvelteKit (e.g. /, /contact)");
74
+ log(" -t, --trailing-slashes Do you like trailing slashes?");
75
+ log(" -r, --reset-time Set modified time to now");
76
+ log(" -c, --change-freq Set change frequency `weekly` | `daily` | …");
77
+ log(" -v, --version Show version");
78
+ log(" --debug Debug mode");
79
+ log(" ");
80
+ process.exit(args.help ? 0 : 1);
81
+ } else if (config && Object.keys(config).length > 0) {
82
+ const hasCliOptions = process.argv.slice(2).length > 0;
83
+ console.log(cliColors.green, ` ✔ Reading config file...`);
84
+ const allowedKeys = Object.keys(defaultConfig);
85
+ const invalidKeys = Object.keys(config).filter((key) => !allowedKeys.includes(key));
86
+ if (invalidKeys.length > 0) console.log(cliColors.yellow, ` ⚠ Invalid properties in config file, so I ignore them: ${invalidKeys.join(", ")}`);
87
+ if (hasCliOptions) console.log(cliColors.yellow, ` ⚠ You have also set CLI options (arguments with '--'), but they are ignored because your config file 'svelte-sitemap.config.ts' is used.`);
88
+ if (!config.domain) {
89
+ console.log(cliColors.yellow, ` ⚠ svelte-sitemap: 'domain' property is required in your config file. See instructions: ${REPO_URL}\n`);
90
+ console.error(cliColors.red, errorMsgGeneration);
91
+ process.exit(0);
92
+ }
93
+ if (!config.domain.startsWith("https://")) {
94
+ console.log(cliColors.yellow, ` ⚠ svelte-sitemap: 'domain' property in your config file must start with https:// See instructions: ${REPO_URL}\n`);
95
+ console.error(cliColors.red, errorMsgGeneration);
96
+ process.exit(0);
97
+ }
98
+ try {
99
+ await createSitemap(withDefaultConfig(config));
100
+ } catch (err) {
101
+ console.error(cliColors.red, errorMsgGeneration, err);
102
+ process.exit(0);
103
+ }
104
+ } else {
105
+ if (stop) {
106
+ console.error(cliColors.red, errorMsgGeneration);
107
+ process.exit(0);
108
+ }
109
+ if (!args.domain) {
110
+ console.log(cliColors.red, ` ⚠ svelte-sitemap: --domain argument is required. See instructions: ${REPO_URL}\n Example:\n svelte-sitemap --domain https://mydomain.com\n`);
111
+ console.error(cliColors.red, errorMsgGeneration);
112
+ process.exit(0);
113
+ }
114
+ if (!args.domain.startsWith("https://")) {
115
+ console.log(cliColors.red, ` ⚠ svelte-sitemap: --domain argument must start with https:// See instructions: ${REPO_URL}\n Example:\n\n svelte-sitemap --domain https://mydomain.com\n`);
116
+ console.error(cliColors.red, errorMsgGeneration);
117
+ process.exit(0);
118
+ }
119
+ const domain = args.domain;
120
+ const debug = args.debug === "" || args.debug === true ? true : false;
121
+ const additional = Array.isArray(args["additional"]) ? args["additional"] : args.additional ? [args.additional] : [];
122
+ const resetTime = args["reset-time"] === "" || args["reset-time"] === true ? true : false;
123
+ const trailingSlashes = args["trailing-slashes"] === "" || args["trailing-slashes"] === true ? true : false;
124
+ const changeFreq = args["change-freq"];
125
+ const outDir = args["out-dir"];
126
+ const ignore = args["ignore"];
127
+ const optionsCli = {
128
+ debug,
129
+ resetTime,
130
+ changeFreq,
131
+ outDir,
132
+ domain,
133
+ attribution: args["attribution"] === "" || args["attribution"] === false ? false : true,
134
+ ignore,
135
+ trailingSlashes,
136
+ additional
137
+ };
138
+ console.log(cliColors.yellow, ` ℹ Hint: Configuration file is now the preferred method to set up svelte-sitemap. See ${REPO_URL}?tab=readme-ov-file#-usage`);
139
+ console.log(cliColors.cyanAndBold, ` ✔ Using CLI options. Config file not found.`);
140
+ try {
141
+ await createSitemap(optionsCli);
142
+ } catch (err) {
143
+ console.error(cliColors.red, errorMsgGeneration, err);
144
+ process.exit(0);
145
+ }
146
+ }
147
+ };
148
+ main();
149
+
150
+ //#endregion
151
+ export { };
152
+ //# sourceMappingURL=cli.js.map
package/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","names":["pkg.version"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport minimist from 'minimist';\nimport pkg from './../package.json' with { type: 'json' };\nimport { APP_NAME, CONFIG_FILES, REPO_URL } from './const.js';\nimport type { ChangeFreq, OptionsSvelteSitemap } from './dto/index.js';\nimport { defaultConfig, loadConfig, withDefaultConfig } from './helpers/config.js';\nimport { cliColors, errorMsgGeneration } from './helpers/vars.helper.js';\nimport { createSitemap } from './index.js';\nconst version = pkg.version;\n\nconst main = async () => {\n console.log(cliColors.cyanAndBold, `> Using ${APP_NAME}`);\n\n let stop = false;\n\n const config = await loadConfig(CONFIG_FILES);\n\n const args = minimist(process.argv.slice(2), {\n string: ['domain', 'out-dir', 'ignore', 'change-freq', 'additional'],\n boolean: ['attribution', 'reset-time', 'trailing-slashes', 'debug', 'version'],\n default: { attribution: true, 'trailing-slashes': false, default: false },\n alias: {\n d: 'domain',\n D: 'domain',\n h: 'help',\n H: 'help',\n v: 'version',\n V: 'version',\n O: 'out-dir',\n o: 'out-dir',\n r: 'reset-time',\n R: 'reset-time',\n c: 'change-freq',\n C: 'change-freq',\n i: 'ignore',\n I: 'ignore',\n t: 'trailing-slashes',\n T: 'trailing-slashes',\n a: 'additional',\n A: 'additional'\n },\n unknown: (err: string) => {\n if (config && Object.keys(config).length > 0) return false;\n console.log(cliColors.yellow, ' ⚠ This argument is not supported:', err);\n // console.log(cliColors.yellow, ' Use: `svelte-sitemap --help` for more options.');\n stop = true;\n return false;\n }\n });\n\n if (args.help || args.version === '' || args.version === true) {\n const log = args.help ? console.log : console.error;\n log('Svelte `sitemap.xml` generator');\n log('');\n log(`svelte-sitemap ${version} (check updates: ${REPO_URL})`);\n log('');\n log('Options:');\n log('');\n log(' -d, --domain Use your domain (eg. https://example.com)');\n log(' -o, --out-dir Custom output dir');\n log(' -i, --ignore Exclude some pages or folders');\n log(' -a, --additional Additional pages outside of SvelteKit (e.g. /, /contact)');\n log(' -t, --trailing-slashes Do you like trailing slashes?');\n log(' -r, --reset-time Set modified time to now');\n log(' -c, --change-freq Set change frequency `weekly` | `daily` | …');\n log(' -v, --version Show version');\n log(' --debug Debug mode');\n log(' ');\n process.exit(args.help ? 0 : 1);\n } else if (config && Object.keys(config).length > 0) {\n // --- CONFIG FILE PATH ---\n const hasCliOptions = process.argv.slice(2).length > 0;\n console.log(cliColors.green, ` ✔ Reading config file...`);\n\n const allowedKeys = Object.keys(defaultConfig);\n const invalidKeys = Object.keys(config).filter((key) => !allowedKeys.includes(key));\n if (invalidKeys.length > 0) {\n console.log(\n cliColors.yellow,\n ` ⚠ Invalid properties in config file, so I ignore them: ${invalidKeys.join(', ')}`\n );\n }\n\n if (hasCliOptions) {\n console.log(\n cliColors.yellow,\n ` ⚠ You have also set CLI options (arguments with '--'), but they are ignored because your config file 'svelte-sitemap.config.ts' is used.`\n );\n }\n\n if (!config.domain) {\n console.log(\n cliColors.yellow,\n ` ⚠ svelte-sitemap: 'domain' property is required in your config file. See instructions: ${REPO_URL}\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n if (!config.domain.startsWith('https://')) {\n console.log(\n cliColors.yellow,\n ` ⚠ svelte-sitemap: 'domain' property in your config file must start with https:// See instructions: ${REPO_URL}\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n try {\n await createSitemap(withDefaultConfig(config));\n } catch (err) {\n console.error(cliColors.red, errorMsgGeneration, err);\n process.exit(0);\n }\n } else {\n // --- CLI ARGUMENTS PATH ---\n if (stop) {\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n if (!args.domain) {\n console.log(\n cliColors.red,\n ` ⚠ svelte-sitemap: --domain argument is required. See instructions: ${REPO_URL}\\n Example:\\n svelte-sitemap --domain https://mydomain.com\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n if (!args.domain.startsWith('https://')) {\n console.log(\n cliColors.red,\n ` ⚠ svelte-sitemap: --domain argument must start with https:// See instructions: ${REPO_URL}\\n Example:\\n\\n svelte-sitemap --domain https://mydomain.com\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n const domain: string = args.domain;\n const debug: boolean = args.debug === '' || args.debug === true ? true : false;\n const additional = Array.isArray(args['additional'])\n ? args['additional']\n : args.additional\n ? [args.additional]\n : [];\n const resetTime: boolean =\n args['reset-time'] === '' || args['reset-time'] === true ? true : false;\n const trailingSlashes: boolean =\n args['trailing-slashes'] === '' || args['trailing-slashes'] === true ? true : false;\n const changeFreq: ChangeFreq = args['change-freq'];\n const outDir: string = args['out-dir'];\n const ignore: string = args['ignore'];\n const attribution: boolean =\n args['attribution'] === '' || args['attribution'] === false ? false : true;\n\n const optionsCli: OptionsSvelteSitemap = {\n debug,\n resetTime,\n changeFreq,\n outDir,\n domain,\n attribution,\n ignore,\n trailingSlashes,\n additional\n };\n\n console.log(\n cliColors.yellow,\n ` ℹ Hint: Configuration file is now the preferred method to set up svelte-sitemap. See ${REPO_URL}?tab=readme-ov-file#-usage`\n );\n console.log(cliColors.cyanAndBold, ` ✔ Using CLI options. Config file not found.`);\n try {\n await createSitemap(optionsCli);\n } catch (err) {\n console.error(cliColors.red, errorMsgGeneration, err);\n process.exit(0);\n }\n }\n};\n\nmain();\n"],"mappings":";;;;;;;;;AAQA,MAAM,UAAUA;AAEhB,MAAM,OAAO,YAAY;AACvB,SAAQ,IAAI,UAAU,aAAa,WAAW,WAAW;CAEzD,IAAI,OAAO;CAEX,MAAM,SAAS,MAAM,WAAW,aAAa;CAE7C,MAAM,OAAO,SAAS,QAAQ,KAAK,MAAM,EAAE,EAAE;EAC3C,QAAQ;GAAC;GAAU;GAAW;GAAU;GAAe;GAAa;EACpE,SAAS;GAAC;GAAe;GAAc;GAAoB;GAAS;GAAU;EAC9E,SAAS;GAAE,aAAa;GAAM,oBAAoB;GAAO,SAAS;GAAO;EACzE,OAAO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;EACpC,MAAM,SAAiB,KAAK;EAC5B,MAAM,SAAiB,KAAK;EAI5B,MAAM,aAAmC;GACvC;GACA;GACA;GACA;GACA;GACA,aARA,KAAK,mBAAmB,MAAM,KAAK,mBAAmB,QAAQ,QAAQ;GAStE;GACA;GACA;GACD;AAED,UAAQ,IACN,UAAU,QACV,0FAA0F,SAAS,4BACpG;AACD,UAAQ,IAAI,UAAU,aAAa,gDAAgD;AACnF,MAAI;AACF,SAAM,cAAc,WAAW;WACxB,KAAK;AACZ,WAAQ,MAAM,UAAU,KAAK,oBAAoB,IAAI;AACrD,WAAQ,KAAK,EAAE;;;;AAKrB,MAAM"}
package/const.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ //#region src/const.d.ts
2
+ declare const CHANGE_FREQ: readonly ["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"];
3
+ //#endregion
4
+ export { CHANGE_FREQ };
5
+ //# sourceMappingURL=const.d.ts.map
package/const.js ADDED
@@ -0,0 +1,27 @@
1
+ //#region src/const.ts
2
+ const APP_NAME = "svelte-sitemap";
3
+ const REPO_URL = "https://github.com/bartholomej/svelte-sitemap";
4
+ const OUT_DIR = "build";
5
+ const CHUNK = { maxSize: 5e4 };
6
+ const CONFIG_FILES = [
7
+ "svelte-sitemap.config.js",
8
+ "svelte-sitemap.config.mjs",
9
+ "svelte-sitemap.config.cjs",
10
+ "svelte-sitemap.config.ts",
11
+ "svelte-sitemap.config.mts",
12
+ "svelte-sitemap.config.cts",
13
+ "svelte-sitemap.config.json"
14
+ ];
15
+ const CHANGE_FREQ = [
16
+ "always",
17
+ "hourly",
18
+ "daily",
19
+ "weekly",
20
+ "monthly",
21
+ "yearly",
22
+ "never"
23
+ ];
24
+
25
+ //#endregion
26
+ export { APP_NAME, CHANGE_FREQ, CHUNK, CONFIG_FILES, OUT_DIR, REPO_URL };
27
+ //# sourceMappingURL=const.js.map
package/const.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.js","names":[],"sources":["../src/const.ts"],"sourcesContent":["export const APP_NAME = 'svelte-sitemap';\n\nexport const REPO_URL = 'https://github.com/bartholomej/svelte-sitemap';\n\nexport const DOMAIN = 'https://example.com';\n\nexport const OUT_DIR = 'build';\n\n// Google recommends to split sitemap into multiple files if there are more than 50k pages\n// https://support.google.com/webmasters/answer/183668?hl=en\nexport const CHUNK = {\n maxSize: 50_000\n};\n\nexport const CONFIG_FILES = [\n 'svelte-sitemap.config.js',\n 'svelte-sitemap.config.mjs',\n 'svelte-sitemap.config.cjs',\n 'svelte-sitemap.config.ts',\n 'svelte-sitemap.config.mts',\n 'svelte-sitemap.config.cts',\n 'svelte-sitemap.config.json'\n];\n\nexport const CHANGE_FREQ = [\n 'always',\n 'hourly',\n 'daily',\n 'weekly',\n 'monthly',\n 'yearly',\n 'never'\n] as const;\n"],"mappings":";AAAA,MAAa,WAAW;AAExB,MAAa,WAAW;AAIxB,MAAa,UAAU;AAIvB,MAAa,QAAQ,EACnB,SAAS,KACV;AAED,MAAa,eAAe;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
@@ -0,0 +1,32 @@
1
+ import { CHANGE_FREQ } from "../const.js";
2
+
3
+ //#region src/dto/global.interface.d.ts
4
+ interface Arguments {
5
+ domain: string;
6
+ options?: Options;
7
+ }
8
+ interface Options {
9
+ debug?: boolean;
10
+ changeFreq?: ChangeFreq;
11
+ resetTime?: boolean;
12
+ outDir?: string;
13
+ attribution?: boolean;
14
+ ignore?: string | string[];
15
+ trailingSlashes?: boolean;
16
+ additional?: string[];
17
+ }
18
+ interface OptionsSvelteSitemap extends Options {
19
+ domain: string;
20
+ }
21
+ interface PagesJson {
22
+ page: string;
23
+ changeFreq?: ChangeFreq;
24
+ lastMod?: string;
25
+ }
26
+ /**
27
+ * Specs: https://www.sitemaps.org/protocol.html
28
+ */
29
+ type ChangeFreq = (typeof CHANGE_FREQ)[number];
30
+ //#endregion
31
+ export { Arguments, ChangeFreq, Options, OptionsSvelteSitemap, PagesJson };
32
+ //# sourceMappingURL=global.interface.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { OUT_DIR } from "../const.js";
2
+ import { loadFile } from "./file.js";
3
+
4
+ //#region src/helpers/config.ts
5
+ const loadConfig = async (paths) => {
6
+ for (const path of paths) {
7
+ const config = await loadFile(path, false);
8
+ if (config) return config;
9
+ }
10
+ };
11
+ const defaultConfig = {
12
+ debug: false,
13
+ changeFreq: null,
14
+ resetTime: false,
15
+ outDir: OUT_DIR,
16
+ attribution: true,
17
+ ignore: null,
18
+ trailingSlashes: false,
19
+ domain: null
20
+ };
21
+ const updateConfig = (currConfig, newConfig) => {
22
+ return {
23
+ ...currConfig,
24
+ ...newConfig
25
+ };
26
+ };
27
+ const withDefaultConfig = (config) => {
28
+ return updateConfig(defaultConfig, config);
29
+ };
30
+
31
+ //#endregion
32
+ export { defaultConfig, loadConfig, withDefaultConfig };
33
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","names":[],"sources":["../../src/helpers/config.ts"],"sourcesContent":["import { OUT_DIR } from '../const.js';\nimport type { OptionsSvelteSitemap } from '../dto/index.js';\nimport { loadFile } from './file.js';\n\nexport const loadConfig = async (paths: string[]): Promise<OptionsSvelteSitemap | undefined> => {\n for (const path of paths) {\n const config = await loadFile<OptionsSvelteSitemap>(path, false);\n if (config) {\n return config;\n }\n }\n return undefined;\n};\n\nexport const defaultConfig: OptionsSvelteSitemap = {\n debug: false,\n changeFreq: null,\n resetTime: false,\n outDir: OUT_DIR,\n attribution: true,\n ignore: null,\n trailingSlashes: false,\n domain: null\n};\n\nexport const updateConfig = (\n currConfig: OptionsSvelteSitemap,\n newConfig: OptionsSvelteSitemap\n): OptionsSvelteSitemap => {\n return { ...currConfig, ...newConfig };\n};\n\nexport const withDefaultConfig = (config: OptionsSvelteSitemap): OptionsSvelteSitemap => {\n return updateConfig(defaultConfig, config);\n};\n"],"mappings":";;;;AAIA,MAAa,aAAa,OAAO,UAA+D;AAC9F,MAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,SAAS,MAAM,SAA+B,MAAM,MAAM;AAChE,MAAI,OACF,QAAO;;;AAMb,MAAa,gBAAsC;CACjD,OAAO;CACP,YAAY;CACZ,WAAW;CACX,QAAQ;CACR,aAAa;CACb,QAAQ;CACR,iBAAiB;CACjB,QAAQ;CACT;AAED,MAAa,gBACX,YACA,cACyB;AACzB,QAAO;EAAE,GAAG;EAAY,GAAG;EAAW;;AAGxC,MAAa,qBAAqB,WAAuD;AACvF,QAAO,aAAa,eAAe,OAAO"}
@@ -0,0 +1,21 @@
1
+ import { existsSync } from "fs";
2
+ import { createJiti } from "jiti";
3
+ import { resolve } from "path";
4
+ import { fileURLToPath } from "url";
5
+
6
+ //#region src/helpers/file.ts
7
+ const jiti = createJiti(fileURLToPath(import.meta.url));
8
+ const loadFile = async (fileName, throwError = true) => {
9
+ const filePath = resolve(resolve(process.cwd(), fileName));
10
+ if (existsSync(filePath)) try {
11
+ return await jiti.import(filePath, { default: true });
12
+ } catch (err) {
13
+ throw err;
14
+ }
15
+ if (throwError) throw new Error(`${filePath} does not exist.`);
16
+ return null;
17
+ };
18
+
19
+ //#endregion
20
+ export { loadFile };
21
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file.js","names":[],"sources":["../../src/helpers/file.ts"],"sourcesContent":["import { existsSync } from 'fs';\nimport { createJiti } from 'jiti';\nimport { resolve } from 'path';\nimport { fileURLToPath } from 'url';\n\nconst filename = fileURLToPath(import.meta.url);\nconst jiti = createJiti(filename);\n\nexport const loadFile = async <T>(fileName: string, throwError = true): Promise<T | null> => {\n const filePath = resolve(resolve(process.cwd(), fileName));\n\n if (existsSync(filePath)) {\n try {\n const module = await jiti.import(filePath, { default: true });\n return module as T;\n } catch (err: any) {\n throw err;\n }\n }\n\n if (throwError) {\n throw new Error(`${filePath} does not exist.`);\n }\n return null;\n};\n"],"mappings":";;;;;;AAMA,MAAM,OAAO,WADI,cAAc,OAAO,KAAK,IAAI,CACd;AAEjC,MAAa,WAAW,OAAU,UAAkB,aAAa,SAA4B;CAC3F,MAAM,WAAW,QAAQ,QAAQ,QAAQ,KAAK,EAAE,SAAS,CAAC;AAE1D,KAAI,WAAW,SAAS,CACtB,KAAI;AAEF,SADe,MAAM,KAAK,OAAO,UAAU,EAAE,SAAS,MAAM,CAAC;UAEtD,KAAU;AACjB,QAAM;;AAIV,KAAI,WACF,OAAM,IAAI,MAAM,GAAG,SAAS,kBAAkB;AAEhD,QAAO"}
@@ -0,0 +1,120 @@
1
+ import { CHANGE_FREQ, CHUNK, OUT_DIR } from "../const.js";
2
+ import { version as version$1 } from "../package.js";
3
+ import { cliColors, errorMsgFolder, errorMsgHtmlFiles, errorMsgWrite, successMsg } from "./vars.helper.js";
4
+ import fg from "fast-glob";
5
+ import fs from "fs";
6
+ import { create } from "xmlbuilder2";
7
+
8
+ //#region src/helpers/global.helper.ts
9
+ const version = version$1;
10
+ const getUrl = (url, domain, options) => {
11
+ let slash = getSlash(domain);
12
+ let trimmed = url.split((options?.outDir ?? OUT_DIR) + "/").pop().replace("index.html", "");
13
+ trimmed = removeHtml(trimmed);
14
+ if (options?.trailingSlashes) trimmed = trimmed.length && !trimmed.endsWith("/") ? trimmed + "/" : trimmed;
15
+ else {
16
+ trimmed = trimmed.endsWith("/") ? trimmed.slice(0, -1) : trimmed;
17
+ slash = trimmed ? slash : "";
18
+ }
19
+ return `${domain}${slash}${trimmed}`;
20
+ };
21
+ const removeHtml = (fileName) => {
22
+ if (fileName?.endsWith(".html")) return fileName.slice(0, -5);
23
+ return fileName;
24
+ };
25
+ async function prepareData(domain, options) {
26
+ const FOLDER = options?.outDir ?? OUT_DIR;
27
+ const ignore = prepareIgnored(options?.ignore, options?.outDir);
28
+ const changeFreq = prepareChangeFreq(options);
29
+ const pages = await fg(`${FOLDER}/**/*.html`, { ignore });
30
+ if (options.additional) pages.push(...options.additional);
31
+ const results = pages.map((page) => {
32
+ return {
33
+ page: getUrl(page, domain, options),
34
+ changeFreq,
35
+ lastMod: options?.resetTime ? (/* @__PURE__ */ new Date()).toISOString().split("T")[0] : ""
36
+ };
37
+ });
38
+ detectErrors({
39
+ folder: !fs.existsSync(FOLDER),
40
+ htmlFiles: !pages.length
41
+ });
42
+ return results;
43
+ }
44
+ const detectErrors = ({ folder, htmlFiles }) => {
45
+ if (folder && htmlFiles) console.error(cliColors.red, errorMsgFolder(OUT_DIR));
46
+ else if (htmlFiles) console.error(cliColors.red, errorMsgHtmlFiles(OUT_DIR));
47
+ };
48
+ const writeSitemap = (items, options, domain) => {
49
+ const outDir = options?.outDir ?? OUT_DIR;
50
+ if (items?.length <= CHUNK.maxSize) createFile(items, options, outDir);
51
+ else {
52
+ const numberOfChunks = Math.ceil(items.length / CHUNK.maxSize);
53
+ console.log(cliColors.cyanAndBold, `> Oh, your site is huge! Writing sitemap in chunks of ${numberOfChunks} pages and its index sitemap.xml`);
54
+ for (let i = 0; i < items.length; i += CHUNK.maxSize) createFile(items.slice(i, i + CHUNK.maxSize), options, outDir, i / CHUNK.maxSize + 1);
55
+ createIndexFile(numberOfChunks, outDir, options, domain);
56
+ }
57
+ };
58
+ const createFile = (items, options, outDir, chunkId) => {
59
+ const sitemap = createXml("urlset");
60
+ addAttribution(sitemap, options);
61
+ for (const item of items) {
62
+ const page = sitemap.ele("url");
63
+ page.ele("loc").txt(item.page);
64
+ if (item.changeFreq) page.ele("changefreq").txt(item.changeFreq);
65
+ if (item.lastMod) page.ele("lastmod").txt(item.lastMod);
66
+ }
67
+ const xml = finishXml(sitemap);
68
+ const fileName = chunkId ? `sitemap-${chunkId}.xml` : "sitemap.xml";
69
+ try {
70
+ fs.writeFileSync(`${outDir}/${fileName}`, xml);
71
+ console.log(cliColors.green, successMsg(outDir, fileName));
72
+ } catch (e) {
73
+ console.error(cliColors.red, errorMsgWrite(outDir, fileName), e);
74
+ }
75
+ };
76
+ const createIndexFile = (numberOfChunks, outDir, options, domain) => {
77
+ const FILENAME = "sitemap.xml";
78
+ const slash = getSlash(domain);
79
+ const sitemap = createXml("sitemapindex");
80
+ addAttribution(sitemap, options);
81
+ for (let i = 1; i <= numberOfChunks; i++) sitemap.ele("sitemap").ele("loc").txt(`${domain}${slash}sitemap-${i}.xml`);
82
+ const xml = finishXml(sitemap);
83
+ try {
84
+ fs.writeFileSync(`${outDir}/${FILENAME}`, xml);
85
+ console.log(cliColors.green, successMsg(outDir, FILENAME));
86
+ } catch (e) {
87
+ console.error(cliColors.red, errorMsgWrite(outDir, FILENAME), e);
88
+ }
89
+ };
90
+ const prepareIgnored = (ignored, outDir = OUT_DIR) => {
91
+ let ignore;
92
+ if (ignored) {
93
+ ignore = Array.isArray(ignored) ? ignored : [ignored];
94
+ ignore = ignore.map((ignoredPage) => `${outDir}/${ignoredPage}`);
95
+ }
96
+ return ignore;
97
+ };
98
+ const prepareChangeFreq = (options) => {
99
+ let result = null;
100
+ if (options?.changeFreq) if (CHANGE_FREQ.includes(options.changeFreq)) result = options.changeFreq;
101
+ else console.log(cliColors.red, ` × Option \`--change-freq ${options.changeFreq}\` is not a valid value. See docs: https://github.com/bartholomej/svelte-sitemap#options`);
102
+ return result;
103
+ };
104
+ const getSlash = (domain) => domain.split("/").pop() ? "/" : "";
105
+ const createXml = (elementName) => {
106
+ return create({
107
+ version: "1.0",
108
+ encoding: "UTF-8"
109
+ }).ele(elementName, { xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" });
110
+ };
111
+ const finishXml = (sitemap) => {
112
+ return sitemap.end({ prettyPrint: true });
113
+ };
114
+ const addAttribution = (sitemap, options) => {
115
+ if (options?.attribution !== false) sitemap.com(` This file was automatically generated by https://github.com/bartholomej/svelte-sitemap v${version} `);
116
+ };
117
+
118
+ //#endregion
119
+ export { prepareData, writeSitemap };
120
+ //# sourceMappingURL=global.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.helper.js","names":["pkg.version"],"sources":["../../src/helpers/global.helper.ts"],"sourcesContent":["import fg from 'fast-glob';\nimport fs from 'fs';\nimport { create } from 'xmlbuilder2';\nimport type { XMLBuilder } from 'xmlbuilder2/lib/interfaces.js';\nimport pkg from '../../package.json' with { type: 'json' };\nimport { CHANGE_FREQ, CHUNK, OUT_DIR } from '../const.js';\nimport type { ChangeFreq, Options, OptionsSvelteSitemap, PagesJson } from './../dto/index.js';\nimport {\n cliColors,\n errorMsgFolder,\n errorMsgHtmlFiles,\n errorMsgWrite,\n successMsg\n} from './vars.helper.js';\n\nconst version = pkg.version;\n\nconst getUrl = (url: string, domain: string, options: Options) => {\n let slash: '' | '/' = getSlash(domain);\n\n let trimmed = url\n .split((options?.outDir ?? OUT_DIR) + '/')\n .pop()\n .replace('index.html', '');\n\n trimmed = removeHtml(trimmed);\n\n // Add all traling slashes\n if (options?.trailingSlashes) {\n trimmed = trimmed.length && !trimmed.endsWith('/') ? trimmed + '/' : trimmed;\n } else {\n trimmed = trimmed.endsWith('/') ? trimmed.slice(0, -1) : trimmed;\n slash = trimmed ? slash : '';\n }\n return `${domain}${slash}${trimmed}`;\n};\n\nexport const removeHtml = (fileName: string) => {\n if (fileName?.endsWith('.html')) {\n return fileName.slice(0, -5);\n }\n return fileName;\n};\n\nexport async function prepareData(domain: string, options?: Options): Promise<PagesJson[]> {\n const FOLDER = options?.outDir ?? OUT_DIR;\n\n const ignore = prepareIgnored(options?.ignore, options?.outDir);\n const changeFreq = prepareChangeFreq(options);\n const pages: string[] = await fg(`${FOLDER}/**/*.html`, { ignore });\n\n if (options.additional) pages.push(...options.additional);\n\n const results = pages.map((page) => {\n return {\n page: getUrl(page, domain, options),\n changeFreq: changeFreq,\n lastMod: options?.resetTime ? new Date().toISOString().split('T')[0] : ''\n };\n });\n\n detectErrors({\n folder: !fs.existsSync(FOLDER),\n htmlFiles: !pages.length\n });\n\n return results;\n}\n\nexport const detectErrors = ({ folder, htmlFiles }: { folder: boolean; htmlFiles: boolean }) => {\n if (folder && htmlFiles) {\n console.error(cliColors.red, errorMsgFolder(OUT_DIR));\n } else if (htmlFiles) {\n // If no page exists, then the static adapter is probably not used\n console.error(cliColors.red, errorMsgHtmlFiles(OUT_DIR));\n }\n};\n\nexport const writeSitemap = (items: PagesJson[], options: Options, domain: string): void => {\n const outDir = options?.outDir ?? OUT_DIR;\n\n if (items?.length <= CHUNK.maxSize) {\n createFile(items, options, outDir);\n } else {\n // If the number of pages is greater than the chunk size, then we split the sitemap into multiple files\n // and create an index file that links to all of them\n // https://support.google.com/webmasters/answer/183668?hl=en\n const numberOfChunks = Math.ceil(items.length / CHUNK.maxSize);\n\n console.log(\n cliColors.cyanAndBold,\n `> Oh, your site is huge! Writing sitemap in chunks of ${numberOfChunks} pages and its index sitemap.xml`\n );\n\n for (let i = 0; i < items.length; i += CHUNK.maxSize) {\n const chunk = items.slice(i, i + CHUNK.maxSize);\n createFile(chunk, options, outDir, i / CHUNK.maxSize + 1);\n }\n createIndexFile(numberOfChunks, outDir, options, domain);\n }\n};\n\nconst createFile = (\n items: PagesJson[],\n options: Options,\n outDir: string,\n chunkId?: number\n): void => {\n const sitemap = createXml('urlset');\n addAttribution(sitemap, options);\n\n for (const item of items) {\n const page = sitemap.ele('url');\n page.ele('loc').txt(item.page);\n if (item.changeFreq) {\n page.ele('changefreq').txt(item.changeFreq);\n }\n if (item.lastMod) {\n page.ele('lastmod').txt(item.lastMod);\n }\n }\n\n const xml = finishXml(sitemap);\n\n const fileName = chunkId ? `sitemap-${chunkId}.xml` : 'sitemap.xml';\n\n try {\n fs.writeFileSync(`${outDir}/${fileName}`, xml);\n console.log(cliColors.green, successMsg(outDir, fileName));\n } catch (e) {\n console.error(cliColors.red, errorMsgWrite(outDir, fileName), e);\n }\n};\n\nconst createIndexFile = (\n numberOfChunks: number,\n outDir: string,\n options: Options,\n domain: string\n): void => {\n const FILENAME = 'sitemap.xml';\n const slash = getSlash(domain);\n\n const sitemap = createXml('sitemapindex');\n addAttribution(sitemap, options);\n\n for (let i = 1; i <= numberOfChunks; i++) {\n sitemap.ele('sitemap').ele('loc').txt(`${domain}${slash}sitemap-${i}.xml`);\n }\n\n const xml = finishXml(sitemap);\n\n try {\n fs.writeFileSync(`${outDir}/${FILENAME}`, xml);\n console.log(cliColors.green, successMsg(outDir, FILENAME));\n } catch (e) {\n console.error(cliColors.red, errorMsgWrite(outDir, FILENAME), e);\n }\n};\n\nconst prepareIgnored = (\n ignored: string | string[],\n outDir: string = OUT_DIR\n): string[] | undefined => {\n let ignore: string[] | undefined;\n if (ignored) {\n ignore = Array.isArray(ignored) ? ignored : [ignored];\n ignore = ignore.map((ignoredPage) => `${outDir}/${ignoredPage}`);\n }\n return ignore;\n};\n\nconst prepareChangeFreq = (options: Options): ChangeFreq => {\n let result: ChangeFreq = null;\n\n if (options?.changeFreq) {\n if (CHANGE_FREQ.includes(options.changeFreq)) {\n result = options.changeFreq;\n } else {\n console.log(\n cliColors.red,\n ` × Option \\`--change-freq ${options.changeFreq}\\` is not a valid value. See docs: https://github.com/bartholomej/svelte-sitemap#options`\n );\n }\n }\n return result;\n};\n\nconst getSlash = (domain: string) => (domain.split('/').pop() ? '/' : '');\n\nconst createXml = (elementName: 'urlset' | 'sitemapindex'): XMLBuilder => {\n return create({ version: '1.0', encoding: 'UTF-8' }).ele(elementName, {\n xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9'\n });\n};\n\nconst finishXml = (sitemap: XMLBuilder): string => {\n return sitemap.end({ prettyPrint: true });\n};\n\nconst addAttribution = (sitemap: XMLBuilder, options: Options): void => {\n if (options?.attribution !== false) {\n sitemap.com(\n ` This file was automatically generated by https://github.com/bartholomej/svelte-sitemap v${version} `\n );\n }\n};\n"],"mappings":";;;;;;;;AAeA,MAAM,UAAUA;AAEhB,MAAM,UAAU,KAAa,QAAgB,YAAqB;CAChE,IAAI,QAAkB,SAAS,OAAO;CAEtC,IAAI,UAAU,IACX,OAAO,SAAS,UAAU,WAAW,IAAI,CACzC,KAA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MAAM;CAG5E,MAAM,MAAM,UAAU,QAAQ;AAE9B,KAAI;AACF,KAAG,cAAc,GAAG,OAAO,GAAG,YAAY,IAAI;AAC9C,UAAQ,IAAI,UAAU,OAAO,WAAW,QAAQ,SAAS,CAAC;UACnD,GAAG;AACV,UAAQ,MAAM,UAAU,KAAK,cAAc,QAAQ,SAAS,EAAE,EAAE;;;AAIpE,MAAM,kBACJ,SACA,SAAiB,YACQ;CACzB,IAAI;AACJ,KAAI,SAAS;AACX,WAAS,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAC,QAAQ;AACrD,WAAS,OAAO,KAAK,gBAAgB,GAAG,OAAO,GAAG,cAAc;;AAElE,QAAO;;AAGT,MAAM,qBAAqB,YAAiC;CAC1D,IAAI,SAAqB;AAEzB,KAAI,SAAS,WACX,KAAI,YAAY,SAAS,QAAQ,WAAW,CAC1C,UAAS,QAAQ;KAEjB,SAAQ,IACN,UAAU,KACV,8BAA8B,QAAQ,WAAW,0FAClD;AAGL,QAAO;;AAGT,MAAM,YAAY,WAAoB,OAAO,MAAM,IAAI,CAAC,KAAK,GAAG,MAAM;AAEtE,MAAM,aAAa,gBAAuD;AACxE,QAAO,OAAO;EAAE,SAAS;EAAO,UAAU;EAAS,CAAC,CAAC,IAAI,aAAa,EACpE,OAAO,+CACR,CAAC;;AAGJ,MAAM,aAAa,YAAgC;AACjD,QAAO,QAAQ,IAAI,EAAE,aAAa,MAAM,CAAC;;AAG3C,MAAM,kBAAkB,SAAqB,YAA2B;AACtE,KAAI,SAAS,gBAAgB,MAC3B,SAAQ,IACN,4FAA4F,QAAQ,GACrG"}
@@ -1,16 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errorMsgHtmlFiles = exports.errorMsgFolder = exports.errorMsgWrite = exports.successMsg = exports.cliColors = void 0;
4
- exports.cliColors = {
5
- cyanAndBold: '\x1b[36m\x1b[1m%s\x1b[22m\x1b[0m',
6
- green: '\x1b[32m%s\x1b[0m',
7
- red: '\x1b[31m%s\x1b[0m'
1
+ //#region src/helpers/vars.helper.ts
2
+ const cliColors = {
3
+ cyanAndBold: "\x1B[36m\x1B[1m%s\x1B[22m\x1B[0m",
4
+ green: "\x1B[32m%s\x1B[0m",
5
+ red: "\x1B[31m%s\x1B[0m",
6
+ yellow: "\x1B[33m%s\x1B[0m"
8
7
  };
9
- const successMsg = (outDir, filename) => ` ✔ done. Check your new sitemap here: ./${outDir}/${filename}`;
10
- exports.successMsg = successMsg;
8
+ const successMsg = (outDir, filename) => ` ✔ Done. Check your new sitemap here: ./${outDir}/${filename}`;
11
9
  const errorMsgWrite = (outDir, filename) => ` × File '${outDir}/${filename}' could not be created.`;
12
- exports.errorMsgWrite = errorMsgWrite;
10
+ const errorMsgGeneration = ` × Sitemap generation failed.`;
13
11
  const errorMsgFolder = (outDir) => ` × Folder '${outDir}/' doesn't exist.\n Make sure you are using this library as 'postbuild' so '${outDir}/' folder was successfully created before running this script. Or are you using Vercel? See https://github.com/bartholomej/svelte-sitemap#error-missing-folder`;
14
- exports.errorMsgFolder = errorMsgFolder;
15
12
  const errorMsgHtmlFiles = (outDir) => ` × There is no static html file in your '${outDir}/' folder. Are you sure you are using Svelte adapter-static with prerender option? See https://github.com/bartholomej/svelte-sitemap#error-missing-html-files`;
16
- exports.errorMsgHtmlFiles = errorMsgHtmlFiles;
13
+
14
+ //#endregion
15
+ export { cliColors, errorMsgFolder, errorMsgGeneration, errorMsgHtmlFiles, errorMsgWrite, successMsg };
16
+ //# sourceMappingURL=vars.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vars.helper.js","names":[],"sources":["../../src/helpers/vars.helper.ts"],"sourcesContent":["export const cliColors = {\n cyanAndBold: '\\x1b[36m\\x1b[1m%s\\x1b[22m\\x1b[0m',\n green: '\\x1b[32m%s\\x1b[0m',\n red: '\\x1b[31m%s\\x1b[0m',\n yellow: '\\x1b[33m%s\\x1b[0m'\n};\n\nexport const successMsg = (outDir: string, filename: string) =>\n ` ✔ Done. Check your new sitemap here: ./${outDir}/${filename}`;\n\nexport const errorMsgWrite = (outDir: string, filename: string) =>\n ` × File '${outDir}/${filename}' could not be created.`;\n\nexport const errorMsgGeneration = ` × Sitemap generation failed.`;\n\nexport const errorMsgFolder = (outDir: string) =>\n ` × Folder '${outDir}/' doesn't exist.\\n Make sure you are using this library as 'postbuild' so '${outDir}/' folder was successfully created before running this script. Or are you using Vercel? See https://github.com/bartholomej/svelte-sitemap#error-missing-folder`;\n\nexport const errorMsgHtmlFiles = (outDir: string) =>\n ` × There is no static html file in your '${outDir}/' folder. Are you sure you are using Svelte adapter-static with prerender option? See https://github.com/bartholomej/svelte-sitemap#error-missing-html-files`;\n"],"mappings":";AAAA,MAAa,YAAY;CACvB,aAAa;CACb,OAAO;CACP,KAAK;CACL,QAAQ;CACT;AAED,MAAa,cAAc,QAAgB,aACzC,4CAA4C,OAAO,GAAG;AAExD,MAAa,iBAAiB,QAAgB,aAC5C,aAAa,OAAO,GAAG,SAAS;AAElC,MAAa,qBAAqB;AAElC,MAAa,kBAAkB,WAC7B,eAAe,OAAO,iFAAiF,OAAO;AAEhH,MAAa,qBAAqB,WAChC,6CAA6C,OAAO"}
package/index.d.ts CHANGED
@@ -1,2 +1,7 @@
1
- #!/usr/bin/env node
2
- export {};
1
+ import { Arguments, ChangeFreq, Options, OptionsSvelteSitemap, PagesJson } from "./dto/global.interface.js";
2
+
3
+ //#region src/index.d.ts
4
+ declare const createSitemap: (options: OptionsSvelteSitemap) => Promise<void>;
5
+ //#endregion
6
+ export { Arguments, ChangeFreq, Options, OptionsSvelteSitemap, PagesJson, createSitemap };
7
+ //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,118 +1,16 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ import { OUT_DIR } from "./const.js";
2
+ import { cliColors, errorMsgWrite } from "./helpers/vars.helper.js";
3
+ import { prepareData, writeSitemap } from "./helpers/global.helper.js";
4
+
5
+ //#region src/index.ts
6
+ const createSitemap = async (options) => {
7
+ if (options?.debug) console.log("OPTIONS", options);
8
+ const json = await prepareData(options.domain, options);
9
+ if (options?.debug) console.log("RESULT", json);
10
+ if (json.length) writeSitemap(json, options, options.domain);
11
+ else console.error(cliColors.red, errorMsgWrite(options.outDir ?? OUT_DIR, "sitemap.xml"));
5
12
  };
6
- var _a, _b;
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- const minimist_1 = __importDefault(require("minimist"));
9
- const package_json_1 = require("./package.json");
10
- const config_1 = require("./src/helpers/config");
11
- const vars_helper_1 = require("./src/helpers/vars.helper");
12
- const index_1 = require("./src/index");
13
- const vars_1 = require("./src/vars");
14
- console.log(vars_helper_1.cliColors.cyanAndBold, `> Using ${vars_1.APP_NAME}`);
15
- const REPO_URL = 'https://github.com/bartholomej/svelte-sitemap';
16
- let stop = false;
17
- // Load svelte-sitemap.cjs
18
- const config = (0, config_1.loadConfig)(vars_1.CONFIG_FILE);
19
- const args = (0, minimist_1.default)(process.argv.slice(2), {
20
- string: ['domain', 'out-dir', 'ignore', 'change-freq', 'additional'],
21
- boolean: ['attribution', 'reset-time', 'trailing-slashes', 'debug', 'version'],
22
- default: { attribution: true, 'trailing-slashes': false, default: false },
23
- alias: {
24
- d: 'domain',
25
- D: 'domain',
26
- h: 'help',
27
- H: 'help',
28
- v: 'version',
29
- V: 'version',
30
- O: 'out-dir',
31
- o: 'out-dir',
32
- r: 'reset-time',
33
- R: 'reset-time',
34
- c: 'change-freq',
35
- C: 'change-freq',
36
- i: 'ignore',
37
- I: 'ignore',
38
- t: 'trailing-slashes',
39
- T: 'trailing-slashes',
40
- a: 'additional',
41
- A: 'additional'
42
- },
43
- unknown: (err) => {
44
- console.log('⚠ Those arguments are not supported:', err);
45
- console.log('Use: `svelte-sitemap --help` for more options.\n');
46
- stop = true;
47
- return false;
48
- }
49
- });
50
- if (args.help || args.version === '' || args.version === true) {
51
- const log = args.help ? console.log : console.error;
52
- log('Svelte `sitemap.xml` generator');
53
- log('');
54
- log(`svelte-sitemap ${package_json_1.version} (check updates: ${REPO_URL})`);
55
- log('');
56
- log('Options:');
57
- log('');
58
- log(' -d, --domain Use your domain (eg. https://example.com)');
59
- log(' -o, --out-dir Custom output dir');
60
- log(' -i, --ignore Exclude some pages or folders');
61
- log(' -a, --additional Additional pages outside of SvelteKit (e.g. /, /contact)');
62
- log(' -t, --trailing-slashes Do you like trailing slashes?');
63
- log(' -r, --reset-time Set modified time to now');
64
- log(' -c, --change-freq Set change frequency `weekly` | `daily` | …');
65
- log(' -v, --version Show version');
66
- log(' --debug Debug mode');
67
- log(' ');
68
- process.exit(args.help ? 0 : 1);
69
- }
70
- else if (!(config === null || config === void 0 ? void 0 : config.domain) && !args.domain) {
71
- console.log(`⚠ svelte-sitemap: --domain argument is required.\n\nSee instructions: ${REPO_URL}\n\nExample:\n\n svelte-sitemap --domain https://mydomain.com\n`);
72
- process.exit(0);
73
- }
74
- else if (
75
- // (config.domain || args.domain) &&
76
- !((_a = config === null || config === void 0 ? void 0 : config.domain) === null || _a === void 0 ? void 0 : _a.includes('http')) &&
77
- !((_b = args.domain) === null || _b === void 0 ? void 0 : _b.includes('http'))) {
78
- console.log(`⚠ svelte-sitemap: --domain argument must starts with https://\n\nSee instructions: ${REPO_URL}\n\nExample:\n\n svelte-sitemap --domain https://mydomain.com\n`);
79
- process.exit(0);
80
- }
81
- else if (stop) {
82
- // Do nothing if there is something suspicious
83
- }
84
- else {
85
- const domain = args.domain ? args.domain : undefined;
86
- const debug = args.debug === '' || args.debug === true ? true : false;
87
- const additional = Array.isArray(args['additional'])
88
- ? args['additional']
89
- : args.additional
90
- ? [args.additional]
91
- : [];
92
- const resetTime = args['reset-time'] === '' || args['reset-time'] === true ? true : false;
93
- const trailingSlashes = args['trailing-slashes'] === '' || args['trailing-slashes'] === true ? true : false;
94
- const changeFreq = args['change-freq'];
95
- const outDir = args['out-dir'];
96
- const ignore = args['ignore'];
97
- const attribution = args['attribution'] === '' || args['attribution'] === false ? false : true;
98
- const optionsCli = {
99
- debug,
100
- resetTime,
101
- changeFreq,
102
- outDir,
103
- domain,
104
- attribution,
105
- ignore,
106
- trailingSlashes,
107
- additional
108
- };
109
- // Config file is preferred
110
- if (config && Object.keys(config).length === 0) {
111
- console.log(vars_helper_1.cliColors.cyanAndBold, ` ✔ Using CLI options. Config file ${vars_1.CONFIG_FILE} not found.`);
112
- (0, index_1.createSitemap)(optionsCli);
113
- }
114
- else {
115
- console.log(vars_helper_1.cliColors.green, ` ✔ Loading config from ${vars_1.CONFIG_FILE}. CLI options are ignored now.`);
116
- (0, index_1.createSitemap)((0, config_1.withDefaultConfig)(config));
117
- }
118
- }
13
+
14
+ //#endregion
15
+ export { createSitemap };
16
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { OUT_DIR } from './const.js';\nimport type { OptionsSvelteSitemap } from './dto/index.js';\nimport { prepareData, writeSitemap } from './helpers/global.helper.js';\nimport { cliColors, errorMsgWrite } from './helpers/vars.helper.js';\n\nexport const createSitemap = async (options: OptionsSvelteSitemap): Promise<void> => {\n if (options?.debug) {\n console.log('OPTIONS', options);\n }\n\n const json = await prepareData(options.domain, options);\n\n if (options?.debug) {\n console.log('RESULT', json);\n }\n\n if (json.length) {\n writeSitemap(json, options, options.domain);\n } else {\n console.error(cliColors.red, errorMsgWrite(options.outDir ?? OUT_DIR, 'sitemap.xml'));\n }\n};\n\nexport type * from './dto/index.js';\n"],"mappings":";;;;;AAKA,MAAa,gBAAgB,OAAO,YAAiD;AACnF,KAAI,SAAS,MACX,SAAQ,IAAI,WAAW,QAAQ;CAGjC,MAAM,OAAO,MAAM,YAAY,QAAQ,QAAQ,QAAQ;AAEvD,KAAI,SAAS,MACX,SAAQ,IAAI,UAAU,KAAK;AAG7B,KAAI,KAAK,OACP,cAAa,MAAM,SAAS,QAAQ,OAAO;KAE3C,SAAQ,MAAM,UAAU,KAAK,cAAc,QAAQ,UAAU,SAAS,cAAc,CAAC"}