@cappa/cli 0.0.3 → 0.0.5

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.
@@ -0,0 +1,5 @@
1
+ //#region src/index.d.ts
2
+ declare function run(_argv?: string[]): Promise<void>;
3
+ //#endregion
4
+ export { run };
5
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1,5 @@
1
+ //#region src/index.d.ts
2
+ declare function run(_argv?: string[]): Promise<void>;
3
+ //#endregion
4
+ export { run };
5
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,158 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let citty = require("citty");
25
+ citty = __toESM(citty);
26
+ let consola = require("consola");
27
+ consola = __toESM(consola);
28
+ let cosmiconfig = require("cosmiconfig");
29
+ cosmiconfig = __toESM(cosmiconfig);
30
+ let jiti = require("jiti");
31
+ jiti = __toESM(jiti);
32
+ let __cappa_core = require("@cappa/core");
33
+ __cappa_core = __toESM(__cappa_core);
34
+
35
+ //#region package.json
36
+ var version = "0.0.4";
37
+
38
+ //#endregion
39
+ //#region src/utils/getPlugins.ts
40
+ async function getPlugins(plugins) {
41
+ if (!plugins) return [];
42
+ const loadedPlugins = [];
43
+ for (const plugin of plugins) if (typeof plugin === "function") {
44
+ const pluginDef = plugin();
45
+ loadedPlugins.push(pluginDef);
46
+ } else loadedPlugins.push(plugin);
47
+ return loadedPlugins;
48
+ }
49
+ function isPromise(value) {
50
+ return value !== null && typeof value === "object" && "then" in value && typeof value.then === "function";
51
+ }
52
+
53
+ //#endregion
54
+ //#region src/utils/getConfig.ts
55
+ /**
56
+ * Converting UserConfig to Config without a change in the object beside the JSON convert.
57
+ */
58
+ async function getConfig(result) {
59
+ const config = result?.config;
60
+ let kubbUserConfig = Promise.resolve(config);
61
+ if (typeof config === "function") {
62
+ const possiblePromise = config();
63
+ if (isPromise(possiblePromise)) kubbUserConfig = possiblePromise;
64
+ kubbUserConfig = Promise.resolve(possiblePromise);
65
+ }
66
+ let JSONConfig = await kubbUserConfig;
67
+ if (Array.isArray(JSONConfig)) {
68
+ const results = [];
69
+ for (const item of JSONConfig) {
70
+ const plugins = item.plugins ? await getPlugins(item.plugins) : void 0;
71
+ results.push({
72
+ ...item,
73
+ plugins
74
+ });
75
+ }
76
+ return results;
77
+ }
78
+ JSONConfig = {
79
+ ...JSONConfig,
80
+ plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
81
+ };
82
+ return JSONConfig;
83
+ }
84
+
85
+ //#endregion
86
+ //#region src/utils/getCosmiConfig.ts
87
+ const tsLoader = async (configFile) => {
88
+ return await (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, {
89
+ jsx: {
90
+ runtime: "automatic",
91
+ importSource: "@cappa/core"
92
+ },
93
+ sourceMaps: true
94
+ }).import(configFile, { default: true });
95
+ };
96
+ async function getCosmiConfig(moduleName, config) {
97
+ const searchPlaces = [
98
+ "package.json",
99
+ `.${moduleName}rc`,
100
+ `.${moduleName}rc.json`,
101
+ `.${moduleName}rc.yaml`,
102
+ `.${moduleName}rc.yml`,
103
+ `.${moduleName}rc.ts`,
104
+ `.${moduleName}rc.js`,
105
+ `.${moduleName}rc.mjs`,
106
+ `.${moduleName}rc.cjs`,
107
+ `${moduleName}.config.ts`,
108
+ `${moduleName}.config.js`,
109
+ `${moduleName}.config.mjs`,
110
+ `${moduleName}.config.cjs`
111
+ ];
112
+ const explorer = (0, cosmiconfig.cosmiconfig)(moduleName, {
113
+ cache: false,
114
+ searchPlaces: [
115
+ ...searchPlaces.map((searchPlace) => {
116
+ return `.config/${searchPlace}`;
117
+ }),
118
+ ...searchPlaces.map((searchPlace) => {
119
+ return `configs/${searchPlace}`;
120
+ }),
121
+ ...searchPlaces
122
+ ],
123
+ loaders: { ".ts": tsLoader }
124
+ });
125
+ const result = config ? await explorer.load(config) : await explorer.search();
126
+ if (result?.isEmpty || !result || !result.config) throw new Error("Config not defined, create a cappa.config.js or pass through your config with the option --config");
127
+ return result;
128
+ }
129
+
130
+ //#endregion
131
+ //#region src/index.ts
132
+ const main = (0, citty.defineCommand)({
133
+ meta: {
134
+ name: "cappa",
135
+ version,
136
+ description: "Cappa CLI"
137
+ },
138
+ async setup() {
139
+ consola.default.log("Cappa CLI:");
140
+ const result = await getCosmiConfig("cappa");
141
+ const config = await getConfig(result);
142
+ consola.default.log(config);
143
+ const screenshotTool = new __cappa_core.ScreenshotTool({});
144
+ await screenshotTool.init();
145
+ try {
146
+ for (const plugin of config.plugins) await plugin.execute(screenshotTool);
147
+ } finally {
148
+ await screenshotTool.close();
149
+ }
150
+ }
151
+ });
152
+ async function run(_argv) {
153
+ await (0, citty.runMain)(main);
154
+ }
155
+
156
+ //#endregion
157
+ exports.run = run;
158
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["loadedPlugins: PluginDef[]","results: Array<Config>","ScreenshotTool"],"sources":["../package.json","../src/utils/getPlugins.ts","../src/utils/getConfig.ts","../src/utils/getCosmiConfig.ts","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@cappa/cli\",\n \"version\": \"0.0.4\",\n \"description\": \"Command line interface for Cappa\",\n \"author\": \"Tim Richter\",\n \"keywords\": [\n \"screenshot\",\n \"cli\"\n ],\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"license\": \"MIT\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"bin\",\n \"package.json\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"bin\": {\n \"cappa\": \"./bin/cappa.cjs\"\n },\n \"scripts\": {\n \"test\": \"vitest\",\n \"screenshot\": \"node src/index.ts\",\n \"build\": \"tsdown\"\n },\n \"dependencies\": {\n \"@cappa/core\": \"workspace:*\",\n \"citty\": \"0.1.6\",\n \"consola\": \"3.4.2\",\n \"cosmiconfig\": \"9.0.0\",\n \"jiti\": \"2.5.1\",\n \"picocolors\": \"1.1.1\",\n \"ts-node\": \"10.9.2\"\n },\n \"devDependencies\": {\n \"@types/node\": \"catalog:\",\n \"tsdown\": \"catalog:\",\n \"vitest\": \"catalog:\",\n \"@vitest/ui\": \"catalog:\",\n \"@vitest/coverage-v8\": \"catalog:\",\n \"typescript\": \"catalog:\"\n }\n}\n","import type { UserConfig, PluginDef } from \"@cappa/core\";\n\nexport async function getPlugins(\n plugins: UserConfig[\"plugins\"]\n): Promise<PluginDef[]> {\n if (!plugins) {\n return [];\n }\n\n const loadedPlugins: PluginDef[] = [];\n\n for (const plugin of plugins) {\n if (typeof plugin === \"function\") {\n // Plugin is a function that returns PluginDef\n const pluginDef = plugin();\n loadedPlugins.push(pluginDef);\n } else {\n // Plugin is already a PluginDef\n loadedPlugins.push(plugin);\n }\n }\n\n return loadedPlugins;\n}\n\nexport function isPromise(value: unknown): value is Promise<unknown> {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"then\" in value &&\n typeof (value as any).then === \"function\"\n );\n}\n","import { getPlugins, isPromise } from \"./getPlugins\";\n\nimport type { UserConfig } from \"@cappa/core\";\nimport type { CosmiconfigResult } from \"./getCosmiConfig.ts\";\nimport type { Config } from \"cosmiconfig\";\n\n/**\n * Converting UserConfig to Config without a change in the object beside the JSON convert.\n */\nexport async function getConfig(\n result: CosmiconfigResult\n): Promise<Array<Config> | Config> {\n const config = result?.config;\n let kubbUserConfig = Promise.resolve(config) as Promise<\n UserConfig | Array<UserConfig>\n >;\n\n // for ts or js files\n if (typeof config === \"function\") {\n const possiblePromise = config();\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise as Promise<\n UserConfig | Array<UserConfig>\n >;\n }\n kubbUserConfig = Promise.resolve(possiblePromise);\n }\n\n let JSONConfig = await kubbUserConfig;\n\n if (Array.isArray(JSONConfig)) {\n const results: Array<Config> = [];\n\n for (const item of JSONConfig) {\n const plugins = item.plugins ? await getPlugins(item.plugins) : undefined;\n\n results.push({\n ...item,\n plugins,\n } as Config);\n }\n\n return results;\n }\n\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins\n ? await getPlugins(JSONConfig.plugins)\n : undefined,\n };\n\n return JSONConfig as Config;\n}\n","import { cosmiconfig } from \"cosmiconfig\";\nimport { createJiti } from \"jiti\";\n\nimport type { UserConfig, defineConfig } from \"@cappa/core\";\n\nexport type CosmiconfigResult = {\n filepath: string;\n isEmpty?: boolean;\n config: ReturnType<typeof defineConfig> | UserConfig;\n};\n\nconst tsLoader = async (configFile: string) => {\n const jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: \"automatic\",\n importSource: \"@cappa/core\",\n },\n sourceMaps: true,\n });\n\n const mod = await jiti.import(configFile, { default: true });\n\n return mod;\n};\n\nexport async function getCosmiConfig(\n moduleName: string,\n config?: string\n): Promise<CosmiconfigResult> {\n const searchPlaces = [\n \"package.json\",\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n\n `${moduleName}.config.ts`,\n `${moduleName}.config.js`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ];\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n ...searchPlaces.map((searchPlace) => {\n return `.config/${searchPlace}`;\n }),\n ...searchPlaces.map((searchPlace) => {\n return `configs/${searchPlace}`;\n }),\n ...searchPlaces,\n ],\n loaders: {\n \".ts\": tsLoader,\n },\n });\n\n const result = config ? await explorer.load(config) : await explorer.search();\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error(\n \"Config not defined, create a cappa.config.js or pass through your config with the option --config\"\n );\n }\n\n return result as CosmiconfigResult;\n}\n","import { defineCommand, runMain } from \"citty\";\nimport consola from \"consola\";\nimport { version } from \"../package.json\";\nimport { getConfig } from \"./utils/getConfig\";\nimport { getCosmiConfig } from \"./utils/getCosmiConfig\";\nimport { type PluginDef, ScreenshotTool } from \"@cappa/core\";\n\nconst name = \"cappa\";\n\nconst main = defineCommand({\n meta: {\n name,\n version,\n description: \"Cappa CLI\",\n },\n async setup() {\n consola.log(\"Cappa CLI:\");\n\n const result = await getCosmiConfig(\"cappa\");\n const config = await getConfig(result);\n\n consola.log(config);\n\n const screenshotTool = new ScreenshotTool({});\n await screenshotTool.init();\n\n try {\n // Wait for all plugins to complete\n for (const plugin of config.plugins) {\n await plugin.execute(screenshotTool);\n }\n } finally {\n // Always close the browser to ensure the process exits\n await screenshotTool.close();\n }\n },\n});\n\nexport async function run(_argv?: string[]): Promise<void> {\n await runMain(main);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAEa;;;;ACAb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EACf,IAAI,WAAW;EACf,IAAI,WAAW;EAEf,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;EACd,GAAG,WAAW;EACf;CACD,MAAM,wCAAuB,YAAY;EACvC,OAAO;EACP,cAAc;GACZ,GAAG,aAAa,KAAK,gBAAgB;AACnC,WAAO,WAAW;KAClB;GACF,GAAG,aAAa,KAAK,gBAAgB;AACnC,WAAO,WAAW;KAClB;GACF,GAAG;GACJ;EACD,SAAS,EACP,OAAO,UACR;EACF,CAAC;CAEF,MAAM,SAAS,SAAS,MAAM,SAAS,KAAK,OAAO,GAAG,MAAM,SAAS,QAAQ;AAE7E,KAAI,QAAQ,WAAW,CAAC,UAAU,CAAC,OAAO,OACxC,OAAM,IAAI,MACR,oGACD;AAGH,QAAO;;;;;AC7DT,MAAM,gCAAqB;CACzB,MAAM;EACJ,MAJS;EAKT;EACA,aAAa;EACd;CACD,MAAM,QAAQ;AACZ,kBAAQ,IAAI,aAAa;EAEzB,MAAM,SAAS,MAAM,eAAe,QAAQ;EAC5C,MAAM,SAAS,MAAM,UAAU,OAAO;AAEtC,kBAAQ,IAAI,OAAO;EAEnB,MAAM,iBAAiB,IAAIC,4BAAe,EAAE,CAAC;AAC7C,QAAM,eAAe,MAAM;AAE3B,MAAI;AAEF,QAAK,MAAM,UAAU,OAAO,QAC1B,OAAM,OAAO,QAAQ,eAAe;YAE9B;AAER,SAAM,eAAe,OAAO;;;CAGjC,CAAC;AAEF,eAAsB,IAAI,OAAiC;AACzD,0BAAc,KAAK"}
package/dist/index.mjs ADDED
@@ -0,0 +1,130 @@
1
+ import { defineCommand, runMain } from "citty";
2
+ import consola from "consola";
3
+ import { cosmiconfig } from "cosmiconfig";
4
+ import { createJiti } from "jiti";
5
+ import { ScreenshotTool } from "@cappa/core";
6
+
7
+ //#region package.json
8
+ var version = "0.0.4";
9
+
10
+ //#endregion
11
+ //#region src/utils/getPlugins.ts
12
+ async function getPlugins(plugins) {
13
+ if (!plugins) return [];
14
+ const loadedPlugins = [];
15
+ for (const plugin of plugins) if (typeof plugin === "function") {
16
+ const pluginDef = plugin();
17
+ loadedPlugins.push(pluginDef);
18
+ } else loadedPlugins.push(plugin);
19
+ return loadedPlugins;
20
+ }
21
+ function isPromise(value) {
22
+ return value !== null && typeof value === "object" && "then" in value && typeof value.then === "function";
23
+ }
24
+
25
+ //#endregion
26
+ //#region src/utils/getConfig.ts
27
+ /**
28
+ * Converting UserConfig to Config without a change in the object beside the JSON convert.
29
+ */
30
+ async function getConfig(result) {
31
+ const config = result?.config;
32
+ let kubbUserConfig = Promise.resolve(config);
33
+ if (typeof config === "function") {
34
+ const possiblePromise = config();
35
+ if (isPromise(possiblePromise)) kubbUserConfig = possiblePromise;
36
+ kubbUserConfig = Promise.resolve(possiblePromise);
37
+ }
38
+ let JSONConfig = await kubbUserConfig;
39
+ if (Array.isArray(JSONConfig)) {
40
+ const results = [];
41
+ for (const item of JSONConfig) {
42
+ const plugins = item.plugins ? await getPlugins(item.plugins) : void 0;
43
+ results.push({
44
+ ...item,
45
+ plugins
46
+ });
47
+ }
48
+ return results;
49
+ }
50
+ JSONConfig = {
51
+ ...JSONConfig,
52
+ plugins: JSONConfig.plugins ? await getPlugins(JSONConfig.plugins) : void 0
53
+ };
54
+ return JSONConfig;
55
+ }
56
+
57
+ //#endregion
58
+ //#region src/utils/getCosmiConfig.ts
59
+ const tsLoader = async (configFile) => {
60
+ return await createJiti(import.meta.url, {
61
+ jsx: {
62
+ runtime: "automatic",
63
+ importSource: "@cappa/core"
64
+ },
65
+ sourceMaps: true
66
+ }).import(configFile, { default: true });
67
+ };
68
+ async function getCosmiConfig(moduleName, config) {
69
+ const searchPlaces = [
70
+ "package.json",
71
+ `.${moduleName}rc`,
72
+ `.${moduleName}rc.json`,
73
+ `.${moduleName}rc.yaml`,
74
+ `.${moduleName}rc.yml`,
75
+ `.${moduleName}rc.ts`,
76
+ `.${moduleName}rc.js`,
77
+ `.${moduleName}rc.mjs`,
78
+ `.${moduleName}rc.cjs`,
79
+ `${moduleName}.config.ts`,
80
+ `${moduleName}.config.js`,
81
+ `${moduleName}.config.mjs`,
82
+ `${moduleName}.config.cjs`
83
+ ];
84
+ const explorer = cosmiconfig(moduleName, {
85
+ cache: false,
86
+ searchPlaces: [
87
+ ...searchPlaces.map((searchPlace) => {
88
+ return `.config/${searchPlace}`;
89
+ }),
90
+ ...searchPlaces.map((searchPlace) => {
91
+ return `configs/${searchPlace}`;
92
+ }),
93
+ ...searchPlaces
94
+ ],
95
+ loaders: { ".ts": tsLoader }
96
+ });
97
+ const result = config ? await explorer.load(config) : await explorer.search();
98
+ if (result?.isEmpty || !result || !result.config) throw new Error("Config not defined, create a cappa.config.js or pass through your config with the option --config");
99
+ return result;
100
+ }
101
+
102
+ //#endregion
103
+ //#region src/index.ts
104
+ const main = defineCommand({
105
+ meta: {
106
+ name: "cappa",
107
+ version,
108
+ description: "Cappa CLI"
109
+ },
110
+ async setup() {
111
+ consola.log("Cappa CLI:");
112
+ const result = await getCosmiConfig("cappa");
113
+ const config = await getConfig(result);
114
+ consola.log(config);
115
+ const screenshotTool = new ScreenshotTool({});
116
+ await screenshotTool.init();
117
+ try {
118
+ for (const plugin of config.plugins) await plugin.execute(screenshotTool);
119
+ } finally {
120
+ await screenshotTool.close();
121
+ }
122
+ }
123
+ });
124
+ async function run(_argv) {
125
+ await runMain(main);
126
+ }
127
+
128
+ //#endregion
129
+ export { run };
130
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["loadedPlugins: PluginDef[]","results: Array<Config>"],"sources":["../package.json","../src/utils/getPlugins.ts","../src/utils/getConfig.ts","../src/utils/getCosmiConfig.ts","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@cappa/cli\",\n \"version\": \"0.0.4\",\n \"description\": \"Command line interface for Cappa\",\n \"author\": \"Tim Richter\",\n \"keywords\": [\n \"screenshot\",\n \"cli\"\n ],\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"license\": \"MIT\",\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"bin\",\n \"package.json\",\n \"README.md\",\n \"LICENSE\"\n ],\n \"bin\": {\n \"cappa\": \"./bin/cappa.cjs\"\n },\n \"scripts\": {\n \"test\": \"vitest\",\n \"screenshot\": \"node src/index.ts\",\n \"build\": \"tsdown\"\n },\n \"dependencies\": {\n \"@cappa/core\": \"workspace:*\",\n \"citty\": \"0.1.6\",\n \"consola\": \"3.4.2\",\n \"cosmiconfig\": \"9.0.0\",\n \"jiti\": \"2.5.1\",\n \"picocolors\": \"1.1.1\",\n \"ts-node\": \"10.9.2\"\n },\n \"devDependencies\": {\n \"@types/node\": \"catalog:\",\n \"tsdown\": \"catalog:\",\n \"vitest\": \"catalog:\",\n \"@vitest/ui\": \"catalog:\",\n \"@vitest/coverage-v8\": \"catalog:\",\n \"typescript\": \"catalog:\"\n }\n}\n","import type { UserConfig, PluginDef } from \"@cappa/core\";\n\nexport async function getPlugins(\n plugins: UserConfig[\"plugins\"]\n): Promise<PluginDef[]> {\n if (!plugins) {\n return [];\n }\n\n const loadedPlugins: PluginDef[] = [];\n\n for (const plugin of plugins) {\n if (typeof plugin === \"function\") {\n // Plugin is a function that returns PluginDef\n const pluginDef = plugin();\n loadedPlugins.push(pluginDef);\n } else {\n // Plugin is already a PluginDef\n loadedPlugins.push(plugin);\n }\n }\n\n return loadedPlugins;\n}\n\nexport function isPromise(value: unknown): value is Promise<unknown> {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"then\" in value &&\n typeof (value as any).then === \"function\"\n );\n}\n","import { getPlugins, isPromise } from \"./getPlugins\";\n\nimport type { UserConfig } from \"@cappa/core\";\nimport type { CosmiconfigResult } from \"./getCosmiConfig.ts\";\nimport type { Config } from \"cosmiconfig\";\n\n/**\n * Converting UserConfig to Config without a change in the object beside the JSON convert.\n */\nexport async function getConfig(\n result: CosmiconfigResult\n): Promise<Array<Config> | Config> {\n const config = result?.config;\n let kubbUserConfig = Promise.resolve(config) as Promise<\n UserConfig | Array<UserConfig>\n >;\n\n // for ts or js files\n if (typeof config === \"function\") {\n const possiblePromise = config();\n if (isPromise(possiblePromise)) {\n kubbUserConfig = possiblePromise as Promise<\n UserConfig | Array<UserConfig>\n >;\n }\n kubbUserConfig = Promise.resolve(possiblePromise);\n }\n\n let JSONConfig = await kubbUserConfig;\n\n if (Array.isArray(JSONConfig)) {\n const results: Array<Config> = [];\n\n for (const item of JSONConfig) {\n const plugins = item.plugins ? await getPlugins(item.plugins) : undefined;\n\n results.push({\n ...item,\n plugins,\n } as Config);\n }\n\n return results;\n }\n\n JSONConfig = {\n ...JSONConfig,\n plugins: JSONConfig.plugins\n ? await getPlugins(JSONConfig.plugins)\n : undefined,\n };\n\n return JSONConfig as Config;\n}\n","import { cosmiconfig } from \"cosmiconfig\";\nimport { createJiti } from \"jiti\";\n\nimport type { UserConfig, defineConfig } from \"@cappa/core\";\n\nexport type CosmiconfigResult = {\n filepath: string;\n isEmpty?: boolean;\n config: ReturnType<typeof defineConfig> | UserConfig;\n};\n\nconst tsLoader = async (configFile: string) => {\n const jiti = createJiti(import.meta.url, {\n jsx: {\n runtime: \"automatic\",\n importSource: \"@cappa/core\",\n },\n sourceMaps: true,\n });\n\n const mod = await jiti.import(configFile, { default: true });\n\n return mod;\n};\n\nexport async function getCosmiConfig(\n moduleName: string,\n config?: string\n): Promise<CosmiconfigResult> {\n const searchPlaces = [\n \"package.json\",\n `.${moduleName}rc`,\n `.${moduleName}rc.json`,\n `.${moduleName}rc.yaml`,\n `.${moduleName}rc.yml`,\n\n `.${moduleName}rc.ts`,\n `.${moduleName}rc.js`,\n `.${moduleName}rc.mjs`,\n `.${moduleName}rc.cjs`,\n\n `${moduleName}.config.ts`,\n `${moduleName}.config.js`,\n `${moduleName}.config.mjs`,\n `${moduleName}.config.cjs`,\n ];\n const explorer = cosmiconfig(moduleName, {\n cache: false,\n searchPlaces: [\n ...searchPlaces.map((searchPlace) => {\n return `.config/${searchPlace}`;\n }),\n ...searchPlaces.map((searchPlace) => {\n return `configs/${searchPlace}`;\n }),\n ...searchPlaces,\n ],\n loaders: {\n \".ts\": tsLoader,\n },\n });\n\n const result = config ? await explorer.load(config) : await explorer.search();\n\n if (result?.isEmpty || !result || !result.config) {\n throw new Error(\n \"Config not defined, create a cappa.config.js or pass through your config with the option --config\"\n );\n }\n\n return result as CosmiconfigResult;\n}\n","import { defineCommand, runMain } from \"citty\";\nimport consola from \"consola\";\nimport { version } from \"../package.json\";\nimport { getConfig } from \"./utils/getConfig\";\nimport { getCosmiConfig } from \"./utils/getCosmiConfig\";\nimport { type PluginDef, ScreenshotTool } from \"@cappa/core\";\n\nconst name = \"cappa\";\n\nconst main = defineCommand({\n meta: {\n name,\n version,\n description: \"Cappa CLI\",\n },\n async setup() {\n consola.log(\"Cappa CLI:\");\n\n const result = await getCosmiConfig(\"cappa\");\n const config = await getConfig(result);\n\n consola.log(config);\n\n const screenshotTool = new ScreenshotTool({});\n await screenshotTool.init();\n\n try {\n // Wait for all plugins to complete\n for (const plugin of config.plugins) {\n await plugin.execute(screenshotTool);\n }\n } finally {\n // Always close the browser to ensure the process exits\n await screenshotTool.close();\n }\n },\n});\n\nexport async function run(_argv?: string[]): Promise<void> {\n await runMain(main);\n}\n"],"mappings":";;;;;;;cAEa;;;;ACAb,eAAsB,WACpB,SACsB;AACtB,KAAI,CAAC,QACH,QAAO,EAAE;CAGX,MAAMA,gBAA6B,EAAE;AAErC,MAAK,MAAM,UAAU,QACnB,KAAI,OAAO,WAAW,YAAY;EAEhC,MAAM,YAAY,QAAQ;AAC1B,gBAAc,KAAK,UAAU;OAG7B,eAAc,KAAK,OAAO;AAI9B,QAAO;;AAGT,SAAgB,UAAU,OAA2C;AACnE,QACE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;AACnC,WAAO,WAAW;KAClB;GACF,GAAG;GACJ;EACD,SAAS,EACP,OAAO,UACR;EACF,CAAC;CAEF,MAAM,SAAS,SAAS,MAAM,SAAS,KAAK,OAAO,GAAG,MAAM,SAAS,QAAQ;AAE7E,KAAI,QAAQ,WAAW,CAAC,UAAU,CAAC,OAAO,OACxC,OAAM,IAAI,MACR,oGACD;AAGH,QAAO;;;;;AC7DT,MAAM,OAAO,cAAc;CACzB,MAAM;EACJ,MAJS;EAKT;EACA,aAAa;EACd;CACD,MAAM,QAAQ;AACZ,UAAQ,IAAI,aAAa;EAEzB,MAAM,SAAS,MAAM,eAAe,QAAQ;EAC5C,MAAM,SAAS,MAAM,UAAU,OAAO;AAEtC,UAAQ,IAAI,OAAO;EAEnB,MAAM,iBAAiB,IAAI,eAAe,EAAE,CAAC;AAC7C,QAAM,eAAe,MAAM;AAE3B,MAAI;AAEF,QAAK,MAAM,UAAU,OAAO,QAC1B,OAAM,OAAO,QAAQ,eAAe;YAE9B;AAER,SAAM,eAAe,OAAO;;;CAGjC,CAAC;AAEF,eAAsB,IAAI,OAAiC;AACzD,OAAM,QAAQ,KAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappa/cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Command line interface for Cappa",
5
5
  "author": "Tim Richter",
6
6
  "keywords": [
@@ -16,10 +16,8 @@
16
16
  "types": "./dist/index.d.ts",
17
17
  "exports": {
18
18
  ".": {
19
- "types": "./dist/index.d.ts",
20
19
  "import": "./dist/index.mjs",
21
- "require": "./dist/index.js",
22
- "default": "./dist/index.mjs"
20
+ "require": "./dist/index.js"
23
21
  },
24
22
  "./package.json": "./package.json"
25
23
  },
@@ -40,7 +38,7 @@
40
38
  "jiti": "2.5.1",
41
39
  "picocolors": "1.1.1",
42
40
  "ts-node": "10.9.2",
43
- "@cappa/core": "0.0.3"
41
+ "@cappa/core": "0.0.5"
44
42
  },
45
43
  "devDependencies": {
46
44
  "@types/node": "22.13.10",