@cappa/cli 0.0.2 → 0.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappa/cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Command line interface for Cappa",
5
5
  "author": "Tim Richter",
6
6
  "keywords": [
@@ -12,6 +12,24 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "main": "./dist/index.js",
15
+ "module": "./dist/index.mjs",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.mjs",
21
+ "require": "./dist/index.js",
22
+ "default": "./dist/index.mjs"
23
+ },
24
+ "./package.json": "./package.json"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "bin",
29
+ "package.json",
30
+ "README.md",
31
+ "LICENSE"
32
+ ],
15
33
  "bin": {
16
34
  "cappa": "./bin/cappa.cjs"
17
35
  },
@@ -22,7 +40,7 @@
22
40
  "jiti": "2.5.1",
23
41
  "picocolors": "1.1.1",
24
42
  "ts-node": "10.9.2",
25
- "@cappa/core": "0.0.2"
43
+ "@cappa/core": "0.0.3"
26
44
  },
27
45
  "devDependencies": {
28
46
  "@types/node": "22.13.10",
@@ -32,15 +50,6 @@
32
50
  "@vitest/coverage-v8": "3.2.4",
33
51
  "typescript": "5.7.3"
34
52
  },
35
- "module": "./dist/index.mjs",
36
- "types": "./dist/index.d.ts",
37
- "exports": {
38
- ".": {
39
- "import": "./dist/index.mjs",
40
- "require": "./dist/index.js"
41
- },
42
- "./package.json": "./package.json"
43
- },
44
53
  "scripts": {
45
54
  "test": "vitest",
46
55
  "screenshot": "node src/index.ts",
package/CHANGELOG.md DELETED
@@ -1,9 +0,0 @@
1
- # @cappa/cli
2
-
3
- ## 0.0.2
4
-
5
- ### Patch Changes
6
-
7
- - b3d2806: Init
8
- - Updated dependencies [b3d2806]
9
- - @cappa/core@0.0.2
package/src/config.ts DELETED
@@ -1,136 +0,0 @@
1
- /**
2
- * Configuration system for Cappa CLI
3
- */
4
-
5
- // TypeScript type definitions
6
- export interface BrowserConfig {
7
- type?: "chromium" | "firefox" | "webkit";
8
- headless?: boolean;
9
- }
10
-
11
- export interface ScreenshotConfig {
12
- outputDir?: string;
13
- viewport?: { width: number; height: number };
14
- quality?: number;
15
- fullPage?: boolean;
16
- }
17
-
18
- export interface PluginConfig {
19
- name?: string;
20
- path?: string;
21
- options?: Record<string, any>;
22
- }
23
-
24
- export interface CappaConfig {
25
- browser?: BrowserConfig;
26
- screenshot?: ScreenshotConfig;
27
- plugins?: (string | PluginConfig)[];
28
- }
29
-
30
- /**
31
- * Define a Cappa configuration
32
- * @param {CappaConfig} config - Configuration object
33
- * @returns {CappaConfig} The configuration object
34
- */
35
- export function defineConfig(config: CappaConfig): CappaConfig {
36
- return config;
37
- }
38
-
39
- /**
40
- * Default configuration
41
- */
42
- const defaultConfig: CappaConfig = {
43
- plugins: [],
44
- browser: {
45
- type: "chromium",
46
- headless: true,
47
- },
48
- screenshot: {
49
- outputDir: "./screenshots",
50
- viewport: { width: 1920, height: 1080 },
51
- quality: 90,
52
- fullPage: true,
53
- },
54
- };
55
-
56
- /**
57
- * Merge configuration with defaults
58
- * @param {CappaConfig} userConfig - User configuration
59
- * @returns {CappaConfig} Merged configuration
60
- */
61
- function mergeConfig(userConfig: CappaConfig): CappaConfig {
62
- return {
63
- ...defaultConfig,
64
- ...userConfig,
65
- browser: {
66
- ...defaultConfig.browser,
67
- ...userConfig.browser,
68
- },
69
- screenshot: {
70
- ...defaultConfig.screenshot,
71
- ...userConfig.screenshot,
72
- },
73
- };
74
- }
75
-
76
- /**
77
- * Load configuration from file
78
- * @param {string} configPath - Path to config file
79
- * @returns {Promise<CappaConfig>} Configuration object
80
- */
81
- async function loadConfig(configPath: string): Promise<CappaConfig> {
82
- try {
83
- let config: any;
84
- const path = await import("path");
85
- const { fileURLToPath } = await import("url");
86
- const resolvedPath = path.resolve(configPath);
87
-
88
- if (configPath.endsWith(".ts")) {
89
- // Load TypeScript config using dynamic import
90
- const module = await import(resolvedPath);
91
- config = module.default || module;
92
- } else if (configPath.endsWith(".js")) {
93
- // Load JavaScript config
94
- const module = await import(resolvedPath);
95
- config = module.default || module;
96
- } else {
97
- throw new Error(`Unsupported config file format: ${configPath}`);
98
- }
99
-
100
- // Handle default export
101
- if (config.default) {
102
- config = config.default;
103
- }
104
-
105
- return mergeConfig(config);
106
- } catch (error: any) {
107
- console.error(`Error loading config from ${configPath}:`, error.message);
108
- throw error;
109
- }
110
- }
111
-
112
- /**
113
- * Find configuration file in current directory
114
- * @returns {string|null} Path to config file or null if not found
115
- */
116
- async function findConfigFile(): Promise<string | null> {
117
- const fs = await import("fs");
118
- const path = await import("path");
119
-
120
- const configFiles = [
121
- "cappa.config.ts",
122
- "cappa.config.js",
123
- "cappa.config.json",
124
- ];
125
-
126
- for (const file of configFiles) {
127
- const filePath = path.join(process.cwd(), file);
128
- if (fs.existsSync(filePath)) {
129
- return filePath;
130
- }
131
- }
132
-
133
- return null;
134
- }
135
-
136
- export { defaultConfig, mergeConfig, loadConfig, findConfigFile };
package/src/index.ts DELETED
@@ -1,41 +0,0 @@
1
- import { defineCommand, runMain } from "citty";
2
- import consola from "consola";
3
- import { version } from "../package.json";
4
- import { getConfig } from "./utils/getConfig";
5
- import { getCosmiConfig } from "./utils/getCosmiConfig";
6
- import { type PluginDef, ScreenshotTool } from "@cappa/core";
7
-
8
- const name = "cappa";
9
-
10
- const main = defineCommand({
11
- meta: {
12
- name,
13
- version,
14
- description: "Cappa CLI",
15
- },
16
- async setup() {
17
- consola.log("Cappa CLI:");
18
-
19
- const result = await getCosmiConfig("cappa");
20
- const config = await getConfig(result);
21
-
22
- consola.log(config);
23
-
24
- const screenshotTool = new ScreenshotTool({});
25
- await screenshotTool.init();
26
-
27
- try {
28
- // Wait for all plugins to complete
29
- for (const plugin of config.plugins) {
30
- await plugin.execute(screenshotTool);
31
- }
32
- } finally {
33
- // Always close the browser to ensure the process exits
34
- await screenshotTool.close();
35
- }
36
- },
37
- });
38
-
39
- export async function run(_argv?: string[]): Promise<void> {
40
- await runMain(main);
41
- }
package/src/types.d.ts DELETED
@@ -1,37 +0,0 @@
1
- /**
2
- * TypeScript type definitions for Cappa CLI configuration
3
- */
4
-
5
- export interface BrowserConfig {
6
- type?: "chromium" | "firefox" | "webkit";
7
- headless?: boolean;
8
- }
9
-
10
- export interface ScreenshotConfig {
11
- outputDir?: string;
12
- viewport?: {
13
- width: number;
14
- height: number;
15
- };
16
- quality?: number;
17
- fullPage?: boolean;
18
- }
19
-
20
- export interface PluginConfig {
21
- name?: string;
22
- path?: string;
23
- options?: Record<string, any>;
24
- }
25
-
26
- export interface CappaConfig {
27
- browser?: BrowserConfig;
28
- screenshot?: ScreenshotConfig;
29
- plugins?: (string | PluginConfig)[];
30
- }
31
-
32
- /**
33
- * Define a Cappa configuration
34
- * @param config - Configuration object
35
- * @returns The configuration object
36
- */
37
- export function defineConfig(config: CappaConfig): CappaConfig;
@@ -1,122 +0,0 @@
1
- import { defineConfig } from "@cappa/core";
2
-
3
- import { getConfig } from "./getConfig.ts";
4
-
5
- import type { CosmiconfigResult } from "./getCosmiConfig.ts";
6
-
7
- test("return Config when config is set with defineConfig", async () => {
8
- const config: CosmiconfigResult["config"] = defineConfig(() => {
9
- return {
10
- input: {
11
- path: "./",
12
- },
13
- output: {
14
- path: "./dist",
15
- },
16
- plugins: [],
17
- };
18
- });
19
- const kubbUserConfig = await getConfig({
20
- config,
21
- filepath: "./",
22
- isEmpty: false,
23
- });
24
-
25
- expect(kubbUserConfig).toEqual({
26
- input: {
27
- path: "./",
28
- },
29
- output: {
30
- path: "./dist",
31
- },
32
- plugins: [],
33
- });
34
- });
35
-
36
- test("return Config[] when config is set with defineConfig", async () => {
37
- const config: CosmiconfigResult["config"] = defineConfig(() => {
38
- return [
39
- {
40
- name: "1",
41
- input: {
42
- path: "./",
43
- },
44
- output: {
45
- path: "./dist",
46
- },
47
- plugins: [],
48
- },
49
- {
50
- name: "2",
51
- input: {
52
- path: "./",
53
- },
54
- output: {
55
- path: "./dist2",
56
- },
57
- plugins: [],
58
- },
59
- ];
60
- });
61
- const loadedConfig = await getConfig({
62
- config,
63
- filepath: "./",
64
- isEmpty: false,
65
- });
66
-
67
- expect(Array.isArray(loadedConfig)).toBeTruthy();
68
-
69
- if (Array.isArray(loadedConfig)) {
70
- const [kubbUserConfig1, kubbUserConfig2] = loadedConfig;
71
-
72
- expect(kubbUserConfig1).toEqual({
73
- name: "1",
74
- input: {
75
- path: "./",
76
- },
77
- output: {
78
- path: "./dist",
79
- },
80
- plugins: [],
81
- });
82
- expect(kubbUserConfig2).toEqual({
83
- name: "2",
84
- input: {
85
- path: "./",
86
- },
87
- output: {
88
- path: "./dist2",
89
- },
90
- plugins: [],
91
- });
92
- }
93
- });
94
-
95
- test("return object when config is set with defineConfig and returns a promise", async () => {
96
- const config: CosmiconfigResult["config"] = defineConfig(() => {
97
- return Promise.resolve({
98
- input: {
99
- path: "./",
100
- },
101
- output: {
102
- path: "./dist",
103
- },
104
- plugins: [],
105
- });
106
- });
107
- const kubbUserConfig = await getConfig({
108
- config,
109
- filepath: "./",
110
- isEmpty: false,
111
- });
112
-
113
- expect(kubbUserConfig).toEqual({
114
- input: {
115
- path: "./",
116
- },
117
- output: {
118
- path: "./dist",
119
- },
120
- plugins: [],
121
- });
122
- });
@@ -1,54 +0,0 @@
1
- import { getPlugins, isPromise } from "./getPlugins";
2
-
3
- import type { UserConfig } from "@cappa/core";
4
- import type { CosmiconfigResult } from "./getCosmiConfig.ts";
5
- import type { Config } from "cosmiconfig";
6
-
7
- /**
8
- * Converting UserConfig to Config without a change in the object beside the JSON convert.
9
- */
10
- export async function getConfig(
11
- result: CosmiconfigResult
12
- ): Promise<Array<Config> | Config> {
13
- const config = result?.config;
14
- let kubbUserConfig = Promise.resolve(config) as Promise<
15
- UserConfig | Array<UserConfig>
16
- >;
17
-
18
- // for ts or js files
19
- if (typeof config === "function") {
20
- const possiblePromise = config();
21
- if (isPromise(possiblePromise)) {
22
- kubbUserConfig = possiblePromise as Promise<
23
- UserConfig | Array<UserConfig>
24
- >;
25
- }
26
- kubbUserConfig = Promise.resolve(possiblePromise);
27
- }
28
-
29
- let JSONConfig = await kubbUserConfig;
30
-
31
- if (Array.isArray(JSONConfig)) {
32
- const results: Array<Config> = [];
33
-
34
- for (const item of JSONConfig) {
35
- const plugins = item.plugins ? await getPlugins(item.plugins) : undefined;
36
-
37
- results.push({
38
- ...item,
39
- plugins,
40
- } as Config);
41
- }
42
-
43
- return results;
44
- }
45
-
46
- JSONConfig = {
47
- ...JSONConfig,
48
- plugins: JSONConfig.plugins
49
- ? await getPlugins(JSONConfig.plugins)
50
- : undefined,
51
- };
52
-
53
- return JSONConfig as Config;
54
- }
@@ -1,72 +0,0 @@
1
- import { cosmiconfig } from "cosmiconfig";
2
- import { createJiti } from "jiti";
3
-
4
- import type { UserConfig, defineConfig } from "@cappa/core";
5
-
6
- export type CosmiconfigResult = {
7
- filepath: string;
8
- isEmpty?: boolean;
9
- config: ReturnType<typeof defineConfig> | UserConfig;
10
- };
11
-
12
- const tsLoader = async (configFile: string) => {
13
- const jiti = createJiti(import.meta.url, {
14
- jsx: {
15
- runtime: "automatic",
16
- importSource: "@cappa/core",
17
- },
18
- sourceMaps: true,
19
- });
20
-
21
- const mod = await jiti.import(configFile, { default: true });
22
-
23
- return mod;
24
- };
25
-
26
- export async function getCosmiConfig(
27
- moduleName: string,
28
- config?: string
29
- ): Promise<CosmiconfigResult> {
30
- const searchPlaces = [
31
- "package.json",
32
- `.${moduleName}rc`,
33
- `.${moduleName}rc.json`,
34
- `.${moduleName}rc.yaml`,
35
- `.${moduleName}rc.yml`,
36
-
37
- `.${moduleName}rc.ts`,
38
- `.${moduleName}rc.js`,
39
- `.${moduleName}rc.mjs`,
40
- `.${moduleName}rc.cjs`,
41
-
42
- `${moduleName}.config.ts`,
43
- `${moduleName}.config.js`,
44
- `${moduleName}.config.mjs`,
45
- `${moduleName}.config.cjs`,
46
- ];
47
- const explorer = cosmiconfig(moduleName, {
48
- cache: false,
49
- searchPlaces: [
50
- ...searchPlaces.map((searchPlace) => {
51
- return `.config/${searchPlace}`;
52
- }),
53
- ...searchPlaces.map((searchPlace) => {
54
- return `configs/${searchPlace}`;
55
- }),
56
- ...searchPlaces,
57
- ],
58
- loaders: {
59
- ".ts": tsLoader,
60
- },
61
- });
62
-
63
- const result = config ? await explorer.load(config) : await explorer.search();
64
-
65
- if (result?.isEmpty || !result || !result.config) {
66
- throw new Error(
67
- "Config not defined, create a cappa.config.js or pass through your config with the option --config"
68
- );
69
- }
70
-
71
- return result as CosmiconfigResult;
72
- }
@@ -1,33 +0,0 @@
1
- import type { UserConfig, PluginDef } from "@cappa/core";
2
-
3
- export async function getPlugins(
4
- plugins: UserConfig["plugins"]
5
- ): Promise<PluginDef[]> {
6
- if (!plugins) {
7
- return [];
8
- }
9
-
10
- const loadedPlugins: PluginDef[] = [];
11
-
12
- for (const plugin of plugins) {
13
- if (typeof plugin === "function") {
14
- // Plugin is a function that returns PluginDef
15
- const pluginDef = plugin();
16
- loadedPlugins.push(pluginDef);
17
- } else {
18
- // Plugin is already a PluginDef
19
- loadedPlugins.push(plugin);
20
- }
21
- }
22
-
23
- return loadedPlugins;
24
- }
25
-
26
- export function isPromise(value: unknown): value is Promise<unknown> {
27
- return (
28
- value !== null &&
29
- typeof value === "object" &&
30
- "then" in value &&
31
- typeof (value as any).then === "function"
32
- );
33
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "include": [
4
- "src/**/*",
5
- "./package.json",
6
- "./tsdown.config.ts",
7
- "./vitest.config.ts"
8
- ]
9
- }
package/tsdown.config.ts DELETED
@@ -1,11 +0,0 @@
1
- import { defineConfig } from "tsdown";
2
-
3
- export default defineConfig({
4
- entry: ["src/index.ts"],
5
- dts: true,
6
- format: ["esm", "cjs"],
7
- platform: "node",
8
- sourcemap: true,
9
- shims: true,
10
- exports: true,
11
- });
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- export default defineConfig({
4
- test: {
5
- dir: "./src",
6
- globals: true,
7
- },
8
- });