Skip to content

Commit

Permalink
Version 2.0.0 (#4)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
GiedriusGrabauskas authored Nov 2, 2017
1 parent 1e44a85 commit cf5bb82
Show file tree
Hide file tree
Showing 8 changed files with 598 additions and 120 deletions.
7 changes: 0 additions & 7 deletions @types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,4 @@ export declare class GlobsUglifyJs {
private uglifyItem(file);
private buildOutFilePath(filePath);
private uglifyFile(file, options?);
/**
* Asynchronously return files list by pattern.
*
* @param {string} pattern
* @param {glob.IOptions} [options={}]
*/
private getGlobFilesList(pattern, options?);
}
1 change: 0 additions & 1 deletion @types/utils/directories.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export declare function Exists(path: string): Promise<boolean>;
export declare function RemoveEmptyDirectories(directoryPath: string): Promise<void>;
export declare function MakeTree(filePath: string): Promise<string>;
36 changes: 10 additions & 26 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
const uglifyjs = require("uglify-js");
const glob = require("glob");
const globby = require("globby");
const path = require("path");
const options_1 = require("./options");
const fs = require("mz/fs");
const fs = require("fs-extra");
const rejection_error_1 = require("./rejection-error");
const Directories = require("./utils/directories");
const JS_EXTENSION = ".js";
Expand Down Expand Up @@ -49,7 +49,7 @@ class GlobsUglifyJs {
}
let filesList;
try {
filesList = yield this.getGlobFilesList(this.globPattern, this.globOptions);
filesList = yield globby(this.globPattern, this.globOptions);
}
catch (error) {
if (this.options.Debug && !this.options.Silence) {
Expand Down Expand Up @@ -202,6 +202,9 @@ class GlobsUglifyJs {
let outputData;
try {
outputData = yield this.uglifyFile(file, this.options.MinifyOptions);
if (outputData.error != null) {
throw outputData.error;
}
}
catch (error) {
throw new rejection_error_1.RejectionError(error, "uglifyFile", file);
Expand Down Expand Up @@ -238,35 +241,16 @@ class GlobsUglifyJs {
}
uglifyFile(file, options) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
try {
let outputData = uglifyjs.minify(file, options);
const inputData = yield fs.readFile(file, "UTF-8");
const outputData = uglifyjs.minify(inputData, options);
resolve(outputData);
}
catch (error) {
reject(error);
}
});
});
}
/**
* Asynchronously return files list by pattern.
*
* @param {string} pattern
* @param {glob.IOptions} [options={}]
*/
getGlobFilesList(pattern, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
glob(pattern, options, (err, matches) => {
if (err != null) {
reject(err);
}
else {
resolve(matches);
}
});
});
}));
});
}
}
Expand Down
32 changes: 6 additions & 26 deletions dist/utils/directories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const fs = require("mz/fs");
const mkdirp = require("mkdirp");
function Exists(path) {
return __awaiter(this, void 0, void 0, function* () {
try {
const stat = yield fs.stat(path);
return stat.isDirectory();
}
catch (error) {
return false;
}
});
}
exports.Exists = Exists;
const fs = require("fs-extra");
function RemoveEmptyDirectories(directoryPath) {
return __awaiter(this, void 0, void 0, function* () {
const isExist = yield Exists(directoryPath);
if (!isExist) {
const stat = yield fs.stat(directoryPath);
if (!stat.isDirectory()) {
return;
}
let files = yield fs.readdir(directoryPath);
Expand All @@ -44,16 +31,9 @@ function RemoveEmptyDirectories(directoryPath) {
exports.RemoveEmptyDirectories = RemoveEmptyDirectories;
function MakeTree(filePath) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const dirname = path.dirname(filePath);
mkdirp(dirname, (error, data) => {
if (error) {
reject(error);
return;
}
resolve(data);
});
});
const dirname = path.dirname(filePath);
yield fs.ensureDir(dirname);
return dirname;
});
}
exports.MakeTree = MakeTree;
Loading

0 comments on commit cf5bb82

Please sign in to comment.