webanvil 0.0.6 → 0.0.8
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/LICENSE +21 -21
- package/README.md +549 -38
- package/bin/webanvil +6 -0
- package/bin/webanvil.cmd +2 -0
- package/dist/_chunks/commands.mjs +1890 -0
- package/dist/_chunks/config.mjs +140 -0
- package/dist/_chunks/project-vite.mjs +9 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +30 -0
- package/dist/index.d.mts +668 -0
- package/dist/index.mjs +6 -0
- package/dist/storybook/react/index.d.mts +3 -0
- package/dist/storybook/react/index.mjs +4 -0
- package/dist/storybook/react/preset +8 -0
- package/dist/storybook/react/preset.d.mts +5 -0
- package/dist/storybook/react/preset.mjs +8 -0
- package/dist/storybook/svelte/index.d.mts +3 -0
- package/dist/storybook/svelte/index.mjs +4 -0
- package/dist/storybook/svelte/preset +8 -0
- package/dist/storybook/svelte/preset.d.mts +5 -0
- package/dist/storybook/svelte/preset.mjs +8 -0
- package/dist/storybook/test/preset +2 -0
- package/dist/storybook/test/preset.d.mts +1 -0
- package/dist/storybook/test/preset.mjs +2 -0
- package/dist/storybook/vue/index.d.mts +3 -0
- package/dist/storybook/vue/index.mjs +4 -0
- package/dist/storybook/vue/preset +8 -0
- package/dist/storybook/vue/preset.d.mts +5 -0
- package/dist/storybook/vue/preset.mjs +8 -0
- package/dist/storybook/web-components/index.d.mts +3 -0
- package/dist/storybook/web-components/index.mjs +4 -0
- package/dist/storybook/web-components/preset +7 -0
- package/dist/storybook/web-components/preset.d.mts +4 -0
- package/dist/storybook/web-components/preset.mjs +7 -0
- package/package.json +151 -60
- package/bin/run +0 -3
- package/bin/run.cmd +0 -3
- package/lib/commands/build.d.ts +0 -3
- package/lib/commands/build.d.ts.map +0 -1
- package/lib/commands/build.js +0 -34
- package/lib/commands/serve.d.ts +0 -3
- package/lib/commands/serve.d.ts.map +0 -1
- package/lib/commands/serve.js +0 -44
- package/lib/commons/io/core/File.d.ts +0 -11
- package/lib/commons/io/core/File.d.ts.map +0 -1
- package/lib/commons/io/core/File.js +0 -23
- package/lib/commons/io/core/Path.d.ts +0 -30
- package/lib/commons/io/core/Path.d.ts.map +0 -1
- package/lib/commons/io/core/Path.js +0 -122
- package/lib/commons/io/sync/fs.d.ts +0 -11
- package/lib/commons/io/sync/fs.d.ts.map +0 -1
- package/lib/commons/io/sync/fs.js +0 -46
- package/lib/commons/io/sync/index.d.ts +0 -5
- package/lib/commons/io/sync/index.d.ts.map +0 -1
- package/lib/commons/io/sync/index.js +0 -9
- package/lib/commons/io/sync/path.d.ts +0 -4
- package/lib/commons/io/sync/path.d.ts.map +0 -1
- package/lib/commons/io/sync/path.js +0 -13
- package/lib/core/Configuration.d.ts +0 -37
- package/lib/core/Configuration.d.ts.map +0 -1
- package/lib/core/Configuration.js +0 -56
- package/lib/core/EventEmitter.d.ts +0 -14
- package/lib/core/EventEmitter.d.ts.map +0 -1
- package/lib/core/EventEmitter.js +0 -42
- package/lib/core/Page.d.ts +0 -14
- package/lib/core/Page.d.ts.map +0 -1
- package/lib/core/Page.js +0 -34
- package/lib/core/Plugin.d.ts +0 -13
- package/lib/core/Plugin.d.ts.map +0 -1
- package/lib/core/Plugin.js +0 -12
- package/lib/core/Renderer/Renderer.d.ts +0 -8
- package/lib/core/Renderer/Renderer.d.ts.map +0 -1
- package/lib/core/Renderer/Renderer.js +0 -9
- package/lib/core/Renderer/index.d.ts +0 -8
- package/lib/core/Renderer/index.d.ts.map +0 -1
- package/lib/core/Renderer/index.js +0 -18
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -1
- package/lib/main.d.ts +0 -2
- package/lib/main.d.ts.map +0 -1
- package/lib/main.js +0 -36
- package/lib/plugins/outlinecss.d.ts +0 -4
- package/lib/plugins/outlinecss.d.ts.map +0 -1
- package/lib/plugins/outlinecss.js +0 -34
- package/lib/renderers/EJSRenderer.d.ts +0 -7
- package/lib/renderers/EJSRenderer.d.ts.map +0 -1
- package/lib/renderers/EJSRenderer.js +0 -34
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { loadConfig } from "c12";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
const NODE_PLUGIN_ERROR = "Node builds require plugins created with definePlugin()";
|
|
5
|
+
const definePlugin = (plugin, options) => ({
|
|
6
|
+
rolldown: () => plugin.rolldown(options),
|
|
7
|
+
vite: () => plugin.vite(options)
|
|
8
|
+
});
|
|
9
|
+
const isUnpluginAdapter = (plugin) => typeof plugin === "object" && plugin !== null && "rolldown" in plugin && typeof plugin.rolldown === "function" && "vite" in plugin && typeof plugin.vite === "function";
|
|
10
|
+
const isWebAnvilPlugin = (plugin) => Array.isArray(plugin) || typeof plugin === "function" || typeof plugin === "object" && plugin !== null && "name" in plugin || isUnpluginAdapter(plugin);
|
|
11
|
+
const resolveRolldownPlugins = (plugins) => plugins.flatMap((plugin) => {
|
|
12
|
+
if (!isUnpluginAdapter(plugin)) throw new Error(NODE_PLUGIN_ERROR);
|
|
13
|
+
return plugin.rolldown();
|
|
14
|
+
});
|
|
15
|
+
const resolveVitePlugins = (plugins) => plugins.map((plugin) => isUnpluginAdapter(plugin) ? plugin.vite() : plugin);
|
|
16
|
+
const copyMappingSchema = z.strictObject({
|
|
17
|
+
from: z.string().min(1),
|
|
18
|
+
to: z.string().min(1)
|
|
19
|
+
});
|
|
20
|
+
const legacyPlatformTarget = (target) => (typeof target === "string" ? [target] : target).find((value) => value === "browser" || value === "neutral");
|
|
21
|
+
const assertSyntaxTarget = (target) => {
|
|
22
|
+
if (target === void 0) return;
|
|
23
|
+
const legacy = legacyPlatformTarget(target);
|
|
24
|
+
if (legacy !== void 0) throw new Error(`build.target no longer selects a platform; use build.platform: "${legacy}" instead`);
|
|
25
|
+
};
|
|
26
|
+
const syntaxTargetSchema = z.union([z.string().min(1), z.array(z.string().min(1)).min(1)]).superRefine((target, context) => {
|
|
27
|
+
const legacy = legacyPlatformTarget(target);
|
|
28
|
+
if (legacy !== void 0) context.addIssue({
|
|
29
|
+
code: "custom",
|
|
30
|
+
message: `build.target no longer selects a platform; use build.platform: "${legacy}" instead`
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
const nativeConfigSchema = () => z.custom((value) => typeof value === "object" && value !== null && !Array.isArray(value), "Expected a configuration object");
|
|
34
|
+
const buildConfigSchema = z.strictObject({
|
|
35
|
+
bundle: z.boolean().optional(),
|
|
36
|
+
mode: z.enum([
|
|
37
|
+
"web",
|
|
38
|
+
"node",
|
|
39
|
+
"storybook"
|
|
40
|
+
]).optional(),
|
|
41
|
+
entry: z.string().min(1).optional(),
|
|
42
|
+
entries: z.record(z.string().min(1), z.string().min(1)).optional(),
|
|
43
|
+
outDir: z.string().min(1).optional(),
|
|
44
|
+
declaration: z.union([z.boolean(), nativeConfigSchema()]).optional(),
|
|
45
|
+
sourcemap: z.boolean().optional(),
|
|
46
|
+
minify: z.boolean().optional(),
|
|
47
|
+
copy: z.array(copyMappingSchema).optional(),
|
|
48
|
+
formats: z.array(z.enum(["esm", "cjs"])).min(1).optional(),
|
|
49
|
+
platform: z.enum([
|
|
50
|
+
"node",
|
|
51
|
+
"browser",
|
|
52
|
+
"neutral"
|
|
53
|
+
]).optional(),
|
|
54
|
+
target: syntaxTargetSchema.optional()
|
|
55
|
+
});
|
|
56
|
+
const formatConfigSchema = nativeConfigSchema();
|
|
57
|
+
const lintConfigSchema = nativeConfigSchema();
|
|
58
|
+
const rolldownConfigSchema = nativeConfigSchema();
|
|
59
|
+
const testConfigSchema = nativeConfigSchema();
|
|
60
|
+
const viteConfigSchema = nativeConfigSchema();
|
|
61
|
+
const storybookConfigSchema = z.strictObject({
|
|
62
|
+
configDir: z.string().min(1).optional(),
|
|
63
|
+
outDir: z.string().min(1).optional(),
|
|
64
|
+
test: z.boolean().optional()
|
|
65
|
+
});
|
|
66
|
+
const pluginSchema = z.custom(isWebAnvilPlugin, "Expected a Vite plugin or a WebAnvil plugin created with definePlugin()");
|
|
67
|
+
const userConfigSchema = z.strictObject({
|
|
68
|
+
build: buildConfigSchema.optional(),
|
|
69
|
+
format: formatConfigSchema.optional(),
|
|
70
|
+
lint: lintConfigSchema.optional(),
|
|
71
|
+
rolldown: rolldownConfigSchema.optional(),
|
|
72
|
+
storybook: storybookConfigSchema.optional(),
|
|
73
|
+
test: testConfigSchema.optional(),
|
|
74
|
+
vite: viteConfigSchema.optional(),
|
|
75
|
+
plugins: z.array(pluginSchema).optional()
|
|
76
|
+
});
|
|
77
|
+
const effectiveUserConfigSchema = userConfigSchema.superRefine((config, context) => {
|
|
78
|
+
const build = config.build ?? {};
|
|
79
|
+
if (build.entries !== void 0 && build.mode !== "node") context.addIssue({
|
|
80
|
+
code: "custom",
|
|
81
|
+
path: ["build", "entries"],
|
|
82
|
+
message: "build.entries is only available in Node mode"
|
|
83
|
+
});
|
|
84
|
+
if (build.mode === "web" && build.platform !== void 0) context.addIssue({
|
|
85
|
+
code: "custom",
|
|
86
|
+
path: ["build", "platform"],
|
|
87
|
+
message: "Web builds do not accept build.platform"
|
|
88
|
+
});
|
|
89
|
+
if (build.mode === "node") {
|
|
90
|
+
for (const [index, plugin] of (config.plugins ?? []).entries()) if (!isUnpluginAdapter(plugin)) context.addIssue({
|
|
91
|
+
code: "custom",
|
|
92
|
+
path: ["plugins", index],
|
|
93
|
+
message: NODE_PLUGIN_ERROR
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
const defaultConfig = {
|
|
98
|
+
build: {
|
|
99
|
+
mode: "node",
|
|
100
|
+
entry: "src/index.ts",
|
|
101
|
+
outDir: "dist"
|
|
102
|
+
},
|
|
103
|
+
test: { environment: "node" }
|
|
104
|
+
};
|
|
105
|
+
const toCommandArguments = (config) => Object.fromEntries(Object.entries(config).filter(([, value]) => value !== void 0).map(([key, value]) => [key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`), value]));
|
|
106
|
+
const defined = (arguments_) => Object.fromEntries(Object.entries(arguments_).filter(([, value]) => value !== void 0));
|
|
107
|
+
const defineConfig = (config) => config;
|
|
108
|
+
const loadConfig$1 = async (cwd = process.cwd()) => {
|
|
109
|
+
const { config, configFile } = await loadConfig({
|
|
110
|
+
name: "webanvil",
|
|
111
|
+
cwd,
|
|
112
|
+
configFile: "webanvil.config",
|
|
113
|
+
packageJson: false,
|
|
114
|
+
rcFile: false
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
config: userConfigSchema.parse(defu(config, defaultConfig)),
|
|
118
|
+
configFile
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
const resolveEffectiveBuildConfig = (config, overrides, explicitEntry) => {
|
|
122
|
+
const build = {
|
|
123
|
+
...config.build,
|
|
124
|
+
...defined(overrides)
|
|
125
|
+
};
|
|
126
|
+
if (explicitEntry) delete build.entries;
|
|
127
|
+
return effectiveUserConfigSchema.parse({
|
|
128
|
+
...config,
|
|
129
|
+
build
|
|
130
|
+
}).build ?? {};
|
|
131
|
+
};
|
|
132
|
+
const withConfig = (select, run) => async (arguments_, resolvedConfig) => {
|
|
133
|
+
const config = resolvedConfig ?? (await loadConfig$1()).config;
|
|
134
|
+
const selectedConfig = select(config) ?? {};
|
|
135
|
+
return run({
|
|
136
|
+
...toCommandArguments(selectedConfig),
|
|
137
|
+
...defined(arguments_)
|
|
138
|
+
}, selectedConfig, config, arguments_);
|
|
139
|
+
};
|
|
140
|
+
export { assertSyntaxTarget, buildConfigSchema, copyMappingSchema, defaultConfig, defineConfig, definePlugin, effectiveUserConfigSchema, formatConfigSchema, isUnpluginAdapter, isWebAnvilPlugin, lintConfigSchema, loadConfig$1 as loadConfig, resolveEffectiveBuildConfig, resolveRolldownPlugins, resolveVitePlugins, rolldownConfigSchema, storybookConfigSchema, syntaxTargetSchema, testConfigSchema, userConfigSchema, viteConfigSchema, withConfig };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { loadConfig, resolveVitePlugins } from "./config.mjs";
|
|
2
|
+
const withProjectVitePlugins = async (config) => {
|
|
3
|
+
const { config: webanvilConfig } = await loadConfig();
|
|
4
|
+
return {
|
|
5
|
+
...config,
|
|
6
|
+
plugins: [...config.plugins ?? [], ...resolveVitePlugins(webanvilConfig.plugins ?? [])]
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export { withProjectVitePlugins };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { build_default, check_default, clean_default, dev_default, format_default, lint_default, logger, preview_default, test_default, typecheck_default } from "./_chunks/commands.mjs";
|
|
2
|
+
import { execute } from "cmdore";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { readPackageJSON } from "pkg-types";
|
|
5
|
+
const main = async (...varargs) => {
|
|
6
|
+
const packageJson = await readPackageJSON(fileURLToPath(new URL("..", import.meta.url)));
|
|
7
|
+
return execute([
|
|
8
|
+
build_default,
|
|
9
|
+
check_default,
|
|
10
|
+
clean_default,
|
|
11
|
+
dev_default,
|
|
12
|
+
format_default,
|
|
13
|
+
lint_default,
|
|
14
|
+
preview_default,
|
|
15
|
+
test_default,
|
|
16
|
+
typecheck_default
|
|
17
|
+
], {
|
|
18
|
+
argv: varargs,
|
|
19
|
+
metadata: {
|
|
20
|
+
name: packageJson.name ?? "webanvil",
|
|
21
|
+
version: packageJson.version
|
|
22
|
+
},
|
|
23
|
+
onError: "throw"
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
main(...process.argv.slice(2)).then((code) => process.exit(code)).catch((error) => {
|
|
27
|
+
logger.error(error instanceof Error ? error.message : String(error));
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
|
30
|
+
export {};
|