@frontic/nuxt 0.8.2 → 0.8.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/dist/module.mjs +43 -31
- package/package.json +1 -1
package/dist/module.mjs
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { defineNuxtModule, createResolver, addServerHandler, hasNuxtModule, installModule, addImports, addComponentsDir, addComponentExports } from '@nuxt/kit';
|
|
6
6
|
|
|
7
|
+
function isFronticUiInitialized(rootDir) {
|
|
8
|
+
const configPath = join(rootDir, "components.json");
|
|
9
|
+
if (!existsSync(configPath)) return false;
|
|
10
|
+
try {
|
|
11
|
+
const config = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
12
|
+
return typeof config.$schema === "string" && config.$schema.includes("frontic.com");
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
7
17
|
const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
8
18
|
const ALL_COMPOSABLES = ["block", "listing", "search", "tree", "page", "context", "client"];
|
|
9
19
|
function isComposableEnabled(config, name) {
|
|
@@ -214,37 +224,39 @@ frontic: { composables: false }
|
|
|
214
224
|
nuxt.options.runtimeConfig.frontic = {
|
|
215
225
|
fetchApiSecret
|
|
216
226
|
};
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
{
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
try {
|
|
230
|
-
await Promise.all(
|
|
231
|
-
readdirSync(componentsPath).map(async (dir) => {
|
|
232
|
-
try {
|
|
233
|
-
const filePath = await resolvePath(join(COMPONENT_DIR_PATH, dir, "index"), {
|
|
234
|
-
extensions: [".ts", ".js"]
|
|
235
|
-
});
|
|
236
|
-
addComponentExports({
|
|
237
|
-
prefix: componentsPrefix,
|
|
238
|
-
filePath: resolve(filePath),
|
|
239
|
-
priority: 1
|
|
240
|
-
});
|
|
241
|
-
} catch (err) {
|
|
242
|
-
if (err instanceof Error) console.warn("Module error: ", err.message);
|
|
243
|
-
}
|
|
244
|
-
})
|
|
227
|
+
if (isFronticUiInitialized(ROOT_DIR_PATH)) {
|
|
228
|
+
const componentsPath = await resolvePath(COMPONENT_DIR_PATH);
|
|
229
|
+
if (existsSync(componentsPath)) {
|
|
230
|
+
addComponentsDir(
|
|
231
|
+
{
|
|
232
|
+
path: componentsPath,
|
|
233
|
+
extensions: [],
|
|
234
|
+
ignore: ["**/*"]
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
prepend: true
|
|
238
|
+
}
|
|
245
239
|
);
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
try {
|
|
241
|
+
await Promise.all(
|
|
242
|
+
readdirSync(componentsPath, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map(async (entry) => {
|
|
243
|
+
try {
|
|
244
|
+
const filePath = await resolvePath(join(COMPONENT_DIR_PATH, entry.name, "index"), {
|
|
245
|
+
extensions: [".ts", ".js"]
|
|
246
|
+
});
|
|
247
|
+
addComponentExports({
|
|
248
|
+
prefix: componentsPrefix,
|
|
249
|
+
filePath: resolve(filePath),
|
|
250
|
+
priority: 1
|
|
251
|
+
});
|
|
252
|
+
} catch (err) {
|
|
253
|
+
if (err instanceof Error) console.warn("Module error: ", err.message);
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
);
|
|
257
|
+
} catch (err) {
|
|
258
|
+
if (err instanceof Error) console.warn(err.message);
|
|
259
|
+
}
|
|
248
260
|
}
|
|
249
261
|
}
|
|
250
262
|
}
|
package/package.json
CHANGED