valaxy 0.25.10 → 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.
|
@@ -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
|
}
|
|
@@ -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,16 +873,16 @@ async function isPagesDirExist(root) {
|
|
|
899
873
|
|
|
900
874
|
// node/modules/fuse.ts
|
|
901
875
|
async function generateFuseList(options) {
|
|
902
|
-
|
|
876
|
+
consola8.start(`Generate List for Fuse Search by (${colors7.cyan("fuse.js")}) ...`);
|
|
903
877
|
const pattern = options.config.siteConfig.fuse.pattern || path4.join(options.userRoot, "pages/**/*.md");
|
|
904
878
|
const files = await fg2(pattern);
|
|
905
879
|
const posts = [];
|
|
906
880
|
for await (const i of files) {
|
|
907
|
-
const raw =
|
|
881
|
+
const raw = fs6.readFileSync(i, "utf-8");
|
|
908
882
|
const { data, excerpt, content } = matter(raw, matterOptions);
|
|
909
883
|
const fmData = data;
|
|
910
884
|
if (fmData.draft) {
|
|
911
|
-
|
|
885
|
+
consola8.warn(`Ignore draft post: ${colors7.dim(i)}`);
|
|
912
886
|
continue;
|
|
913
887
|
}
|
|
914
888
|
if (fmData.hide)
|
|
@@ -938,30 +912,30 @@ async function generateFuseList(options) {
|
|
|
938
912
|
return posts;
|
|
939
913
|
}
|
|
940
914
|
async function execFuse(options) {
|
|
941
|
-
|
|
915
|
+
consola8.info("Start generate fuse list...");
|
|
942
916
|
const fuseList = await generateFuseList(options);
|
|
943
|
-
await
|
|
917
|
+
await fs6.ensureDir("./dist");
|
|
944
918
|
const publicFolder = path4.resolve(options.userRoot, "public");
|
|
945
919
|
const publicFuseFile = path4.resolve(publicFolder, options.config.siteConfig.fuse.dataPath);
|
|
946
920
|
const publicRelativeFile = path4.join("public", options.config.siteConfig.fuse.dataPath);
|
|
947
|
-
await
|
|
948
|
-
|
|
949
|
-
|
|
921
|
+
await fs6.ensureFile(publicFuseFile);
|
|
922
|
+
fs6.writeJSONSync(publicFuseFile, fuseList);
|
|
923
|
+
consola8.success(`Generate fuse list in ${colors7.dim(publicFolder)}`);
|
|
950
924
|
const distFolder = path4.resolve(options.userRoot, "dist");
|
|
951
925
|
const distFuseFile = path4.resolve(distFolder, options.config.siteConfig.fuse.dataPath);
|
|
952
|
-
await
|
|
953
|
-
|
|
954
|
-
|
|
926
|
+
await fs6.ensureDir(distFolder);
|
|
927
|
+
fs6.writeJSONSync(distFuseFile, fuseList);
|
|
928
|
+
consola8.success(`Generate fuse list in ${colors7.dim(distFolder)}`);
|
|
955
929
|
try {
|
|
956
930
|
const gitignorePath = path4.resolve(options.userRoot, ".gitignore");
|
|
957
|
-
const gitignore = await
|
|
931
|
+
const gitignore = await fs6.readFile(gitignorePath, "utf-8");
|
|
958
932
|
const ignorePath = publicRelativeFile.replace(/\\/g, "/");
|
|
959
933
|
if (!gitignore.includes(ignorePath)) {
|
|
960
|
-
await
|
|
934
|
+
await fs6.appendFile(gitignorePath, `
|
|
961
935
|
# valaxy fuse
|
|
962
936
|
${ignorePath}
|
|
963
937
|
`);
|
|
964
|
-
|
|
938
|
+
consola8.success(`Add ${colors7.dim(ignorePath)} to ${colors7.dim(".gitignore")}`);
|
|
965
939
|
}
|
|
966
940
|
} catch {
|
|
967
941
|
}
|
|
@@ -991,26 +965,26 @@ var fuseModule = defineValaxyModule({
|
|
|
991
965
|
|
|
992
966
|
// node/modules/rss/utils.ts
|
|
993
967
|
import { readFile } from "fs/promises";
|
|
994
|
-
import { dirname as dirname3, join, resolve as
|
|
968
|
+
import { dirname as dirname3, join, resolve as resolve4 } from "path";
|
|
995
969
|
import { ensurePrefix as ensurePrefix2 } from "@antfu/utils";
|
|
996
|
-
import { consola as
|
|
970
|
+
import { consola as consola9 } from "consola";
|
|
997
971
|
import { colors as colors8 } from "consola/utils";
|
|
998
972
|
import dayjs from "dayjs";
|
|
999
973
|
import fg3 from "fast-glob";
|
|
1000
974
|
import { Feed } from "feed";
|
|
1001
|
-
import
|
|
975
|
+
import fs8 from "fs-extra";
|
|
1002
976
|
import matter2 from "gray-matter";
|
|
1003
977
|
import MarkdownIt from "markdown-it";
|
|
1004
978
|
import ora3 from "ora";
|
|
1005
979
|
import { getBorderCharacters, table } from "table";
|
|
1006
980
|
|
|
1007
981
|
// node/utils/date.ts
|
|
1008
|
-
import
|
|
982
|
+
import fs7 from "fs-extra";
|
|
1009
983
|
async function getCreatedTime(file) {
|
|
1010
|
-
return await getGitTimestamp(file, "created") || (await
|
|
984
|
+
return await getGitTimestamp(file, "created") || (await fs7.stat(file)).ctime;
|
|
1011
985
|
}
|
|
1012
986
|
async function getUpdatedTime(file) {
|
|
1013
|
-
return await getGitTimestamp(file, "created") || (await
|
|
987
|
+
return await getGitTimestamp(file, "created") || (await fs7.stat(file)).mtime;
|
|
1014
988
|
}
|
|
1015
989
|
|
|
1016
990
|
// node/modules/rss/utils.ts
|
|
@@ -1025,7 +999,7 @@ async function build(options) {
|
|
|
1025
999
|
const siteConfig = config.siteConfig;
|
|
1026
1000
|
const lang = siteConfig.lang || "en";
|
|
1027
1001
|
if (!siteConfig.url || siteConfig.url === "/") {
|
|
1028
|
-
|
|
1002
|
+
consola9.error("You must set `url` (like `https://example.com`) in `site.config.ts` to generate rss.");
|
|
1029
1003
|
return;
|
|
1030
1004
|
}
|
|
1031
1005
|
const siteUrl = siteConfig.url;
|
|
@@ -1128,9 +1102,9 @@ async function getPosts(params, options) {
|
|
|
1128
1102
|
async function writeFeed(feedOptions, posts, options, feedNameMap) {
|
|
1129
1103
|
const feed = new Feed(feedOptions);
|
|
1130
1104
|
posts.forEach((item) => feed.addItem(item));
|
|
1131
|
-
await
|
|
1132
|
-
const path18 =
|
|
1133
|
-
const publicFolder =
|
|
1105
|
+
await fs8.ensureDir(dirname3(`./dist/${feedNameMap.atom}`));
|
|
1106
|
+
const path18 = resolve4(options.userRoot, "./dist");
|
|
1107
|
+
const publicFolder = resolve4(options.userRoot, "public");
|
|
1134
1108
|
const { config } = options;
|
|
1135
1109
|
const siteConfig = config.siteConfig;
|
|
1136
1110
|
const now = dayjs().format("YYYY-MM-DD HH:mm:ss zzz");
|
|
@@ -1149,24 +1123,24 @@ async function writeFeed(feedOptions, posts, options, feedNameMap) {
|
|
|
1149
1123
|
data = feed.atom1();
|
|
1150
1124
|
else if (type === "json")
|
|
1151
1125
|
data = feed.json1();
|
|
1152
|
-
await
|
|
1153
|
-
|
|
1126
|
+
await fs8.writeFile(distFeedPath, data, "utf-8");
|
|
1127
|
+
consola9.debug(`[${colors8.cyan(type)}] dist: ${colors8.dim(distFeedPath)}`);
|
|
1154
1128
|
tableData.push([colors8.cyan(type), colors8.yellow("dist"), colors8.dim(distFeedPath)]);
|
|
1155
|
-
const publicFeedPath =
|
|
1129
|
+
const publicFeedPath = resolve4(publicFolder, feedNameMap[type]);
|
|
1156
1130
|
const publicRelativeFile = join("public", feedNameMap[type]);
|
|
1157
|
-
await
|
|
1158
|
-
|
|
1131
|
+
await fs8.writeFile(publicFeedPath, data, "utf-8");
|
|
1132
|
+
consola9.debug(`[${colors8.cyan(type)}] public: ${colors8.dim(publicFeedPath)}`);
|
|
1159
1133
|
tableData.push(["", colors8.green("public"), colors8.dim(publicFeedPath)]);
|
|
1160
1134
|
try {
|
|
1161
|
-
const gitignorePath =
|
|
1162
|
-
const gitignore = await
|
|
1135
|
+
const gitignorePath = resolve4(options.userRoot, ".gitignore");
|
|
1136
|
+
const gitignore = await fs8.readFile(gitignorePath, "utf-8");
|
|
1163
1137
|
const ignorePath = publicRelativeFile.replace(/\\/g, "/");
|
|
1164
1138
|
if (!gitignore.includes(ignorePath)) {
|
|
1165
|
-
await
|
|
1139
|
+
await fs8.appendFile(gitignorePath, `
|
|
1166
1140
|
# valaxy rss
|
|
1167
1141
|
${ignorePath}
|
|
1168
1142
|
`);
|
|
1169
|
-
|
|
1143
|
+
consola9.success(`Add ${colors8.dim(ignorePath)} to ${colors8.dim(".gitignore")}`);
|
|
1170
1144
|
}
|
|
1171
1145
|
} catch {
|
|
1172
1146
|
}
|
|
@@ -1217,15 +1191,15 @@ var rssModule = defineValaxyModule({
|
|
|
1217
1191
|
// node/cli/build.ts
|
|
1218
1192
|
import path14 from "path";
|
|
1219
1193
|
import process9 from "process";
|
|
1220
|
-
import { consola as
|
|
1194
|
+
import { consola as consola15 } from "consola";
|
|
1221
1195
|
import { colors as colors15 } from "consola/utils";
|
|
1222
1196
|
import { mergeConfig as mergeConfig4 } from "vite";
|
|
1223
1197
|
|
|
1224
1198
|
// node/build.ts
|
|
1225
|
-
import { join as join8, resolve as
|
|
1226
|
-
import { consola as
|
|
1199
|
+
import { join as join8, resolve as resolve12 } from "path";
|
|
1200
|
+
import { consola as consola13 } from "consola";
|
|
1227
1201
|
import { colors as colors12 } from "consola/utils";
|
|
1228
|
-
import
|
|
1202
|
+
import fs21 from "fs-extra";
|
|
1229
1203
|
import { mergeConfig as mergeViteConfig2, build as viteBuild } from "vite";
|
|
1230
1204
|
import generateSitemap from "vite-ssg-sitemap";
|
|
1231
1205
|
import { build as viteSsgBuild } from "vite-ssg/node";
|
|
@@ -1233,21 +1207,21 @@ import { build as viteSsgBuild } from "vite-ssg/node";
|
|
|
1233
1207
|
// node/plugins/preset.ts
|
|
1234
1208
|
import VueI18n from "@intlify/unplugin-vue-i18n/vite";
|
|
1235
1209
|
import UnheadVite from "@unhead/addons/vite";
|
|
1236
|
-
import { consola as
|
|
1237
|
-
import { resolve as
|
|
1210
|
+
import { consola as consola12 } from "consola";
|
|
1211
|
+
import { resolve as resolve11 } from "pathe";
|
|
1238
1212
|
import Components from "unplugin-vue-components/vite";
|
|
1239
1213
|
import Layouts from "vite-plugin-vue-layouts";
|
|
1240
1214
|
import { groupIconVitePlugin } from "vitepress-plugin-group-icons";
|
|
1241
1215
|
|
|
1242
1216
|
// node/plugins/extendConfig.ts
|
|
1243
|
-
import { dirname as dirname4, join as join3, resolve as
|
|
1217
|
+
import { dirname as dirname4, join as join3, resolve as resolve5 } from "path";
|
|
1244
1218
|
import { uniq as uniq3 } from "@antfu/utils";
|
|
1245
1219
|
import { mergeConfig as mergeConfig2, searchForWorkspaceRoot } from "vite";
|
|
1246
1220
|
|
|
1247
1221
|
// node/common.ts
|
|
1248
1222
|
import { join as join2 } from "path";
|
|
1249
1223
|
import { uniq as uniq2 } from "@antfu/utils";
|
|
1250
|
-
import
|
|
1224
|
+
import fs9 from "fs-extra";
|
|
1251
1225
|
import { loadConfigFromFile as loadConfigFromFile2, mergeConfig } from "vite";
|
|
1252
1226
|
async function mergeViteConfigs({ userRoot: userRoot2, themeRoot }, command) {
|
|
1253
1227
|
const configEnv = {
|
|
@@ -1257,7 +1231,7 @@ async function mergeViteConfigs({ userRoot: userRoot2, themeRoot }, command) {
|
|
|
1257
1231
|
let resolvedConfig = {};
|
|
1258
1232
|
const files = uniq2([themeRoot, userRoot2]).map((i) => join2(i, "vite.config.ts"));
|
|
1259
1233
|
const loadViteConfigPromiseArr = files.map(async (file) => {
|
|
1260
|
-
if (!await
|
|
1234
|
+
if (!await fs9.exists(file))
|
|
1261
1235
|
return;
|
|
1262
1236
|
return loadConfigFromFile2(configEnv, file);
|
|
1263
1237
|
});
|
|
@@ -1305,9 +1279,9 @@ async function getIndexHtml({ clientRoot, themeRoot, userRoot: userRoot2, config
|
|
|
1305
1279
|
}
|
|
1306
1280
|
for (const root of roots) {
|
|
1307
1281
|
const path18 = join2(root, "index.html");
|
|
1308
|
-
if (!
|
|
1282
|
+
if (!fs9.existsSync(path18))
|
|
1309
1283
|
continue;
|
|
1310
|
-
const indexHtml = await
|
|
1284
|
+
const indexHtml = await fs9.readFile(path18, "utf-8");
|
|
1311
1285
|
head += `
|
|
1312
1286
|
${(indexHtml.match(/<head>([\s\S]*?)<\/head>/i)?.[1] || "").trim()}`;
|
|
1313
1287
|
body += `
|
|
@@ -1398,7 +1372,7 @@ function createConfigPlugin(options) {
|
|
|
1398
1372
|
},
|
|
1399
1373
|
optimizeDeps: {
|
|
1400
1374
|
// do not entry node file
|
|
1401
|
-
entries: [
|
|
1375
|
+
entries: [resolve5(options.clientRoot, "main.ts")],
|
|
1402
1376
|
// must need it
|
|
1403
1377
|
include: includedDeps,
|
|
1404
1378
|
exclude: EXCLUDE
|
|
@@ -1445,14 +1419,14 @@ async function getAlias(options) {
|
|
|
1445
1419
|
{ find: /^#valaxy\/(.*)/, replacement: "/@valaxyjs/$1" },
|
|
1446
1420
|
{ find: "~/", replacement: `${toAtFS(options.userRoot)}/` },
|
|
1447
1421
|
{ find: "valaxy/client/", replacement: `${toAtFS(options.clientRoot)}/` },
|
|
1448
|
-
{ find: "valaxy/package.json", replacement: toAtFS(
|
|
1449
|
-
{ 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")) },
|
|
1450
1424
|
{ find: "@valaxyjs/client/", replacement: `${toAtFS(options.clientRoot)}/` },
|
|
1451
1425
|
// import theme
|
|
1452
1426
|
{ find: "virtual:valaxy-theme", replacement: `${toAtFS(options.themeRoot)}/client/index.ts` },
|
|
1453
|
-
{ find: `valaxy-theme-${options.theme}/client`, replacement: `${toAtFS(
|
|
1454
|
-
{ find: `valaxy-theme-${options.theme}/`, replacement: `${toAtFS(
|
|
1455
|
-
{ 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` }
|
|
1456
1430
|
];
|
|
1457
1431
|
if (options.config.vue?.browserTemplateCompilation) {
|
|
1458
1432
|
alias.push(
|
|
@@ -1462,20 +1436,20 @@ async function getAlias(options) {
|
|
|
1462
1436
|
options.addons.forEach((addon) => {
|
|
1463
1437
|
alias.push({
|
|
1464
1438
|
find: `${addon.name}/client/`,
|
|
1465
|
-
replacement: `${toAtFS(`${
|
|
1439
|
+
replacement: `${toAtFS(`${resolve5(addon.root)}`)}/client/`
|
|
1466
1440
|
});
|
|
1467
1441
|
alias.push({
|
|
1468
1442
|
find: `${addon.name}/App.vue`,
|
|
1469
|
-
replacement: `${toAtFS(
|
|
1443
|
+
replacement: `${toAtFS(resolve5(addon.root))}/App.vue`
|
|
1470
1444
|
});
|
|
1471
1445
|
alias.push({
|
|
1472
1446
|
find: addon.name,
|
|
1473
|
-
replacement: `${toAtFS(
|
|
1447
|
+
replacement: `${toAtFS(resolve5(addon.root))}/client/index.ts`
|
|
1474
1448
|
});
|
|
1475
1449
|
});
|
|
1476
1450
|
alias.push({
|
|
1477
1451
|
find: /^valaxy-addon-(.*)$/,
|
|
1478
|
-
replacement: toAtFS(
|
|
1452
|
+
replacement: toAtFS(resolve5(options.clientRoot, "./addons/index.ts"))
|
|
1479
1453
|
});
|
|
1480
1454
|
return alias;
|
|
1481
1455
|
}
|
|
@@ -2412,7 +2386,7 @@ function lineNumberPlugin(md3, enable = false) {
|
|
|
2412
2386
|
}
|
|
2413
2387
|
|
|
2414
2388
|
// node/plugins/markdown/plugins/markdown-it/snippet.ts
|
|
2415
|
-
import
|
|
2389
|
+
import fs10 from "fs-extra";
|
|
2416
2390
|
import path5 from "pathe";
|
|
2417
2391
|
var rawPathRegexp = /^(.+?(?:\.([a-z0-9]+))?)(#[\w-]+)?(?: ?\{(\d+(?:[,-]\d+)*)? ?(\S+)?\})? ?(?:\[(.+)\])?$/;
|
|
2418
2392
|
function rawPathToToken(rawPath) {
|
|
@@ -2515,13 +2489,13 @@ function snippetPlugin(md3, srcDir) {
|
|
|
2515
2489
|
return fence(...args);
|
|
2516
2490
|
if (includes)
|
|
2517
2491
|
includes.push(src);
|
|
2518
|
-
const isAFile =
|
|
2519
|
-
if (!
|
|
2492
|
+
const isAFile = fs10.statSync(src).isFile();
|
|
2493
|
+
if (!fs10.existsSync(src) || !isAFile) {
|
|
2520
2494
|
token.content = isAFile ? `Code snippet path not found: ${src}` : `Invalid code snippet option`;
|
|
2521
2495
|
token.info = "";
|
|
2522
2496
|
return fence(...args);
|
|
2523
2497
|
}
|
|
2524
|
-
let content =
|
|
2498
|
+
let content = fs10.readFileSync(src, "utf8");
|
|
2525
2499
|
if (regionName) {
|
|
2526
2500
|
const lines = content.split(/\r?\n/);
|
|
2527
2501
|
const region = findRegion(lines, regionName);
|
|
@@ -2684,7 +2658,7 @@ function treatAsHtml(filename) {
|
|
|
2684
2658
|
|
|
2685
2659
|
// node/plugins/markdown/utils/processInclude.ts
|
|
2686
2660
|
import path6 from "path";
|
|
2687
|
-
import
|
|
2661
|
+
import fs11 from "fs-extra";
|
|
2688
2662
|
function processIncludes(srcDir, src, file) {
|
|
2689
2663
|
const includesRE = /<!--\s*@include:\s*(.*?)\s*-->/g;
|
|
2690
2664
|
const rangeRE = /\{(\d*),(\d*)\}$/;
|
|
@@ -2696,7 +2670,7 @@ function processIncludes(srcDir, src, file) {
|
|
|
2696
2670
|
const atPresent = m1[0] === "@";
|
|
2697
2671
|
try {
|
|
2698
2672
|
const includePath = atPresent ? path6.join(srcDir, m1.slice(m1[1] === "/" ? 2 : 1)) : path6.join(path6.dirname(file), m1);
|
|
2699
|
-
let content =
|
|
2673
|
+
let content = fs11.readFileSync(includePath, "utf-8");
|
|
2700
2674
|
if (range) {
|
|
2701
2675
|
const [, startLine, endLine] = range;
|
|
2702
2676
|
const lines = content.split(/\r?\n/);
|
|
@@ -2847,10 +2821,10 @@ function createFixPlugins(options) {
|
|
|
2847
2821
|
|
|
2848
2822
|
// node/plugins/setupClient.ts
|
|
2849
2823
|
import { existsSync } from "fs";
|
|
2850
|
-
import { join as join4, resolve as
|
|
2824
|
+
import { join as join4, resolve as resolve6 } from "path";
|
|
2851
2825
|
import { slash as slash3, uniq as uniq4 } from "@antfu/utils";
|
|
2852
2826
|
function createClientSetupPlugin({ clientRoot, themeRoot, userRoot: userRoot2 }) {
|
|
2853
|
-
const setupEntry = slash3(
|
|
2827
|
+
const setupEntry = slash3(resolve6(clientRoot, "setup"));
|
|
2854
2828
|
return {
|
|
2855
2829
|
name: "valaxy:setup",
|
|
2856
2830
|
enforce: "pre",
|
|
@@ -2889,10 +2863,10 @@ function createClientSetupPlugin({ clientRoot, themeRoot, userRoot: userRoot2 })
|
|
|
2889
2863
|
}
|
|
2890
2864
|
|
|
2891
2865
|
// node/plugins/unocss.ts
|
|
2892
|
-
import { resolve as
|
|
2866
|
+
import { resolve as resolve8 } from "path";
|
|
2893
2867
|
import defu3 from "defu";
|
|
2894
|
-
import
|
|
2895
|
-
import { createJiti as
|
|
2868
|
+
import fs13 from "fs-extra";
|
|
2869
|
+
import { createJiti as createJiti2 } from "jiti";
|
|
2896
2870
|
import {
|
|
2897
2871
|
presetAttributify,
|
|
2898
2872
|
presetIcons,
|
|
@@ -2903,11 +2877,11 @@ import {
|
|
|
2903
2877
|
} from "unocss";
|
|
2904
2878
|
|
|
2905
2879
|
// node/plugins/setupNode.ts
|
|
2906
|
-
import { resolve as
|
|
2880
|
+
import { resolve as resolve7 } from "path";
|
|
2907
2881
|
import { isObject } from "@antfu/utils";
|
|
2908
|
-
import
|
|
2909
|
-
import { createJiti
|
|
2910
|
-
var
|
|
2882
|
+
import fs12 from "fs-extra";
|
|
2883
|
+
import { createJiti } from "jiti";
|
|
2884
|
+
var jiti = createJiti(import.meta.url);
|
|
2911
2885
|
function deepMerge(a, b, rootPath = "") {
|
|
2912
2886
|
a = { ...a };
|
|
2913
2887
|
Object.keys(b).forEach((key) => {
|
|
@@ -2923,9 +2897,9 @@ function deepMerge(a, b, rootPath = "") {
|
|
|
2923
2897
|
async function loadSetups(roots, name, arg, initial, merge = true) {
|
|
2924
2898
|
let returns = initial;
|
|
2925
2899
|
for (const root of roots) {
|
|
2926
|
-
const path18 =
|
|
2927
|
-
if (
|
|
2928
|
-
const setup = await
|
|
2900
|
+
const path18 = resolve7(root, "setup", name);
|
|
2901
|
+
if (fs12.existsSync(path18)) {
|
|
2902
|
+
const setup = await jiti.import(path18, { default: true });
|
|
2929
2903
|
const result = await setup(arg);
|
|
2930
2904
|
if (result !== null) {
|
|
2931
2905
|
returns = merge ? deepMerge(returns, result) : result;
|
|
@@ -2936,7 +2910,7 @@ async function loadSetups(roots, name, arg, initial, merge = true) {
|
|
|
2936
2910
|
}
|
|
2937
2911
|
|
|
2938
2912
|
// node/plugins/unocss.ts
|
|
2939
|
-
var
|
|
2913
|
+
var jiti2 = createJiti2(import.meta.url);
|
|
2940
2914
|
async function createSafelist(options) {
|
|
2941
2915
|
const { config } = options;
|
|
2942
2916
|
const safeIcons = [
|
|
@@ -3035,14 +3009,14 @@ async function createUnocssPlugin(options) {
|
|
|
3035
3009
|
const dirs = [themeRoot, clientRoot];
|
|
3036
3010
|
dirs.forEach(
|
|
3037
3011
|
(dir) => unoConfigFiles.forEach(
|
|
3038
|
-
(file) => configFiles.push(
|
|
3012
|
+
(file) => configFiles.push(resolve8(dir, file))
|
|
3039
3013
|
)
|
|
3040
3014
|
);
|
|
3041
3015
|
let config = {};
|
|
3042
3016
|
const configDeps = [];
|
|
3043
3017
|
for (const configFile of configFiles) {
|
|
3044
|
-
if (await
|
|
3045
|
-
const uConfig = await
|
|
3018
|
+
if (await fs13.exists(configFile)) {
|
|
3019
|
+
const uConfig = await jiti2.import(configFile, { default: true });
|
|
3046
3020
|
config = defu3(config, uConfig);
|
|
3047
3021
|
configDeps.push(configFile);
|
|
3048
3022
|
}
|
|
@@ -3056,19 +3030,19 @@ async function createUnocssPlugin(options) {
|
|
|
3056
3030
|
}
|
|
3057
3031
|
|
|
3058
3032
|
// node/plugins/valaxy/index.ts
|
|
3059
|
-
import { consola as
|
|
3033
|
+
import { consola as consola11 } from "consola";
|
|
3060
3034
|
import { colors as colors11 } from "consola/utils";
|
|
3061
|
-
import
|
|
3062
|
-
import { join as join7, relative, resolve as
|
|
3035
|
+
import fs19 from "fs-extra";
|
|
3036
|
+
import { join as join7, relative, resolve as resolve9 } from "pathe";
|
|
3063
3037
|
|
|
3064
3038
|
// node/virtual/addons.ts
|
|
3065
|
-
import
|
|
3039
|
+
import fs14 from "fs-extra";
|
|
3066
3040
|
import pascalCase from "pascalcase";
|
|
3067
3041
|
import { join as join5 } from "pathe";
|
|
3068
3042
|
var templateAddons = {
|
|
3069
3043
|
id: "/@valaxyjs/addons",
|
|
3070
3044
|
async getContent(options) {
|
|
3071
|
-
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")));
|
|
3072
3046
|
const spliceImportName = (str) => `Addon${pascalCase(str)}App`;
|
|
3073
3047
|
const imports = globalAddonComponents.map((addon) => `import ${spliceImportName(addon.name)} from "${addon.name}/App.vue"`).join("\n");
|
|
3074
3048
|
const components = globalAddonComponents.map((addon) => `{ component: ${spliceImportName(addon.name)}, props: ${JSON.stringify(addon.props)} }`).join(",");
|
|
@@ -3079,17 +3053,17 @@ export default [${components}]`;
|
|
|
3079
3053
|
|
|
3080
3054
|
// node/virtual/blogs.ts
|
|
3081
3055
|
import path8 from "path";
|
|
3082
|
-
import
|
|
3056
|
+
import fs15 from "fs-extra";
|
|
3083
3057
|
function createBlogTemplate(name) {
|
|
3084
3058
|
return {
|
|
3085
3059
|
id: `/@valaxyjs/blog/${name}s`,
|
|
3086
3060
|
async getContent({ userRoot: userRoot2 }) {
|
|
3087
3061
|
const root = path8.resolve(userRoot2, "pages", "collections");
|
|
3088
|
-
if (!await
|
|
3062
|
+
if (!await fs15.pathExists(root)) {
|
|
3089
3063
|
return `export default []`;
|
|
3090
3064
|
}
|
|
3091
|
-
const isDir = (file) =>
|
|
3092
|
-
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"));
|
|
3093
3067
|
const imports = [];
|
|
3094
3068
|
const getImportedName = (idx) => `__valaxy_${name}_${idx + 1}`;
|
|
3095
3069
|
files.forEach((file, idx) => {
|
|
@@ -3125,7 +3099,7 @@ var templateConfig = {
|
|
|
3125
3099
|
};
|
|
3126
3100
|
|
|
3127
3101
|
// node/virtual/locales.ts
|
|
3128
|
-
import
|
|
3102
|
+
import fs16 from "fs-extra";
|
|
3129
3103
|
var templateLocales = {
|
|
3130
3104
|
id: "/@valaxyjs/locales",
|
|
3131
3105
|
async getContent({ roots, config }) {
|
|
@@ -3145,7 +3119,7 @@ var templateLocales = {
|
|
|
3145
3119
|
roots.forEach((root, i) => {
|
|
3146
3120
|
languages.forEach((lang) => {
|
|
3147
3121
|
const langYml = `${root}/locales/${lang}.yml`;
|
|
3148
|
-
if (
|
|
3122
|
+
if (fs16.existsSync(langYml) && fs16.readFileSync(langYml, "utf-8")) {
|
|
3149
3123
|
const varName = lang.replace("-", "") + i;
|
|
3150
3124
|
imports.unshift(`import ${varName} from "${toAtFS(langYml)}"`);
|
|
3151
3125
|
imports.push(`messages['${lang}'] = replaceArrMerge(${varName}, messages['${lang}'])`);
|
|
@@ -3260,7 +3234,7 @@ function createTransformCodeBlock(options) {
|
|
|
3260
3234
|
|
|
3261
3235
|
// node/plugins/markdown/transform/dead-links.ts
|
|
3262
3236
|
import { slash as slash4 } from "@antfu/utils";
|
|
3263
|
-
import
|
|
3237
|
+
import fs17 from "fs-extra";
|
|
3264
3238
|
import path9 from "pathe";
|
|
3265
3239
|
function createScanDeadLinks(options) {
|
|
3266
3240
|
const srcDir = path9.resolve(options.userRoot, "pages");
|
|
@@ -3307,7 +3281,7 @@ function createScanDeadLinks(options) {
|
|
|
3307
3281
|
)
|
|
3308
3282
|
// /index => /
|
|
3309
3283
|
).replace(/\/index$/, "");
|
|
3310
|
-
if (!options.pages.includes(resolved) && !
|
|
3284
|
+
if (!options.pages.includes(resolved) && !fs17.existsSync(path9.resolve(dir, publicDir, `${resolved}.html`)) && !shouldIgnoreDeadLink(url)) {
|
|
3311
3285
|
recordDeadLink(url);
|
|
3312
3286
|
}
|
|
3313
3287
|
}
|
|
@@ -3454,11 +3428,11 @@ function transformFootnoteTooltip(code, _id) {
|
|
|
3454
3428
|
}
|
|
3455
3429
|
|
|
3456
3430
|
// node/plugins/markdown/transform/hexo.ts
|
|
3457
|
-
import { consola as
|
|
3431
|
+
import { consola as consola10 } from "consola";
|
|
3458
3432
|
import { colors as colors10 } from "consola/utils";
|
|
3459
3433
|
function transformHexoTags(code, id) {
|
|
3460
3434
|
if (code.includes("{%") && code.includes("%}")) {
|
|
3461
|
-
|
|
3435
|
+
consola10.error(
|
|
3462
3436
|
`${`${id}
|
|
3463
3437
|
`} Please ${colors10.red("remove")} ${colors10.cyan("{% %}")}, because it conflicts with ${colors10.yellow("markdown-it-attrs")}.`
|
|
3464
3438
|
);
|
|
@@ -3470,7 +3444,7 @@ function transformHexoTags(code, id) {
|
|
|
3470
3444
|
|
|
3471
3445
|
// node/plugins/markdown/transform/markdown.ts
|
|
3472
3446
|
import path10 from "path";
|
|
3473
|
-
import
|
|
3447
|
+
import fs18 from "fs-extra";
|
|
3474
3448
|
function genProvideCode(name, data) {
|
|
3475
3449
|
return [
|
|
3476
3450
|
`const $${name} = ${transformObject(data)}`,
|
|
@@ -3502,7 +3476,7 @@ function injectPageDataCode(pageData) {
|
|
|
3502
3476
|
}
|
|
3503
3477
|
function createTransformMarkdown(options) {
|
|
3504
3478
|
const loaderVuePath = path10.resolve(options.clientRoot, "templates", "loader.vue");
|
|
3505
|
-
const loaderVue =
|
|
3479
|
+
const loaderVue = fs18.readFileSync(loaderVuePath, "utf-8");
|
|
3506
3480
|
return (code, id, pageData) => {
|
|
3507
3481
|
const isDev = options.mode === "dev";
|
|
3508
3482
|
if (!isDev) {
|
|
@@ -3654,7 +3628,7 @@ async function createMarkdownToVueRenderFn(options, _viteConfig) {
|
|
|
3654
3628
|
var nullVue = 'import { defineComponent } from "vue"; export default defineComponent({ render: () => null });';
|
|
3655
3629
|
function generateAppVue(root) {
|
|
3656
3630
|
const appVue = join7(root, "App.vue");
|
|
3657
|
-
if (!
|
|
3631
|
+
if (!fs19.existsSync(appVue))
|
|
3658
3632
|
return nullVue;
|
|
3659
3633
|
const scripts = [
|
|
3660
3634
|
`import AppVue from "${toAtFS(appVue)}"`,
|
|
@@ -3726,8 +3700,8 @@ async function createValaxyPlugin(options, serverOptions = {}) {
|
|
|
3726
3700
|
const { code: newCode, deadLinks, includes } = await markdownToVue(code, id);
|
|
3727
3701
|
if (deadLinks.length) {
|
|
3728
3702
|
hasDeadLinks = true;
|
|
3729
|
-
|
|
3730
|
-
|
|
3703
|
+
consola11.error(`Dead links found in ${id}`);
|
|
3704
|
+
consola11.error(deadLinks);
|
|
3731
3705
|
}
|
|
3732
3706
|
if (includes.length) {
|
|
3733
3707
|
includes.forEach((i) => {
|
|
@@ -3774,7 +3748,7 @@ async function createValaxyPlugin(options, serverOptions = {}) {
|
|
|
3774
3748
|
valaxyConfig.themeConfig = themeConfig;
|
|
3775
3749
|
return reloadConfigAndEntries(valaxyConfig);
|
|
3776
3750
|
}
|
|
3777
|
-
if (file ===
|
|
3751
|
+
if (file === resolve9(options.themeRoot, "valaxy.config.ts")) {
|
|
3778
3752
|
const themeValaxyConfig = await resolveThemeValaxyConfig(options);
|
|
3779
3753
|
const valaxyConfig2 = mergeValaxyConfig(options.config, themeValaxyConfig);
|
|
3780
3754
|
const { config } = await processValaxyOptions(options, valaxyConfig2);
|
|
@@ -3813,11 +3787,11 @@ async function createValaxyPlugin(options, serverOptions = {}) {
|
|
|
3813
3787
|
}
|
|
3814
3788
|
|
|
3815
3789
|
// node/plugins/vueRouter.ts
|
|
3816
|
-
import
|
|
3790
|
+
import fs20 from "fs-extra";
|
|
3817
3791
|
import matter3 from "gray-matter";
|
|
3818
3792
|
import { convert } from "html-to-text";
|
|
3819
3793
|
import { MarkdownItAsync } from "markdown-it-async";
|
|
3820
|
-
import { resolve as
|
|
3794
|
+
import { resolve as resolve10 } from "pathe";
|
|
3821
3795
|
import VueRouter from "unplugin-vue-router/vite";
|
|
3822
3796
|
|
|
3823
3797
|
// node/plugins/presets/statistics.ts
|
|
@@ -3894,7 +3868,7 @@ async function createRouterPlugin(valaxyApp) {
|
|
|
3894
3868
|
return VueRouter({
|
|
3895
3869
|
extensions: [".vue", ".md"],
|
|
3896
3870
|
routesFolder: roots.map((root) => `${root}/pages`),
|
|
3897
|
-
dts:
|
|
3871
|
+
dts: resolve10(options.tempDir, "typed-router.d.ts"),
|
|
3898
3872
|
...valaxyConfig.router,
|
|
3899
3873
|
/**
|
|
3900
3874
|
* @experimental See https://github.com/posva/unplugin-vue-router/issues/43
|
|
@@ -3933,7 +3907,7 @@ async function createRouterPlugin(valaxyApp) {
|
|
|
3933
3907
|
}
|
|
3934
3908
|
const path18 = route.components.get("default") || "";
|
|
3935
3909
|
if (path18.endsWith(".md")) {
|
|
3936
|
-
const md3 =
|
|
3910
|
+
const md3 = fs20.readFileSync(path18, "utf-8");
|
|
3937
3911
|
const { data, excerpt, content } = matter3(md3, matterOptions);
|
|
3938
3912
|
const mdFm = data;
|
|
3939
3913
|
const lastUpdated = options.config.siteConfig.lastUpdated;
|
|
@@ -3943,10 +3917,10 @@ async function createRouterPlugin(valaxyApp) {
|
|
|
3943
3917
|
delete mdFm.photos;
|
|
3944
3918
|
}
|
|
3945
3919
|
if (!mdFm.date)
|
|
3946
|
-
mdFm.date = (await
|
|
3920
|
+
mdFm.date = (await fs20.stat(path18)).mtime;
|
|
3947
3921
|
if (lastUpdated) {
|
|
3948
3922
|
if (!mdFm.updated)
|
|
3949
|
-
mdFm.updated = (await
|
|
3923
|
+
mdFm.updated = (await fs20.stat(path18)).ctime;
|
|
3950
3924
|
}
|
|
3951
3925
|
if (mdFm.from) {
|
|
3952
3926
|
if (Array.isArray(mdFm.from)) {
|
|
@@ -4075,7 +4049,7 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
|
|
|
4075
4049
|
* latter override former
|
|
4076
4050
|
*/
|
|
4077
4051
|
dirs: componentsDirs,
|
|
4078
|
-
dts:
|
|
4052
|
+
dts: resolve11(options.tempDir, "components.d.ts"),
|
|
4079
4053
|
...valaxyConfig.components
|
|
4080
4054
|
}),
|
|
4081
4055
|
// https://github.com/antfu/unocss
|
|
@@ -4103,10 +4077,10 @@ async function ViteValaxyPlugins(valaxyApp, serverOptions = {}) {
|
|
|
4103
4077
|
);
|
|
4104
4078
|
} catch (e) {
|
|
4105
4079
|
console.error(e);
|
|
4106
|
-
|
|
4107
|
-
|
|
4080
|
+
consola12.error("Failed to load rollup-plugin-visualizer");
|
|
4081
|
+
consola12.error("Please install `rollup-plugin-visualizer` to enable the feature");
|
|
4108
4082
|
console.log();
|
|
4109
|
-
|
|
4083
|
+
consola12.info("pnpm add -D rollup-plugin-visualizer");
|
|
4110
4084
|
console.log();
|
|
4111
4085
|
}
|
|
4112
4086
|
}
|
|
@@ -4219,7 +4193,7 @@ async function ssgBuild(valaxyApp, viteConfig = {}) {
|
|
|
4219
4193
|
const newPaths = paths;
|
|
4220
4194
|
const posts = paths.filter((path18) => path18.startsWith("/posts/"));
|
|
4221
4195
|
const pageNumber = Math.ceil(posts.length / options.config.siteConfig.pageSize);
|
|
4222
|
-
|
|
4196
|
+
consola13.info(`Generate ${colors12.yellow(pageNumber)} pages for pagination.`);
|
|
4223
4197
|
for (let i = 1; i <= pageNumber; i++)
|
|
4224
4198
|
newPaths.push(`/page/${i}`);
|
|
4225
4199
|
if (!options.config.vite?.ssgOptions?.includeAllRoutes)
|
|
@@ -4233,28 +4207,28 @@ async function ssgBuild(valaxyApp, viteConfig = {}) {
|
|
|
4233
4207
|
}
|
|
4234
4208
|
async function postProcessForSSG(options) {
|
|
4235
4209
|
const { userRoot: userRoot2 } = options;
|
|
4236
|
-
const indexPath =
|
|
4237
|
-
if (
|
|
4238
|
-
|
|
4239
|
-
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");
|
|
4240
4214
|
const htmlTag = "</html>";
|
|
4241
4215
|
if (!indexFile.endsWith(htmlTag)) {
|
|
4242
|
-
|
|
4216
|
+
consola13.warn("fix incomplete index.html...");
|
|
4243
4217
|
const htmlTagStart = indexFile.lastIndexOf(htmlTag);
|
|
4244
|
-
await
|
|
4218
|
+
await fs21.writeFile(indexPath, indexFile.slice(0, htmlTagStart + htmlTag.length), "utf-8");
|
|
4245
4219
|
}
|
|
4246
4220
|
}
|
|
4247
4221
|
if (!options.config.siteConfig.redirects?.useVueRouter)
|
|
4248
4222
|
await generateClientRedirects(options);
|
|
4249
4223
|
}
|
|
4250
4224
|
async function generateClientRedirects(options) {
|
|
4251
|
-
|
|
4252
|
-
const outputPath =
|
|
4225
|
+
consola13.info("generate client redirects...");
|
|
4226
|
+
const outputPath = resolve12(options.userRoot, "dist");
|
|
4253
4227
|
const redirectRules = collectRedirects(options.redirects);
|
|
4254
4228
|
const task = redirectRules.map(async (rule) => {
|
|
4255
4229
|
const fromPath = join8(outputPath, `${rule.from}.html`);
|
|
4256
4230
|
const toPath = join8(outputPath, `${rule.to}.html`);
|
|
4257
|
-
const routeExist = await
|
|
4231
|
+
const routeExist = await fs21.pathExists(toPath);
|
|
4258
4232
|
if (!routeExist)
|
|
4259
4233
|
throw new Error(`the route of '${rule.to}' not exists`);
|
|
4260
4234
|
await writeRedirectFiles(rule.to, fromPath);
|
|
@@ -4299,7 +4273,7 @@ async function createServer(valaxyApp, viteConfig = {}, serverOptions = {}) {
|
|
|
4299
4273
|
import os from "os";
|
|
4300
4274
|
import path13 from "path";
|
|
4301
4275
|
import process8 from "process";
|
|
4302
|
-
import { consola as
|
|
4276
|
+
import { consola as consola14 } from "consola";
|
|
4303
4277
|
import { colors as colors14 } from "consola/utils";
|
|
4304
4278
|
import ora4 from "ora";
|
|
4305
4279
|
import { mergeConfig as mergeConfig3 } from "vite";
|
|
@@ -4371,7 +4345,7 @@ async function initServer(valaxyApp, viteConfig) {
|
|
|
4371
4345
|
serverSpinner.succeed(`${valaxyPrefix} ${colors14.green("server ready.")}`);
|
|
4372
4346
|
return server;
|
|
4373
4347
|
} catch (e) {
|
|
4374
|
-
|
|
4348
|
+
consola14.error("failed to start server. error:\n");
|
|
4375
4349
|
console.error(e);
|
|
4376
4350
|
process8.exit(1);
|
|
4377
4351
|
}
|
|
@@ -4379,7 +4353,7 @@ async function initServer(valaxyApp, viteConfig) {
|
|
|
4379
4353
|
if (import.meta.hot) {
|
|
4380
4354
|
await import.meta.hot.data.stopping;
|
|
4381
4355
|
let reload = async () => {
|
|
4382
|
-
|
|
4356
|
+
consola14.info("HMR: Stop Server");
|
|
4383
4357
|
await GLOBAL_STATE.server?.close();
|
|
4384
4358
|
};
|
|
4385
4359
|
import.meta.hot.on("vite:beforeFullReload", () => {
|
|
@@ -4426,19 +4400,19 @@ async function execBuild({ ssg, root, output, log }) {
|
|
|
4426
4400
|
);
|
|
4427
4401
|
await callHookWithLog("config:init", valaxyApp);
|
|
4428
4402
|
await callHookWithLog("build:before", valaxyApp);
|
|
4429
|
-
|
|
4403
|
+
consola15.box("\u{1F320} Start building...");
|
|
4430
4404
|
try {
|
|
4431
4405
|
if (ssg) {
|
|
4432
|
-
|
|
4406
|
+
consola15.info(`use ${colors15.yellow("vite-ssg")} to do ssg build...`);
|
|
4433
4407
|
try {
|
|
4434
4408
|
await ssgBuild(valaxyApp, viteConfig);
|
|
4435
4409
|
await postProcessForSSG(options);
|
|
4436
4410
|
} catch (e) {
|
|
4437
|
-
|
|
4411
|
+
consola15.error("[vite-ssg] An internal error occurred.");
|
|
4438
4412
|
console.log(e);
|
|
4439
4413
|
}
|
|
4440
4414
|
} else {
|
|
4441
|
-
|
|
4415
|
+
consola15.info("use vite do spa build...");
|
|
4442
4416
|
await build2(valaxyApp, viteConfig);
|
|
4443
4417
|
}
|
|
4444
4418
|
} catch (e) {
|
|
@@ -4478,35 +4452,35 @@ function registerBuildCommand(cli2) {
|
|
|
4478
4452
|
// node/cli/clean.ts
|
|
4479
4453
|
import path15 from "path";
|
|
4480
4454
|
import process10 from "process";
|
|
4481
|
-
import { consola as
|
|
4482
|
-
import
|
|
4455
|
+
import { consola as consola16 } from "consola";
|
|
4456
|
+
import fs22 from "fs-extra";
|
|
4483
4457
|
async function cleanDist() {
|
|
4484
4458
|
const distDir = path15.join(process10.cwd(), "dist");
|
|
4485
4459
|
const cacheDir = path15.join(process10.cwd(), ".valaxy");
|
|
4486
|
-
|
|
4487
|
-
if (await
|
|
4488
|
-
|
|
4460
|
+
consola16.box("\u{1F9F9} Starting clean...");
|
|
4461
|
+
if (await fs22.exists(distDir)) {
|
|
4462
|
+
consola16.info("dist directory exists, removing...");
|
|
4489
4463
|
try {
|
|
4490
|
-
await
|
|
4491
|
-
|
|
4464
|
+
await fs22.rm(distDir, { recursive: true, force: true });
|
|
4465
|
+
consola16.success("dist directory has been successfully removed.");
|
|
4492
4466
|
} catch (error) {
|
|
4493
|
-
|
|
4494
|
-
|
|
4467
|
+
consola16.error("Failed to remove dist directory.");
|
|
4468
|
+
consola16.error(error);
|
|
4495
4469
|
}
|
|
4496
4470
|
} else {
|
|
4497
|
-
|
|
4471
|
+
consola16.info("No dist directory found, nothing to clean.");
|
|
4498
4472
|
}
|
|
4499
|
-
if (await
|
|
4500
|
-
|
|
4473
|
+
if (await fs22.exists(cacheDir)) {
|
|
4474
|
+
consola16.info(".valaxy cache directory exists, removing...");
|
|
4501
4475
|
try {
|
|
4502
|
-
await
|
|
4503
|
-
|
|
4476
|
+
await fs22.rm(cacheDir, { recursive: true, force: true });
|
|
4477
|
+
consola16.success(".valaxy cache directory has been successfully removed.");
|
|
4504
4478
|
} catch (error) {
|
|
4505
|
-
|
|
4506
|
-
|
|
4479
|
+
consola16.error("Failed to remove .valaxy cache directory.");
|
|
4480
|
+
consola16.error(error);
|
|
4507
4481
|
}
|
|
4508
4482
|
} else {
|
|
4509
|
-
|
|
4483
|
+
consola16.info("No .valaxy cache directory found, nothing to clean.");
|
|
4510
4484
|
}
|
|
4511
4485
|
}
|
|
4512
4486
|
function registerCleanCommand(cli2) {
|
|
@@ -4522,15 +4496,21 @@ function registerCleanCommand(cli2) {
|
|
|
4522
4496
|
}
|
|
4523
4497
|
|
|
4524
4498
|
// node/cli/debug.ts
|
|
4525
|
-
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";
|
|
4526
4503
|
function registerDebugCommand(cli2) {
|
|
4527
4504
|
cli2.command("debug", "Debug your blog", async () => {
|
|
4528
|
-
|
|
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}`));
|
|
4529
4509
|
});
|
|
4530
4510
|
}
|
|
4531
4511
|
|
|
4532
4512
|
// node/cli/deploy.ts
|
|
4533
|
-
import
|
|
4513
|
+
import process12 from "process";
|
|
4534
4514
|
import { confirm, intro, outro, select } from "@clack/prompts";
|
|
4535
4515
|
function registerDeployCommand(cli2) {
|
|
4536
4516
|
cli2.command("deploy", "deploy your blog to the cloud", async () => {
|
|
@@ -4539,7 +4519,7 @@ function registerDeployCommand(cli2) {
|
|
|
4539
4519
|
message: "Do you want to build your blog before deploying?"
|
|
4540
4520
|
});
|
|
4541
4521
|
if (shouldBuild) {
|
|
4542
|
-
await execBuild({ ssg: true, root:
|
|
4522
|
+
await execBuild({ ssg: true, root: process12.cwd(), output: "dist", log: "info" });
|
|
4543
4523
|
}
|
|
4544
4524
|
const deployType = await select({
|
|
4545
4525
|
message: "Where do you want to deploy?",
|
|
@@ -4579,7 +4559,7 @@ function registerDeployCommand(cli2) {
|
|
|
4579
4559
|
|
|
4580
4560
|
// node/cli/dev.ts
|
|
4581
4561
|
import path16 from "path";
|
|
4582
|
-
import
|
|
4562
|
+
import process14 from "process";
|
|
4583
4563
|
import { mergeConfig as mergeConfig5 } from "vite";
|
|
4584
4564
|
|
|
4585
4565
|
// node/utils/net.ts
|
|
@@ -4590,28 +4570,28 @@ async function findFreePort(start) {
|
|
|
4590
4570
|
return await findFreePort(start + 1);
|
|
4591
4571
|
}
|
|
4592
4572
|
function isPortFree(port) {
|
|
4593
|
-
return new Promise((
|
|
4573
|
+
return new Promise((resolve14) => {
|
|
4594
4574
|
const server = net.createServer((socket) => {
|
|
4595
4575
|
socket.write("Echo server\r\n");
|
|
4596
4576
|
socket.pipe(socket);
|
|
4597
4577
|
});
|
|
4598
4578
|
server.listen(port, "0.0.0.0");
|
|
4599
4579
|
server.on("error", () => {
|
|
4600
|
-
|
|
4580
|
+
resolve14(false);
|
|
4601
4581
|
});
|
|
4602
4582
|
server.on("listening", () => {
|
|
4603
4583
|
server.close();
|
|
4604
|
-
|
|
4584
|
+
resolve14(true);
|
|
4605
4585
|
});
|
|
4606
4586
|
});
|
|
4607
4587
|
}
|
|
4608
4588
|
|
|
4609
4589
|
// node/cli/utils/shortcuts.ts
|
|
4610
4590
|
import { exec } from "child_process";
|
|
4611
|
-
import
|
|
4612
|
-
import
|
|
4591
|
+
import os3 from "os";
|
|
4592
|
+
import process13 from "process";
|
|
4613
4593
|
import * as readline from "readline";
|
|
4614
|
-
import { colors as
|
|
4594
|
+
import { colors as colors17 } from "consola/utils";
|
|
4615
4595
|
import qrcode from "qrcode";
|
|
4616
4596
|
var SHORTCUTS = [
|
|
4617
4597
|
{
|
|
@@ -4636,7 +4616,7 @@ var SHORTCUTS = [
|
|
|
4636
4616
|
key: "q",
|
|
4637
4617
|
description: "qr",
|
|
4638
4618
|
action(server) {
|
|
4639
|
-
const addresses = Object.values(
|
|
4619
|
+
const addresses = Object.values(os3.networkInterfaces()).flat().filter((details) => details?.family === "IPv4" && !details.address.includes("127.0.0.1"));
|
|
4640
4620
|
const port = server.config.server.port;
|
|
4641
4621
|
const remoteUrl = `http://${addresses[0]?.address || "localhost"}:${port}`;
|
|
4642
4622
|
qrcode.toString(remoteUrl, { type: "terminal" }, (err, qrCode) => {
|
|
@@ -4650,7 +4630,7 @@ var SHORTCUTS = [
|
|
|
4650
4630
|
key: "e",
|
|
4651
4631
|
description: "edit",
|
|
4652
4632
|
action() {
|
|
4653
|
-
exec(`code "${
|
|
4633
|
+
exec(`code "${process13.cwd()}"`, (err) => {
|
|
4654
4634
|
if (err)
|
|
4655
4635
|
console.error("Failed to open editor", err);
|
|
4656
4636
|
});
|
|
@@ -4658,18 +4638,18 @@ var SHORTCUTS = [
|
|
|
4658
4638
|
}
|
|
4659
4639
|
];
|
|
4660
4640
|
function bindShortcuts(server, createDevServer) {
|
|
4661
|
-
if (!server.httpServer ||
|
|
4662
|
-
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);
|
|
4663
4643
|
return;
|
|
4664
4644
|
}
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
readline.emitKeypressEvents(
|
|
4668
|
-
if (
|
|
4669
|
-
|
|
4645
|
+
process13.stdin.resume();
|
|
4646
|
+
process13.stdin.setEncoding("utf8");
|
|
4647
|
+
readline.emitKeypressEvents(process13.stdin);
|
|
4648
|
+
if (process13.stdin.isTTY)
|
|
4649
|
+
process13.stdin.setRawMode(true);
|
|
4670
4650
|
async function onKeyPress(str, key) {
|
|
4671
4651
|
if (key.ctrl && key.name === "c") {
|
|
4672
|
-
|
|
4652
|
+
process13.exit();
|
|
4673
4653
|
} else {
|
|
4674
4654
|
const shortcut = SHORTCUTS.find((shortcut2) => shortcut2.key === str);
|
|
4675
4655
|
if (!shortcut)
|
|
@@ -4677,19 +4657,19 @@ function bindShortcuts(server, createDevServer) {
|
|
|
4677
4657
|
try {
|
|
4678
4658
|
await shortcut.action(server, createDevServer);
|
|
4679
4659
|
} catch (error) {
|
|
4680
|
-
console.error(
|
|
4660
|
+
console.error(colors17.red("Error executing shortcut:"), key, error);
|
|
4681
4661
|
}
|
|
4682
4662
|
}
|
|
4683
4663
|
}
|
|
4684
|
-
|
|
4664
|
+
process13.stdin.on("keypress", onKeyPress);
|
|
4685
4665
|
server.httpServer.on("close", () => {
|
|
4686
|
-
|
|
4666
|
+
process13.stdin.off("keypress", onKeyPress);
|
|
4687
4667
|
});
|
|
4688
4668
|
}
|
|
4689
4669
|
|
|
4690
4670
|
// node/cli/dev.ts
|
|
4691
4671
|
async function startValaxyDev({
|
|
4692
|
-
root =
|
|
4672
|
+
root = process14.cwd(),
|
|
4693
4673
|
port,
|
|
4694
4674
|
remote,
|
|
4695
4675
|
log,
|
|
@@ -4697,7 +4677,7 @@ async function startValaxyDev({
|
|
|
4697
4677
|
}) {
|
|
4698
4678
|
setEnv();
|
|
4699
4679
|
if (!isPagesDirExist(root))
|
|
4700
|
-
|
|
4680
|
+
process14.exit(0);
|
|
4701
4681
|
port = port || await findFreePort(4859);
|
|
4702
4682
|
const resolvedOptions = await resolveOptions({ userRoot: root });
|
|
4703
4683
|
setTimezone(resolvedOptions.config.siteConfig.timezone);
|
|
@@ -4765,16 +4745,16 @@ function registerDevCommand(cli2) {
|
|
|
4765
4745
|
}
|
|
4766
4746
|
|
|
4767
4747
|
// node/cli/utils/post.ts
|
|
4768
|
-
import { dirname as dirname5, join as join9, resolve as
|
|
4769
|
-
import { consola as
|
|
4770
|
-
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";
|
|
4771
4751
|
import dayjs2 from "dayjs";
|
|
4772
4752
|
import { render } from "ejs";
|
|
4773
|
-
import
|
|
4753
|
+
import fs24 from "fs-extra";
|
|
4774
4754
|
|
|
4775
4755
|
// node/cli/utils/constants.ts
|
|
4776
|
-
import
|
|
4777
|
-
var userRoot =
|
|
4756
|
+
import process15 from "process";
|
|
4757
|
+
var userRoot = process15.cwd();
|
|
4778
4758
|
var defaultPostTemplate = `---
|
|
4779
4759
|
layout: <%=layout%>
|
|
4780
4760
|
title: <%=title%>
|
|
@@ -4785,13 +4765,13 @@ date: <%=date%>
|
|
|
4785
4765
|
// node/cli/utils/scaffold.ts
|
|
4786
4766
|
import { readFile as readFile2 } from "fs/promises";
|
|
4787
4767
|
import path17 from "path";
|
|
4788
|
-
import
|
|
4768
|
+
import fs23 from "fs-extra";
|
|
4789
4769
|
async function getTemplate(layout) {
|
|
4790
4770
|
const { clientRoot, themeRoot } = await resolveOptions({ userRoot });
|
|
4791
4771
|
const roots = [userRoot, themeRoot, clientRoot];
|
|
4792
4772
|
for (const root of roots) {
|
|
4793
4773
|
const scaffoldPath = path17.resolve(root, "scaffolds", `${layout}.md`);
|
|
4794
|
-
if (await
|
|
4774
|
+
if (await fs23.exists(scaffoldPath))
|
|
4795
4775
|
return readFile2(scaffoldPath, "utf-8");
|
|
4796
4776
|
}
|
|
4797
4777
|
return false;
|
|
@@ -4799,22 +4779,22 @@ async function getTemplate(layout) {
|
|
|
4799
4779
|
|
|
4800
4780
|
// node/cli/utils/post.ts
|
|
4801
4781
|
async function create(params) {
|
|
4802
|
-
const pagesPath =
|
|
4782
|
+
const pagesPath = resolve13(userRoot, params.path || "pages");
|
|
4803
4783
|
let counter = 0;
|
|
4804
4784
|
while (true) {
|
|
4805
4785
|
const postFileName = `${params.title}${counter ? `-${counter}` : ""}`;
|
|
4806
4786
|
const postFilePath = params.folder ? join9(postFileName, "index.md") : `${postFileName}.md`;
|
|
4807
|
-
const targetPath =
|
|
4808
|
-
if (!await
|
|
4809
|
-
await
|
|
4787
|
+
const targetPath = resolve13(pagesPath, "posts", postFilePath);
|
|
4788
|
+
if (!await fs24.exists(targetPath)) {
|
|
4789
|
+
await fs24.ensureDir(dirname5(targetPath));
|
|
4810
4790
|
const content = await genLayoutTemplate(params);
|
|
4811
4791
|
try {
|
|
4812
|
-
await
|
|
4813
|
-
|
|
4792
|
+
await fs24.writeFile(targetPath, content, "utf-8");
|
|
4793
|
+
consola18.success(`[valaxy new]: successfully generated file ${colors18.magenta(targetPath)}`);
|
|
4814
4794
|
} catch (e) {
|
|
4815
4795
|
console.log(e);
|
|
4816
|
-
|
|
4817
|
-
|
|
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.`);
|
|
4818
4798
|
}
|
|
4819
4799
|
return targetPath;
|
|
4820
4800
|
}
|
|
@@ -4875,7 +4855,7 @@ function registerNewCommand(cli2) {
|
|
|
4875
4855
|
}
|
|
4876
4856
|
|
|
4877
4857
|
// node/cli/index.ts
|
|
4878
|
-
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");
|
|
4879
4859
|
registerDevCommand(cli);
|
|
4880
4860
|
registerBuildCommand(cli);
|
|
4881
4861
|
registerNewCommand(cli);
|
|
@@ -4911,7 +4891,6 @@ export {
|
|
|
4911
4891
|
resolveImportPath,
|
|
4912
4892
|
mergeViteConfigs,
|
|
4913
4893
|
getIndexHtml,
|
|
4914
|
-
loadConfig,
|
|
4915
4894
|
loadConfigFromFile,
|
|
4916
4895
|
defaultSiteConfig,
|
|
4917
4896
|
defineSiteConfig,
|