diff --git a/dist/index.js b/dist/index.js index ed518c75..c6e1905d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1072,6 +1072,8 @@ module.exports = var commands = __webpack_require__(43); var fs = __webpack_require__(44); + var mkdirp = __webpack_require__(46); + var path = __webpack_require__(45); var child_process_1 = __webpack_require__(42); var DefaultPreset_1 = __webpack_require__(14); var JavaScriptObfuscator_1 = __webpack_require__(9); @@ -1141,6 +1143,9 @@ module.exports = }, { key: 'processData', value: function processData() { + var outputPath = this.getOutputPath(), + dirName = path.dirname(outputPath); + mkdirp.sync(dirName); fs.writeFileSync(this.getOutputPath(), JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(this.data, JavaScriptObfuscatorCLI.buildOptions()), { encoding: JavaScriptObfuscatorCLI.encoding }); @@ -2641,6 +2646,18 @@ module.exports = module.exports = require("fs"); +/***/ }, +/* 45 */ +/***/ function(module, exports) { + + module.exports = require("path"); + +/***/ }, +/* 46 */ +/***/ function(module, exports) { + + module.exports = require("mkdirp"); + /***/ } /******/ ]); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/package.json b/package.json index a7695808..2de52c0b 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "escodegen": "^1.8.0", "esprima": "^2.7.2", "estraverse": "^4.2.0", + "mkdirp": "^0.5.1", "source-map-support": "^0.4.0" }, "devDependencies": { diff --git a/src/cli/JavaScriptObfuscatorCLI.ts b/src/cli/JavaScriptObfuscatorCLI.ts index d117f6a9..8b2518de 100644 --- a/src/cli/JavaScriptObfuscatorCLI.ts +++ b/src/cli/JavaScriptObfuscatorCLI.ts @@ -1,5 +1,7 @@ import * as commands from 'commander'; import * as fs from 'fs'; +import * as mkdirp from 'mkdirp'; +import * as path from 'path'; import { execSync } from "child_process"; import { IOptionsPreset } from "../interfaces/IOptionsPreset"; @@ -173,6 +175,11 @@ export class JavaScriptObfuscatorCLI { } private processData (): void { + let outputPath: string = this.getOutputPath(), + dirName: string = path.dirname(outputPath); + + mkdirp.sync(dirName); + fs.writeFileSync( this.getOutputPath(), JavaScriptObfuscator.obfuscate(this.data, JavaScriptObfuscatorCLI.buildOptions()), diff --git a/test/JavaScriptObfuscatorCLI.spec.ts b/test/JavaScriptObfuscatorCLI.spec.ts index 1a65f258..19fe9af0 100644 --- a/test/JavaScriptObfuscatorCLI.spec.ts +++ b/test/JavaScriptObfuscatorCLI.spec.ts @@ -1,13 +1,26 @@ +import * as fs from 'fs'; + import { JavaScriptObfuscatorCLI } from "../src/cli/JavaScriptObfuscatorCLI"; let assert: any = require('chai').assert; describe('JavaScriptObfuscatorCLI', () => { + let CLI: JavaScriptObfuscatorCLI, + fixturesDirName: string = 'test/fixtures', + tmpDirName: string = 'test/tmp', + fixtureFileName: string = 'sample.js', + fixtureFilePath: string = `${fixturesDirName}/${fixtureFileName}`, + outputFileName: string = 'sample-obfuscated.js', + outputFilePath: string = `${tmpDirName}/${outputFileName}`; + describe('run (): void', () => { - it('should obfuscate file with JS code', () => { - let CLI: JavaScriptObfuscatorCLI = new JavaScriptObfuscatorCLI([ + beforeEach(() => { + CLI = new JavaScriptObfuscatorCLI([ 'node', 'javascript-obfuscator', + fixtureFilePath, + '--output', + outputFilePath, '--compact', 'false', '--selfDefending', @@ -15,8 +28,15 @@ describe('JavaScriptObfuscatorCLI', () => { ]); CLI.run(); + }); + it('should obfuscate file with JS code', () => { assert.equal(1, 1); }); + + afterEach(() => { + fs.unlinkSync(outputFilePath); + fs.rmdirSync(tmpDirName); + }); }); }); diff --git a/typings.json b/typings.json index 2bfbd93b..a91366f5 100644 --- a/typings.json +++ b/typings.json @@ -9,6 +9,7 @@ "esprima": "github:DefinitelyTyped/DefinitelyTyped/esprima/esprima.d.ts", "escodegen": "github:DefinitelyTyped/DefinitelyTyped/escodegen/escodegen.d.ts", "estraverse": "github:DefinitelyTyped/DefinitelyTyped/estraverse/estraverse.d.ts", + "mkdirp": "github:DefinitelyTyped/DefinitelyTyped/mkdirp/mkdirp.d.ts", "mocha": "github:DefinitelyTyped/DefinitelyTyped/mocha/mocha.d.ts", "chai": "github:DefinitelyTyped/DefinitelyTyped/chai/chai.d.ts" } diff --git a/typings/browser.d.ts b/typings/browser.d.ts index adcac8b6..4ae3311b 100644 --- a/typings/browser.d.ts +++ b/typings/browser.d.ts @@ -5,5 +5,6 @@ /// /// /// +/// /// /// diff --git a/typings/browser/ambient/mkdirp/index.d.ts b/typings/browser/ambient/mkdirp/index.d.ts new file mode 100644 index 00000000..a4106356 --- /dev/null +++ b/typings/browser/ambient/mkdirp/index.d.ts @@ -0,0 +1,17 @@ +// Generated by typings +// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/mkdirp/mkdirp.d.ts +// Type definitions for mkdirp 0.3.0 +// Project: http://github.com/substack/node-mkdirp +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'mkdirp' { + + function mkdirp(dir: string, cb: (err: any, made: string) => void): void; + function mkdirp(dir: string, flags: any, cb: (err: any, made: string) => void): void; + + namespace mkdirp { + function sync(dir: string, flags?: any): string; + } + export = mkdirp; +} \ No newline at end of file diff --git a/typings/main.d.ts b/typings/main.d.ts index c2c7d481..8577f206 100644 --- a/typings/main.d.ts +++ b/typings/main.d.ts @@ -5,5 +5,6 @@ /// /// /// +/// /// /// diff --git a/typings/main/ambient/mkdirp/index.d.ts b/typings/main/ambient/mkdirp/index.d.ts new file mode 100644 index 00000000..a4106356 --- /dev/null +++ b/typings/main/ambient/mkdirp/index.d.ts @@ -0,0 +1,17 @@ +// Generated by typings +// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/mkdirp/mkdirp.d.ts +// Type definitions for mkdirp 0.3.0 +// Project: http://github.com/substack/node-mkdirp +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'mkdirp' { + + function mkdirp(dir: string, cb: (err: any, made: string) => void): void; + function mkdirp(dir: string, flags: any, cb: (err: any, made: string) => void): void; + + namespace mkdirp { + function sync(dir: string, flags?: any): string; + } + export = mkdirp; +} \ No newline at end of file