nuxt-site-config-kit 0.7.5 → 0.8.1
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/dist/index.cjs +40 -14
- package/dist/index.d.ts +12 -4
- package/dist/index.mjs +40 -17
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -14,21 +14,21 @@ async function getPkgJsonContextConfig(rootDir) {
|
|
|
14
14
|
description: pkgJson.description
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
async function initSiteConfig() {
|
|
18
|
-
const nuxt = kit.tryUseNuxt();
|
|
17
|
+
async function initSiteConfig(nuxt = kit.tryUseNuxt()) {
|
|
19
18
|
if (!nuxt)
|
|
20
19
|
return;
|
|
21
20
|
let siteConfig = nuxt._siteConfig;
|
|
22
21
|
if (siteConfig)
|
|
23
22
|
return siteConfig;
|
|
24
|
-
const rootDir = nuxt?.options.rootDir || process.cwd();
|
|
25
23
|
siteConfig = siteConfigStack.createSiteConfigStack();
|
|
26
|
-
const isNodeEnv = !!process.env.NODE_ENV;
|
|
27
24
|
siteConfig.push({
|
|
28
25
|
_context: "defaults",
|
|
26
|
+
locale: "en",
|
|
29
27
|
trailingSlash: false,
|
|
30
28
|
titleSeparator: "|"
|
|
31
29
|
});
|
|
30
|
+
const rootDir = nuxt?.options.rootDir || process.cwd();
|
|
31
|
+
const isNodeEnv = !!process.env.NODE_ENV;
|
|
32
32
|
siteConfig.push({
|
|
33
33
|
_context: "system",
|
|
34
34
|
name: rootDir.split("/").pop(),
|
|
@@ -60,19 +60,23 @@ async function initSiteConfig() {
|
|
|
60
60
|
nuxt._siteConfig = siteConfig;
|
|
61
61
|
return siteConfig;
|
|
62
62
|
}
|
|
63
|
-
async function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
async function installNuxtSiteConfig(nuxt = kit.tryUseNuxt()) {
|
|
64
|
+
await kit.installModule(await kit.resolvePath("nuxt-site-config"));
|
|
65
|
+
await initSiteConfig(nuxt);
|
|
66
|
+
}
|
|
67
|
+
function getSiteConfigStack(nuxt = kit.tryUseNuxt()) {
|
|
68
|
+
if (!nuxt)
|
|
69
|
+
throw new Error("Nuxt context is missing.");
|
|
70
|
+
if (!nuxt._siteConfig)
|
|
71
|
+
throw new Error("Site config is not initialized. Make sure you are running your module after nuxt-site-config.");
|
|
72
|
+
return nuxt._siteConfig;
|
|
69
73
|
}
|
|
70
|
-
|
|
71
|
-
const container =
|
|
74
|
+
function updateSiteConfig(input, nuxt = kit.tryUseNuxt()) {
|
|
75
|
+
const container = getSiteConfigStack(nuxt);
|
|
72
76
|
container.push(input);
|
|
73
77
|
}
|
|
74
|
-
|
|
75
|
-
const container =
|
|
78
|
+
function useSiteConfig(nuxt = kit.tryUseNuxt()) {
|
|
79
|
+
const container = getSiteConfigStack(nuxt);
|
|
76
80
|
return container.get();
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -119,8 +123,30 @@ async function assertSiteConfig(mode, options) {
|
|
|
119
123
|
};
|
|
120
124
|
}
|
|
121
125
|
|
|
126
|
+
function withSiteUrl(path, options = {}) {
|
|
127
|
+
const siteConfig = useSiteConfig();
|
|
128
|
+
if (!siteConfig.url && options.throwErrorOnMissingSiteUrl)
|
|
129
|
+
throw new Error("Missing url in site config. Please add `{ site: { url: <url> } }` to nuxt.config.ts.");
|
|
130
|
+
const nuxt = kit.useNuxt();
|
|
131
|
+
const base = nuxt.options.app.baseURL || nuxt.options.nitro.baseURL || "/";
|
|
132
|
+
return siteConfigStack.resolveSitePath(path, {
|
|
133
|
+
absolute: true,
|
|
134
|
+
siteUrl: siteConfig.url || "",
|
|
135
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
136
|
+
base,
|
|
137
|
+
withBase: options.withBase
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function withSiteTrailingSlash(path) {
|
|
141
|
+
const siteConfig = useSiteConfig();
|
|
142
|
+
return siteConfigStack.fixSlashes(siteConfig.trailingSlash, path);
|
|
143
|
+
}
|
|
144
|
+
|
|
122
145
|
exports.assertSiteConfig = assertSiteConfig;
|
|
123
146
|
exports.initSiteConfig = initSiteConfig;
|
|
147
|
+
exports.installNuxtSiteConfig = installNuxtSiteConfig;
|
|
124
148
|
exports.requireSiteConfig = requireSiteConfig;
|
|
125
149
|
exports.updateSiteConfig = updateSiteConfig;
|
|
126
150
|
exports.useSiteConfig = useSiteConfig;
|
|
151
|
+
exports.withSiteTrailingSlash = withSiteTrailingSlash;
|
|
152
|
+
exports.withSiteUrl = withSiteUrl;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SiteConfigInput, SiteConfigStack, SiteConfig } from 'site-config-stack';
|
|
2
2
|
export { SiteConfig, SiteConfigInput, SiteConfigStack } from 'site-config-stack';
|
|
3
|
+
import { Nuxt } from '@nuxt/schema';
|
|
3
4
|
|
|
4
5
|
type AssertionModes = 'prerender' | 'generate' | 'build';
|
|
5
6
|
interface ModuleAssertion {
|
|
@@ -17,9 +18,10 @@ declare module '@nuxt/schema' {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
declare function initSiteConfig(): Promise<SiteConfigStack | undefined>;
|
|
21
|
-
declare function
|
|
22
|
-
declare function
|
|
21
|
+
declare function initSiteConfig(nuxt?: Nuxt | null): Promise<SiteConfigStack | undefined>;
|
|
22
|
+
declare function installNuxtSiteConfig(nuxt?: Nuxt | null): Promise<void>;
|
|
23
|
+
declare function updateSiteConfig(input: SiteConfigInput, nuxt?: Nuxt | null): void;
|
|
24
|
+
declare function useSiteConfig(nuxt?: Nuxt | null): SiteConfig;
|
|
23
25
|
|
|
24
26
|
declare function requireSiteConfig(context: string, requirements: Partial<Record<keyof SiteConfig, string>>, modes: Partial<Record<AssertionModes, boolean>>): void;
|
|
25
27
|
declare function assertSiteConfig(mode: AssertionModes, options?: {
|
|
@@ -30,4 +32,10 @@ declare function assertSiteConfig(mode: AssertionModes, options?: {
|
|
|
30
32
|
messages: string[];
|
|
31
33
|
}>;
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
declare function withSiteUrl(path: string, options?: {
|
|
36
|
+
withBase?: boolean;
|
|
37
|
+
throwErrorOnMissingSiteUrl?: boolean;
|
|
38
|
+
}): string;
|
|
39
|
+
declare function withSiteTrailingSlash(path: string): string;
|
|
40
|
+
|
|
41
|
+
export { AssertionModes, ModuleAssertion, assertSiteConfig, initSiteConfig, installNuxtSiteConfig, requireSiteConfig, updateSiteConfig, useSiteConfig, withSiteTrailingSlash, withSiteUrl };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { tryUseNuxt, useNuxt, useLogger } from '@nuxt/kit';
|
|
1
|
+
import { tryUseNuxt, installModule, resolvePath, useNuxt, useLogger } from '@nuxt/kit';
|
|
2
2
|
import { readPackageJSON } from 'pkg-types';
|
|
3
|
-
import { createSiteConfigStack, envSiteConfig } from 'site-config-stack';
|
|
3
|
+
import { createSiteConfigStack, envSiteConfig, resolveSitePath, fixSlashes } from 'site-config-stack';
|
|
4
4
|
|
|
5
5
|
async function getPkgJsonContextConfig(rootDir) {
|
|
6
6
|
const pkgJson = await readPackageJSON(void 0, { startingFrom: rootDir });
|
|
@@ -12,21 +12,21 @@ async function getPkgJsonContextConfig(rootDir) {
|
|
|
12
12
|
description: pkgJson.description
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
async function initSiteConfig() {
|
|
16
|
-
const nuxt = tryUseNuxt();
|
|
15
|
+
async function initSiteConfig(nuxt = tryUseNuxt()) {
|
|
17
16
|
if (!nuxt)
|
|
18
17
|
return;
|
|
19
18
|
let siteConfig = nuxt._siteConfig;
|
|
20
19
|
if (siteConfig)
|
|
21
20
|
return siteConfig;
|
|
22
|
-
const rootDir = nuxt?.options.rootDir || process.cwd();
|
|
23
21
|
siteConfig = createSiteConfigStack();
|
|
24
|
-
const isNodeEnv = !!process.env.NODE_ENV;
|
|
25
22
|
siteConfig.push({
|
|
26
23
|
_context: "defaults",
|
|
24
|
+
locale: "en",
|
|
27
25
|
trailingSlash: false,
|
|
28
26
|
titleSeparator: "|"
|
|
29
27
|
});
|
|
28
|
+
const rootDir = nuxt?.options.rootDir || process.cwd();
|
|
29
|
+
const isNodeEnv = !!process.env.NODE_ENV;
|
|
30
30
|
siteConfig.push({
|
|
31
31
|
_context: "system",
|
|
32
32
|
name: rootDir.split("/").pop(),
|
|
@@ -58,19 +58,23 @@ async function initSiteConfig() {
|
|
|
58
58
|
nuxt._siteConfig = siteConfig;
|
|
59
59
|
return siteConfig;
|
|
60
60
|
}
|
|
61
|
-
async function
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
async function installNuxtSiteConfig(nuxt = tryUseNuxt()) {
|
|
62
|
+
await installModule(await resolvePath("nuxt-site-config"));
|
|
63
|
+
await initSiteConfig(nuxt);
|
|
64
|
+
}
|
|
65
|
+
function getSiteConfigStack(nuxt = tryUseNuxt()) {
|
|
66
|
+
if (!nuxt)
|
|
67
|
+
throw new Error("Nuxt context is missing.");
|
|
68
|
+
if (!nuxt._siteConfig)
|
|
69
|
+
throw new Error("Site config is not initialized. Make sure you are running your module after nuxt-site-config.");
|
|
70
|
+
return nuxt._siteConfig;
|
|
67
71
|
}
|
|
68
|
-
|
|
69
|
-
const container =
|
|
72
|
+
function updateSiteConfig(input, nuxt = tryUseNuxt()) {
|
|
73
|
+
const container = getSiteConfigStack(nuxt);
|
|
70
74
|
container.push(input);
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
const container =
|
|
76
|
+
function useSiteConfig(nuxt = tryUseNuxt()) {
|
|
77
|
+
const container = getSiteConfigStack(nuxt);
|
|
74
78
|
return container.get();
|
|
75
79
|
}
|
|
76
80
|
|
|
@@ -117,4 +121,23 @@ async function assertSiteConfig(mode, options) {
|
|
|
117
121
|
};
|
|
118
122
|
}
|
|
119
123
|
|
|
120
|
-
|
|
124
|
+
function withSiteUrl(path, options = {}) {
|
|
125
|
+
const siteConfig = useSiteConfig();
|
|
126
|
+
if (!siteConfig.url && options.throwErrorOnMissingSiteUrl)
|
|
127
|
+
throw new Error("Missing url in site config. Please add `{ site: { url: <url> } }` to nuxt.config.ts.");
|
|
128
|
+
const nuxt = useNuxt();
|
|
129
|
+
const base = nuxt.options.app.baseURL || nuxt.options.nitro.baseURL || "/";
|
|
130
|
+
return resolveSitePath(path, {
|
|
131
|
+
absolute: true,
|
|
132
|
+
siteUrl: siteConfig.url || "",
|
|
133
|
+
trailingSlash: siteConfig.trailingSlash,
|
|
134
|
+
base,
|
|
135
|
+
withBase: options.withBase
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function withSiteTrailingSlash(path) {
|
|
139
|
+
const siteConfig = useSiteConfig();
|
|
140
|
+
return fixSlashes(siteConfig.trailingSlash, path);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { assertSiteConfig, initSiteConfig, installNuxtSiteConfig, requireSiteConfig, updateSiteConfig, useSiteConfig, withSiteTrailingSlash, withSiteUrl };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-site-config-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.1",
|
|
5
5
|
"description": "Shared site configuration build-time utilities for Nuxt 3 modules.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://github.com/sponsors/harlan-zw",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"defu": "^6.1.2",
|
|
32
32
|
"pkg-types": "^1.0.3",
|
|
33
33
|
"ufo": "^1.1.2",
|
|
34
|
-
"site-config-stack": "0.
|
|
34
|
+
"site-config-stack": "0.8.1"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"lint": "eslint . --fix",
|