valaxy 0.25.9 → 0.25.11
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/client/composables/app/useValaxyApp.ts +9 -2
- package/client/composables/locale.ts +18 -10
- package/dist/{chunk-MSK4KQXZ.js → chunk-YYHL7OM3.js} +239 -259
- package/dist/{config-CSOxBD5d.d.ts → config-bf4WqwPK.d.ts} +8 -0
- package/dist/node/cli/index.js +1 -1
- package/dist/node/index.d.ts +2 -6
- package/dist/node/index.js +1 -3
- package/dist/types/index.d.ts +2 -2
- package/package.json +9 -8
- package/shared/utils/i18n.ts +1 -1
- package/types/config.ts +8 -0
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// node/cli/index.ts
|
|
2
|
-
import
|
|
2
|
+
import process16 from "process";
|
|
3
3
|
import yargs from "yargs";
|
|
4
4
|
import { hideBin } from "yargs/helpers";
|
|
5
5
|
|
|
6
6
|
// package.json
|
|
7
|
-
var version = "0.25.
|
|
7
|
+
var version = "0.25.11";
|
|
8
8
|
|
|
9
9
|
// node/modules/fuse.ts
|
|
10
10
|
import path4 from "path";
|
|
11
|
-
import { consola as
|
|
11
|
+
import { consola as consola8 } from "consola";
|
|
12
12
|
import { colors as colors7 } from "consola/utils";
|
|
13
13
|
import fg2 from "fast-glob";
|
|
14
|
-
import
|
|
14
|
+
import fs6 from "fs-extra";
|
|
15
15
|
import matter from "gray-matter";
|
|
16
16
|
|
|
17
17
|
// node/modules/index.ts
|
|
@@ -37,12 +37,12 @@ function commonOptions(args) {
|
|
|
37
37
|
import { dirname as dirname2 } from "path";
|
|
38
38
|
import process4 from "process";
|
|
39
39
|
import { ensureSuffix, uniq } from "@antfu/utils";
|
|
40
|
-
import { consola as
|
|
40
|
+
import { consola as consola6 } from "consola";
|
|
41
41
|
import { colors as colors6 } from "consola/utils";
|
|
42
42
|
import _debug from "debug";
|
|
43
43
|
import fg from "fast-glob";
|
|
44
|
-
import
|
|
45
|
-
import { resolve as
|
|
44
|
+
import fs4 from "fs-extra";
|
|
45
|
+
import { resolve as resolve3 } from "pathe";
|
|
46
46
|
|
|
47
47
|
// node/build/bundle.ts
|
|
48
48
|
import path from "path";
|
|
@@ -155,12 +155,12 @@ function getRollupOptions(options) {
|
|
|
155
155
|
|
|
156
156
|
// node/config/addon.ts
|
|
157
157
|
import path2 from "path";
|
|
158
|
-
import
|
|
158
|
+
import fs from "fs-extra";
|
|
159
159
|
|
|
160
160
|
// node/config/valaxy.ts
|
|
161
161
|
import process2 from "process";
|
|
162
162
|
import { isFunction } from "@antfu/utils";
|
|
163
|
-
import { consola as
|
|
163
|
+
import { consola as consola3 } from "consola";
|
|
164
164
|
import { colors as colors2 } from "consola/utils";
|
|
165
165
|
import { createDefu } from "defu";
|
|
166
166
|
import { mergeConfig as mergeViteConfig } from "vite";
|
|
@@ -180,39 +180,13 @@ function countPerformanceTime() {
|
|
|
180
180
|
|
|
181
181
|
// node/config/site.ts
|
|
182
182
|
import { webcrypto } from "crypto";
|
|
183
|
-
import { consola as
|
|
183
|
+
import { consola as consola2 } from "consola";
|
|
184
184
|
import { colors } from "consola/utils";
|
|
185
185
|
import { options as floatingVueOptions } from "floating-vue";
|
|
186
186
|
|
|
187
187
|
// node/config/utils.ts
|
|
188
188
|
import process from "process";
|
|
189
|
-
import {
|
|
190
|
-
import fs from "fs-extra";
|
|
191
|
-
import { createJiti } from "jiti";
|
|
192
|
-
import { resolve } from "pathe";
|
|
193
|
-
var jiti = createJiti(import.meta.url, {
|
|
194
|
-
// for hmr
|
|
195
|
-
moduleCache: false
|
|
196
|
-
});
|
|
197
|
-
async function loadConfig(options) {
|
|
198
|
-
const { name, cwd } = options;
|
|
199
|
-
const filePath = resolve(cwd, `${name}.config.ts`);
|
|
200
|
-
let data = {};
|
|
201
|
-
if (await fs.exists(filePath)) {
|
|
202
|
-
try {
|
|
203
|
-
data = await jiti.import(filePath, { default: true });
|
|
204
|
-
} catch (e) {
|
|
205
|
-
console.error(e);
|
|
206
|
-
consola2.error(`Failed to load config file: ${filePath}`);
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
consola2.debug(`Config file not found: ${filePath}`);
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
config: data,
|
|
213
|
-
configFile: filePath
|
|
214
|
-
};
|
|
215
|
-
}
|
|
189
|
+
import { loadConfig } from "define-config-ts";
|
|
216
190
|
async function loadConfigFromFile(file, options = {}) {
|
|
217
191
|
const { config, configFile } = await loadConfig({
|
|
218
192
|
name: file,
|
|
@@ -327,7 +301,7 @@ async function resolveSiteConfig(root) {
|
|
|
327
301
|
const { config: userSiteConfig, configFile: siteConfigFile } = await resolveSiteConfigFromRoot(root);
|
|
328
302
|
const duration = endCount();
|
|
329
303
|
if (userSiteConfig && siteConfigFile)
|
|
330
|
-
|
|
304
|
+
consola2.success(`Resolve ${colors.cyan("siteConfig")} from ${colors.dim(siteConfigFile)} ${colors.yellow(duration)}`);
|
|
331
305
|
return {
|
|
332
306
|
siteConfig: userSiteConfig,
|
|
333
307
|
siteConfigFile
|
|
@@ -407,7 +381,7 @@ async function resolveValaxyConfig(options) {
|
|
|
407
381
|
const { config: userValaxyConfig, configFile } = await resolveValaxyConfigFromRoot(configRoot);
|
|
408
382
|
const duration = endCount();
|
|
409
383
|
if (configFile && userValaxyConfig && Object.keys(userValaxyConfig).length !== 0)
|
|
410
|
-
|
|
384
|
+
consola3.success(`Resolve ${colors2.cyan("userValaxyConfig")} from ${colors2.dim(configFile)} ${colors2.yellow(duration)}`);
|
|
411
385
|
const theme = options.theme || userValaxyConfig?.theme || "yun";
|
|
412
386
|
return {
|
|
413
387
|
config: userValaxyConfig,
|
|
@@ -425,7 +399,7 @@ async function resolveAddonsConfig(addons, options) {
|
|
|
425
399
|
let valaxyConfig = {};
|
|
426
400
|
for (const addon of addons) {
|
|
427
401
|
const addonConfigPath = path2.resolve(addon.root, "valaxy.config.ts");
|
|
428
|
-
if (!await
|
|
402
|
+
if (!await fs.exists(addonConfigPath))
|
|
429
403
|
continue;
|
|
430
404
|
const { config, configFile } = await resolveValaxyConfigFromRoot(addon.root, options);
|
|
431
405
|
if (!config)
|
|
@@ -441,10 +415,10 @@ import { colors as colors4 } from "consola/utils";
|
|
|
441
415
|
import defu from "defu";
|
|
442
416
|
|
|
443
417
|
// node/logger/index.ts
|
|
444
|
-
import { consola as
|
|
418
|
+
import { consola as consola4 } from "consola";
|
|
445
419
|
import { colors as colors3 } from "consola/utils";
|
|
446
420
|
import ora from "ora";
|
|
447
|
-
var logger =
|
|
421
|
+
var logger = consola4.create({});
|
|
448
422
|
var valaxyPrefix = colors3.magenta("[valaxy]");
|
|
449
423
|
var vLogger = {
|
|
450
424
|
success: (...args) => logger.success(valaxyPrefix, ...args),
|
|
@@ -499,7 +473,7 @@ var replaceArrMerge = createDefu2((obj, key, value) => {
|
|
|
499
473
|
// node/utils/getGitTimestamp.ts
|
|
500
474
|
import { spawn } from "cross-spawn";
|
|
501
475
|
function getGitTimestamp(file, type = "updated") {
|
|
502
|
-
return new Promise((
|
|
476
|
+
return new Promise((resolve14, _reject) => {
|
|
503
477
|
const params = ["log"];
|
|
504
478
|
if (type === "updated")
|
|
505
479
|
params.push("-1");
|
|
@@ -510,10 +484,10 @@ function getGitTimestamp(file, type = "updated") {
|
|
|
510
484
|
let output = "";
|
|
511
485
|
child.stdout.on("data", (d) => output += String(d));
|
|
512
486
|
child.on("close", () => {
|
|
513
|
-
|
|
487
|
+
resolve14(+new Date(output));
|
|
514
488
|
});
|
|
515
489
|
child.on("error", () => {
|
|
516
|
-
|
|
490
|
+
resolve14(0);
|
|
517
491
|
});
|
|
518
492
|
});
|
|
519
493
|
}
|
|
@@ -523,7 +497,7 @@ var EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i;
|
|
|
523
497
|
|
|
524
498
|
// shared/utils/i18n.ts
|
|
525
499
|
function tObject(data, lang) {
|
|
526
|
-
if (typeof data === "object") {
|
|
500
|
+
if (data && typeof data === "object") {
|
|
527
501
|
return data[lang] || Object.values(data)[0] || "";
|
|
528
502
|
}
|
|
529
503
|
return data;
|
|
@@ -547,7 +521,7 @@ function $t(key) {
|
|
|
547
521
|
|
|
548
522
|
// node/utils/resolve.ts
|
|
549
523
|
import { ensurePrefix, slash } from "@antfu/utils";
|
|
550
|
-
import { consola as
|
|
524
|
+
import { consola as consola5 } from "consola";
|
|
551
525
|
import { resolvePath } from "mlly";
|
|
552
526
|
import { resolveGlobal } from "resolve-global";
|
|
553
527
|
var isInstalledGlobally = {};
|
|
@@ -563,7 +537,7 @@ async function resolveImportPath(importName, ensure = false) {
|
|
|
563
537
|
url: import.meta.url
|
|
564
538
|
});
|
|
565
539
|
} catch (error) {
|
|
566
|
-
|
|
540
|
+
consola5.log(error);
|
|
567
541
|
}
|
|
568
542
|
if (isInstalledGlobally.value) {
|
|
569
543
|
try {
|
|
@@ -574,33 +548,33 @@ async function resolveImportPath(importName, ensure = false) {
|
|
|
574
548
|
if (ensure)
|
|
575
549
|
throw new Error(`Failed to resolve package ${importName}`);
|
|
576
550
|
else
|
|
577
|
-
|
|
551
|
+
consola5.warn(`Failed to resolve package ${importName}`);
|
|
578
552
|
}
|
|
579
553
|
|
|
580
554
|
// node/utils/addons.ts
|
|
581
555
|
import process3 from "process";
|
|
582
556
|
import { colors as colors5 } from "consola/utils";
|
|
583
557
|
import defu2 from "defu";
|
|
584
|
-
import
|
|
558
|
+
import fs3 from "fs-extra";
|
|
585
559
|
import ora2 from "ora";
|
|
586
|
-
import { resolve as
|
|
560
|
+
import { resolve as resolve2 } from "pathe";
|
|
587
561
|
|
|
588
562
|
// node/utils/root.ts
|
|
589
563
|
import { dirname } from "path";
|
|
590
|
-
import
|
|
591
|
-
import { resolve
|
|
564
|
+
import fs2 from "fs-extra";
|
|
565
|
+
import { resolve } from "pathe";
|
|
592
566
|
async function getModuleRoot(name, entry) {
|
|
593
567
|
if (!name)
|
|
594
568
|
return "";
|
|
595
569
|
if (isPath(name)) {
|
|
596
570
|
if (entry) {
|
|
597
|
-
const isFile =
|
|
598
|
-
return
|
|
571
|
+
const isFile = fs2.lstatSync(entry).isFile();
|
|
572
|
+
return resolve(isFile ? dirname(entry) : entry, name);
|
|
599
573
|
} else {
|
|
600
574
|
throw new Error(`entry is required when ${name} is path`);
|
|
601
575
|
}
|
|
602
576
|
} else {
|
|
603
|
-
return
|
|
577
|
+
return resolve(dirname(await resolveImportPath(`${name}/package.json`) || ""));
|
|
604
578
|
}
|
|
605
579
|
}
|
|
606
580
|
|
|
@@ -631,12 +605,12 @@ async function parseAddons(addons, userRoot2 = process3.cwd()) {
|
|
|
631
605
|
}
|
|
632
606
|
async function readAddonModule(name, options = {}) {
|
|
633
607
|
const root = await getAddonRoot(name, options.cwd || process3.cwd());
|
|
634
|
-
const packageJSONPath =
|
|
635
|
-
if (!await
|
|
608
|
+
const packageJSONPath = resolve2(root, "./package.json");
|
|
609
|
+
if (!await fs3.exists(packageJSONPath)) {
|
|
636
610
|
logger.error(`No addon named ${name} found`);
|
|
637
611
|
return;
|
|
638
612
|
}
|
|
639
|
-
const packageJSON = await
|
|
613
|
+
const packageJSON = await fs3.readJSON(packageJSONPath);
|
|
640
614
|
const resolver = {
|
|
641
615
|
enable: true,
|
|
642
616
|
name: packageJSON.name,
|
|
@@ -714,9 +688,9 @@ async function processSiteConfig(options) {
|
|
|
714
688
|
const siteConfig = config.siteConfig;
|
|
715
689
|
siteConfig.url = ensureSuffix("/", siteConfig.url || "");
|
|
716
690
|
siteConfig.cdn.prefix = ensureSuffix("/", siteConfig.cdn.prefix || "");
|
|
717
|
-
const themePkgPath =
|
|
691
|
+
const themePkgPath = resolve3(themeRoot, "package.json");
|
|
718
692
|
try {
|
|
719
|
-
config.themeConfig.pkg = await
|
|
693
|
+
config.themeConfig.pkg = await fs4.readJson(themePkgPath, "utf-8");
|
|
720
694
|
} catch (e) {
|
|
721
695
|
console.error(`valaxy-theme-${theme} doesn't have package.json`);
|
|
722
696
|
}
|
|
@@ -754,16 +728,16 @@ async function processValaxyOptions(valaxyOptions, valaxyConfig) {
|
|
|
754
728
|
}
|
|
755
729
|
async function resolveOptions(options = { userRoot: process4.cwd() }, mode = "dev") {
|
|
756
730
|
const pkgRoot = dirname2(await resolveImportPath("valaxy/package.json", true));
|
|
757
|
-
const clientRoot =
|
|
758
|
-
const userRoot2 =
|
|
759
|
-
|
|
731
|
+
const clientRoot = resolve3(pkgRoot, "client");
|
|
732
|
+
const userRoot2 = resolve3(options.userRoot || process4.cwd());
|
|
733
|
+
consola6.start(`Resolve ${colors6.magenta("valaxy")} config ...`);
|
|
760
734
|
const [resolvedValaxy, resolvedSite, resolvedTheme, pages] = await Promise.all([
|
|
761
735
|
resolveValaxyConfig(options),
|
|
762
736
|
resolveSiteConfig(options.userRoot),
|
|
763
737
|
// resolveThemeConfig(options),
|
|
764
738
|
resolveThemeConfigFromRoot(options.userRoot),
|
|
765
739
|
fg(["**.md"], {
|
|
766
|
-
cwd:
|
|
740
|
+
cwd: resolve3(userRoot2, "pages"),
|
|
767
741
|
ignore: ["**/node_modules"]
|
|
768
742
|
})
|
|
769
743
|
]);
|
|
@@ -776,7 +750,7 @@ async function resolveOptions(options = { userRoot: process4.cwd() }, mode = "de
|
|
|
776
750
|
let valaxyOptions = {
|
|
777
751
|
mode,
|
|
778
752
|
pkgRoot,
|
|
779
|
-
tempDir:
|
|
753
|
+
tempDir: resolve3(userRoot2, ".valaxy"),
|
|
780
754
|
clientRoot,
|
|
781
755
|
userRoot: userRoot2,
|
|
782
756
|
themeRoot,
|
|
@@ -808,7 +782,7 @@ async function resolveOptions(options = { userRoot: process4.cwd() }, mode = "de
|
|
|
808
782
|
const themeValaxyConfig = await resolveThemeValaxyConfig(valaxyOptions);
|
|
809
783
|
const valaxyConfig = mergeValaxyConfig(userValaxyConfig, themeValaxyConfig);
|
|
810
784
|
valaxyOptions = await processValaxyOptions(valaxyOptions, valaxyConfig);
|
|
811
|
-
|
|
785
|
+
fs4.ensureDirSync(valaxyOptions.tempDir);
|
|
812
786
|
return valaxyOptions;
|
|
813
787
|
}
|
|
814
788
|
async function resolveThemeValaxyConfig(options) {
|
|
@@ -816,7 +790,7 @@ async function resolveThemeValaxyConfig(options) {
|
|
|
816
790
|
const { config: themeValaxyConfig } = await resolveValaxyConfigFromRoot(options.themeRoot, options);
|
|
817
791
|
const duration = endCount();
|
|
818
792
|
if (themeValaxyConfig)
|
|
819
|
-
|
|
793
|
+
consola6.success(`Resolve ${colors6.cyan("valaxy.config.ts")} from ${colors6.blue(`theme(${options.theme})`)} ${colors6.yellow(duration)}`);
|
|
820
794
|
return themeValaxyConfig;
|
|
821
795
|
}
|
|
822
796
|
|
|
@@ -874,15 +848,15 @@ var matterOptions = {
|
|
|
874
848
|
// node/utils/env.ts
|
|
875
849
|
import path3 from "path";
|
|
876
850
|
import process5 from "process";
|
|
877
|
-
import { consola as
|
|
878
|
-
import
|
|
851
|
+
import { consola as consola7 } from "consola";
|
|
852
|
+
import fs5 from "fs-extra";
|
|
879
853
|
function isProd() {
|
|
880
854
|
return process5.env.NODE_ENV === "production";
|
|
881
855
|
}
|
|
882
856
|
function setEnv(env = "development") {
|
|
883
857
|
process5.env.NODE_ENV = env;
|
|
884
|
-
|
|
885
|
-
logger.level =
|
|
858
|
+
consola7.level = isProd() ? 2 : 3;
|
|
859
|
+
logger.level = consola7.level;
|
|
886
860
|
}
|
|
887
861
|
function setEnvProd() {
|
|
888
862
|
return setEnv("production");
|
|
@@ -891,7 +865,7 @@ function setTimezone(timezone) {
|
|
|
891
865
|
process5.env.TZ = timezone;
|
|
892
866
|
}
|
|
893
867
|
async function isPagesDirExist(root) {
|
|
894
|
-
const exist = await
|
|
868
|
+
const exist = await fs5.exists(path3.resolve(root, "pages"));
|
|
895
869
|
if (!exist)
|
|
896
870
|
logger.error(`No pages directory found in ${root}`);
|
|
897
871
|
return exist;
|
|
@@ -899,15 +873,16 @@ async function isPagesDirExist(root) {
|
|
|
899
873
|
|
|
900
874
|
// node/modules/fuse.ts
|
|
901
875
|
async function generateFuseList(options) {
|
|
902
|
-
|
|
903
|
-
const
|
|
876
|
+
consola8.start(`Generate List for Fuse Search by (${colors7.cyan("fuse.js")}) ...`);
|
|
877
|
+
const pattern = options.config.siteConfig.fuse.pattern || path4.join(options.userRoot, "pages/**/*.md");
|
|
878
|
+
const files = await fg2(pattern);
|
|
904
879
|
const posts = [];
|
|
905
880
|
for await (const i of files) {
|
|
906
|
-
const raw =
|
|
881
|
+
const raw = fs6.readFileSync(i, "utf-8");
|
|
907
882
|
const { data, excerpt, content } = matter(raw, matterOptions);
|
|
908
883
|
const fmData = data;
|
|
909
884
|
if (fmData.draft) {
|
|
910
|
-
|
|
885
|
+
consola8.warn(`Ignore draft post: ${colors7.dim(i)}`);
|
|
911
886
|
continue;
|
|
912
887
|
}
|
|
913
888
|
if (fmData.hide)
|
|
@@ -937,30 +912,30 @@ async function generateFuseList(options) {
|
|
|
937
912
|
return posts;
|
|
938
913
|
}
|
|
939
914
|
async function execFuse(options) {
|
|
940
|
-
|
|
915
|
+
consola8.info("Start generate fuse list...");
|
|
941
916
|
const fuseList = await generateFuseList(options);
|
|
942
|
-
await
|
|
917
|
+
await fs6.ensureDir("./dist");
|
|
943
918
|
const publicFolder = path4.resolve(options.userRoot, "public");
|
|
944
919
|
const publicFuseFile = path4.resolve(publicFolder, options.config.siteConfig.fuse.dataPath);
|
|
945
920
|
const publicRelativeFile = path4.join("public", options.config.siteConfig.fuse.dataPath);
|
|
946
|
-
await
|
|
947
|
-
|
|
948
|
-
|
|
921
|
+
await fs6.ensureFile(publicFuseFile);
|
|
922
|
+
fs6.writeJSONSync(publicFuseFile, fuseList);
|
|
923
|
+
consola8.success(`Generate fuse list in ${colors7.dim(publicFolder)}`);
|
|
949
924
|
const distFolder = path4.resolve(options.userRoot, "dist");
|
|
950
925
|
const distFuseFile = path4.resolve(distFolder, options.config.siteConfig.fuse.dataPath);
|
|
951
|
-
await
|
|
952
|
-
|
|
953
|
-
|
|
926
|
+
await fs6.ensureDir(distFolder);
|
|
927
|
+
fs6.writeJSONSync(distFuseFile, fuseList);
|
|
928
|
+
consola8.success(`Generate fuse list in ${colors7.dim(distFolder)}`);
|
|
954
929
|
try {
|
|
955
930
|
const gitignorePath = path4.resolve(options.userRoot, ".gitignore");
|
|
956
|
-
const gitignore = await
|
|
931
|
+
const gitignore = await fs6.readFile(gitignorePath, "utf-8");
|
|
957
932
|
const ignorePath = publicRelativeFile.replace(/\\/g, "/");
|
|
958
933
|
if (!gitignore.includes(ignorePath)) {
|
|
959
|
-
await
|
|
934
|
+
await fs6.appendFile(gitignorePath, `
|
|
960
935
|
# valaxy fuse
|
|
961
936
|
${ignorePath}
|
|
962
937
|
`);
|
|
963
|
-
|
|
938
|
+
consola8.success(`Add ${colors7.dim(ignorePath)} to ${colors7.dim(".gitignore")}`);
|
|
964
939
|
}
|
|
965
940
|
} catch {
|
|
966
941
|
}
|
|
@@ -990,26 +965,26 @@ var fuseModule = defineValaxyModule({
|
|
|
990
965
|
|
|
991
966
|
// node/modules/rss/utils.ts
|
|
992
967
|
import { readFile } from "fs/promises";
|
|
993
|
-
import { dirname as dirname3, join, resolve as
|
|
968
|
+
import { dirname as dirname3, join, resolve as resolve4 } from "path";
|
|
994
969
|
import { ensurePrefix as ensurePrefix2 } from "@antfu/utils";
|
|
995
|
-
import { consola as
|
|
970
|
+
import { consola as consola9 } from "consola";
|
|
996
971
|
import { colors as colors8 } from "consola/utils";
|
|
997
972
|
import dayjs from "dayjs";
|
|
998
973
|
import fg3 from "fast-glob";
|
|
999
974
|
import { Feed } from "feed";
|
|
1000
|
-
import
|
|
975
|
+
import fs8 from "fs-extra";
|
|
1001
976
|
import matter2 from "gray-matter";
|
|
1002
977
|
import MarkdownIt from "markdown-it";
|
|
1003
978
|
import ora3 from "ora";
|
|
1004
979
|
import { getBorderCharacters, table } from "table";
|
|
1005
980
|
|
|
1006
981
|
// node/utils/date.ts
|
|
1007
|
-
import
|
|
982
|
+
import fs7 from "fs-extra";
|
|
1008
983
|
async function getCreatedTime(file) {
|
|
1009
|
-
return await getGitTimestamp(file, "created") || (await
|
|
984
|
+
return await getGitTimestamp(file, "created") || (await fs7.stat(file)).ctime;
|
|
1010
985
|
}
|
|
1011
986
|
async function getUpdatedTime(file) {
|
|
1012
|
-
return await getGitTimestamp(file, "created") || (await
|
|
987
|
+
return await getGitTimestamp(file, "created") || (await fs7.stat(file)).mtime;
|
|
1013
988
|
}
|
|
1014
989
|
|
|
1015
990
|
// node/modules/rss/utils.ts
|
|
@@ -1024,7 +999,7 @@ async function build(options) {
|
|
|
1024
999
|
const siteConfig = config.siteConfig;
|
|
1025
1000
|
const lang = siteConfig.lang || "en";
|
|
1026
1001
|
if (!siteConfig.url || siteConfig.url === "/") {
|
|
1027
|
-
|
|
1002
|
+
consola9.error("You must set `url` (like `https://example.com`) in `site.config.ts` to generate rss.");
|
|
1028
1003
|
return;
|
|
1029
1004
|
}
|
|
1030
1005
|
const siteUrl = siteConfig.url;
|
|
@@ -1127,9 +1102,9 @@ async function getPosts(params, options) {
|
|
|
1127
1102
|
async function writeFeed(feedOptions, posts, options, feedNameMap) {
|
|
1128
1103
|
const feed = new Feed(feedOptions);
|
|
1129
1104
|
posts.forEach((item) => feed.addItem(item));
|
|
1130
|
-
await
|
|
1131
|
-
const path18 =
|
|
1132
|
-
const publicFolder =
|
|
1105
|
+
await fs8.ensureDir(dirname3(`./dist/${feedNameMap.atom}`));
|
|
1106
|
+
const path18 = resolve4(options.userRoot, "./dist");
|
|
1107
|
+
const publicFolder = resolve4(options.userRoot, "public");
|
|
1133
1108
|
const { config } = options;
|
|
1134
1109
|
const siteConfig = config.siteConfig;
|
|
1135
1110
|
const now = dayjs().format("YYYY-MM-DD HH:mm:ss zzz");
|
|
@@ -1148,24 +1123,24 @@ async function writeFeed(feedOptions, posts, options, feedNameMap) {
|
|
|
1148
1123
|
data = feed.atom1();
|
|
1149
1124
|
else if (type === "json")
|
|
1150
1125
|
data = feed.json1();
|
|
1151
|
-
await
|
|
1152
|
-
|
|
1126
|
+
await fs8.writeFile(distFeedPath, data, "utf-8");
|
|
1127
|
+
consola9.debug(`[${colors8.cyan(type)}] dist: ${colors8.dim(distFeedPath)}`);
|
|
1153
1128
|
tableData.push([colors8.cyan(type), colors8.yellow("dist"), colors8.dim(distFeedPath)]);
|
|
1154
|
-
const publicFeedPath =
|
|
1129
|
+
const publicFeedPath = resolve4(publicFolder, feedNameMap[type]);
|
|
1155
1130
|
const publicRelativeFile = join("public", feedNameMap[type]);
|
|
1156
|
-
await
|
|
1157
|
-
|
|
1131
|
+
await fs8.writeFile(publicFeedPath, data, "utf-8");
|
|
1132
|
+
consola9.debug(`[${colors8.cyan(type)}] public: ${colors8.dim(publicFeedPath)}`);
|
|
1158
1133
|
tableData.push(["", colors8.green("public"), colors8.dim(publicFeedPath)]);
|
|
1159
1134
|
try {
|
|
1160
|
-
const gitignorePath =
|
|
1161
|
-
const gitignore = await
|
|
1135
|
+
const gitignorePath = resolve4(options.userRoot, ".gitignore");
|
|
1136
|
+
const gitignore = await fs8.readFile(gitignorePath, "utf-8");
|
|
1162
1137
|
const ignorePath = publicRelativeFile.replace(/\\/g, "/");
|
|
1163
1138
|
if (!gitignore.includes(ignorePath)) {
|
|
1164
|
-
await
|
|
1139
|
+
await fs8.appendFile(gitignorePath, `
|
|
1165
1140
|
# valaxy rss
|
|
1166
1141
|
${ignorePath}
|
|
1167
1142
|
`);
|
|
1168
|
-
|
|
1143
|
+
consola9.success(`Add ${colors8.dim(ignorePath)} to ${colors8.dim(".gitignore")}`);
|
|
1169
1144
|
}
|
|
1170
1145
|
} catch {
|
|
1171
1146
|
}
|
|
@@ -1216,15 +1191,15 @@ var rssModule = defineValaxyModule({
|
|
|
1216
1191
|
// node/cli/build.ts
|
|
1217
1192
|
import path14 from "path";
|
|
1218
1193
|
import process9 from "process";
|
|
1219
|
-
import { consola as
|
|
1194
|
+
import { consola as consola15 } from "consola";
|
|
1220
1195
|
import { colors as colors15 } from "consola/utils";
|
|
1221
1196
|
import { mergeConfig as mergeConfig4 } from "vite";
|
|
1222
1197
|
|
|
1223
1198
|
// node/build.ts
|
|
1224
|
-
import { join as join8, resolve as
|
|
1225
|
-
import { consola as
|
|
1199
|
+
import { join as join8, resolve as resolve12 } from "path";
|
|
1200
|
+
import { consola as consola13 } from "consola";
|
|
1226
1201
|
import { colors as colors12 } from "consola/utils";
|
|
1227
|
-
import
|
|
1202
|
+
import fs21 from "fs-extra";
|
|
1228
1203
|
import { mergeConfig as mergeViteConfig2, build as viteBuild } from "vite";
|
|
1229
1204
|
import generateSitemap from "vite-ssg-sitemap";
|
|
1230
1205
|
import { build as viteSsgBuild } from "vite-ssg/node";
|
|
@@ -1232,21 +1207,21 @@ import { build as viteSsgBuild } from "vite-ssg/node";
|
|
|
1232
1207
|
// node/plugins/preset.ts
|
|
1233
1208
|
import VueI18n from "@intlify/unplugin-vue-i18n/vite";
|
|
1234
1209
|
import UnheadVite from "@unhead/addons/vite";
|
|
1235
|
-
import { consola as
|
|
1236
|
-
import { resolve as
|
|
1210
|
+
import { consola as consola12 } from "consola";
|
|
1211
|
+
import { resolve as resolve11 } from "pathe";
|
|
1237
1212
|
import Components from "unplugin-vue-components/vite";
|
|
1238
1213
|
import Layouts from "vite-plugin-vue-layouts";
|
|
1239
1214
|
import { groupIconVitePlugin } from "vitepress-plugin-group-icons";
|
|
1240
1215
|
|
|
1241
1216
|
// node/plugins/extendConfig.ts
|
|
1242
|
-
import { dirname as dirname4, join as join3, resolve as
|
|
1217
|
+
import { dirname as dirname4, join as join3, resolve as resolve5 } from "path";
|
|
1243
1218
|
import { uniq as uniq3 } from "@antfu/utils";
|
|
1244
1219
|
import { mergeConfig as mergeConfig2, searchForWorkspaceRoot } from "vite";
|
|
1245
1220
|
|
|
1246
1221
|
// node/common.ts
|
|
1247
1222
|
import { join as join2 } from "path";
|
|
1248
1223
|
import { uniq as uniq2 } from "@antfu/utils";
|
|
1249
|
-
import
|
|
1224
|
+
import fs9 from "fs-extra";
|
|
1250
1225
|
import { loadConfigFromFile as loadConfigFromFile2, mergeConfig } from "vite";
|
|
1251
1226
|
async function mergeViteConfigs({ userRoot: userRoot2, themeRoot }, command) {
|
|
1252
1227
|
const configEnv = {
|
|
@@ -1256,7 +1231,7 @@ async function mergeViteConfigs({ userRoot: userRoot2, themeRoot }, command) {
|
|
|
1256
1231
|
let resolvedConfig = {};
|
|
1257
1232
|
const files = uniq2([themeRoot, userRoot2]).map((i) => join2(i, "vite.config.ts"));
|
|
1258
1233
|
const loadViteConfigPromiseArr = files.map(async (file) => {
|
|
1259
|
-
if (!await
|
|
1234
|
+
if (!await fs9.exists(file))
|
|
1260
1235
|
return;
|
|
1261
1236
|
return loadConfigFromFile2(configEnv, file);
|
|
1262
1237
|
});
|
|
@@ -1304,9 +1279,9 @@ async function getIndexHtml({ clientRoot, themeRoot, userRoot: userRoot2, config
|
|
|
1304
1279
|
}
|
|
1305
1280
|
for (const root of roots) {
|
|
1306
1281
|
const path18 = join2(root, "index.html");
|
|
1307
|
-
if (!
|
|
1282
|
+
if (!fs9.existsSync(path18))
|
|
1308
1283
|
continue;
|
|
1309
|
-
const indexHtml = await
|
|
1284
|
+
const indexHtml = await fs9.readFile(path18, "utf-8");
|
|
1310
1285
|
head += `
|
|
1311
1286
|
${(indexHtml.match(/<head>([\s\S]*?)<\/head>/i)?.[1] || "").trim()}`;
|
|
1312
1287
|
body += `
|
|
@@ -1397,7 +1372,7 @@ function createConfigPlugin(options) {
|
|
|
1397
1372
|
},
|
|
1398
1373
|
optimizeDeps: {
|
|
1399
1374
|
// do not entry node file
|
|
1400
|
-
entries: [
|
|
1375
|
+
entries: [resolve5(options.clientRoot, "main.ts")],
|
|
1401
1376
|
// must need it
|
|
1402
1377
|
include: includedDeps,
|
|
1403
1378
|
exclude: EXCLUDE
|
|
@@ -1444,14 +1419,14 @@ async function getAlias(options) {
|
|
|
1444
1419
|
{ find: /^#valaxy\/(.*)/, replacement: "/@valaxyjs/$1" },
|
|
1445
1420
|
{ find: "~/", replacement: `${toAtFS(options.userRoot)}/` },
|
|
1446
1421
|
{ find: "valaxy/client/", replacement: `${toAtFS(options.clientRoot)}/` },
|
|
1447
|
-
{ find: "valaxy/package.json", replacement: toAtFS(
|
|
1448
|
-
{ find: /^valaxy$/, replacement: toAtFS(
|
|
1422
|
+
{ find: "valaxy/package.json", replacement: toAtFS(resolve5(options.clientRoot, "../package.json")) },
|
|
1423
|
+
{ find: /^valaxy$/, replacement: toAtFS(resolve5(options.clientRoot, "index.ts")) },
|
|
1449
1424
|
{ find: "@valaxyjs/client/", replacement: `${toAtFS(options.clientRoot)}/` },
|
|
1450
1425
|
// import theme
|
|
1451
1426
|
{ find: "virtual:valaxy-theme", replacement: `${toAtFS(options.themeRoot)}/client/index.ts` },
|
|
1452
|
-
{ find: `valaxy-theme-${options.theme}/client`, replacement: `${toAtFS(
|
|
1453
|
-
{ find: `valaxy-theme-${options.theme}/`, replacement: `${toAtFS(
|
|
1454
|
-
{ find: `valaxy-theme-${options.theme}`, replacement: `${toAtFS(
|
|
1427
|
+
{ find: `valaxy-theme-${options.theme}/client`, replacement: `${toAtFS(resolve5(options.themeRoot))}/client/index.ts` },
|
|
1428
|
+
{ find: `valaxy-theme-${options.theme}/`, replacement: `${toAtFS(resolve5(options.themeRoot))}/` },
|
|
1429
|
+
{ find: `valaxy-theme-${options.theme}`, replacement: `${toAtFS(resolve5(options.themeRoot))}/client/index.ts` }
|
|
1455
1430
|
];
|
|
1456
1431
|
if (options.config.vue?.browserTemplateCompilation) {
|
|
1457
1432
|
alias.push(
|
|
@@ -1461,20 +1436,20 @@ async function getAlias(options) {
|
|
|
1461
1436
|
options.addons.forEach((addon) => {
|
|
1462
1437
|
alias.push({
|
|
1463
1438
|
find: `${addon.name}/client/`,
|
|
1464
|
-
replacement: `${toAtFS(`${
|
|
1439
|
+
replacement: `${toAtFS(`${resolve5(addon.root)}`)}/client/`
|
|
1465
1440
|
});
|
|
1466
1441
|
alias.push({
|
|
1467
1442
|
find: `${addon.name}/App.vue`,
|
|
1468
|
-
replacement: `${toAtFS(
|
|
1443
|
+
replacement: `${toAtFS(resolve5(addon.root))}/App.vue`
|
|
1469
1444
|
});
|
|
1470
1445
|
alias.push({
|
|
1471
1446
|
find: addon.name,
|
|
1472
|
-
replacement: `${toAtFS(
|
|
1447
|
+
replacement: `${toAtFS(resolve5(addon.root))}/client/index.ts`
|
|
1473
1448
|
});
|
|
1474
1449
|
});
|
|
1475
1450
|
alias.push({
|
|
1476
1451
|
find: /^valaxy-addon-(.*)$/,
|
|
1477
|
-
replacement: toAtFS(
|
|
1452
|
+
replacement: toAtFS(resolve5(options.clientRoot, "./addons/index.ts"))
|
|
1478
1453
|
});
|
|
1479
1454
|
return alias;
|
|
1480
1455
|
}
|
|
@@ -2411,7 +2386,7 @@ function lineNumberPlugin(md3, enable = false) {
|
|
|
2411
2386
|
}
|
|
2412
2387
|
|
|
2413
2388
|
// node/plugins/markdown/plugins/markdown-it/snippet.ts
|
|
2414
|
-
import
|
|
2389
|
+
import fs10 from "fs-extra";
|
|
2415
2390
|
import path5 from "pathe";
|
|
2416
2391
|
var rawPathRegexp = /^(.+?(?:\.([a-z0-9]+))?)(#[\w-]+)?(?: ?\{(\d+(?:[,-]\d+)*)? ?(\S+)?\})? ?(?:\[(.+)\])?$/;
|
|
2417
2392
|
function rawPathToToken(rawPath) {
|
|
@@ -2514,13 +2489,13 @@ function snippetPlugin(md3, srcDir) {
|
|
|
2514
2489
|
return fence(...args);
|
|
2515
2490
|
if (includes)
|
|
2516
2491
|
includes.push(src);
|
|
2517
|
-
const isAFile =
|
|
2518
|
-
if (!
|
|
2492
|
+
const isAFile = fs10.statSync(src).isFile();
|
|
2493
|
+
if (!fs10.existsSync(src) || !isAFile) {
|
|
2519
2494
|
token.content = isAFile ? `Code snippet path not found: ${src}` : `Invalid code snippet option`;
|
|
2520
2495
|
token.info = "";
|
|
2521
2496
|
return fence(...args);
|
|
2522
2497
|
}
|
|
2523
|
-
let content =
|
|
2498
|
+
let content = fs10.readFileSync(src, "utf8");
|
|
2524
2499
|
if (regionName) {
|
|
2525
2500
|
const lines = content.split(/\r?\n/);
|
|
2526
2501
|
const region = findRegion(lines, regionName);
|
|
@@ -2683,7 +2658,7 @@ function treatAsHtml(filename) {
|
|
|
2683
2658
|
|
|
2684
2659
|
// node/plugins/markdown/utils/processInclude.ts
|
|
2685
2660
|
import path6 from "path";
|
|
2686
|
-
import
|
|
2661
|
+
import fs11 from "fs-extra";
|
|
2687
2662
|
function processIncludes(srcDir, src, file) {
|
|
2688
2663
|
const includesRE = /<!--\s*@include:\s*(.*?)\s*-->/g;
|
|
2689
2664
|
const rangeRE = /\{(\d*),(\d*)\}$/;
|
|
@@ -2695,7 +2670,7 @@ function processIncludes(srcDir, src, file) {
|
|
|
2695
2670
|
const atPresent = m1[0] === "@";
|
|
2696
2671
|
try {
|
|
2697
2672
|
const includePath = atPresent ? path6.join(srcDir, m1.slice(m1[1] === "/" ? 2 : 1)) : path6.join(path6.dirname(file), m1);
|
|
2698
|
-
let content =
|
|
2673
|
+
let content = fs11.readFileSync(includePath, "utf-8");
|
|
2699
2674
|
if (range) {
|
|
2700
2675
|
const [, startLine, endLine] = range;
|
|
2701
2676
|
const lines = content.split(/\r?\n/);
|
|
@@ -2846,10 +2821,10 @@ function createFixPlugins(options) {
|
|
|
2846
2821
|
|
|
2847
2822
|
// node/plugins/setupClient.ts
|
|
2848
2823
|
import { existsSync } from "fs";
|
|
2849
|
-
import { join as join4, resolve as
|
|
2824
|
+
import { join as join4, resolve as resolve6 } from "path";
|
|
2850
2825
|
import { slash as slash3, uniq as uniq4 } from "@antfu/utils";
|
|
2851
2826
|
function createClientSetupPlugin({ clientRoot, themeRoot, userRoot: userRoot2 }) {
|
|
2852
|
-
const setupEntry = slash3(
|
|
2827
|
+
const setupEntry = slash3(resolve6(clientRoot, "setup"));
|
|
2853
2828
|
return {
|
|
2854
2829
|
name: "valaxy:setup",
|
|
2855
2830
|
enforce: "pre",
|
|
@@ -2888,10 +2863,10 @@ function createClientSetupPlugin({ clientRoot, themeRoot, userRoot: userRoot2 })
|
|
|
2888
2863
|
}
|
|
2889
2864
|
|
|
2890
2865
|
// node/plugins/unocss.ts
|
|
2891
|
-
import { resolve as
|
|
2866
|
+
import { resolve as resolve8 } from "path";
|
|
2892
2867
|
import defu3 from "defu";
|
|
2893
|
-
import
|
|
2894
|
-
import { createJiti as
|
|
2868
|
+
import fs13 from "fs-extra";
|
|
2869
|
+
import { createJiti as createJiti2 } from "jiti";
|
|
2895
2870
|
import {
|
|
2896
2871
|
presetAttributify,
|
|
2897
2872
|
presetIcons,
|
|
@@ -2902,11 +2877,11 @@ import {
|
|
|
2902
2877
|
} from "unocss";
|
|
2903
2878
|
|
|
2904
2879
|
// node/plugins/setupNode.ts
|
|
2905
|
-
import { resolve as
|
|
2880
|
+
import { resolve as resolve7 } from "path";
|
|
2906
2881
|
import { isObject } from "@antfu/utils";
|
|
2907
|
-
import
|
|
2908
|
-
import { createJiti
|
|
2909
|
-
var
|
|
2882
|
+
import fs12 from "fs-extra";
|
|
2883
|
+
import { createJiti } from "jiti";
|
|
2884
|
+
var jiti = createJiti(import.meta.url);
|
|
2910
2885
|
function deepMerge(a, b, rootPath = "") {
|
|
2911
2886
|
a = { ...a };
|
|
2912
2887
|
Object.keys(b).forEach((key) => {
|
|
@@ -2922,9 +2897,9 @@ function deepMerge(a, b, rootPath = "") {
|
|
|
2922
2897
|
async function loadSetups(roots, name, arg, initial, merge = true) {
|
|
2923
2898
|
let returns = initial;
|
|
2924
2899
|
for (const root of roots) {
|
|
2925
|
-
const path18 =
|
|
2926
|
-
if (
|
|
2927
|
-
const setup = await
|
|
2900
|
+
const path18 = resolve7(root, "setup", name);
|
|
2901
|
+
if (fs12.existsSync(path18)) {
|
|
2902
|
+
const setup = await jiti.import(path18, { default: true });
|
|
2928
2903
|
const result = await setup(arg);
|
|
2929
2904
|
if (result !== null) {
|
|
2930
2905
|
returns = merge ? deepMerge(returns, result) : result;
|
|
@@ -2935,7 +2910,7 @@ async function loadSetups(roots, name, arg, initial, merge = true) {
|
|
|
2935
2910
|
}
|
|
2936
2911
|
|
|
2937
2912
|
// node/plugins/unocss.ts
|
|
2938
|
-
var
|
|
2913
|
+
var jiti2 = createJiti2(import.meta.url);
|
|
2939
2914
|
async function createSafelist(options) {
|
|
2940
2915
|
const { config } = options;
|
|
2941
2916
|
const safeIcons = [
|
|
@@ -3034,14 +3009,14 @@ async function createUnocssPlugin(options) {
|
|
|
3034
3009
|
const dirs = [themeRoot, clientRoot];
|
|
3035
3010
|
dirs.forEach(
|
|
3036
3011
|
(dir) => unoConfigFiles.forEach(
|
|
3037
|
-
(file) => configFiles.push(
|
|
3012
|
+
(file) => configFiles.push(resolve8(dir, file))
|
|
3038
3013
|
)
|
|
3039
3014
|
);
|
|
3040
3015
|
let config = {};
|
|
3041
3016
|
const configDeps = [];
|
|
3042
3017
|
for (const configFile of configFiles) {
|
|
3043
|
-
if (await
|
|
3044
|
-
const uConfig = await
|
|
3018
|
+
if (await fs13.exists(configFile)) {
|
|
3019
|
+
const uConfig = await jiti2.import(configFile, { default: true });
|
|
3045
3020
|
config = defu3(config, uConfig);
|
|
3046
3021
|
configDeps.push(configFile);
|
|
3047
3022
|
}
|
|
@@ -3055,19 +3030,19 @@ async function createUnocssPlugin(options) {
|
|
|
3055
3030
|
}
|
|
3056
3031
|
|
|
3057
3032
|
// node/plugins/valaxy/index.ts
|
|
3058
|
-
import { consola as
|
|
3033
|
+
import { consola as consola11 } from "consola";
|
|
3059
3034
|
import { colors as colors11 } from "consola/utils";
|
|
3060
|
-
import
|
|
3061
|
-
import { join as join7, relative, resolve as
|
|
3035
|
+
import fs19 from "fs-extra";
|
|
3036
|
+
import { join as join7, relative, resolve as resolve9 } from "pathe";
|
|
3062
3037
|
|
|
3063
3038
|
// node/virtual/addons.ts
|
|
3064
|
-
import
|
|
3039
|
+
import fs14 from "fs-extra";
|
|
3065
3040
|
import pascalCase from "pascalcase";
|
|
3066
3041
|
import { join as join5 } from "pathe";
|
|
3067
3042
|
var templateAddons = {
|
|
3068
3043
|
id: "/@valaxyjs/addons",
|
|
3069
3044
|
async getContent(options) {
|
|
3070
|
-
const globalAddonComponents = options.addons.filter((v) => v.global).filter((v) =>
|
|
3045
|
+
const globalAddonComponents = options.addons.filter((v) => v.global).filter((v) => fs14.existsSync(join5(v.root, "./App.vue")));
|
|
3071
3046
|
const spliceImportName = (str) => `Addon${pascalCase(str)}App`;
|
|
3072
3047
|
const imports = globalAddonComponents.map((addon) => `import ${spliceImportName(addon.name)} from "${addon.name}/App.vue"`).join("\n");
|
|
3073
3048
|
const components = globalAddonComponents.map((addon) => `{ component: ${spliceImportName(addon.name)}, props: ${JSON.stringify(addon.props)} }`).join(",");
|
|
@@ -3078,17 +3053,17 @@ export default [${components}]`;
|
|
|
3078
3053
|
|
|
3079
3054
|
// node/virtual/blogs.ts
|
|
3080
3055
|
import path8 from "path";
|
|
3081
|
-
import
|
|
3056
|
+
import fs15 from "fs-extra";
|
|
3082
3057
|
function createBlogTemplate(name) {
|
|
3083
3058
|
return {
|
|
3084
3059
|
id: `/@valaxyjs/blog/${name}s`,
|
|
3085
3060
|
async getContent({ userRoot: userRoot2 }) {
|
|
3086
3061
|
const root = path8.resolve(userRoot2, "pages", "collections");
|
|
3087
|
-
if (!await
|
|
3062
|
+
if (!await fs15.pathExists(root)) {
|
|
3088
3063
|
return `export default []`;
|
|
3089
3064
|
}
|
|
3090
|
-
const isDir = (file) =>
|
|
3091
|
-
const files =
|
|
3065
|
+
const isDir = (file) => fs15.statSync(path8.join(root, file)).isDirectory();
|
|
3066
|
+
const files = fs15.readdirSync(root).filter((file) => isDir(file)).map((file) => path8.join(root, file, "index.ts"));
|
|
3092
3067
|
const imports = [];
|
|
3093
3068
|
const getImportedName = (idx) => `__valaxy_${name}_${idx + 1}`;
|
|
3094
3069
|
files.forEach((file, idx) => {
|
|
@@ -3124,7 +3099,7 @@ var templateConfig = {
|
|
|
3124
3099
|
};
|
|
3125
3100
|
|
|
3126
3101
|
// node/virtual/locales.ts
|
|
3127
|
-
import
|
|
3102
|
+
import fs16 from "fs-extra";
|
|
3128
3103
|
var templateLocales = {
|
|
3129
3104
|
id: "/@valaxyjs/locales",
|
|
3130
3105
|
async getContent({ roots, config }) {
|
|
@@ -3144,7 +3119,7 @@ var templateLocales = {
|
|
|
3144
3119
|
roots.forEach((root, i) => {
|
|
3145
3120
|
languages.forEach((lang) => {
|
|
3146
3121
|
const langYml = `${root}/locales/${lang}.yml`;
|
|
3147
|
-
if (
|
|
3122
|
+
if (fs16.existsSync(langYml) && fs16.readFileSync(langYml, "utf-8")) {
|
|
3148
3123
|
const varName = lang.replace("-", "") + i;
|
|
3149
3124
|
imports.unshift(`import ${varName} from "${toAtFS(langYml)}"`);
|
|
3150
3125
|
imports.push(`messages['${lang}'] = replaceArrMerge(${varName}, messages['${lang}'])`);
|
|
@@ -3259,7 +3234,7 @@ function createTransformCodeBlock(options) {
|
|
|
3259
3234
|
|
|
3260
3235
|
// node/plugins/markdown/transform/dead-links.ts
|
|
3261
3236
|
import { slash as slash4 } from "@antfu/utils";
|
|
3262
|
-
import
|
|
3237
|
+
import fs17 from "fs-extra";
|
|
3263
3238
|
import path9 from "pathe";
|
|
3264
3239
|
function createScanDeadLinks(options) {
|
|
3265
3240
|
const srcDir = path9.resolve(options.userRoot, "pages");
|
|
@@ -3306,7 +3281,7 @@ function createScanDeadLinks(options) {
|
|
|
3306
3281
|
)
|
|
3307
3282
|
// /index => /
|
|
3308
3283
|
).replace(/\/index$/, "");
|
|
3309
|
-
if (!options.pages.includes(resolved) && !
|
|
3284
|
+
if (!options.pages.includes(resolved) && !fs17.existsSync(path9.resolve(dir, publicDir, `${resolved}.html`)) && !shouldIgnoreDeadLink(url)) {
|
|
3310
3285
|
recordDeadLink(url);
|
|
3311
3286
|
}
|
|
3312
3287
|
}
|
|
@@ -3453,11 +3428,11 @@ function transformFootnoteTooltip(code, _id) {
|
|
|
3453
3428
|
}
|
|
3454
3429
|
|
|
3455
3430
|
// node/plugins/markdown/transform/hexo.ts
|
|
3456
|
-
import { consola as
|
|
3431
|
+
import { consola as consola10 } from "consola";
|
|
3457
3432
|
import { colors as colors10 } from "consola/utils";
|
|
3458
3433
|
function transformHexoTags(code, id) {
|
|
3459
3434
|
if (code.includes("{%") && code.includes("%}")) {
|
|
3460
|
-
|
|
3435
|
+
consola10.error(
|
|
3461
3436
|
`${`${id}
|
|
3462
3437
|
`} Please ${colors10.red("remove")} ${colors10.cyan("{% %}")}, because it conflicts with ${colors10.yellow("markdown-it-attrs")}.`
|
|
3463
3438
|
);
|
|
@@ -3469,7 +3444,7 @@ function transformHexoTags(code, id) {
|
|
|
3469
3444
|
|
|
3470
3445
|
// node/plugins/markdown/transform/markdown.ts
|
|
3471
3446
|
import path10 from "path";
|
|
3472
|
-
import
|
|
3447
|
+
import fs18 from "fs-extra";
|
|
3473
3448
|
function genProvideCode(name, data) {
|
|
3474
3449
|
return [
|
|
3475
3450
|
`const $${name} = ${transformObject(data)}`,
|
|
@@ -3501,7 +3476,7 @@ function injectPageDataCode(pageData) {
|
|
|
3501
3476
|
}
|
|
3502
3477
|
function createTransformMarkdown(options) {
|
|
3503
3478
|
const loaderVuePath = path10.resolve(options.clientRoot, "templates", "loader.vue");
|
|
3504
|
-
const loaderVue =
|
|
3479
|
+
const loaderVue = fs18.readFileSync(loaderVuePath, "utf-8");
|
|
3505
3480
|
return (code, id, pageData) => {
|
|
3506
3481
|
const isDev = options.mode === "dev";
|
|
3507
3482
|
if (!isDev) {
|
|
@@ -3653,7 +3628,7 @@ async function createMarkdownToVueRenderFn(options, _viteConfig) {
|
|
|
3653
3628
|
var nullVue = 'import { defineComponent } from "vue"; export default defineComponent({ render: () => null });';
|
|
3654
3629
|
function generateAppVue(root) {
|
|
3655
3630
|
const appVue = join7(root, "App.vue");
|
|
3656
|
-
if (!
|
|
3631
|
+
if (!fs19.existsSync(appVue))
|
|
3657
3632
|
return nullVue;
|
|
3658
3633
|
const scripts = [
|
|
3659
3634
|
`import AppVue from "${toAtFS(appVue)}"`,
|
|
@@ -3725,8 +3700,8 @@ async function createValaxyPlugin(options, serverOptions = {}) {
|
|
|
3725
3700
|
const { code: newCode, deadLinks, includes } = await markdownToVue(code, id);
|
|
3726
3701
|
if (deadLinks.length) {
|
|
3727
3702
|
hasDeadLinks = true;
|
|
3728
|
-
|
|
3729
|
-
|
|
3703
|
+
consola11.error(`Dead links found in ${id}`);
|
|
3704
|
+
consola11.error(deadLinks);
|
|
3730
3705
|
}
|
|
3731
3706
|
if (includes.length) {
|
|
3732
3707
|
includes.forEach((i) => {
|
|
@@ -3773,7 +3748,7 @@ async function createValaxyPlugin(options, serverOptions = {}) {
|
|
|
3773
3748
|
valaxyConfig.themeConfig = themeConfig;
|
|
3774
3749
|
return reloadConfigAndEntries(valaxyConfig);
|
|
3775
3750
|
}
|
|
3776
|
-
if (file ===
|
|
3751
|
+
if (file === resolve9(options.themeRoot, "valaxy.config.ts")) {
|
|
3777
3752
|
const themeValaxyConfig = await resolveThemeValaxyConfig(options);
|
|
3778
3753
|
const valaxyConfig2 = mergeValaxyConfig(options.config, themeValaxyConfig);
|
|
3779
3754
|
const { config } = await processValaxyOptions(options, valaxyConfig2);
|
|
@@ -3812,11 +3787,11 @@ async function createValaxyPlugin(options, serverOptions = {}) {
|
|
|
3812
3787
|
}
|
|
3813
3788
|
|
|
3814
3789
|
// node/plugins/vueRouter.ts
|
|
3815
|
-
import
|
|
3790
|
+
import fs20 from "fs-extra";
|
|
3816
3791
|
import matter3 from "gray-matter";
|
|
3817
3792
|
import { convert } from "html-to-text";
|
|
3818
3793
|
import { MarkdownItAsync } from "markdown-it-async";
|
|
3819
|
-
import { resolve as
|
|
3794
|
+
import { resolve as resolve10 } from "pathe";
|
|
3820
3795
|
import VueRouter from "unplugin-vue-router/vite";
|
|
3821
3796
|
|
|
3822
3797
|
// node/plugins/presets/statistics.ts
|
|
@@ -3893,7 +3868,7 @@ async function createRouterPlugin(valaxyApp) {
|
|
|
3893
3868
|
return VueRouter({
|
|
3894
3869
|
extensions: [".vue", ".md"],
|
|
3895
3870
|
routesFolder: roots.map((root) => `${root}/pages`),
|
|
3896
|
-
dts:
|
|
3871
|
+
dts: resolve10(options.tempDir, "typed-router.d.ts"),
|
|
3897
3872
|
...valaxyConfig.router,
|
|
3898
3873
|
/**
|
|
3899
3874
|
* @experimental See https://github.com/posva/unplugin-vue-router/issues/43
|
|
@@ -3932,7 +3907,7 @@ async function createRouterPlugin(valaxyApp) {
|
|
|
3932
3907
|
}
|
|
3933
3908
|
const path18 = route.components.get("default") || "";
|
|
3934
3909
|
if (path18.endsWith(".md")) {
|
|
3935
|
-
const md3 =
|
|
3910
|
+
const md3 = fs20.readFileSync(path18, "utf-8");
|
|
3936
3911
|
const { data, excerpt, content } = matter3(md3, matterOptions);
|
|
3937
3912
|
const mdFm = data;
|
|
3938
3913
|
const lastUpdated = options.config.siteConfig.lastUpdated;
|
|
@@ -3942,10 +3917,10 @@ async function createRouterPlugin(valaxyApp) {
|
|
|
3942
3917
|
delete mdFm.photos;
|
|
3943
3918
|
}
|
|
3944
3919
|
if (!mdFm.date)
|
|
3945
|
-
mdFm.date = (await
|
|
3920
|
+
mdFm.date = (await fs20.stat(path18)).mtime;
|
|
3946
3921
|
if (lastUpdated) {
|
|
3947
3922
|
if (!mdFm.updated)
|
|
3948
|
-
mdFm.updated = (await
|
|
3923
|
+
mdFm.updated = (await fs20.stat(path18)).ctime;
|
|
3949
3924
|
}
|
|
3950
3925
|
if (mdFm.from) {
|
|
3951
3926
|
if (Array.isArray(mdFm.from)) {
|
|
@@ -4074,7 +4049,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
|
|
|
4074
4049
|
* latter override former
|
|
4075
4050
|
*/
|
|
4076
4051
|
dirs: componentsDirs,
|
|
4077
|
-
dts:
|
|
4052
|
+
dts: resolve11(options.tempDir, "components.d.ts"),
|
|
4078
4053
|
...valaxyConfig.components
|
|
4079
4054
|
}),
|
|
4080
4055
|
// https://github.com/antfu/unocss
|
|
@@ -4102,10 +4077,10 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
|
|
|
4102
4077
|
);
|
|
4103
4078
|
} catch (e) {
|
|
4104
4079
|
console.error(e);
|
|
4105
|
-
|
|
4106
|
-
|
|
4080
|
+
consola12.error("Failed to load rollup-plugin-visualizer");
|
|
4081
|
+
consola12.error("Please install `rollup-plugin-visualizer` to enable the feature");
|
|
4107
4082
|
console.log();
|
|
4108
|
-
|
|
4083
|
+
consola12.info("pnpm add -D rollup-plugin-visualizer");
|
|
4109
4084
|
console.log();
|
|
4110
4085
|
}
|
|
4111
4086
|
}
|
|
@@ -4218,7 +4193,7 @@ async function ssgBuild(valaxyApp, viteConfig = {}) {
|
|
|
4218
4193
|
const newPaths = paths;
|
|
4219
4194
|
const posts = paths.filter((path18) => path18.startsWith("/posts/"));
|
|
4220
4195
|
const pageNumber = Math.ceil(posts.length / options.config.siteConfig.pageSize);
|
|
4221
|
-
|
|
4196
|
+
consola13.info(`Generate ${colors12.yellow(pageNumber)} pages for pagination.`);
|
|
4222
4197
|
for (let i = 1; i <= pageNumber; i++)
|
|
4223
4198
|
newPaths.push(`/page/${i}`);
|
|
4224
4199
|
if (!options.config.vite?.ssgOptions?.includeAllRoutes)
|
|
@@ -4232,28 +4207,28 @@ async function ssgBuild(valaxyApp, viteConfig = {}) {
|
|
|
4232
4207
|
}
|
|
4233
4208
|
async function postProcessForSSG(options) {
|
|
4234
4209
|
const { userRoot: userRoot2 } = options;
|
|
4235
|
-
const indexPath =
|
|
4236
|
-
if (
|
|
4237
|
-
|
|
4238
|
-
const indexFile = await
|
|
4210
|
+
const indexPath = resolve12(userRoot2, "dist/index.html");
|
|
4211
|
+
if (fs21.existsSync(indexPath)) {
|
|
4212
|
+
consola13.info("post process for ssg...");
|
|
4213
|
+
const indexFile = await fs21.readFile(indexPath, "utf-8");
|
|
4239
4214
|
const htmlTag = "</html>";
|
|
4240
4215
|
if (!indexFile.endsWith(htmlTag)) {
|
|
4241
|
-
|
|
4216
|
+
consola13.warn("fix incomplete index.html...");
|
|
4242
4217
|
const htmlTagStart = indexFile.lastIndexOf(htmlTag);
|
|
4243
|
-
await
|
|
4218
|
+
await fs21.writeFile(indexPath, indexFile.slice(0, htmlTagStart + htmlTag.length), "utf-8");
|
|
4244
4219
|
}
|
|
4245
4220
|
}
|
|
4246
4221
|
if (!options.config.siteConfig.redirects?.useVueRouter)
|
|
4247
4222
|
await generateClientRedirects(options);
|
|
4248
4223
|
}
|
|
4249
4224
|
async function generateClientRedirects(options) {
|
|
4250
|
-
|
|
4251
|
-
const outputPath =
|
|
4225
|
+
consola13.info("generate client redirects...");
|
|
4226
|
+
const outputPath = resolve12(options.userRoot, "dist");
|
|
4252
4227
|
const redirectRules = collectRedirects(options.redirects);
|
|
4253
4228
|
const task = redirectRules.map(async (rule) => {
|
|
4254
4229
|
const fromPath = join8(outputPath, `${rule.from}.html`);
|
|
4255
4230
|
const toPath = join8(outputPath, `${rule.to}.html`);
|
|
4256
|
-
const routeExist = await
|
|
4231
|
+
const routeExist = await fs21.pathExists(toPath);
|
|
4257
4232
|
if (!routeExist)
|
|
4258
4233
|
throw new Error(`the route of '${rule.to}' not exists`);
|
|
4259
4234
|
await writeRedirectFiles(rule.to, fromPath);
|
|
@@ -4298,7 +4273,7 @@ async function createServer(valaxyApp, viteConfig = {}, serverOptions = {}) {
|
|
|
4298
4273
|
import os from "os";
|
|
4299
4274
|
import path13 from "path";
|
|
4300
4275
|
import process8 from "process";
|
|
4301
|
-
import { consola as
|
|
4276
|
+
import { consola as consola14 } from "consola";
|
|
4302
4277
|
import { colors as colors14 } from "consola/utils";
|
|
4303
4278
|
import ora4 from "ora";
|
|
4304
4279
|
import { mergeConfig as mergeConfig3 } from "vite";
|
|
@@ -4370,7 +4345,7 @@ async function initServer(valaxyApp, viteConfig) {
|
|
|
4370
4345
|
serverSpinner.succeed(`${valaxyPrefix} ${colors14.green("server ready.")}`);
|
|
4371
4346
|
return server;
|
|
4372
4347
|
} catch (e) {
|
|
4373
|
-
|
|
4348
|
+
consola14.error("failed to start server. error:\n");
|
|
4374
4349
|
console.error(e);
|
|
4375
4350
|
process8.exit(1);
|
|
4376
4351
|
}
|
|
@@ -4378,7 +4353,7 @@ async function initServer(valaxyApp, viteConfig) {
|
|
|
4378
4353
|
if (import.meta.hot) {
|
|
4379
4354
|
await import.meta.hot.data.stopping;
|
|
4380
4355
|
let reload = async () => {
|
|
4381
|
-
|
|
4356
|
+
consola14.info("HMR: Stop Server");
|
|
4382
4357
|
await GLOBAL_STATE.server?.close();
|
|
4383
4358
|
};
|
|
4384
4359
|
import.meta.hot.on("vite:beforeFullReload", () => {
|
|
@@ -4425,19 +4400,19 @@ async function execBuild({ ssg, root, output, log }) {
|
|
|
4425
4400
|
);
|
|
4426
4401
|
await callHookWithLog("config:init", valaxyApp);
|
|
4427
4402
|
await callHookWithLog("build:before", valaxyApp);
|
|
4428
|
-
|
|
4403
|
+
consola15.box("\u{1F320} Start building...");
|
|
4429
4404
|
try {
|
|
4430
4405
|
if (ssg) {
|
|
4431
|
-
|
|
4406
|
+
consola15.info(`use ${colors15.yellow("vite-ssg")} to do ssg build...`);
|
|
4432
4407
|
try {
|
|
4433
4408
|
await ssgBuild(valaxyApp, viteConfig);
|
|
4434
4409
|
await postProcessForSSG(options);
|
|
4435
4410
|
} catch (e) {
|
|
4436
|
-
|
|
4411
|
+
consola15.error("[vite-ssg] An internal error occurred.");
|
|
4437
4412
|
console.log(e);
|
|
4438
4413
|
}
|
|
4439
4414
|
} else {
|
|
4440
|
-
|
|
4415
|
+
consola15.info("use vite do spa build...");
|
|
4441
4416
|
await build2(valaxyApp, viteConfig);
|
|
4442
4417
|
}
|
|
4443
4418
|
} catch (e) {
|
|
@@ -4477,35 +4452,35 @@ function registerBuildCommand(cli2) {
|
|
|
4477
4452
|
// node/cli/clean.ts
|
|
4478
4453
|
import path15 from "path";
|
|
4479
4454
|
import process10 from "process";
|
|
4480
|
-
import { consola as
|
|
4481
|
-
import
|
|
4455
|
+
import { consola as consola16 } from "consola";
|
|
4456
|
+
import fs22 from "fs-extra";
|
|
4482
4457
|
async function cleanDist() {
|
|
4483
4458
|
const distDir = path15.join(process10.cwd(), "dist");
|
|
4484
4459
|
const cacheDir = path15.join(process10.cwd(), ".valaxy");
|
|
4485
|
-
|
|
4486
|
-
if (await
|
|
4487
|
-
|
|
4460
|
+
consola16.box("\u{1F9F9} Starting clean...");
|
|
4461
|
+
if (await fs22.exists(distDir)) {
|
|
4462
|
+
consola16.info("dist directory exists, removing...");
|
|
4488
4463
|
try {
|
|
4489
|
-
await
|
|
4490
|
-
|
|
4464
|
+
await fs22.rm(distDir, { recursive: true, force: true });
|
|
4465
|
+
consola16.success("dist directory has been successfully removed.");
|
|
4491
4466
|
} catch (error) {
|
|
4492
|
-
|
|
4493
|
-
|
|
4467
|
+
consola16.error("Failed to remove dist directory.");
|
|
4468
|
+
consola16.error(error);
|
|
4494
4469
|
}
|
|
4495
4470
|
} else {
|
|
4496
|
-
|
|
4471
|
+
consola16.info("No dist directory found, nothing to clean.");
|
|
4497
4472
|
}
|
|
4498
|
-
if (await
|
|
4499
|
-
|
|
4473
|
+
if (await fs22.exists(cacheDir)) {
|
|
4474
|
+
consola16.info(".valaxy cache directory exists, removing...");
|
|
4500
4475
|
try {
|
|
4501
|
-
await
|
|
4502
|
-
|
|
4476
|
+
await fs22.rm(cacheDir, { recursive: true, force: true });
|
|
4477
|
+
consola16.success(".valaxy cache directory has been successfully removed.");
|
|
4503
4478
|
} catch (error) {
|
|
4504
|
-
|
|
4505
|
-
|
|
4479
|
+
consola16.error("Failed to remove .valaxy cache directory.");
|
|
4480
|
+
consola16.error(error);
|
|
4506
4481
|
}
|
|
4507
4482
|
} else {
|
|
4508
|
-
|
|
4483
|
+
consola16.info("No .valaxy cache directory found, nothing to clean.");
|
|
4509
4484
|
}
|
|
4510
4485
|
}
|
|
4511
4486
|
function registerCleanCommand(cli2) {
|
|
@@ -4521,15 +4496,21 @@ function registerCleanCommand(cli2) {
|
|
|
4521
4496
|
}
|
|
4522
4497
|
|
|
4523
4498
|
// node/cli/debug.ts
|
|
4524
|
-
import
|
|
4499
|
+
import os2 from "os";
|
|
4500
|
+
import process11 from "process";
|
|
4501
|
+
import { consola as consola17 } from "consola";
|
|
4502
|
+
import { colors as colors16 } from "consola/utils";
|
|
4525
4503
|
function registerDebugCommand(cli2) {
|
|
4526
4504
|
cli2.command("debug", "Debug your blog", async () => {
|
|
4527
|
-
|
|
4505
|
+
console.log();
|
|
4506
|
+
consola17.log(" Operating System:", colors16.green(os2.platform()));
|
|
4507
|
+
consola17.log(" Node.JS Version:", colors16.green(process11.version));
|
|
4508
|
+
consola17.log(" Valaxy Version:", colors16.cyan(`v${version}`));
|
|
4528
4509
|
});
|
|
4529
4510
|
}
|
|
4530
4511
|
|
|
4531
4512
|
// node/cli/deploy.ts
|
|
4532
|
-
import
|
|
4513
|
+
import process12 from "process";
|
|
4533
4514
|
import { confirm, intro, outro, select } from "@clack/prompts";
|
|
4534
4515
|
function registerDeployCommand(cli2) {
|
|
4535
4516
|
cli2.command("deploy", "deploy your blog to the cloud", async () => {
|
|
@@ -4538,7 +4519,7 @@ function registerDeployCommand(cli2) {
|
|
|
4538
4519
|
message: "Do you want to build your blog before deploying?"
|
|
4539
4520
|
});
|
|
4540
4521
|
if (shouldBuild) {
|
|
4541
|
-
await execBuild({ ssg: true, root:
|
|
4522
|
+
await execBuild({ ssg: true, root: process12.cwd(), output: "dist", log: "info" });
|
|
4542
4523
|
}
|
|
4543
4524
|
const deployType = await select({
|
|
4544
4525
|
message: "Where do you want to deploy?",
|
|
@@ -4578,7 +4559,7 @@ function registerDeployCommand(cli2) {
|
|
|
4578
4559
|
|
|
4579
4560
|
// node/cli/dev.ts
|
|
4580
4561
|
import path16 from "path";
|
|
4581
|
-
import
|
|
4562
|
+
import process14 from "process";
|
|
4582
4563
|
import { mergeConfig as mergeConfig5 } from "vite";
|
|
4583
4564
|
|
|
4584
4565
|
// node/utils/net.ts
|
|
@@ -4589,28 +4570,28 @@ async function findFreePort(start) {
|
|
|
4589
4570
|
return await findFreePort(start + 1);
|
|
4590
4571
|
}
|
|
4591
4572
|
function isPortFree(port) {
|
|
4592
|
-
return new Promise((
|
|
4573
|
+
return new Promise((resolve14) => {
|
|
4593
4574
|
const server = net.createServer((socket) => {
|
|
4594
4575
|
socket.write("Echo server\r\n");
|
|
4595
4576
|
socket.pipe(socket);
|
|
4596
4577
|
});
|
|
4597
4578
|
server.listen(port, "0.0.0.0");
|
|
4598
4579
|
server.on("error", () => {
|
|
4599
|
-
|
|
4580
|
+
resolve14(false);
|
|
4600
4581
|
});
|
|
4601
4582
|
server.on("listening", () => {
|
|
4602
4583
|
server.close();
|
|
4603
|
-
|
|
4584
|
+
resolve14(true);
|
|
4604
4585
|
});
|
|
4605
4586
|
});
|
|
4606
4587
|
}
|
|
4607
4588
|
|
|
4608
4589
|
// node/cli/utils/shortcuts.ts
|
|
4609
4590
|
import { exec } from "child_process";
|
|
4610
|
-
import
|
|
4611
|
-
import
|
|
4591
|
+
import os3 from "os";
|
|
4592
|
+
import process13 from "process";
|
|
4612
4593
|
import * as readline from "readline";
|
|
4613
|
-
import { colors as
|
|
4594
|
+
import { colors as colors17 } from "consola/utils";
|
|
4614
4595
|
import qrcode from "qrcode";
|
|
4615
4596
|
var SHORTCUTS = [
|
|
4616
4597
|
{
|
|
@@ -4635,7 +4616,7 @@ var SHORTCUTS = [
|
|
|
4635
4616
|
key: "q",
|
|
4636
4617
|
description: "qr",
|
|
4637
4618
|
action(server) {
|
|
4638
|
-
const addresses = Object.values(
|
|
4619
|
+
const addresses = Object.values(os3.networkInterfaces()).flat().filter((details) => details?.family === "IPv4" && !details.address.includes("127.0.0.1"));
|
|
4639
4620
|
const port = server.config.server.port;
|
|
4640
4621
|
const remoteUrl = `http://${addresses[0]?.address || "localhost"}:${port}`;
|
|
4641
4622
|
qrcode.toString(remoteUrl, { type: "terminal" }, (err, qrCode) => {
|
|
@@ -4649,7 +4630,7 @@ var SHORTCUTS = [
|
|
|
4649
4630
|
key: "e",
|
|
4650
4631
|
description: "edit",
|
|
4651
4632
|
action() {
|
|
4652
|
-
exec(`code "${
|
|
4633
|
+
exec(`code "${process13.cwd()}"`, (err) => {
|
|
4653
4634
|
if (err)
|
|
4654
4635
|
console.error("Failed to open editor", err);
|
|
4655
4636
|
});
|
|
@@ -4657,18 +4638,18 @@ var SHORTCUTS = [
|
|
|
4657
4638
|
}
|
|
4658
4639
|
];
|
|
4659
4640
|
function bindShortcuts(server, createDevServer) {
|
|
4660
|
-
if (!server.httpServer ||
|
|
4661
|
-
console.log("restart server to enable shortcuts", server.httpServer,
|
|
4641
|
+
if (!server.httpServer || process13.env.CI) {
|
|
4642
|
+
console.log("restart server to enable shortcuts", server.httpServer, process13.stdin.isTTY, process13.env.CI);
|
|
4662
4643
|
return;
|
|
4663
4644
|
}
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
readline.emitKeypressEvents(
|
|
4667
|
-
if (
|
|
4668
|
-
|
|
4645
|
+
process13.stdin.resume();
|
|
4646
|
+
process13.stdin.setEncoding("utf8");
|
|
4647
|
+
readline.emitKeypressEvents(process13.stdin);
|
|
4648
|
+
if (process13.stdin.isTTY)
|
|
4649
|
+
process13.stdin.setRawMode(true);
|
|
4669
4650
|
async function onKeyPress(str, key) {
|
|
4670
4651
|
if (key.ctrl && key.name === "c") {
|
|
4671
|
-
|
|
4652
|
+
process13.exit();
|
|
4672
4653
|
} else {
|
|
4673
4654
|
const shortcut = SHORTCUTS.find((shortcut2) => shortcut2.key === str);
|
|
4674
4655
|
if (!shortcut)
|
|
@@ -4676,19 +4657,19 @@ function bindShortcuts(server, createDevServer) {
|
|
|
4676
4657
|
try {
|
|
4677
4658
|
await shortcut.action(server, createDevServer);
|
|
4678
4659
|
} catch (error) {
|
|
4679
|
-
console.error(
|
|
4660
|
+
console.error(colors17.red("Error executing shortcut:"), key, error);
|
|
4680
4661
|
}
|
|
4681
4662
|
}
|
|
4682
4663
|
}
|
|
4683
|
-
|
|
4664
|
+
process13.stdin.on("keypress", onKeyPress);
|
|
4684
4665
|
server.httpServer.on("close", () => {
|
|
4685
|
-
|
|
4666
|
+
process13.stdin.off("keypress", onKeyPress);
|
|
4686
4667
|
});
|
|
4687
4668
|
}
|
|
4688
4669
|
|
|
4689
4670
|
// node/cli/dev.ts
|
|
4690
4671
|
async function startValaxyDev({
|
|
4691
|
-
root =
|
|
4672
|
+
root = process14.cwd(),
|
|
4692
4673
|
port,
|
|
4693
4674
|
remote,
|
|
4694
4675
|
log,
|
|
@@ -4696,7 +4677,7 @@ async function startValaxyDev({
|
|
|
4696
4677
|
}) {
|
|
4697
4678
|
setEnv();
|
|
4698
4679
|
if (!isPagesDirExist(root))
|
|
4699
|
-
|
|
4680
|
+
process14.exit(0);
|
|
4700
4681
|
port = port || await findFreePort(4859);
|
|
4701
4682
|
const resolvedOptions = await resolveOptions({ userRoot: root });
|
|
4702
4683
|
setTimezone(resolvedOptions.config.siteConfig.timezone);
|
|
@@ -4764,16 +4745,16 @@ function registerDevCommand(cli2) {
|
|
|
4764
4745
|
}
|
|
4765
4746
|
|
|
4766
4747
|
// node/cli/utils/post.ts
|
|
4767
|
-
import { dirname as dirname5, join as join9, resolve as
|
|
4768
|
-
import { consola as
|
|
4769
|
-
import { colors as
|
|
4748
|
+
import { dirname as dirname5, join as join9, resolve as resolve13 } from "path";
|
|
4749
|
+
import { consola as consola18 } from "consola";
|
|
4750
|
+
import { colors as colors18 } from "consola/utils";
|
|
4770
4751
|
import dayjs2 from "dayjs";
|
|
4771
4752
|
import { render } from "ejs";
|
|
4772
|
-
import
|
|
4753
|
+
import fs24 from "fs-extra";
|
|
4773
4754
|
|
|
4774
4755
|
// node/cli/utils/constants.ts
|
|
4775
|
-
import
|
|
4776
|
-
var userRoot =
|
|
4756
|
+
import process15 from "process";
|
|
4757
|
+
var userRoot = process15.cwd();
|
|
4777
4758
|
var defaultPostTemplate = `---
|
|
4778
4759
|
layout: <%=layout%>
|
|
4779
4760
|
title: <%=title%>
|
|
@@ -4784,13 +4765,13 @@ date: <%=date%>
|
|
|
4784
4765
|
// node/cli/utils/scaffold.ts
|
|
4785
4766
|
import { readFile as readFile2 } from "fs/promises";
|
|
4786
4767
|
import path17 from "path";
|
|
4787
|
-
import
|
|
4768
|
+
import fs23 from "fs-extra";
|
|
4788
4769
|
async function getTemplate(layout) {
|
|
4789
4770
|
const { clientRoot, themeRoot } = await resolveOptions({ userRoot });
|
|
4790
4771
|
const roots = [userRoot, themeRoot, clientRoot];
|
|
4791
4772
|
for (const root of roots) {
|
|
4792
4773
|
const scaffoldPath = path17.resolve(root, "scaffolds", `${layout}.md`);
|
|
4793
|
-
if (await
|
|
4774
|
+
if (await fs23.exists(scaffoldPath))
|
|
4794
4775
|
return readFile2(scaffoldPath, "utf-8");
|
|
4795
4776
|
}
|
|
4796
4777
|
return false;
|
|
@@ -4798,22 +4779,22 @@ async function getTemplate(layout) {
|
|
|
4798
4779
|
|
|
4799
4780
|
// node/cli/utils/post.ts
|
|
4800
4781
|
async function create(params) {
|
|
4801
|
-
const pagesPath =
|
|
4782
|
+
const pagesPath = resolve13(userRoot, params.path || "pages");
|
|
4802
4783
|
let counter = 0;
|
|
4803
4784
|
while (true) {
|
|
4804
4785
|
const postFileName = `${params.title}${counter ? `-${counter}` : ""}`;
|
|
4805
4786
|
const postFilePath = params.folder ? join9(postFileName, "index.md") : `${postFileName}.md`;
|
|
4806
|
-
const targetPath =
|
|
4807
|
-
if (!await
|
|
4808
|
-
await
|
|
4787
|
+
const targetPath = resolve13(pagesPath, "posts", postFilePath);
|
|
4788
|
+
if (!await fs24.exists(targetPath)) {
|
|
4789
|
+
await fs24.ensureDir(dirname5(targetPath));
|
|
4809
4790
|
const content = await genLayoutTemplate(params);
|
|
4810
4791
|
try {
|
|
4811
|
-
await
|
|
4812
|
-
|
|
4792
|
+
await fs24.writeFile(targetPath, content, "utf-8");
|
|
4793
|
+
consola18.success(`[valaxy new]: successfully generated file ${colors18.magenta(targetPath)}`);
|
|
4813
4794
|
} catch (e) {
|
|
4814
4795
|
console.log(e);
|
|
4815
|
-
|
|
4816
|
-
|
|
4796
|
+
consola18.error(`[valaxy new]: failed to write file ${targetPath}`);
|
|
4797
|
+
consola18.warn(`You should run ${colors18.green("valaxy new")} in your valaxy project root directory.`);
|
|
4817
4798
|
}
|
|
4818
4799
|
return targetPath;
|
|
4819
4800
|
}
|
|
@@ -4874,7 +4855,7 @@ function registerNewCommand(cli2) {
|
|
|
4874
4855
|
}
|
|
4875
4856
|
|
|
4876
4857
|
// node/cli/index.ts
|
|
4877
|
-
var cli = yargs(hideBin(
|
|
4858
|
+
var cli = yargs(hideBin(process16.argv)).scriptName("valaxy").usage("$0 [args]").version(version).showHelpOnFail(false).alias("h", "help").alias("v", "version");
|
|
4878
4859
|
registerDevCommand(cli);
|
|
4879
4860
|
registerBuildCommand(cli);
|
|
4880
4861
|
registerNewCommand(cli);
|
|
@@ -4910,7 +4891,6 @@ export {
|
|
|
4910
4891
|
resolveImportPath,
|
|
4911
4892
|
mergeViteConfigs,
|
|
4912
4893
|
getIndexHtml,
|
|
4913
|
-
loadConfig,
|
|
4914
4894
|
loadConfigFromFile,
|
|
4915
4895
|
defaultSiteConfig,
|
|
4916
4896
|
defineSiteConfig,
|