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

Commit 6a9185f

Browse files
Merge pull request #1 from SimplrJS/v0.3.0
V0.3.0
2 parents 93ec02d + 446ffb3 commit 6a9185f

15 files changed

Lines changed: 162 additions & 81 deletions

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,75 @@
11
glob-uglifyjs
22
===========
3-
Uglify files with glob pattern.
3+
Uglify JS files with glob pattern.
44

5-
## Usage
5+
6+
## Installation
7+
```sh
8+
$ npm install glob-uglifyjs
9+
```
10+
11+
12+
## Features
13+
- Uglify `js` files with [node-glob](https://github.com/isaacs/node-glob) pattern.
14+
- Remove source files after uglify.
15+
16+
17+
## Command line
18+
19+
### Usage
620
```sh
721
$ glob-uglifyjs -h
822
```
923

24+
### Arguments
25+
| Argument | Type | Default | Description |
26+
|--------------------------------|---------|-----------------------------|----------------------------|
27+
| -h, --help | boolean | `false` | Show help. |
28+
| -p, --pattern <sup>[1]</sup> | string | | Files glob pattern. |
29+
| -v, --version | boolean | `false` | Show version number. |
30+
| -c, --config | string | `glob-uglifyjs.config.json` | Path to JSON config file. |
31+
32+
<sup>[1]</sup> - argument required.
33+
34+
35+
## Config
36+
37+
### Example
38+
```json
39+
{
40+
"pattern": "/**/*",
41+
"options": {
42+
"UseMinExt": false,
43+
"MinifyOptions": {},
44+
"OutDir": "dist-min",
45+
"RootDir": "dist",
46+
"RemoveSource": false,
47+
"Debug": false
48+
}
49+
}
50+
```
51+
52+
### Properties
53+
54+
| Property | Type | Description |
55+
|-------------------------|---------------------|------------------------|
56+
| pattern<sup>[1]</sup> | string | Files glob pattern. |
57+
| options | [Options](#options) | glob-uglifyjs options. |
58+
59+
<sup>[1]</sup> - property required.
60+
61+
### Options
62+
| Option | Type | Default | Description |
63+
|-----------------|--------------------|-----------------|------------------------------------------------------------------------------------|
64+
| UseMinExt | boolean | `true` | Use `min` extensions in output files. |
65+
| MinifyOptions | object | `{}` | UglifyJS minify options. [Read more](https://github.com/mishoo/UglifyJS2). |
66+
| OutDir | string | ` ` | Redirect output structure to the directory. |
67+
| RootDir | string | ` ` | Specifies the root directory of input files. |
68+
| RemoveSource | boolean | `false` | Remove all source files specified by glob pattern. |
69+
| Debug | boolean | `false` | Show errors details information. |
70+
| exclude | string \| string[] | `undefined` | Add a pattern or an array of glob patterns to exclude matches. Read more in [node-glob options](https://github.com/isaacs/node-glob#options) `ignore`. |
71+
| Cwd | string | `process.cwd()` | Current working directory. |
72+
73+
1074
## License
1175
Released under the [PGL-3.0 license](LICENSE).

dist/arguments.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Options } from './options';
1+
import { Options } from "./options";
22
export interface Arguments {
33
pattern: string;
44
options: Options;

dist/arguments.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
const yargs = require('yargs');
21
Object.defineProperty(exports, "__esModule", { value: true });
2+
const yargs = require("yargs");
3+
function GetVersion() {
4+
let packageJson = require("../package.json");
5+
return packageJson.version || "";
6+
}
37
exports.default = yargs
4-
.help('h', 'Show help')
5-
.alias('h', 'help')
8+
.help("h", "Show help")
9+
.alias("h", "help")
610
.version(() => {
7-
return `Current version: ${require('../package.json').version}`;
11+
return `Current version: ${GetVersion()}`;
812
})
9-
.alias('v', 'version')
13+
.alias("v", "version")
1014
.option("p", {
1115
alias: "pattern",
1216
describe: "Files glob pattern",
1317
type: "string"
1418
})
1519
.require("pattern", "Pattern required")
16-
.config('config')
17-
.alias('c', 'config')
18-
.default('config', 'glob-uglifyjs.config.json')
19-
.usage('Usage: glob-uglifyjs [options]')
20+
.config("config")
21+
.alias("c", "config")
22+
.default("config", "glob-uglifyjs.config.json")
23+
.usage("Usage: glob-uglifyjs [options]")
2024
.argv;

dist/cli.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2-
const arguments_1 = require('./arguments');
3-
const main_1 = require('./main');
4-
new main_1.default(arguments_1.default.pattern, arguments_1.default.options || {});
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const arguments_1 = require("./arguments");
4+
const main_1 = require("./main");
5+
new main_1.GlobsUglifyJs(arguments_1.default.pattern, arguments_1.default.options || {});

dist/main.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Options } from './options';
2-
export default class GlobsUglifyJs {
1+
import { Options } from "./options";
2+
export declare class GlobsUglifyJs {
33
private globPattern;
44
private options;
55
constructor(globPattern: string, options?: Options);
66
private main();
77
private deleteFiles(fileList);
88
private deleteFile(filePath);
9-
private uglifyFile(file);
9+
private uglifyFile(file, options?);
1010
private startRecursiveUglify(filesList, results?);
1111
private recursiveUglify(file);
1212
private ensureDirectoryExistence(filePath);
@@ -26,11 +26,11 @@ export default class GlobsUglifyJs {
2626
private hasMinifiedExt(nameWithoutExt);
2727
private resolveOutFilePath(filePath);
2828
/**
29-
* Asynchronously write data to file with flag 'wx'.
29+
* Asynchronously write data to file with flag "wx".
3030
*
3131
* @private
3232
* @param {string} filePath File path.
33-
* @param {string} data Data in 'utf-8'.
33+
* @param {string} data Data in "utf-8".
3434
* @returns
3535
*
3636
* @memberOf GlobsUglifyJs

dist/main.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
return new (P || (P = Promise))(function (resolve, reject) {
33
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4-
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
4+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
55
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
6-
step((generator = generator.apply(thisArg, _arguments)).next());
6+
step((generator = generator.apply(thisArg, _arguments || [])).next());
77
});
88
};
9-
const uglifyjs = require('uglify-js');
10-
const glob = require('glob');
11-
const path = require('path');
12-
const options_1 = require('./options');
13-
const fs = require('fs');
14-
const rejection_error_1 = require('./rejection-error');
9+
Object.defineProperty(exports, "__esModule", { value: true });
10+
const uglifyjs = require("uglify-js");
11+
const glob = require("glob");
12+
const path = require("path");
13+
const options_1 = require("./options");
14+
const fs = require("fs");
15+
const rejection_error_1 = require("./rejection-error");
1516
const JS_EXTENSION = ".js";
1617
const MINIFY_EXTENSION_PREFIX = ".min";
1718
class RecursiveUglifyResults {
@@ -110,11 +111,11 @@ class GlobsUglifyJs {
110111
});
111112
});
112113
}
113-
uglifyFile(file) {
114+
uglifyFile(file, options) {
114115
return __awaiter(this, void 0, void 0, function* () {
115116
return new Promise((resolve, reject) => {
116117
try {
117-
let outputData = uglifyjs.minify(file);
118+
let outputData = uglifyjs.minify(file, options);
118119
resolve(outputData);
119120
}
120121
catch (error) {
@@ -156,7 +157,7 @@ class GlobsUglifyJs {
156157
return __awaiter(this, void 0, void 0, function* () {
157158
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
158159
try {
159-
let outputData = yield this.uglifyFile(file)
160+
let outputData = yield this.uglifyFile(file, this.options.MinifyOptions)
160161
.catch(error => {
161162
throw new rejection_error_1.default(error, "uglifyFile", file);
162163
});
@@ -248,7 +249,7 @@ class GlobsUglifyJs {
248249
}
249250
files = yield this.readFilesInDirectory(directoryPath);
250251
}
251-
if (files.length == 0) {
252+
if (files.length === 0) {
252253
yield this.removeDirectory(directoryPath)
253254
.catch(error => {
254255
reject(new rejection_error_1.default(error, "removeDirectory"));
@@ -317,11 +318,11 @@ class GlobsUglifyJs {
317318
});
318319
}
319320
/**
320-
* Asynchronously write data to file with flag 'wx'.
321+
* Asynchronously write data to file with flag "wx".
321322
*
322323
* @private
323324
* @param {string} filePath File path.
324-
* @param {string} data Data in 'utf-8'.
325+
* @param {string} data Data in "utf-8".
325326
* @returns
326327
*
327328
* @memberOf GlobsUglifyJs
@@ -393,5 +394,4 @@ class GlobsUglifyJs {
393394
return pattern + JS_EXTENSION;
394395
}
395396
}
396-
Object.defineProperty(exports, "__esModule", { value: true });
397-
exports.default = GlobsUglifyJs;
397+
exports.GlobsUglifyJs = GlobsUglifyJs;

dist/options.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference types="uglify-js" />
2-
import * as uglifyjs from 'uglify-js';
2+
import * as uglifyjs from "uglify-js";
33
export interface Options {
44
[key: string]: any;
55
UseMinExt?: boolean;
@@ -9,7 +9,7 @@ export interface Options {
99
RootDir?: string;
1010
RemoveSource?: boolean;
1111
Debug?: boolean;
12-
exclude?: Array<string>;
12+
exclude?: Array<string> | string;
1313
}
1414
export default class OptionsConstructor implements Options {
1515
constructor(importData?: Options);
@@ -21,5 +21,5 @@ export default class OptionsConstructor implements Options {
2121
readonly RootDir: string;
2222
readonly RemoveSource: boolean;
2323
readonly Debug: boolean;
24-
readonly Exclue: Array<string> | undefined;
24+
readonly Exclue: Array<string> | string | undefined;
2525
}

dist/options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const process = require('process');
1+
Object.defineProperty(exports, "__esModule", { value: true });
2+
const process = require("process");
23
class OptionsConstructor {
34
constructor(importData) {
45
this.options = {
@@ -51,5 +52,4 @@ class OptionsConstructor {
5152
return this.options.exclude;
5253
}
5354
}
54-
Object.defineProperty(exports, "__esModule", { value: true });
5555
exports.default = OptionsConstructor;

dist/rejection-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Object.defineProperty(exports, "__esModule", { value: true });
12
class RejectionError {
23
constructor(error, type, uniqId) {
34
this.error = error;
@@ -34,5 +35,4 @@ class RejectionError {
3435
throw this.error;
3536
}
3637
}
37-
Object.defineProperty(exports, "__esModule", { value: true });
3838
exports.default = RejectionError;

package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "glob-uglifyjs",
3-
"version": "0.2.0",
4-
"description": "Uglify files with glob pattern.",
3+
"version": "0.3.0",
4+
"description": "Uglify JS files with glob pattern.",
55
"main": "dist/main.js",
66
"scripts": {
77
"build": "tsc -p .",
@@ -18,22 +18,28 @@
1818
"glob",
1919
"folders"
2020
],
21-
"author": "Giedrius Grabauskas<giedrius@quatrodev.com>",
22-
"license": "GPL-3.0",
2321
"files": [
2422
"dist",
2523
"**/*.md"
2624
],
25+
"author": "Giedrius Grabauskas <giedrius@quatrodev.com> (https://github.com/GiedriusGrabauskas)",
26+
"bugs": "https://github.com/SimplrJS/glob-uglifyjs/issues",
27+
"repository": "SimplrJS/glob-uglifyjs",
28+
"homepage": "https://github.com/SimplrJS/glob-uglifyjs",
29+
"license": "GPL-3.0",
30+
"engines": {
31+
"node": ">=6.0.0"
32+
},
2733
"devDependencies": {
2834
"@types/glob": "^5.0.30",
2935
"@types/uglify-js": "^2.6.28",
30-
"@types/yargs": "0.0.33",
31-
"typescript": "^2.0.6"
36+
"@types/yargs": "6.6.0",
37+
"typescript": "^2.2.2"
3238
},
3339
"dependencies": {
3440
"glob": "^7.1.1",
35-
"uglify-js": "^2.7.3",
36-
"yargs": "^6.0.0"
41+
"uglify-js": "^2.8.21",
42+
"yargs": "^7.0.2"
3743
},
3844
"bin": {
3945
"glob-uglifyjs": "./dist/cli.js"

0 commit comments

Comments
 (0)