@dcf-micro/utils-node 5.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +43 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.mjs +147 -0
- package/package.json +52 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
export { Package } from '@manypkg/get-packages';
|
|
3
|
+
export { default as colors } from 'chalk';
|
|
4
|
+
export { consola } from 'consola';
|
|
5
|
+
export * from 'execa';
|
|
6
|
+
export { default as fs } from 'node:fs/promises';
|
|
7
|
+
export { PackageJson, readPackageJSON } from 'pkg-types';
|
|
8
|
+
export { rimraf } from 'rimraf';
|
|
9
|
+
export * from '@changesets/git';
|
|
10
|
+
export { add as gitAdd } from '@changesets/git';
|
|
11
|
+
|
|
12
|
+
declare enum UNICODE {
|
|
13
|
+
FAILURE = "\u2716",
|
|
14
|
+
SUCCESS = "\u2714"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare const dateUtil: typeof dayjs;
|
|
18
|
+
|
|
19
|
+
declare function outputJSON(filePath: string, data: any, spaces?: number): Promise<void>;
|
|
20
|
+
declare function ensureFile(filePath: string): Promise<void>;
|
|
21
|
+
declare function readJSON(filePath: string): Promise<any>;
|
|
22
|
+
|
|
23
|
+
declare function getStagedFiles(): Promise<string[]>;
|
|
24
|
+
|
|
25
|
+
declare function generatorContentHash(content: string, hashLSize?: number): string;
|
|
26
|
+
|
|
27
|
+
declare function findMonorepoRoot(cwd?: string): string;
|
|
28
|
+
declare function getPackagesSync(): any;
|
|
29
|
+
declare function getPackages(): Promise<any>;
|
|
30
|
+
declare function getPackage(pkgName: string): Promise<any>;
|
|
31
|
+
|
|
32
|
+
declare function toPosixPath(pathname: string): string;
|
|
33
|
+
|
|
34
|
+
declare function prettierFormat(filepath: string): Promise<string>;
|
|
35
|
+
|
|
36
|
+
interface SpinnerOptions {
|
|
37
|
+
failedText?: string;
|
|
38
|
+
successText?: string;
|
|
39
|
+
title: string;
|
|
40
|
+
}
|
|
41
|
+
declare function spinner<T>({ failedText, successText, title }: SpinnerOptions, callback: () => Promise<T>): Promise<T>;
|
|
42
|
+
|
|
43
|
+
export { UNICODE, dateUtil, ensureFile, findMonorepoRoot, generatorContentHash, getPackage, getPackages, getPackagesSync, getStagedFiles, outputJSON, prettierFormat, readJSON, spinner, toPosixPath };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
export { Package } from '@manypkg/get-packages';
|
|
3
|
+
export { default as colors } from 'chalk';
|
|
4
|
+
export { consola } from 'consola';
|
|
5
|
+
export * from 'execa';
|
|
6
|
+
export { default as fs } from 'node:fs/promises';
|
|
7
|
+
export { PackageJson, readPackageJSON } from 'pkg-types';
|
|
8
|
+
export { rimraf } from 'rimraf';
|
|
9
|
+
export * from '@changesets/git';
|
|
10
|
+
export { add as gitAdd } from '@changesets/git';
|
|
11
|
+
|
|
12
|
+
declare enum UNICODE {
|
|
13
|
+
FAILURE = "\u2716",
|
|
14
|
+
SUCCESS = "\u2714"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare const dateUtil: typeof dayjs;
|
|
18
|
+
|
|
19
|
+
declare function outputJSON(filePath: string, data: any, spaces?: number): Promise<void>;
|
|
20
|
+
declare function ensureFile(filePath: string): Promise<void>;
|
|
21
|
+
declare function readJSON(filePath: string): Promise<any>;
|
|
22
|
+
|
|
23
|
+
declare function getStagedFiles(): Promise<string[]>;
|
|
24
|
+
|
|
25
|
+
declare function generatorContentHash(content: string, hashLSize?: number): string;
|
|
26
|
+
|
|
27
|
+
declare function findMonorepoRoot(cwd?: string): string;
|
|
28
|
+
declare function getPackagesSync(): any;
|
|
29
|
+
declare function getPackages(): Promise<any>;
|
|
30
|
+
declare function getPackage(pkgName: string): Promise<any>;
|
|
31
|
+
|
|
32
|
+
declare function toPosixPath(pathname: string): string;
|
|
33
|
+
|
|
34
|
+
declare function prettierFormat(filepath: string): Promise<string>;
|
|
35
|
+
|
|
36
|
+
interface SpinnerOptions {
|
|
37
|
+
failedText?: string;
|
|
38
|
+
successText?: string;
|
|
39
|
+
title: string;
|
|
40
|
+
}
|
|
41
|
+
declare function spinner<T>({ failedText, successText, title }: SpinnerOptions, callback: () => Promise<T>): Promise<T>;
|
|
42
|
+
|
|
43
|
+
export { UNICODE, dateUtil, ensureFile, findMonorepoRoot, generatorContentHash, getPackage, getPackages, getPackagesSync, getStagedFiles, outputJSON, prettierFormat, readJSON, spinner, toPosixPath };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import timezone from 'dayjs/plugin/timezone';
|
|
3
|
+
import utc from 'dayjs/plugin/utc';
|
|
4
|
+
import { promises } from 'node:fs';
|
|
5
|
+
import path, { dirname, posix } from 'node:path';
|
|
6
|
+
import { execa as execa$1 } from 'execa';
|
|
7
|
+
export * from 'execa';
|
|
8
|
+
export * from '@changesets/git';
|
|
9
|
+
export { add as gitAdd } from '@changesets/git';
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
import { getPackages as getPackages$1, getPackagesSync as getPackagesSync$1 } from '@manypkg/get-packages';
|
|
12
|
+
import { findUpSync } from 'find-up';
|
|
13
|
+
import fs from 'node:fs/promises';
|
|
14
|
+
export { default as fs } from 'node:fs/promises';
|
|
15
|
+
import { resolveConfig, getFileInfo, format } from 'prettier';
|
|
16
|
+
import ora from 'ora';
|
|
17
|
+
export { default as colors } from 'chalk';
|
|
18
|
+
export { consola } from 'consola';
|
|
19
|
+
export { readPackageJSON } from 'pkg-types';
|
|
20
|
+
export { rimraf } from 'rimraf';
|
|
21
|
+
|
|
22
|
+
var UNICODE = /* @__PURE__ */ ((UNICODE2) => {
|
|
23
|
+
UNICODE2["FAILURE"] = "\u2716";
|
|
24
|
+
UNICODE2["SUCCESS"] = "\u2714";
|
|
25
|
+
return UNICODE2;
|
|
26
|
+
})(UNICODE || {});
|
|
27
|
+
|
|
28
|
+
dayjs.extend(utc);
|
|
29
|
+
dayjs.extend(timezone);
|
|
30
|
+
dayjs.tz.setDefault("Asia/Shanghai");
|
|
31
|
+
const dateUtil = dayjs;
|
|
32
|
+
|
|
33
|
+
async function outputJSON(filePath, data, spaces = 2) {
|
|
34
|
+
try {
|
|
35
|
+
const dir = dirname(filePath);
|
|
36
|
+
await promises.mkdir(dir, { recursive: true });
|
|
37
|
+
const jsonData = JSON.stringify(data, null, spaces);
|
|
38
|
+
await promises.writeFile(filePath, jsonData, "utf8");
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error("Error writing JSON file:", error);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function ensureFile(filePath) {
|
|
45
|
+
try {
|
|
46
|
+
const dir = dirname(filePath);
|
|
47
|
+
await promises.mkdir(dir, { recursive: true });
|
|
48
|
+
await promises.writeFile(filePath, "", { flag: "a" });
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error("Error ensuring file:", error);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function readJSON(filePath) {
|
|
55
|
+
try {
|
|
56
|
+
const data = await promises.readFile(filePath, "utf8");
|
|
57
|
+
return JSON.parse(data);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("Error reading JSON file:", error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function getStagedFiles() {
|
|
65
|
+
try {
|
|
66
|
+
const { stdout } = await execa$1("git", [
|
|
67
|
+
"-c",
|
|
68
|
+
"submodule.recurse=false",
|
|
69
|
+
"diff",
|
|
70
|
+
"--staged",
|
|
71
|
+
"--diff-filter=ACMR",
|
|
72
|
+
"--name-only",
|
|
73
|
+
"--ignore-submodules",
|
|
74
|
+
"-z"
|
|
75
|
+
]);
|
|
76
|
+
let changedList = stdout ? stdout.replace(/\0$/, "").split("\0") : [];
|
|
77
|
+
changedList = changedList.map((item) => path.resolve(process.cwd(), item));
|
|
78
|
+
const changedSet = new Set(changedList);
|
|
79
|
+
changedSet.delete("");
|
|
80
|
+
return [...changedSet];
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error("Failed to get staged files:", error);
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function generatorContentHash(content, hashLSize) {
|
|
88
|
+
const hash = createHash("md5").update(content, "utf8").digest("hex");
|
|
89
|
+
if (hashLSize) {
|
|
90
|
+
return hash.slice(0, hashLSize);
|
|
91
|
+
}
|
|
92
|
+
return hash;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function findMonorepoRoot(cwd = process.cwd()) {
|
|
96
|
+
const lockFile = findUpSync("pnpm-lock.yaml", {
|
|
97
|
+
cwd,
|
|
98
|
+
type: "file"
|
|
99
|
+
});
|
|
100
|
+
return dirname(lockFile || "");
|
|
101
|
+
}
|
|
102
|
+
function getPackagesSync() {
|
|
103
|
+
const root = findMonorepoRoot();
|
|
104
|
+
return getPackagesSync$1(root);
|
|
105
|
+
}
|
|
106
|
+
async function getPackages() {
|
|
107
|
+
const root = findMonorepoRoot();
|
|
108
|
+
return await getPackages$1(root);
|
|
109
|
+
}
|
|
110
|
+
async function getPackage(pkgName) {
|
|
111
|
+
const { packages } = await getPackages();
|
|
112
|
+
return packages.find((pkg) => pkg.packageJson.name === pkgName);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function toPosixPath(pathname) {
|
|
116
|
+
return pathname.split(`\\`).join(posix.sep);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function prettierFormat(filepath) {
|
|
120
|
+
const prettierOptions = await resolveConfig(filepath, {});
|
|
121
|
+
const fileInfo = await getFileInfo(filepath);
|
|
122
|
+
const input = await fs.readFile(filepath, "utf8");
|
|
123
|
+
const output = await format(input, {
|
|
124
|
+
...prettierOptions,
|
|
125
|
+
parser: fileInfo.inferredParser
|
|
126
|
+
});
|
|
127
|
+
if (output !== input) {
|
|
128
|
+
await fs.writeFile(filepath, output, "utf8");
|
|
129
|
+
}
|
|
130
|
+
return output;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function spinner({ failedText, successText, title }, callback) {
|
|
134
|
+
const loading = ora(title).start();
|
|
135
|
+
try {
|
|
136
|
+
const result = await callback();
|
|
137
|
+
loading.succeed(successText || "Success!");
|
|
138
|
+
return result;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
loading.fail(failedText || "Failed!");
|
|
141
|
+
throw error;
|
|
142
|
+
} finally {
|
|
143
|
+
loading.stop();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { UNICODE, dateUtil, ensureFile, findMonorepoRoot, generatorContentHash, getPackage, getPackages, getPackagesSync, getStagedFiles, outputJSON, prettierFormat, readJSON, spinner, toPosixPath };
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcf-micro/utils-node",
|
|
3
|
+
"version": "5.5.9",
|
|
4
|
+
"homepage": "https://github.com/vbenjs/vue-vben-admin",
|
|
5
|
+
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/vbenjs/vue-vben-admin.git",
|
|
9
|
+
"directory": "internal/node-utils"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "pnpm unbuild",
|
|
15
|
+
"stub": "pnpm unbuild --stub"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"main": "./dist/index.mjs",
|
|
21
|
+
"module": "./dist/index.mjs",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./src/index.ts",
|
|
26
|
+
"import": "./dist/index.mjs",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.mjs",
|
|
35
|
+
"default": "./dist/index.mjs"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@changesets/git": "catalog:",
|
|
41
|
+
"@manypkg/get-packages": "catalog:",
|
|
42
|
+
"chalk": "catalog:",
|
|
43
|
+
"consola": "catalog:",
|
|
44
|
+
"dayjs": "catalog:",
|
|
45
|
+
"execa": "catalog:",
|
|
46
|
+
"find-up": "catalog:",
|
|
47
|
+
"ora": "catalog:",
|
|
48
|
+
"pkg-types": "catalog:",
|
|
49
|
+
"prettier": "catalog:",
|
|
50
|
+
"rimraf": "catalog:"
|
|
51
|
+
}
|
|
52
|
+
}
|