Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit cf5bb82

Browse files
Version 2.0.0 (#4)
* Updated dependencies and updated author with contributors. * Upgraded API usage. * 2.0.0-beta * 2.0.0-beta.1 * Fixed error handle. * 2.0.0-beta.2 * 2.0.0-beta.3 * 2.0.0-beta.4 * Updated typescript version * Added pacakge-lock.json
1 parent 1e44a85 commit cf5bb82

8 files changed

Lines changed: 598 additions & 120 deletions

File tree

@types/main.d.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,4 @@ export declare class GlobsUglifyJs {
1919
private uglifyItem(file);
2020
private buildOutFilePath(filePath);
2121
private uglifyFile(file, options?);
22-
/**
23-
* Asynchronously return files list by pattern.
24-
*
25-
* @param {string} pattern
26-
* @param {glob.IOptions} [options={}]
27-
*/
28-
private getGlobFilesList(pattern, options?);
2922
}

@types/utils/directories.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export declare function Exists(path: string): Promise<boolean>;
21
export declare function RemoveEmptyDirectories(directoryPath: string): Promise<void>;
32
export declare function MakeTree(filePath: string): Promise<string>;

dist/main.js

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
88
};
99
Object.defineProperty(exports, "__esModule", { value: true });
1010
const uglifyjs = require("uglify-js");
11-
const glob = require("glob");
11+
const globby = require("globby");
1212
const path = require("path");
1313
const options_1 = require("./options");
14-
const fs = require("mz/fs");
14+
const fs = require("fs-extra");
1515
const rejection_error_1 = require("./rejection-error");
1616
const Directories = require("./utils/directories");
1717
const JS_EXTENSION = ".js";
@@ -49,7 +49,7 @@ class GlobsUglifyJs {
4949
}
5050
let filesList;
5151
try {
52-
filesList = yield this.getGlobFilesList(this.globPattern, this.globOptions);
52+
filesList = yield globby(this.globPattern, this.globOptions);
5353
}
5454
catch (error) {
5555
if (this.options.Debug && !this.options.Silence) {
@@ -202,6 +202,9 @@ class GlobsUglifyJs {
202202
let outputData;
203203
try {
204204
outputData = yield this.uglifyFile(file, this.options.MinifyOptions);
205+
if (outputData.error != null) {
206+
throw outputData.error;
207+
}
205208
}
206209
catch (error) {
207210
throw new rejection_error_1.RejectionError(error, "uglifyFile", file);
@@ -238,35 +241,16 @@ class GlobsUglifyJs {
238241
}
239242
uglifyFile(file, options) {
240243
return __awaiter(this, void 0, void 0, function* () {
241-
return new Promise((resolve, reject) => {
244+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
242245
try {
243-
let outputData = uglifyjs.minify(file, options);
246+
const inputData = yield fs.readFile(file, "UTF-8");
247+
const outputData = uglifyjs.minify(inputData, options);
244248
resolve(outputData);
245249
}
246250
catch (error) {
247251
reject(error);
248252
}
249-
});
250-
});
251-
}
252-
/**
253-
* Asynchronously return files list by pattern.
254-
*
255-
* @param {string} pattern
256-
* @param {glob.IOptions} [options={}]
257-
*/
258-
getGlobFilesList(pattern, options = {}) {
259-
return __awaiter(this, void 0, void 0, function* () {
260-
return new Promise((resolve, reject) => {
261-
glob(pattern, options, (err, matches) => {
262-
if (err != null) {
263-
reject(err);
264-
}
265-
else {
266-
resolve(matches);
267-
}
268-
});
269-
});
253+
}));
270254
});
271255
}
272256
}

dist/utils/directories.js

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
88
};
99
Object.defineProperty(exports, "__esModule", { value: true });
1010
const path = require("path");
11-
const fs = require("mz/fs");
12-
const mkdirp = require("mkdirp");
13-
function Exists(path) {
14-
return __awaiter(this, void 0, void 0, function* () {
15-
try {
16-
const stat = yield fs.stat(path);
17-
return stat.isDirectory();
18-
}
19-
catch (error) {
20-
return false;
21-
}
22-
});
23-
}
24-
exports.Exists = Exists;
11+
const fs = require("fs-extra");
2512
function RemoveEmptyDirectories(directoryPath) {
2613
return __awaiter(this, void 0, void 0, function* () {
27-
const isExist = yield Exists(directoryPath);
28-
if (!isExist) {
14+
const stat = yield fs.stat(directoryPath);
15+
if (!stat.isDirectory()) {
2916
return;
3017
}
3118
let files = yield fs.readdir(directoryPath);
@@ -44,16 +31,9 @@ function RemoveEmptyDirectories(directoryPath) {
4431
exports.RemoveEmptyDirectories = RemoveEmptyDirectories;
4532
function MakeTree(filePath) {
4633
return __awaiter(this, void 0, void 0, function* () {
47-
return new Promise((resolve, reject) => {
48-
const dirname = path.dirname(filePath);
49-
mkdirp(dirname, (error, data) => {
50-
if (error) {
51-
reject(error);
52-
return;
53-
}
54-
resolve(data);
55-
});
56-
});
34+
const dirname = path.dirname(filePath);
35+
yield fs.ensureDir(dirname);
36+
return dirname;
5737
});
5838
}
5939
exports.MakeTree = MakeTree;

0 commit comments

Comments
 (0)