zuby 1.0.41 → 1.0.43
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/commands/build.js +68 -42
- package/commands/dev.js +14 -5
- package/config.d.ts +20 -3
- package/config.js +73 -10
- package/constants.d.ts +1 -0
- package/constants.js +1 -0
- package/context/index.d.ts +4 -0
- package/context/index.js +3 -0
- package/context/types.d.ts +11 -0
- package/defineConfig.d.ts +3 -1
- package/defineConfig.js +5 -0
- package/examples/basic/js/pages/index.jsx +4 -4
- package/examples/basic/ts/pages/index.tsx +4 -4
- package/index.d.ts +5 -1
- package/index.js +5 -1
- package/package.json +1 -1
- package/pageContext/index.d.ts +120 -0
- package/pageContext/index.js +134 -0
- package/plugins/chunkNamingPlugin/index.d.ts +2 -2
- package/plugins/compileTimePlugin/index.d.ts +2 -2
- package/plugins/compileTimePlugin/index.js +65 -69
- package/plugins/contextPlugin/index.d.ts +2 -2
- package/plugins/contextPlugin/index.js +2 -1
- package/plugins/dependenciesPlugin/index.d.ts +7 -0
- package/plugins/dependenciesPlugin/index.js +46 -0
- package/plugins/manifestPlugin/index.d.ts +2 -2
- package/plugins/prerenderPlugin/index.d.ts +2 -2
- package/plugins/prerenderPlugin/index.js +91 -101
- package/server/index.js +138 -0
- package/templates/index.js +1 -1
- package/types.d.ts +88 -7
- package/types.js +14 -0
package/commands/build.js
CHANGED
|
@@ -1,36 +1,35 @@
|
|
|
1
|
-
import { MODES } from '../types.js';
|
|
2
|
-
import { getZubyInternalConfig } from '../config.js';
|
|
1
|
+
import { MODES, PLUGIN_HOOKS } from '../types.js';
|
|
2
|
+
import { executePlugins, getZubyInternalConfig } from '../config.js';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import { getTitle } from '../branding.js';
|
|
5
5
|
import { build as viteBuild } from 'vite';
|
|
6
|
-
import { dirname, join } from 'path';
|
|
6
|
+
import { dirname, join, resolve } from 'path';
|
|
7
7
|
import { normalizePath } from '../utils/pathUtils.js';
|
|
8
|
-
import { existsSync, rmSync, writeFileSync, copyFileSync,
|
|
8
|
+
import { existsSync, rmSync, writeFileSync, copyFileSync, readFileSync, } from 'fs';
|
|
9
9
|
import { TEMPLATES } from '../templates/types.js';
|
|
10
10
|
import { glob } from 'glob';
|
|
11
11
|
import { fileURLToPath } from 'url';
|
|
12
12
|
import { getZubyPackageConfig } from '../packageConfig.js';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { getTemplates } from '../templates/index.js';
|
|
14
|
+
import { CLIENT_CHUNKS_MANIFEST, SERVER_CHUNKS_MANIFEST } from '../constants.js';
|
|
15
15
|
const __filename = fileURLToPath(import.meta.url);
|
|
16
16
|
const __dirname = dirname(__filename);
|
|
17
17
|
export default async function build(options) {
|
|
18
18
|
const zubyInternalConfig = await getZubyInternalConfig(options.configFile);
|
|
19
|
-
const { vite: viteConfig, customLogger: logger, outDir,
|
|
19
|
+
const { vite: viteConfig, customLogger: logger, outDir, cacheDir, plugins } = zubyInternalConfig;
|
|
20
|
+
let buildStep = 1;
|
|
21
|
+
const buildSteps = 2 + plugins.filter(plugin => plugin?.buildStep).length;
|
|
22
|
+
const nextBuildStep = (description) => {
|
|
23
|
+
logger?.info(`${chalk.bgYellow.bold.whiteBright(` Step ${buildStep++}/${buildSteps} `)} ${chalk.gray(description)}`);
|
|
24
|
+
};
|
|
20
25
|
process.env.NODE_ENV = MODES.production;
|
|
21
26
|
logger?.info(getTitle(chalk.gray(`building for production...`)));
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
rmSync(outDir || '', {
|
|
25
|
-
recursive: true,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
27
|
+
// Load templates from the project directory
|
|
28
|
+
const templates = await getTemplates();
|
|
28
29
|
// Load the entry file from the project directory
|
|
29
30
|
// or jsxProvider
|
|
30
31
|
const entryFile = await getEntryFile(zubyInternalConfig);
|
|
31
|
-
|
|
32
|
-
logger?.info(`${chalk.bgYellow.bold.whiteBright(` Step 1/4 `)} ${chalk.gray(`building client...`)}`);
|
|
33
|
-
await viteBuild({
|
|
32
|
+
const clientViteBuildConfig = {
|
|
34
33
|
configFile: false,
|
|
35
34
|
...viteConfig,
|
|
36
35
|
build: {
|
|
@@ -45,10 +44,8 @@ export default async function build(options) {
|
|
|
45
44
|
},
|
|
46
45
|
cacheDir: normalizePath(join(cacheDir, 'client')),
|
|
47
46
|
mode: MODES.production,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
logger?.info(`${chalk.bgYellow.bold.whiteBright(` Step 2/4 `)} ${chalk.gray(`building server...`)}`);
|
|
51
|
-
await viteBuild({
|
|
47
|
+
};
|
|
48
|
+
const serverViteBuildConfig = {
|
|
52
49
|
...viteConfig,
|
|
53
50
|
configFile: false,
|
|
54
51
|
publicDir: false,
|
|
@@ -60,6 +57,36 @@ export default async function build(options) {
|
|
|
60
57
|
},
|
|
61
58
|
cacheDir: normalizePath(join(cacheDir, 'server')),
|
|
62
59
|
mode: MODES.production,
|
|
60
|
+
};
|
|
61
|
+
// Run build setup hook
|
|
62
|
+
await executePlugins(zubyInternalConfig, PLUGIN_HOOKS.ZubyBuildSetup, {
|
|
63
|
+
clientViteBuildConfig,
|
|
64
|
+
serverViteBuildConfig,
|
|
65
|
+
templates,
|
|
66
|
+
});
|
|
67
|
+
// Run build start hook
|
|
68
|
+
await executePlugins(zubyInternalConfig, PLUGIN_HOOKS.ZubyBuildStart, {
|
|
69
|
+
templates,
|
|
70
|
+
});
|
|
71
|
+
// Clean build directory
|
|
72
|
+
if (existsSync(outDir || '')) {
|
|
73
|
+
rmSync(outDir || '', {
|
|
74
|
+
recursive: true,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// Client build
|
|
78
|
+
nextBuildStep('building client...');
|
|
79
|
+
await viteBuild(clientViteBuildConfig);
|
|
80
|
+
// Run build client done hook
|
|
81
|
+
await executePlugins(zubyInternalConfig, PLUGIN_HOOKS.ZubyBuildClientDone, {
|
|
82
|
+
templates,
|
|
83
|
+
});
|
|
84
|
+
// Server build
|
|
85
|
+
nextBuildStep('building server...');
|
|
86
|
+
await viteBuild(serverViteBuildConfig);
|
|
87
|
+
// Run build server done hook
|
|
88
|
+
await executePlugins(zubyInternalConfig, PLUGIN_HOOKS.ZubyBuildServerDone, {
|
|
89
|
+
templates,
|
|
63
90
|
});
|
|
64
91
|
// Add serialized zuby config to build directory
|
|
65
92
|
writeFileSync(normalizePath(join(outDir, 'zuby.config.json')), JSON.stringify(zubyInternalConfig, null, 2));
|
|
@@ -72,30 +99,29 @@ export default async function build(options) {
|
|
|
72
99
|
name,
|
|
73
100
|
version,
|
|
74
101
|
}));
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
// Load the chunks manifest files
|
|
103
|
+
const clientChunksManifestPath = resolve(outDir, CLIENT_CHUNKS_MANIFEST);
|
|
104
|
+
const serverChunksManifestPath = resolve(outDir, SERVER_CHUNKS_MANIFEST);
|
|
105
|
+
const clientChunksManifest = existsSync(clientChunksManifestPath)
|
|
106
|
+
? JSON.parse(readFileSync(clientChunksManifestPath, 'utf-8'))
|
|
107
|
+
: {};
|
|
108
|
+
const serverChunksManifest = existsSync(serverChunksManifestPath)
|
|
109
|
+
? JSON.parse(readFileSync(serverChunksManifestPath, 'utf-8'))
|
|
110
|
+
: {};
|
|
111
|
+
// Run build done hook
|
|
112
|
+
// to execute plugins that are part of the build process
|
|
113
|
+
await executePlugins(zubyInternalConfig, PLUGIN_HOOKS.ZubyBuildDone, {
|
|
114
|
+
templates,
|
|
115
|
+
clientChunksManifest,
|
|
116
|
+
serverChunksManifest,
|
|
117
|
+
}, zubyPlugin => {
|
|
118
|
+
// Hide plugins that are not part of the build process
|
|
119
|
+
// from the CLI output to avoid confusion
|
|
120
|
+
if (!zubyPlugin.buildStep)
|
|
89
121
|
return;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
mkdirSync(destDir, {
|
|
93
|
-
recursive: true,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return copyFile(srcFile, destFile);
|
|
122
|
+
// Increment build step with plugin description
|
|
123
|
+
nextBuildStep(zubyPlugin.description || zubyPlugin.name);
|
|
97
124
|
});
|
|
98
|
-
await Promise.all(copyFilePromises);
|
|
99
125
|
logger?.info(`Done! 🎉`);
|
|
100
126
|
}
|
|
101
127
|
export async function getEntryFile(zubyInternalConfig) {
|
package/commands/dev.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PLUGIN_HOOKS } from '../types.js';
|
|
2
|
+
import { executePlugins, getZubyInternalConfig } from '../config.js';
|
|
2
3
|
import { performance } from 'node:perf_hooks';
|
|
3
4
|
import { getTitle } from '../branding.js';
|
|
4
5
|
import chalk from 'chalk';
|
|
5
6
|
import ZubyDevServer from '../server/zubyDevServer.js';
|
|
6
7
|
export default async function dev(options) {
|
|
7
|
-
const
|
|
8
|
-
const { customLogger: logger } =
|
|
8
|
+
const zubyInternalConfig = await getZubyInternalConfig(options.configFile);
|
|
9
|
+
const { customLogger: logger, server } = zubyInternalConfig;
|
|
9
10
|
const startTime = performance.now();
|
|
10
|
-
const { host = '127.0.0.1', port = 3000 } =
|
|
11
|
-
const zubyDevServer = new ZubyDevServer(
|
|
11
|
+
const { host = '127.0.0.1', port = 3000 } = server;
|
|
12
|
+
const zubyDevServer = new ZubyDevServer(zubyInternalConfig);
|
|
13
|
+
// Run dev setup hook
|
|
14
|
+
await executePlugins(zubyInternalConfig, PLUGIN_HOOKS.ZubyDevSetup, {
|
|
15
|
+
devServer: zubyDevServer,
|
|
16
|
+
});
|
|
12
17
|
await zubyDevServer.listen();
|
|
18
|
+
// Run dev start hook
|
|
19
|
+
await executePlugins(zubyInternalConfig, PLUGIN_HOOKS.ZubyDevStart, {
|
|
20
|
+
devServer: zubyDevServer,
|
|
21
|
+
});
|
|
13
22
|
const readyTime = performance.now();
|
|
14
23
|
logger?.info(` ${getTitle(chalk.gray(`started in ${Math.round(readyTime - startTime)}ms`))}\r\n`);
|
|
15
24
|
logger?.info(` ┃ Mode development`);
|
package/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ZubyConfig, ZubyInternalConfig } from './types.js';
|
|
1
|
+
import { PluginHook, ZubyConfig, ZubyHookParams, ZubyInternalConfig, ZubyPlugin } from './types.js';
|
|
2
|
+
import type { PluginOption as VitePluginOption, Plugin as VitePlugin } from 'vite';
|
|
2
3
|
/**
|
|
3
4
|
* Returns the path to the ZubyConfig file.
|
|
4
5
|
*/
|
|
@@ -26,8 +27,24 @@ export declare const validateConfig: (config: ZubyConfig) => void;
|
|
|
26
27
|
*/
|
|
27
28
|
export declare const mergeDefaultConfig: (config: ZubyConfig) => Promise<ZubyInternalConfig>;
|
|
28
29
|
/**
|
|
29
|
-
* This function returns the array of built-in
|
|
30
|
+
* This function returns the array of built-in plugins.
|
|
30
31
|
* Check which framework components are relying on each plugin
|
|
31
32
|
* before removing any of them.
|
|
32
33
|
*/
|
|
33
|
-
export declare const getBuiltInPlugins: () =>
|
|
34
|
+
export declare const getBuiltInPlugins: () => VitePlugin<any>[];
|
|
35
|
+
/**
|
|
36
|
+
* Executes the Zuby plugins for the given hook.
|
|
37
|
+
* @param config The ZubyConfig or ZubyInternalConfig object.
|
|
38
|
+
* @param hookName The name of the hook to execute.
|
|
39
|
+
* @param params Additional params to pass to the plugins.
|
|
40
|
+
* @param beforeHook Callback function to execute before each plugin hook.
|
|
41
|
+
* @param afterHook Callback function to execute after each plugin hook.
|
|
42
|
+
* @example executePlugins(config, 'zuby:config:setup', { config, logger })
|
|
43
|
+
*/
|
|
44
|
+
export declare const executePlugins: (config: ZubyConfig | ZubyInternalConfig, hookName: PluginHook, params?: ExecutePluginsParams, beforeHook?: (plugin: ZubyPlugin) => void | Promise<void>, afterHook?: (plugin: ZubyPlugin, hookResult: any) => void | Promise<void>) => Promise<void>;
|
|
45
|
+
export type ExecutePluginsParams = Omit<ZubyHookParams, 'command' | 'logger' | 'config'>;
|
|
46
|
+
/**
|
|
47
|
+
* Normalizes the plugins to common array format.
|
|
48
|
+
* @param plugins
|
|
49
|
+
*/
|
|
50
|
+
export declare const normalizePlugins: (plugins: (ZubyPlugin | ZubyPlugin[] | VitePluginOption | VitePluginOption[])[]) => Promise<(ZubyPlugin | VitePlugin)[]>;
|
package/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PLUGIN_HOOKS, } from './types.js';
|
|
1
2
|
import { BUILD_CHUNKS_MANIFEST, ZUBY_CONFIG_FILE } from './constants.js';
|
|
2
3
|
import { existsSync } from 'fs';
|
|
3
4
|
import { bundleRequire } from 'bundle-require';
|
|
@@ -6,8 +7,9 @@ import { createLogger } from './logger/index.js';
|
|
|
6
7
|
import contextPlugin from './plugins/contextPlugin/index.js';
|
|
7
8
|
import compileTimePlugin from './plugins/compileTimePlugin/index.js';
|
|
8
9
|
import chunkNamingPlugin from './plugins/chunkNamingPlugin/index.js';
|
|
9
|
-
import prerenderPlugin from './plugins/prerenderPlugin/index.js';
|
|
10
10
|
import manifestPlugin from './plugins/manifestPlugin/index.js';
|
|
11
|
+
import prerenderPlugin from './plugins/prerenderPlugin/index.js';
|
|
12
|
+
import standaloneBuildPlugin from './plugins/dependenciesPlugin/index.js';
|
|
11
13
|
let zubyInternalConfig;
|
|
12
14
|
/**
|
|
13
15
|
* Returns the path to the ZubyConfig file.
|
|
@@ -33,8 +35,9 @@ export const getZubyConfig = async (configFilePath) => {
|
|
|
33
35
|
const { mod } = await bundleRequire({
|
|
34
36
|
filepath: configFilePath,
|
|
35
37
|
});
|
|
36
|
-
// Find the default export
|
|
37
|
-
|
|
38
|
+
// Find the default export
|
|
39
|
+
// and wait for it to resolve if it's a promise
|
|
40
|
+
const zubyConfig = await Promise.resolve(mod.default || mod);
|
|
38
41
|
if (!zubyConfig) {
|
|
39
42
|
throw new Error(`No valid default export found in ZubyConfig file: ${configFilePath}`);
|
|
40
43
|
}
|
|
@@ -52,8 +55,12 @@ export const getZubyInternalConfig = async (configFilePath, cache = true) => {
|
|
|
52
55
|
return zubyInternalConfig;
|
|
53
56
|
const zubyConfig = await getZubyConfig(configFilePath);
|
|
54
57
|
zubyConfig.configFilePath = configFilePath;
|
|
58
|
+
// Run config setup hook
|
|
59
|
+
await executePlugins(zubyConfig, PLUGIN_HOOKS.ZubyConfigSetup);
|
|
55
60
|
validateConfig(zubyConfig);
|
|
56
61
|
zubyInternalConfig = await mergeDefaultConfig(zubyConfig);
|
|
62
|
+
// Run config done hook
|
|
63
|
+
await executePlugins(zubyInternalConfig, PLUGIN_HOOKS.ZubyConfigDone);
|
|
57
64
|
return zubyInternalConfig;
|
|
58
65
|
};
|
|
59
66
|
/**
|
|
@@ -82,6 +89,11 @@ export const mergeDefaultConfig = async (config) => {
|
|
|
82
89
|
config.cacheDir = config.cacheDir ?? '.zuby-cache';
|
|
83
90
|
config.output = config.output ?? 'static';
|
|
84
91
|
config.prerenderPaths = config.prerenderPaths ?? [];
|
|
92
|
+
config.plugins = await normalizePlugins([
|
|
93
|
+
...getBuiltInPlugins(),
|
|
94
|
+
...(config.jsx?.getPlugins() ?? []),
|
|
95
|
+
...(config.plugins ?? []),
|
|
96
|
+
]);
|
|
85
97
|
// Default server config
|
|
86
98
|
config.server = config.server ?? {};
|
|
87
99
|
config.server.host = config.server.host ?? '127.0.0.1';
|
|
@@ -116,19 +128,15 @@ export const mergeDefaultConfig = async (config) => {
|
|
|
116
128
|
config.vite.build.ssrEmitAssets = config.vite.build.ssrEmitAssets ?? true;
|
|
117
129
|
config.vite.build.modulePreload = { polyfill: false };
|
|
118
130
|
config.vite.optimizeDeps = config.vite.optimizeDeps ?? {};
|
|
119
|
-
// Merge
|
|
120
|
-
config.vite.plugins = [
|
|
121
|
-
...getBuiltInPlugins(),
|
|
122
|
-
...(config.jsx?.getPlugins() ?? []),
|
|
123
|
-
...(config.vite?.plugins ?? []),
|
|
124
|
-
];
|
|
131
|
+
// Merge Vite plugins with Zuby plugins
|
|
132
|
+
config.vite.plugins = [...(config.plugins ?? []), ...(config.vite.plugins ?? [])];
|
|
125
133
|
return {
|
|
126
134
|
...config,
|
|
127
135
|
templateExtensions: ['js', 'jsx', 'ts', 'tsx'],
|
|
128
136
|
};
|
|
129
137
|
};
|
|
130
138
|
/**
|
|
131
|
-
* This function returns the array of built-in
|
|
139
|
+
* This function returns the array of built-in plugins.
|
|
132
140
|
* Check which framework components are relying on each plugin
|
|
133
141
|
* before removing any of them.
|
|
134
142
|
*/
|
|
@@ -139,5 +147,60 @@ export const getBuiltInPlugins = () => {
|
|
|
139
147
|
chunkNamingPlugin(),
|
|
140
148
|
manifestPlugin(),
|
|
141
149
|
prerenderPlugin(),
|
|
150
|
+
standaloneBuildPlugin(),
|
|
142
151
|
];
|
|
143
152
|
};
|
|
153
|
+
/**
|
|
154
|
+
* Executes the Zuby plugins for the given hook.
|
|
155
|
+
* @param config The ZubyConfig or ZubyInternalConfig object.
|
|
156
|
+
* @param hookName The name of the hook to execute.
|
|
157
|
+
* @param params Additional params to pass to the plugins.
|
|
158
|
+
* @param beforeHook Callback function to execute before each plugin hook.
|
|
159
|
+
* @param afterHook Callback function to execute after each plugin hook.
|
|
160
|
+
* @example executePlugins(config, 'zuby:config:setup', { config, logger })
|
|
161
|
+
*/
|
|
162
|
+
export const executePlugins = async (config, hookName, params = {}, beforeHook = () => { }, afterHook = () => { }) => {
|
|
163
|
+
const logger = config.customLogger ||
|
|
164
|
+
createLogger(config.logLevel, {
|
|
165
|
+
allowClearScreen: false,
|
|
166
|
+
prefix: '[Zuby]',
|
|
167
|
+
});
|
|
168
|
+
const command = process.env.NODE_ENV === 'production' ? 'build' : 'dev';
|
|
169
|
+
const plugins = config.plugins || [];
|
|
170
|
+
for (const plugin of plugins) {
|
|
171
|
+
// Skip if the plugin is not an object
|
|
172
|
+
// or if it doesn't have hooks
|
|
173
|
+
if (!plugin || !('hooks' in plugin))
|
|
174
|
+
continue;
|
|
175
|
+
const zubyPlugin = plugin;
|
|
176
|
+
const hooks = zubyPlugin?.hooks || {};
|
|
177
|
+
const hook = hooks[hookName];
|
|
178
|
+
// Skip if the hook has invalid type
|
|
179
|
+
if (!hook || typeof hook !== 'function')
|
|
180
|
+
continue;
|
|
181
|
+
// Execute the callback function before each hook
|
|
182
|
+
await beforeHook(zubyPlugin);
|
|
183
|
+
// Execute the hook
|
|
184
|
+
const hookResult = await hook({
|
|
185
|
+
...params,
|
|
186
|
+
config,
|
|
187
|
+
logger,
|
|
188
|
+
command,
|
|
189
|
+
});
|
|
190
|
+
// Execute the callback function after each hook
|
|
191
|
+
await afterHook(zubyPlugin, hookResult);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Normalizes the plugins to common array format.
|
|
196
|
+
* @param plugins
|
|
197
|
+
*/
|
|
198
|
+
export const normalizePlugins = async (plugins) => {
|
|
199
|
+
// Resolve the plugins if they are promises
|
|
200
|
+
const resolvePlugins = await Promise.resolve(plugins);
|
|
201
|
+
return resolvePlugins
|
|
202
|
+
// Flatten the array and normalize inner arrays
|
|
203
|
+
.flatMap(plugin => (Array.isArray(plugin) ? normalizePlugins(plugin) : [plugin]))
|
|
204
|
+
// Remove false, undefined, null values
|
|
205
|
+
.filter(plugin => !!plugin);
|
|
206
|
+
};
|
package/constants.d.ts
CHANGED
package/constants.js
CHANGED
package/context/index.d.ts
CHANGED
|
@@ -15,5 +15,9 @@ export declare class ZubyContext {
|
|
|
15
15
|
get version(): string | undefined;
|
|
16
16
|
get renderToStream(): import("../types.js").RenderToStream | undefined;
|
|
17
17
|
get renderToString(): import("../types.js").RenderToString | undefined;
|
|
18
|
+
get i18n(): {
|
|
19
|
+
locales: string[];
|
|
20
|
+
defaultLocale: string;
|
|
21
|
+
} | undefined;
|
|
18
22
|
}
|
|
19
23
|
export declare const getContext: () => ZubyContext;
|
package/context/index.js
CHANGED
package/context/types.d.ts
CHANGED
|
@@ -34,4 +34,15 @@ export interface ZubyRawContext {
|
|
|
34
34
|
* @example 1.0.0
|
|
35
35
|
*/
|
|
36
36
|
version?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The internalization config from ZubyConfig.
|
|
39
|
+
* @example {
|
|
40
|
+
* locales: ['en', 'de', 'cs', 'pl'],
|
|
41
|
+
* defaultLocale: 'en'
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
i18n?: {
|
|
45
|
+
locales: string[];
|
|
46
|
+
defaultLocale: string;
|
|
47
|
+
};
|
|
37
48
|
}
|
package/defineConfig.d.ts
CHANGED
|
@@ -4,10 +4,12 @@ import { ZubyConfig } from './types.js';
|
|
|
4
4
|
*
|
|
5
5
|
* It is not required, but it provides type safety and autocompletion in your IDE.
|
|
6
6
|
* See the full Zuby Configuration API Documentation
|
|
7
|
+
*
|
|
8
|
+
* @link https://zuby.futrou.com/reference/configuration
|
|
7
9
|
* @param config
|
|
8
10
|
* @example defineConfig({
|
|
9
11
|
* outDir: 'build',
|
|
10
12
|
* srcDir: './',
|
|
11
13
|
* })
|
|
12
14
|
*/
|
|
13
|
-
export declare const defineConfig: (config: ZubyConfig) => ZubyConfig
|
|
15
|
+
export declare const defineConfig: (config: ZubyConfig | (() => ZubyConfig | Promise<ZubyConfig>)) => ZubyConfig | Promise<ZubyConfig>;
|
package/defineConfig.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* It is not required, but it provides type safety and autocompletion in your IDE.
|
|
5
5
|
* See the full Zuby Configuration API Documentation
|
|
6
|
+
*
|
|
7
|
+
* @link https://zuby.futrou.com/reference/configuration
|
|
6
8
|
* @param config
|
|
7
9
|
* @example defineConfig({
|
|
8
10
|
* outDir: 'build',
|
|
@@ -10,5 +12,8 @@
|
|
|
10
12
|
* })
|
|
11
13
|
*/
|
|
12
14
|
export const defineConfig = (config) => {
|
|
15
|
+
if (typeof config === 'function') {
|
|
16
|
+
return config();
|
|
17
|
+
}
|
|
13
18
|
return config;
|
|
14
19
|
};
|
|
@@ -12,14 +12,14 @@ export default function Home() {
|
|
|
12
12
|
</p>
|
|
13
13
|
<ul role="list" className="link-card-grid">
|
|
14
14
|
<Card
|
|
15
|
-
href="https://zuby.futrou.com
|
|
15
|
+
href="https://zuby.futrou.com"
|
|
16
16
|
title="Documentation"
|
|
17
17
|
body="Find config API, tips and tricks, and more in the Zuby.js docs."
|
|
18
18
|
/>
|
|
19
19
|
<Card
|
|
20
|
-
href="https://zuby.futrou.com/
|
|
21
|
-
title="
|
|
22
|
-
body="
|
|
20
|
+
href="https://zuby.futrou.com/reference/configuration"
|
|
21
|
+
title="API Reference"
|
|
22
|
+
body="Find config API, tips and tricks, and more in the Zuby.js API docs."
|
|
23
23
|
/>
|
|
24
24
|
</ul>
|
|
25
25
|
</main>
|
|
@@ -12,14 +12,14 @@ export default function Home() {
|
|
|
12
12
|
</p>
|
|
13
13
|
<ul role="list" className="link-card-grid">
|
|
14
14
|
<Card
|
|
15
|
-
href="https://zuby.futrou.com
|
|
15
|
+
href="https://zuby.futrou.com"
|
|
16
16
|
title="Documentation"
|
|
17
17
|
body="Find config API, tips and tricks, and more in the Zuby.js docs."
|
|
18
18
|
/>
|
|
19
19
|
<Card
|
|
20
|
-
href="https://zuby.futrou.com/
|
|
21
|
-
title="
|
|
22
|
-
body="
|
|
20
|
+
href="https://zuby.futrou.com/reference/configuration"
|
|
21
|
+
title="API Reference"
|
|
22
|
+
body="Find config API, tips and tricks, and more in the Zuby.js API docs."
|
|
23
23
|
/>
|
|
24
24
|
</ul>
|
|
25
25
|
</main>
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
-
export * from './config.js';
|
|
3
2
|
export * from './defineConfig.js';
|
|
3
|
+
export * from './context/index.js';
|
|
4
|
+
export * from './pageContext/index.js';
|
|
5
|
+
export { ZubyContext as Context } from './context/index.js';
|
|
6
|
+
export { ZubyPageContext as PageContext } from './pageContext/index.js';
|
|
7
|
+
export { ZubyPageContext as HandlerContext } from './pageContext/index.js';
|
package/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
|
-
export * from './config.js';
|
|
3
2
|
export * from './defineConfig.js';
|
|
3
|
+
export * from './context/index.js';
|
|
4
|
+
export * from './pageContext/index.js';
|
|
5
|
+
export { ZubyContext as Context } from './context/index.js';
|
|
6
|
+
export { ZubyPageContext as PageContext } from './pageContext/index.js';
|
|
7
|
+
export { ZubyPageContext as HandlerContext } from './pageContext/index.js';
|