@vuepress/utils 2.0.0-beta.8 → 2.0.0-rc.0

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,123 @@
1
+ export { default as debug } from 'debug';
2
+ export { default as fs } from 'fs-extra';
3
+ export { globby } from 'globby';
4
+ export { default as hash } from 'hash-sum';
5
+ import { Ora } from 'ora';
6
+ export { default as ora } from 'ora';
7
+ export { default as colors } from 'picocolors';
8
+ export { default as path } from 'upath';
9
+ import { HeadConfig, HeadAttrsConfig } from '@vuepress/shared';
10
+
11
+ /**
12
+ * Format millisecond
13
+ */
14
+ declare const formatMs: (ms: number) => string;
15
+
16
+ declare const info: (...args: any[]) => void;
17
+ declare const tip: (...args: any[]) => void;
18
+ declare const success: (...args: any[]) => void;
19
+ declare const warn: (...args: any[]) => void;
20
+ declare const error: (...args: any[]) => void;
21
+ declare const createError: (message?: string | undefined) => Error;
22
+ declare const logger: {
23
+ info: (...args: any[]) => void;
24
+ tip: (...args: any[]) => void;
25
+ success: (...args: any[]) => void;
26
+ warn: (...args: any[]) => void;
27
+ error: (...args: any[]) => void;
28
+ createError: (message?: string | undefined) => Error;
29
+ };
30
+
31
+ declare const withSpinner: (msg: string) => <T>(target: (spinner?: Ora) => Promise<T>) => Promise<T>;
32
+
33
+ declare const getDirname: (importMetaUrl: string) => string;
34
+
35
+ /**
36
+ * A helper for dynamically importing a file path
37
+ *
38
+ * We need to use `pathToFileURL` to transform file path wo compat with windows
39
+ */
40
+ declare const importFile: <T>(filePath: string) => Promise<T>;
41
+ /**
42
+ * A wrapper of `importFile` and returns the default export
43
+ */
44
+ declare const importFileDefault: <T>(filePath: string) => Promise<T>;
45
+
46
+ /**
47
+ * Check if `child` is a sub path of `parent` or not. Return `true` if
48
+ * they are the same path
49
+ */
50
+ declare const isChildPath: (child: string, parent: string) => boolean;
51
+
52
+ declare const sanitizeFileName: (name: string) => string;
53
+
54
+ /**
55
+ * Render head config to string
56
+ */
57
+ declare const renderHead: ([tag, attrs, innerHTML,]: HeadConfig) => string;
58
+
59
+ /**
60
+ * Render head attrs config to string
61
+ */
62
+ declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
63
+
64
+ /**
65
+ * HTML outlets of the template renderer
66
+ */
67
+ declare const TEMPLATE_RENDERER_OUTLETS: {
68
+ CONTENT: string;
69
+ HEAD: string;
70
+ LANG: string;
71
+ PREFETCH: string;
72
+ PRELOAD: string;
73
+ SCRIPTS: string;
74
+ STYLES: string;
75
+ VERSION: string;
76
+ };
77
+ /**
78
+ * Context type of the template renderer
79
+ */
80
+ interface TemplateRendererContext {
81
+ /**
82
+ * The rendered page content. Typically to be put inside `<div id="app"></div>`
83
+ */
84
+ content: string;
85
+ /**
86
+ * The rendered page head. Typically to be put inside `<head></head>`
87
+ */
88
+ head: string;
89
+ /**
90
+ * The language of the page. Typically to be put inside `<html lang="{{ lang }}">`
91
+ */
92
+ lang: string;
93
+ /**
94
+ * The rendered prefetch links. Typically to be put inside `<head></head>`
95
+ */
96
+ prefetch: string;
97
+ /**
98
+ * The rendered preload links. Typically to be put inside `<head></head>`
99
+ */
100
+ preload: string;
101
+ /**
102
+ * The rendered scripts. Typically to be put before `</body>`
103
+ */
104
+ scripts: string;
105
+ /**
106
+ * The rendered styles. Typically to be put inside `<head></head>`
107
+ */
108
+ styles: string;
109
+ /**
110
+ * The version of VuePress
111
+ */
112
+ version: string;
113
+ }
114
+ /**
115
+ * Type of the template renderer function
116
+ */
117
+ type TemplateRenderer = (template: string, context: TemplateRendererContext) => string | Promise<string>;
118
+ /**
119
+ * The default template renderer implementation
120
+ */
121
+ declare const templateRenderer: TemplateRenderer;
122
+
123
+ export { TEMPLATE_RENDERER_OUTLETS, TemplateRenderer, TemplateRendererContext, createError, error, formatMs, getDirname, importFile, importFileDefault, info, isChildPath, logger, renderHead, renderHeadAttrs, sanitizeFileName, success, templateRenderer, tip, warn, withSpinner };
package/dist/index.js ADDED
@@ -0,0 +1,153 @@
1
+ // src/index.ts
2
+ import debug from "debug";
3
+ import fs from "fs-extra";
4
+ import { globby } from "globby";
5
+ import hash from "hash-sum";
6
+ import ora2 from "ora";
7
+ import colors2 from "picocolors";
8
+ import path3 from "upath";
9
+
10
+ // src/console/formatMs.ts
11
+ var formatMs = (ms) => {
12
+ if (ms < 1e3)
13
+ return `${ms}ms`;
14
+ return `${(ms / 1e3).toFixed(2)}s`;
15
+ };
16
+
17
+ // src/console/logger.ts
18
+ import colors from "picocolors";
19
+ var info = (...args) => {
20
+ console.log(colors.cyan("info"), ...args);
21
+ };
22
+ var tip = (...args) => {
23
+ console.log(colors.blue("tip"), ...args);
24
+ };
25
+ var success = (...args) => {
26
+ console.log(colors.green("success"), ...args);
27
+ };
28
+ var warn = (...args) => {
29
+ console.warn(colors.yellow("warning"), ...args);
30
+ };
31
+ var error = (...args) => {
32
+ console.error(colors.red("error"), ...args);
33
+ };
34
+ var createError = (message) => {
35
+ error(message);
36
+ return new Error(message);
37
+ };
38
+ var logger = {
39
+ info,
40
+ tip,
41
+ success,
42
+ warn,
43
+ error,
44
+ createError
45
+ };
46
+
47
+ // src/console/withSpinner.ts
48
+ import process from "process";
49
+ import ora from "ora";
50
+ var withSpinner = (msg) => async (target) => {
51
+ if (process.env.DEBUG) {
52
+ return target();
53
+ }
54
+ const start = Date.now();
55
+ const spinner = ora();
56
+ try {
57
+ spinner.start(msg);
58
+ const result = await target(spinner);
59
+ spinner.succeed(`${msg} - done in ${formatMs(Date.now() - start)}`);
60
+ return result;
61
+ } catch (e) {
62
+ spinner.fail(`${msg} - failed in ${formatMs(Date.now() - start)}`);
63
+ throw e;
64
+ }
65
+ };
66
+
67
+ // src/module/getDirname.ts
68
+ import { fileURLToPath } from "url";
69
+ import path from "upath";
70
+ var getDirname = (importMetaUrl) => path.dirname(fileURLToPath(importMetaUrl));
71
+
72
+ // src/module/importFile.ts
73
+ import { pathToFileURL } from "url";
74
+ var importFile = (filePath) => import(pathToFileURL(filePath).toString());
75
+ var importFileDefault = (filePath) => importFile(filePath).then((m) => m.default);
76
+
77
+ // src/module/isChildPath.ts
78
+ import path2 from "upath";
79
+ var isChildPath = (child, parent) => {
80
+ const childPath = path2.normalize(child);
81
+ const parentPath = path2.normalize(parent);
82
+ if (!path2.win32.isAbsolute(childPath) || !path2.win32.isAbsolute(parentPath)) {
83
+ return false;
84
+ }
85
+ const relativePath = path2.relative(parentPath, childPath);
86
+ return relativePath === "" || !relativePath.startsWith("..");
87
+ };
88
+
89
+ // src/module/sanitizeFileName.ts
90
+ var INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
91
+ var DRIVE_LETTER_REGEX = /^[a-z]:/i;
92
+ var sanitizeFileName = (name) => {
93
+ const driveLetter = DRIVE_LETTER_REGEX.exec(name)?.[0] || "";
94
+ return driveLetter + name.substring(driveLetter.length).replace(INVALID_CHAR_REGEX, "_").replace(/^_+/, "");
95
+ };
96
+
97
+ // src/ssr/renderHeadAttrs.ts
98
+ var renderHeadAttrs = (attrs) => Object.entries(attrs).filter((item) => item[1] !== false).map(
99
+ ([key, value]) => value === true ? ` ${key}` : ` ${key}="${attrs[key]}"`
100
+ ).join("");
101
+
102
+ // src/ssr/renderHead.ts
103
+ var renderHead = ([
104
+ tag,
105
+ attrs,
106
+ innerHTML = ""
107
+ ]) => {
108
+ const openTag = `<${tag}${renderHeadAttrs(attrs)}>`;
109
+ if (tag === "link" || tag === "meta" || tag === "base") {
110
+ return openTag;
111
+ }
112
+ return `${openTag}${innerHTML}</${tag}>`;
113
+ };
114
+
115
+ // src/ssr/templateRenderer.ts
116
+ var TEMPLATE_RENDERER_OUTLETS = {
117
+ CONTENT: "<!--vuepress-ssr-content-->",
118
+ HEAD: "<!--vuepress-ssr-head-->",
119
+ LANG: "{{ lang }}",
120
+ PREFETCH: "<!--vuepress-ssr-prefetch-->",
121
+ PRELOAD: "<!--vuepress-ssr-preload-->",
122
+ SCRIPTS: "<!--vuepress-ssr-scripts-->",
123
+ STYLES: "<!--vuepress-ssr-styles-->",
124
+ VERSION: "{{ version }}"
125
+ };
126
+ var templateRenderer = (template, { content, head, lang, prefetch, preload, scripts, styles, version }) => template.replace(TEMPLATE_RENDERER_OUTLETS.CONTENT, () => content).replace(TEMPLATE_RENDERER_OUTLETS.HEAD, head).replace(TEMPLATE_RENDERER_OUTLETS.LANG, lang).replace(TEMPLATE_RENDERER_OUTLETS.PREFETCH, prefetch).replace(TEMPLATE_RENDERER_OUTLETS.PRELOAD, preload).replace(TEMPLATE_RENDERER_OUTLETS.SCRIPTS, scripts).replace(TEMPLATE_RENDERER_OUTLETS.STYLES, styles).replace(TEMPLATE_RENDERER_OUTLETS.VERSION, version);
127
+ export {
128
+ TEMPLATE_RENDERER_OUTLETS,
129
+ colors2 as colors,
130
+ createError,
131
+ debug,
132
+ error,
133
+ formatMs,
134
+ fs,
135
+ getDirname,
136
+ globby,
137
+ hash,
138
+ importFile,
139
+ importFileDefault,
140
+ info,
141
+ isChildPath,
142
+ logger,
143
+ ora2 as ora,
144
+ path3 as path,
145
+ renderHead,
146
+ renderHeadAttrs,
147
+ sanitizeFileName,
148
+ success,
149
+ templateRenderer,
150
+ tip,
151
+ warn,
152
+ withSpinner
153
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/utils",
3
- "version": "2.0.0-beta.8",
3
+ "version": "2.0.0-rc.0",
4
4
  "description": "Utils package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -15,31 +15,49 @@
15
15
  "url": "git+https://github.com/vuepress/vuepress-next.git"
16
16
  },
17
17
  "license": "MIT",
18
- "author": "Evan You",
19
- "main": "lib/index.js",
20
- "types": "lib/index.d.ts",
18
+ "author": "meteorlxy",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": "./dist/index.js",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
21
26
  "files": [
22
- "lib"
27
+ "dist"
23
28
  ],
24
- "scripts": {
25
- "build": "tsc -b tsconfig.build.json",
26
- "clean": "rimraf lib *.tsbuildinfo"
27
- },
28
29
  "dependencies": {
29
- "@types/debug": "^4.1.5",
30
- "@types/fs-extra": "^9.0.9",
31
- "@types/hash-sum": "^1.0.0",
32
- "@vuepress/shared": "2.0.0-beta.7",
33
- "chalk": "^4.1.0",
34
- "debug": "^4.3.1",
35
- "fs-extra": "^9.1.0",
36
- "globby": "^11.0.3",
30
+ "@types/debug": "^4.1.12",
31
+ "@types/fs-extra": "^11.0.4",
32
+ "@types/hash-sum": "^1.0.2",
33
+ "debug": "^4.3.4",
34
+ "fs-extra": "^11.1.1",
35
+ "globby": "^14.0.0",
37
36
  "hash-sum": "^2.0.0",
38
- "ora": "^5.4.0",
39
- "upath": "^2.0.1"
37
+ "ora": "^7.0.1",
38
+ "picocolors": "^1.0.0",
39
+ "upath": "^2.0.1",
40
+ "@vuepress/shared": "2.0.0-rc.0"
40
41
  },
41
42
  "publishConfig": {
42
43
  "access": "public"
43
44
  },
44
- "gitHead": "5ab99126fcaecb845248fcf9d3c88c25ce8572cb"
45
- }
45
+ "tsup": {
46
+ "clean": true,
47
+ "dts": "./src/index.ts",
48
+ "entry": [
49
+ "./src/index.ts"
50
+ ],
51
+ "format": [
52
+ "esm"
53
+ ],
54
+ "outDir": "./dist",
55
+ "sourcemap": false,
56
+ "target": "es2022",
57
+ "tsconfig": "../tsconfig.dts.json"
58
+ },
59
+ "scripts": {
60
+ "build": "tsup",
61
+ "clean": "rimraf dist"
62
+ }
63
+ }
package/CHANGELOG.md DELETED
@@ -1,148 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [2.0.0-beta.8](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.7...v2.0.0-beta.8) (2021-04-11)
7
-
8
-
9
- ### Features
10
-
11
- * **utils:** add logger.createError method ([0c198d7](https://github.com/vuepress/vuepress-next/commit/0c198d7f9e122828b37a2db670048cfc2ce20e81))
12
-
13
-
14
-
15
-
16
-
17
- # [2.0.0-beta.7](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.6...v2.0.0-beta.7) (2021-04-09)
18
-
19
- **Note:** Version bump only for package @vuepress/utils
20
-
21
-
22
-
23
-
24
-
25
- # [2.0.0-beta.5](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.4...v2.0.0-beta.5) (2021-03-26)
26
-
27
- **Note:** Version bump only for package @vuepress/utils
28
-
29
-
30
-
31
-
32
-
33
- # [2.0.0-beta.4](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.3...v2.0.0-beta.4) (2021-03-20)
34
-
35
- **Note:** Version bump only for package @vuepress/utils
36
-
37
-
38
-
39
-
40
-
41
- # [2.0.0-beta.1](https://github.com/vuepress/vuepress-next/compare/v2.0.0-beta.0...v2.0.0-beta.1) (2021-03-13)
42
-
43
- **Note:** Version bump only for package @vuepress/utils
44
-
45
-
46
-
47
-
48
-
49
- # [2.0.0-beta.0](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.26...v2.0.0-beta.0) (2021-03-13)
50
-
51
- **Note:** Version bump only for package @vuepress/utils
52
-
53
-
54
-
55
-
56
-
57
- # [2.0.0-alpha.25](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.24...v2.0.0-alpha.25) (2021-02-20)
58
-
59
- **Note:** Version bump only for package @vuepress/utils
60
-
61
-
62
-
63
-
64
-
65
- # [2.0.0-alpha.24](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.23...v2.0.0-alpha.24) (2021-02-13)
66
-
67
- **Note:** Version bump only for package @vuepress/utils
68
-
69
-
70
-
71
-
72
-
73
- # [2.0.0-alpha.20](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.19...v2.0.0-alpha.20) (2021-02-04)
74
-
75
- **Note:** Version bump only for package @vuepress/utils
76
-
77
-
78
-
79
-
80
-
81
- # [2.0.0-alpha.19](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.18...v2.0.0-alpha.19) (2021-01-24)
82
-
83
- **Note:** Version bump only for package @vuepress/utils
84
-
85
-
86
-
87
-
88
-
89
- # [2.0.0-alpha.18](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.17...v2.0.0-alpha.18) (2021-01-17)
90
-
91
- **Note:** Version bump only for package @vuepress/utils
92
-
93
-
94
-
95
-
96
-
97
- # [2.0.0-alpha.15](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.14...v2.0.0-alpha.15) (2021-01-04)
98
-
99
- **Note:** Version bump only for package @vuepress/utils
100
-
101
-
102
-
103
-
104
-
105
- # [2.0.0-alpha.13](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.12...v2.0.0-alpha.13) (2020-12-23)
106
-
107
- **Note:** Version bump only for package @vuepress/utils
108
-
109
-
110
-
111
-
112
-
113
- # [2.0.0-alpha.7](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.6...v2.0.0-alpha.7) (2020-12-09)
114
-
115
- **Note:** Version bump only for package @vuepress/utils
116
-
117
-
118
-
119
-
120
-
121
- # [2.0.0-alpha.6](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.5...v2.0.0-alpha.6) (2020-12-09)
122
-
123
- **Note:** Version bump only for package @vuepress/utils
124
-
125
-
126
-
127
-
128
-
129
- # [2.0.0-alpha.4](https://github.com/vuepress/vuepress-next/compare/v2.0.0-alpha.3...v2.0.0-alpha.4) (2020-12-02)
130
-
131
-
132
- ### Features
133
-
134
- * **utils:** add hasExportDefault util ([575a9c5](https://github.com/vuepress/vuepress-next/commit/575a9c5d9eee44c0ce20b0712830e2eb2a303780))
135
-
136
-
137
-
138
-
139
-
140
- # 2.0.0-alpha.1 (2020-12-01)
141
-
142
-
143
- ### Features
144
-
145
- * **utils:** add logger and debug utils ([203d58d](https://github.com/vuepress/vuepress-next/commit/203d58d8d97c6a3158d4a783188ce2b64e54f19c))
146
- * **utils:** add ora util ([f67b4d3](https://github.com/vuepress/vuepress-next/commit/f67b4d3f62fee077f947362c975c08c81470b0b0))
147
- * **utils:** add withSpinner util ([82c6bb5](https://github.com/vuepress/vuepress-next/commit/82c6bb5d3e3a76088ee286fc10dabd9da4d59b22))
148
- * **utils:** disable withSpinner if DEBUG env is set ([af19507](https://github.com/vuepress/vuepress-next/commit/af1950784fb17c258a4c07dbaf7439cf0ec2c762))
@@ -1,6 +0,0 @@
1
- /**
2
- * Check if a module is esm with `export default`
3
- */
4
- export declare const hasExportDefault: <T = any>(mod: unknown) => mod is {
5
- default: T;
6
- };
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasExportDefault = void 0;
4
- const shared_1 = require("@vuepress/shared");
5
- /**
6
- * Check if a module is esm with `export default`
7
- */
8
- const hasExportDefault = (mod) => shared_1.isPlainObject(mod) &&
9
- !!mod.__esModule &&
10
- Object.prototype.hasOwnProperty.call(mod, 'default');
11
- exports.hasExportDefault = hasExportDefault;
package/lib/index.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import * as debug from 'debug';
2
- import * as chalk from 'chalk';
3
- import * as fs from 'fs-extra';
4
- import * as globby from 'globby';
5
- import * as ora from 'ora';
6
- import * as path from 'upath';
7
- import hash = require('hash-sum');
8
- export { debug, chalk, fs, globby, hash, ora, path };
9
- export * from './hasExportDefault';
10
- export * from './logger';
11
- export * from './renderHead';
12
- export * from './renderHeadAttrs';
13
- export * from './requireResolve';
14
- export * from './withSpinner';
package/lib/index.js DELETED
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.path = exports.ora = exports.hash = exports.globby = exports.fs = exports.chalk = exports.debug = void 0;
14
- const debug = require("debug");
15
- exports.debug = debug;
16
- const chalk = require("chalk");
17
- exports.chalk = chalk;
18
- const fs = require("fs-extra");
19
- exports.fs = fs;
20
- const globby = require("globby");
21
- exports.globby = globby;
22
- const ora = require("ora");
23
- exports.ora = ora;
24
- const path = require("upath");
25
- exports.path = path;
26
- const hash = require("hash-sum");
27
- exports.hash = hash;
28
- __exportStar(require("./hasExportDefault"), exports);
29
- __exportStar(require("./logger"), exports);
30
- __exportStar(require("./renderHead"), exports);
31
- __exportStar(require("./renderHeadAttrs"), exports);
32
- __exportStar(require("./requireResolve"), exports);
33
- __exportStar(require("./withSpinner"), exports);
package/lib/logger.d.ts DELETED
@@ -1,14 +0,0 @@
1
- export declare const info: (...args: any[]) => void;
2
- export declare const tip: (...args: any[]) => void;
3
- export declare const success: (...args: any[]) => void;
4
- export declare const warn: (...args: any[]) => void;
5
- export declare const error: (...args: any[]) => void;
6
- export declare const createError: (message?: string | undefined) => Error;
7
- export declare const logger: {
8
- info: (...args: any[]) => void;
9
- tip: (...args: any[]) => void;
10
- success: (...args: any[]) => void;
11
- warn: (...args: any[]) => void;
12
- error: (...args: any[]) => void;
13
- createError: (message?: string | undefined) => Error;
14
- };
package/lib/logger.js DELETED
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logger = exports.createError = exports.error = exports.warn = exports.success = exports.tip = exports.info = void 0;
4
- const chalk = require("chalk");
5
- const info = (...args) => {
6
- console.log(chalk.cyan('info'), ...args);
7
- };
8
- exports.info = info;
9
- const tip = (...args) => {
10
- console.log(chalk.blue('tip'), ...args);
11
- };
12
- exports.tip = tip;
13
- const success = (...args) => {
14
- console.log(chalk.green('success'), ...args);
15
- };
16
- exports.success = success;
17
- const warn = (...args) => {
18
- console.warn(chalk.yellow('warning'), ...args);
19
- };
20
- exports.warn = warn;
21
- const error = (...args) => {
22
- console.error(chalk.red('error'), ...args);
23
- };
24
- exports.error = error;
25
- const createError = (message) => {
26
- exports.error(message);
27
- return new Error(message);
28
- };
29
- exports.createError = createError;
30
- exports.logger = {
31
- info: exports.info,
32
- tip: exports.tip,
33
- success: exports.success,
34
- warn: exports.warn,
35
- error: exports.error,
36
- createError: exports.createError,
37
- };
@@ -1,5 +0,0 @@
1
- import type { HeadConfig } from '@vuepress/shared';
2
- /**
3
- * Render head config to string
4
- */
5
- export declare const renderHead: ([tag, attrs, innerHTML,]: HeadConfig) => string;
package/lib/renderHead.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderHead = void 0;
4
- const renderHeadAttrs_1 = require("./renderHeadAttrs");
5
- /**
6
- * Render head config to string
7
- */
8
- const renderHead = ([tag, attrs, innerHTML = '',]) => {
9
- const openTag = `<${tag}${renderHeadAttrs_1.renderHeadAttrs(attrs)}>`;
10
- if (tag === 'link' || tag === 'meta' || tag === 'base') {
11
- return openTag;
12
- }
13
- return `${openTag}${innerHTML}</${tag}>`;
14
- };
15
- exports.renderHead = renderHead;
@@ -1,5 +0,0 @@
1
- import type { HeadAttrsConfig } from '@vuepress/shared';
2
- /**
3
- * Render head attrs config to string
4
- */
5
- export declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderHeadAttrs = void 0;
4
- /**
5
- * Render head attrs config to string
6
- */
7
- const renderHeadAttrs = (attrs) => Object.entries(attrs)
8
- .filter((item) => item[1] !== false)
9
- .map(([key, value]) => value === true ? ` ${key}` : ` ${key}="${attrs[key]}"`)
10
- .join('');
11
- exports.renderHeadAttrs = renderHeadAttrs;
@@ -1,7 +0,0 @@
1
- /**
2
- * Wrapper of `require.resolve` of nodejs
3
- *
4
- * Return `null` if the module cannot be resolved
5
- * instead of throwing an error
6
- */
7
- export declare const requireResolve: (request: string) => string | null;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireResolve = void 0;
4
- /**
5
- * Wrapper of `require.resolve` of nodejs
6
- *
7
- * Return `null` if the module cannot be resolved
8
- * instead of throwing an error
9
- */
10
- const requireResolve = (request) => {
11
- try {
12
- return require.resolve(request);
13
- }
14
- catch (_a) {
15
- return null;
16
- }
17
- };
18
- exports.requireResolve = requireResolve;
@@ -1 +0,0 @@
1
- export declare const withSpinner: (msg: string) => <T>(target: () => Promise<T>) => Promise<T>;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withSpinner = void 0;
4
- const ora = require("ora");
5
- const withSpinner = (msg) => async (target) => {
6
- if (process.env.DEBUG) {
7
- return target();
8
- }
9
- const spinner = ora();
10
- try {
11
- spinner.start(msg);
12
- const result = await target();
13
- spinner.succeed(`${msg} - done`);
14
- return result;
15
- }
16
- catch (e) {
17
- spinner.fail(`${msg} - failed`);
18
- throw e;
19
- }
20
- };
21
- exports.withSpinner = withSpinner;