@aiot-toolkit/shared-utils 2.0.2-beta.16 → 2.0.2-beta.18

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,5 +1,5 @@
1
1
  import { ILog, Loglevel } from './interface/ILog';
2
- interface IStyle {
2
+ export interface IStyle {
3
3
  color?: string;
4
4
  bgColor?: string;
5
5
  bold?: boolean;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Schema, SomeJTDSchemaType } from 'ajv/dist/core';
3
2
  import { ILog } from '../interface/ILog';
4
3
  export type JSONSchemaType = Schema & SomeJTDSchemaType;
@@ -1,3 +1,5 @@
1
+ import Fs from 'fs-extra';
2
+ import { RimrafSyncOptions } from 'rimraf';
1
3
  type OneMatchType = string | RegExp | ((path: string) => boolean);
2
4
  export type MatchType = OneMatchType | OneMatchType[];
3
5
  /**
@@ -66,9 +68,24 @@ declare class FileUtil {
66
68
  */
67
69
  static copyFiles(sourceDir: string, targetDir: string, excludes?: MatchType, includes?: MatchType): void;
68
70
  /**
69
- * 校验文件
70
- * @param fileList
71
+ * 检查指定的文件列表是否全部存在
72
+ * @param fileList 文件列表
71
73
  */
72
74
  static checkFilePath(fileList: string[]): boolean;
75
+ static del(patterns: string | string[], options?: RimrafSyncOptions): Promise<boolean>;
76
+ /**
77
+ * 创建目录
78
+ *
79
+ * *支持 windows 系统创建隐藏目录
80
+ * @param path
81
+ * @param options
82
+ * @returns
83
+ */
84
+ static mkdirSync(path: Fs.PathLike, options?: Fs.MakeDirectoryOptions & {
85
+ /**
86
+ * 是否为隐藏目录-windows系统有效
87
+ */
88
+ hidden: true;
89
+ }): string | undefined;
73
90
  }
74
91
  export default FileUtil;
@@ -1,10 +1,21 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  const fs_extra_1 = __importDefault(require("fs-extra"));
7
16
  const path_1 = __importDefault(require("path"));
17
+ const rimraf_1 = require("rimraf");
18
+ const fswin_1 = __importDefault(require("fswin"));
8
19
  /**
9
20
  * FileUtil
10
21
  */
@@ -133,17 +144,31 @@ class FileUtil {
133
144
  }
134
145
  }
135
146
  /**
136
- * 校验文件
137
- * @param fileList
147
+ * 检查指定的文件列表是否全部存在
148
+ * @param fileList 文件列表
138
149
  */
139
150
  static checkFilePath(fileList) {
140
- let checkPass = true;
141
- fileList.forEach((filePath) => {
142
- if (!fs_extra_1.default.existsSync(filePath)) {
143
- checkPass = false;
144
- }
151
+ return fileList === null || fileList === void 0 ? void 0 : fileList.every((filePath) => fs_extra_1.default.existsSync(filePath));
152
+ }
153
+ static del(patterns, options) {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ return (0, rimraf_1.rimrafSync)(patterns, Object.assign({ glob: true }, options));
145
156
  });
146
- return checkPass;
157
+ }
158
+ /**
159
+ * 创建目录
160
+ *
161
+ * *支持 windows 系统创建隐藏目录
162
+ * @param path
163
+ * @param options
164
+ * @returns
165
+ */
166
+ static mkdirSync(path, options) {
167
+ const result = fs_extra_1.default.mkdirSync(path, options);
168
+ if (fswin_1.default && (options === null || options === void 0 ? void 0 : options.hidden)) {
169
+ fswin_1.default.setAttributesSync(path.toString(), { IS_HIDDEN: true });
170
+ }
171
+ return result;
147
172
  }
148
173
  }
149
174
  exports.default = FileUtil;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import Koa from 'koa';
3
2
  import { default as Router } from 'koa-router';
4
3
  import { Server } from 'net';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/shared-utils",
3
- "version": "2.0.2-beta.16",
3
+ "version": "2.0.2-beta.18",
4
4
  "description": "The common method functions of the aiot-toolkit.",
5
5
  "homepage": "",
6
6
  "license": "ISC",
@@ -22,11 +22,13 @@
22
22
  "cli-progress": "^3.12.0",
23
23
  "dayjs": "^1.11.9",
24
24
  "fs-extra": "^11.2.0",
25
+ "fswin": "^3.24.829",
25
26
  "koa": "^2.15.3",
26
27
  "koa-router": "^12.0.1",
27
28
  "koa-static": "^5.0.0",
28
29
  "portfinder": "^1.0.32",
29
30
  "qrcode": "^1.5.4",
31
+ "rimraf": "^5.0.9",
30
32
  "simple-git": "^3.25.0"
31
33
  },
32
34
  "devDependencies": {
@@ -37,5 +39,5 @@
37
39
  "@types/koa-static": "^4.0.4",
38
40
  "@types/qrcode": "^1.5.5"
39
41
  },
40
- "gitHead": "785701c64914f50acd18ab71ea41b2f5a2cd161c"
42
+ "gitHead": "e39f0ad4fe3bfe8e733499742c5a39ab80fa2cd0"
41
43
  }