qarpeo 0.1.4 → 0.1.5
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 +49 -25
- package/package.json +1 -1
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readFileSync, writeFileSync, appendFileSync, readdirSync, statSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, appendFileSync, readdirSync, statSync, rmSync } from 'node:fs';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { defineNuxtModule, useLogger, createResolver, addVitePlugin, addTemplate, hasNuxtModule, installModule, addNitroPlugin, addImports, addServerImports, addTypeTemplate, updateTemplates, addServerImportsDir, addServerHandler, addRouteMiddleware, addComponent, extendPages, addPlugin } from '@nuxt/kit';
|
|
@@ -19,7 +19,7 @@ import 'drizzle-orm/node-sqlite';
|
|
|
19
19
|
import 'node:process';
|
|
20
20
|
import 'node:readline/promises';
|
|
21
21
|
|
|
22
|
-
const version = "0.1.
|
|
22
|
+
const version = "0.1.5";
|
|
23
23
|
|
|
24
24
|
function ensureDevEnv(rootDir) {
|
|
25
25
|
const envPath = join(rootDir, ".env");
|
|
@@ -275,21 +275,25 @@ async function resolveAllCmsSources(options) {
|
|
|
275
275
|
if (isRemoteSource(src.from)) {
|
|
276
276
|
const hash = createHash("sha256").update(src.from).digest("hex").slice(0, 12);
|
|
277
277
|
const targetDir = resolve(cacheDir, `qarpeo/cms-sources/source-${hash}`);
|
|
278
|
+
const _auth = src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
|
278
279
|
try {
|
|
279
|
-
await downloadTemplate(src.from, {
|
|
280
|
-
dir: targetDir,
|
|
281
|
-
preferOffline: true,
|
|
282
|
-
auth: src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN
|
|
283
|
-
});
|
|
284
|
-
resolvedDir = targetDir;
|
|
285
|
-
} catch (err) {
|
|
286
|
-
console.warn(
|
|
287
|
-
`[qarpeo:cms] Failed to download remote source "${src.from}":`,
|
|
288
|
-
err?.message || err
|
|
289
|
-
);
|
|
290
280
|
if (existsSync(targetDir)) {
|
|
281
|
+
const cached = await readdir(targetDir);
|
|
282
|
+
if (cached.length > 0) {
|
|
283
|
+
resolvedDir = targetDir;
|
|
284
|
+
} else {
|
|
285
|
+
rmSync(targetDir, { recursive: true, force: true });
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (!resolvedDir) {
|
|
289
|
+
await downloadTemplate(src.from, { dir: targetDir, auth: _auth });
|
|
291
290
|
resolvedDir = targetDir;
|
|
292
291
|
}
|
|
292
|
+
} catch (err) {
|
|
293
|
+
console.warn(
|
|
294
|
+
`[qarpeo:cms] Failed to download remote source "${src.from}": ${err?.message ?? String(err)}`
|
|
295
|
+
);
|
|
296
|
+
if (existsSync(targetDir)) resolvedDir = targetDir;
|
|
293
297
|
}
|
|
294
298
|
} else {
|
|
295
299
|
resolvedDir = resolve(sourceFileDir, src.from);
|
|
@@ -319,21 +323,25 @@ async function resolveAllCmsSources(options) {
|
|
|
319
323
|
if (isRemoteSource(src.from)) {
|
|
320
324
|
const hash = createHash("sha256").update(src.from).digest("hex").slice(0, 12);
|
|
321
325
|
const targetDir = resolve(cacheDir, `qarpeo/cms-sources/source-${hash}`);
|
|
326
|
+
const _auth2 = src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
|
322
327
|
try {
|
|
323
|
-
await downloadTemplate(src.from, {
|
|
324
|
-
dir: targetDir,
|
|
325
|
-
preferOffline: true,
|
|
326
|
-
auth: src.token || process.env.GITHUB_TOKEN || process.env.GH_TOKEN
|
|
327
|
-
});
|
|
328
|
-
resolvedDir = targetDir;
|
|
329
|
-
} catch (err) {
|
|
330
|
-
console.warn(
|
|
331
|
-
`[qarpeo:cms] Failed to download remote source "${src.from}":`,
|
|
332
|
-
err?.message || err
|
|
333
|
-
);
|
|
334
328
|
if (existsSync(targetDir)) {
|
|
329
|
+
const cached = await readdir(targetDir);
|
|
330
|
+
if (cached.length > 0) {
|
|
331
|
+
resolvedDir = targetDir;
|
|
332
|
+
} else {
|
|
333
|
+
rmSync(targetDir, { recursive: true, force: true });
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (!resolvedDir) {
|
|
337
|
+
await downloadTemplate(src.from, { dir: targetDir, auth: _auth2 });
|
|
335
338
|
resolvedDir = targetDir;
|
|
336
339
|
}
|
|
340
|
+
} catch (err) {
|
|
341
|
+
console.warn(
|
|
342
|
+
`[qarpeo:cms] Failed to download remote source "${src.from}": ${err?.message ?? String(err)}`
|
|
343
|
+
);
|
|
344
|
+
if (existsSync(targetDir)) resolvedDir = targetDir;
|
|
337
345
|
}
|
|
338
346
|
} else {
|
|
339
347
|
resolvedDir = resolve(contentDir, src.from);
|
|
@@ -3275,7 +3283,23 @@ export default queueHandler;
|
|
|
3275
3283
|
const cmsPath = cmsConfig.path || "/cms";
|
|
3276
3284
|
const contentDirName = cmsConfig.contentDir || "content";
|
|
3277
3285
|
const resolvedContentDir = existsSync(resolve(nuxt.options.rootDir, contentDirName)) ? resolve(nuxt.options.rootDir, contentDirName) : resolve(nuxt.options.srcDir || nuxt.options.rootDir, contentDirName);
|
|
3278
|
-
const cacheDir =
|
|
3286
|
+
const cacheDir = resolve(nuxt.options.rootDir, ".nuxt");
|
|
3287
|
+
try {
|
|
3288
|
+
const dotenvPath = resolve(nuxt.options.rootDir, ".env");
|
|
3289
|
+
if (existsSync(dotenvPath)) {
|
|
3290
|
+
const raw = readFileSync(dotenvPath, "utf8");
|
|
3291
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
3292
|
+
const trimmed = line.trim();
|
|
3293
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
3294
|
+
const eqIdx = trimmed.indexOf("=");
|
|
3295
|
+
if (eqIdx < 1) continue;
|
|
3296
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
3297
|
+
const val = trimmed.slice(eqIdx + 1).trim().replace(/^["']|["']$/g, "");
|
|
3298
|
+
if (key && !(key in process.env)) process.env[key] = val;
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
} catch {
|
|
3302
|
+
}
|
|
3279
3303
|
let resolvedSources = [];
|
|
3280
3304
|
try {
|
|
3281
3305
|
resolvedSources = await resolveAllCmsSources({
|