lib/build.js
function publisher(outputJsFile, done, forceMinified){
		// Check if JSCrambler configs file exist
		const time = process.hrtime();
		const jscramblerConfigs = path.resolve('jscrambler.json');
		fs.stat( jscramblerConfigs, function (err) {
			if ( err ){
				let newTime =
				console.log('  obfuscating code with jScrambler was not executed, because the configs file `jscrambler.json` is not present into project\'s directory.'.yellow);
				console.log('Publication finished!'.gray); // +beautifyTime( process.hrtime(time) ).green + '\u0007'
				return done(err);
			}

			console.log('  obfuscating code with jScrambler...'.gray);
			try {
				var configs = require(jscramblerConfigs);
			} catch (e) {
				return done('    Error on obfuscation! The file configs is not a valid JSON'.red);
			}

			if ( !_.isObject(configs.keys) ||
				_.isEmpty(configs.keys.accessKey) ||
				_.isEmpty(configs.keys.secretKey) ||
				_.isEmpty(configs.applicationId)
			){
				return done( new Error('    Error on obfuscation! Jcrambler\'s configs missed. Ex.: accessKey, secretKey or applicationId.') );
			}


			// Set the file for obfuscation
			if ( !_.isArray(configs.filesSrc) )
				configs.filesSrc = [];

			if ( configs.filesSrc.indexOf(outputJsFile) == -1 )
				configs.filesSrc.push(outputJsFile);

			configs.filesDest = path.dirname( packageJSONFile ); // The project's dirname


			/*
			{
				keys: {
					accessKey: 'YOUR_JSCRAMBLER_ACCESS_KEY',
					secretKey: 'YOUR_JSCRAMBLER_SECRET_KEY'
				},
				host: 'api4.jscrambler.com',
				port: 443,
				applicationId: 'YOUR_APPLICATION_ID',
				filesSrc: [
					'/path/to/src/*.html',
					'/path/to/src/*.js'
				],
				filesDest: '/path/to/destDir/',
				params: {
					stringSplitting: {
						chunk: 1
					}
				}
			}
			*/

			const symbolTable = path.join( configs.filesDest, "symbolTable.json");

			jscrambler
				.protectAndDownload(configs)
				.then(function () {
					try{
						const st = fs.statSync( symbolTable );
						fs.unlinkSync(symbolTable);
					}catch(e){}

					if ( !forceMinified ){
						console.log('Publication finished in '.gray+beautifyTime( process.hrtime(time) ).green + '\u0007');
						return done();
					}

					minify(outputJsFile,{},function(err){
						if (err){
							return done(err);
						}
						console.log('Publication finished in '.gray+beautifyTime( process.hrtime(time) ).green + '\u0007');
						return done();
					});


				})
				.catch(function (err) {
					let message = '    Error on obfuscation! Error while obfuscating the code with jScrambler';
					if ( err && err.message )
						message = `  Error on obfuscation! jScrambler: ${err.message}`;
					done( new Error(message) );
				});

		});
	}
function publisher(outputJsFile, done, forceMinified){
		// Check if JSCrambler configs file exist
		const time = process.hrtime();
		const jscramblerConfigs = path.resolve('jscrambler.json');
		fs.stat( jscramblerConfigs, function (err) {
			if ( err ){
				let newTime =
				console.log('  obfuscating code with jScrambler was not executed, because the configs file `jscrambler.json` is not present into project\'s directory.'.yellow);
				console.log('Publication finished!'.gray); // +beautifyTime( process.hrtime(time) ).green + '\u0007'
				return done(err);
			}

			console.log('  obfuscating code with jScrambler...'.gray);
			try {
				var configs = require(jscramblerConfigs);
			} catch (e) {
				return done('    Error on obfuscation! The file configs is not a valid JSON'.red);
			}

			if ( !_.isObject(configs.keys) ||
				_.isEmpty(configs.keys.accessKey) ||
				_.isEmpty(configs.keys.secretKey) ||
				_.isEmpty(configs.applicationId)
			){
				return done( new Error('    Error on obfuscation! Jcrambler\'s configs missed. Ex.: accessKey, secretKey or applicationId.') );
			}


			// Set the file for obfuscation
			if ( !_.isArray(configs.filesSrc) )
				configs.filesSrc = [];

			if ( configs.filesSrc.indexOf(outputJsFile) == -1 )
				configs.filesSrc.push(outputJsFile);

			configs.filesDest = path.dirname( packageJSONFile ); // The project's dirname


			/*
			{
				keys: {
					accessKey: 'YOUR_JSCRAMBLER_ACCESS_KEY',
					secretKey: 'YOUR_JSCRAMBLER_SECRET_KEY'
				},
				host: 'api4.jscrambler.com',
				port: 443,
				applicationId: 'YOUR_APPLICATION_ID',
				filesSrc: [
					'/path/to/src/*.html',
					'/path/to/src/*.js'
				],
				filesDest: '/path/to/destDir/',
				params: {
					stringSplitting: {
						chunk: 1
					}
				}
			}
			*/

			const symbolTable = path.join( configs.filesDest, "symbolTable.json");

			jscrambler
				.protectAndDownload(configs)
				.then(function () {
					try{
						const st = fs.statSync( symbolTable );
						fs.unlinkSync(symbolTable);
					}catch(e){}

					if ( !forceMinified ){
						console.log('Publication finished in '.gray+beautifyTime( process.hrtime(time) ).green + '\u0007');
						return done();
					}

					minify(outputJsFile,{},function(err){
						if (err){
							return done(err);
						}
						console.log('Publication finished in '.gray+beautifyTime( process.hrtime(time) ).green + '\u0007');
						return done();
					});


				})
				.catch(function (err) {
					let message = '    Error on obfuscation! Error while obfuscating the code with jScrambler';
					if ( err && err.message )
						message = `  Error on obfuscation! jScrambler: ${err.message}`;
					done( new Error(message) );
				});

		});
	}
function publisher ( outputJsFile , done , forceMinified ) { // Check if JSCrambler configs file exist const time = process . hrtime ( ) ; const jscramblerConfigs = path . resolve ( 'jscrambler.json' ) ; fs . stat ( jscramblerConfigs , function ( err ) { if ( err ) { let newTime = console . log ( '  obfuscating code with jScrambler was not executed, because the configs file `jscrambler.json` is not present into project\'s directory.' . yellow ) ; console . log ( 'Publication finished!' . gray ) ; // +beautifyTime( process.hrtime(time) ).green + '\u0007' return done ( err ) ; } console . log ( '  obfuscating code with jScrambler...' . gray ) ; try { var configs = require ( jscramblerConfigs ) ; } catch ( e ) { return done ( '    Error on obfuscation! The file configs is not a valid JSON' . red ) ; } if ( ! _ . isObject ( configs . keys ) || _ . isEmpty ( configs . keys . accessKey ) || _ . isEmpty ( configs . keys . secretKey ) || _ . isEmpty ( configs . applicationId ) ) { return done ( new Error ( '    Error on obfuscation! Jcrambler\'s configs missed. Ex.: accessKey, secretKey or applicationId.' ) ) ; } // Set the file for obfuscation if ( ! _ . isArray ( configs . filesSrc ) ) configs . filesSrc = [ ] ; if ( configs . filesSrc . indexOf ( outputJsFile ) == - 1 ) configs . filesSrc . push ( outputJsFile ) ; configs . filesDest = path . dirname ( packageJSONFile ) ; // The project's dirname /*
			{
				keys: {
					accessKey: 'YOUR_JSCRAMBLER_ACCESS_KEY',
					secretKey: 'YOUR_JSCRAMBLER_SECRET_KEY'
				},
				host: 'api4.jscrambler.com',
				port: 443,
				applicationId: 'YOUR_APPLICATION_ID',
				filesSrc: [
					'/path/to/src/*.html',
					'/path/to/src/*.js'
				],
				filesDest: '/path/to/destDir/',
				params: {
					stringSplitting: {
						chunk: 1
					}
				}
			}
			*/ const symbolTable = path . join ( configs . filesDest , "symbolTable.json" ) ; jscrambler . protectAndDownload ( configs ) . then ( function ( ) { try { const st = fs . statSync ( symbolTable ) ; fs . unlinkSync ( symbolTable ) ; } catch ( e ) { } if ( ! forceMinified ) { console . log ( 'Publication finished in ' . gray + beautifyTime ( process . hrtime ( time ) ) . green + '\u0007' ) ; return done ( ) ; } minify ( outputJsFile , { } , function ( err ) { if ( err ) { return done ( err ) ; } console . log ( 'Publication finished in ' . gray + beautifyTime ( process . hrtime ( time ) ) . green + '\u0007' ) ; return done ( ) ; } ) ; } ) . catch ( function ( err ) { let message = '    Error on obfuscation! Error while obfuscating the code with jScrambler' ; if ( err && err . message ) message = ` ${ err . message } ` ; done ( new Error ( message ) ) ; } ) ; } ) ; }
Function for publisher and obfuscation method
Function for publisher and obfuscation method