@vuepress/utils 2.0.0-beta.50-pre → 2.0.0-beta.50-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ export { default as chalk } from 'chalk';
2
+ export { default as debug } from 'debug';
3
+ export { default as fs } from 'fs-extra';
4
+ export { globby } from 'globby';
5
+ export { default as hash } from 'hash-sum';
6
+ export { default as ora } from 'ora';
7
+ export { default as path } from 'upath';
8
+ import { HeadConfig, HeadAttrsConfig } from '@vuepress/shared';
9
+
10
+ declare const getDirname: (importMetaUrl: string) => string;
11
+
12
+ /**
13
+ * A helper for dynamically importing a file path
14
+ *
15
+ * We need to use `pathToFileURL` to transform file path wo compat with windows
16
+ */
17
+ declare const importFile: <T>(filePath: string) => Promise<T>;
18
+ /**
19
+ * A wrapper of `importFile` and returns the default export
20
+ */
21
+ declare const importFileDefault: <T>(filePath: string) => Promise<T>;
22
+
23
+ /**
24
+ * Check if `child` is a sub path of `parent` or not. Return `true` if
25
+ * they are the same path
26
+ */
27
+ declare const isChildPath: (child: string, parent: string) => boolean;
28
+
29
+ declare const info: (...args: any[]) => void;
30
+ declare const tip: (...args: any[]) => void;
31
+ declare const success: (...args: any[]) => void;
32
+ declare const warn: (...args: any[]) => void;
33
+ declare const error: (...args: any[]) => void;
34
+ declare const createError: (message?: string | undefined) => Error;
35
+ declare const logger: {
36
+ info: (...args: any[]) => void;
37
+ tip: (...args: any[]) => void;
38
+ success: (...args: any[]) => void;
39
+ warn: (...args: any[]) => void;
40
+ error: (...args: any[]) => void;
41
+ createError: (message?: string | undefined) => Error;
42
+ };
43
+
44
+ /**
45
+ * Render head config to string
46
+ */
47
+ declare const renderHead: ([tag, attrs, innerHTML,]: HeadConfig) => string;
48
+
49
+ /**
50
+ * Render head attrs config to string
51
+ */
52
+ declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
53
+
54
+ declare const withSpinner: (msg: string) => <T>(target: () => Promise<T>) => Promise<T>;
55
+
56
+ export { createError, error, getDirname, importFile, importFileDefault, info, isChildPath, logger, renderHead, renderHeadAttrs, success, tip, warn, withSpinner };
package/dist/index.js ADDED
@@ -0,0 +1,120 @@
1
+ // src/index.ts
2
+ import chalk2 from "chalk";
3
+ import debug from "debug";
4
+ import fs from "fs-extra";
5
+ import { globby } from "globby";
6
+ import hash from "hash-sum";
7
+ import ora2 from "ora";
8
+ import path3 from "upath";
9
+
10
+ // src/getDirname.ts
11
+ import { fileURLToPath } from "url";
12
+ import path from "upath";
13
+ var getDirname = (importMetaUrl) => path.dirname(fileURLToPath(importMetaUrl));
14
+
15
+ // src/importFile.ts
16
+ import { pathToFileURL } from "url";
17
+ var importFile = (filePath) => import(pathToFileURL(filePath).toString());
18
+ var importFileDefault = (filePath) => importFile(filePath).then((m) => m.default);
19
+
20
+ // src/isChildPath.ts
21
+ import path2 from "upath";
22
+ var isChildPath = (child, parent) => {
23
+ const childPath = path2.normalize(child);
24
+ const parentPath = path2.normalize(parent);
25
+ if (!path2.win32.isAbsolute(childPath) || !path2.win32.isAbsolute(parentPath)) {
26
+ return false;
27
+ }
28
+ const relativePath = path2.relative(parentPath, childPath);
29
+ return relativePath === "" || !relativePath.startsWith("..");
30
+ };
31
+
32
+ // src/logger.ts
33
+ import chalk from "chalk";
34
+ var info = (...args) => {
35
+ console.log(chalk.cyan("info"), ...args);
36
+ };
37
+ var tip = (...args) => {
38
+ console.log(chalk.blue("tip"), ...args);
39
+ };
40
+ var success = (...args) => {
41
+ console.log(chalk.green("success"), ...args);
42
+ };
43
+ var warn = (...args) => {
44
+ console.warn(chalk.yellow("warning"), ...args);
45
+ };
46
+ var error = (...args) => {
47
+ console.error(chalk.red("error"), ...args);
48
+ };
49
+ var createError = (message) => {
50
+ error(message);
51
+ return new Error(message);
52
+ };
53
+ var logger = {
54
+ info,
55
+ tip,
56
+ success,
57
+ warn,
58
+ error,
59
+ createError
60
+ };
61
+
62
+ // src/renderHeadAttrs.ts
63
+ var renderHeadAttrs = (attrs) => Object.entries(attrs).filter((item) => item[1] !== false).map(
64
+ ([key, value]) => value === true ? ` ${key}` : ` ${key}="${attrs[key]}"`
65
+ ).join("");
66
+
67
+ // src/renderHead.ts
68
+ var renderHead = ([
69
+ tag,
70
+ attrs,
71
+ innerHTML = ""
72
+ ]) => {
73
+ const openTag = `<${tag}${renderHeadAttrs(attrs)}>`;
74
+ if (tag === "link" || tag === "meta" || tag === "base") {
75
+ return openTag;
76
+ }
77
+ return `${openTag}${innerHTML}</${tag}>`;
78
+ };
79
+
80
+ // src/withSpinner.ts
81
+ import process from "process";
82
+ import ora from "ora";
83
+ var withSpinner = (msg) => async (target) => {
84
+ if (process.env.DEBUG) {
85
+ return target();
86
+ }
87
+ const spinner = ora();
88
+ try {
89
+ spinner.start(msg);
90
+ const result = await target();
91
+ spinner.succeed(`${msg} - done`);
92
+ return result;
93
+ } catch (e) {
94
+ spinner.fail(`${msg} - failed`);
95
+ throw e;
96
+ }
97
+ };
98
+ export {
99
+ chalk2 as chalk,
100
+ createError,
101
+ debug,
102
+ error,
103
+ fs,
104
+ getDirname,
105
+ globby,
106
+ hash,
107
+ importFile,
108
+ importFileDefault,
109
+ info,
110
+ isChildPath,
111
+ logger,
112
+ ora2 as ora,
113
+ path3 as path,
114
+ renderHead,
115
+ renderHeadAttrs,
116
+ success,
117
+ tip,
118
+ warn,
119
+ withSpinner
120
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/utils",
3
- "version": "2.0.0-beta.50-pre",
3
+ "version": "2.0.0-beta.50-pre.1",
4
4
  "description": "Utils package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -24,13 +24,13 @@
24
24
  "main": "./dist/index.js",
25
25
  "types": "./dist/index.d.ts",
26
26
  "files": [
27
- "./dist"
27
+ "dist"
28
28
  ],
29
29
  "dependencies": {
30
30
  "@types/debug": "^4.1.7",
31
31
  "@types/fs-extra": "^9.0.13",
32
32
  "@types/hash-sum": "^1.0.0",
33
- "@vuepress/shared": "2.0.0-beta.50-pre",
33
+ "@vuepress/shared": "2.0.0-beta.50-pre.1",
34
34
  "chalk": "^5.0.1",
35
35
  "debug": "^4.3.4",
36
36
  "fs-extra": "^10.1.0",