Socket
Socket
Sign inDemoInstall

contego

Package Overview
Dependencies
35
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

82

index.js

@@ -1,2 +0,1 @@

#!/usr/bin/env node

@@ -11,3 +10,3 @@ const fs = require('fs-extra')

function getAllFiles(sourcePath, ignoreRegex = undefined) {
function getAllFiles(sourcePath, destPath, debug = false, ignoreRegex = undefined) {
let cabinet = [];

@@ -23,3 +22,3 @@ let files = fs.readdirSync(sourcePath)

if (stat.isDirectory()) {
if (name == 'node_modules') {
if (name.match(/node_modules|\.git/i)) {
return true;

@@ -30,5 +29,17 @@ }

}
cabinet = cabinet.concat(getAllFiles(fullpath))
} else if (stat.isFile() && path.extname(name) === '.js') {
cabinet.push(fullpath);
let newDest = fullpath.replace(sourcePath, destPath)
cabinet = cabinet.concat(getAllFiles(fullpath, newDest, debug, ignoreRegex))
} else if (stat.isFile()) {
//console.log('file', fullpath)
if (path.extname(name) === '.js') {
//console.log('pushing', fullpath)
cabinet.push(fullpath)
} else {
//console.log('copying', fullpath, sourcePath, destPath)
let dpath = fullpath.replace(sourcePath, destPath)
if (debug) {
console.log(`copying file ${fullpath} to ${dpath}`)
}
fs.copyFileSync(fullpath, dpath)
}
}

@@ -43,7 +54,7 @@ } catch (e) {

if (debug) {
console.log(`reading file ${filpath}`)
console.log(`reading file ${filepath}`)
}
let contents = fs.readFileSync(filepath, { encoding: 'utf8' })
if (debug) {
console.log(`converting file ${filpath}`)
console.log(`converting file ${filepath}`)
}

@@ -71,2 +82,3 @@ let ast = esprima.parse(contents)

function writeFile(filepath, data) {
fs.ensureFileSync(filepath)
fs.writeFileSync(filepath, data, { encoding: 'utf8' })

@@ -76,12 +88,27 @@ }

function convertAll(sourcePath, destPath, es = false, debug = false, ignorRegexStr = undefined) {
const jsFiles = getAllFiles(sourcePath)
jsFiles.forEach(function (file) {
const contents = contego(file, es, debug)
let dpath = file.replace(sourcePath, destPath)
if (debug) {
console.log(`writing file ${dpath}`)
function convertAll(sourcePath, destPath, es = false, error = false, debug = false, ignorRegexStr = undefined) {
const jsFiles = getAllFiles(sourcePath, destPath, debug, ignorRegexStr)
try {
jsFiles.forEach(function (file) {
let dpath = file.replace(sourcePath, destPath)
try {
const contents = contego(file, es, debug)
if (debug) {
console.log(`writing file ${dpath}`)
}
writeFile(dpath, contents)
} catch (e) {
if (error) {
throw e
}
console.warn(`error while converting file ${file}`)
fs.copyFileSync(file, dpath)
}
})
} catch (e) {
if (error) {
throw e
}
writeFile(dpath, contents)
})
console.warn(`error while converting file ${e.message}`)
}
if (debug) {

@@ -96,4 +123,5 @@ console.log(`all js files contego'ed successfully`)

.version(require('./package').version, '-v, --version')
.usage('/Users/pradeep/sourcedir /Users/pradeep/destdir -u js -d false ')
.option('-u, --uglify [type]', 'Use uglify, define type of js syntax [js|es|null]', 'js')
.usage('/Users/pradeep/sourcedir /Users/pradeep/destdir -u js -d false')
.option('-e, --error [type]', 'throw error [true|false]', 'false')
.option('-u, --uglify [type]', 'Use uglify, define type of js syntax [js|es|null]', 'es')
.option('-d, --debug [type]', 'Run in debug mode type of debug [false|true]', 'false')

@@ -113,6 +141,16 @@ .option('-r, --ignore [ignoreRegexString]', 'Regex value to ignore files like ^[a-zA-Z0-9_]+\.js', '')

}
convertAll(src, dest, program.uglify, program.debug, program.ignore)
});
if (program.error == 'true') {
program.error = true;
} else {
program.error = false;
}
if (program.debug == 'true') {
program.debug = true;
} else {
program.debug = false;
}
convertAll(src, dest, program.uglify, program.error, program.debug, program.ignore)
})
program.parse(process.argv);
program.parse(process.argv)
{
"name": "contego",
"version": "0.0.3",
"version": "0.0.4",
"description": "simple code protect for javascript files",

@@ -5,0 +5,0 @@ "main": "index.js",

## Contego
Install

@@ -14,7 +12,7 @@ ``` bash

$ contego <source dir> <dest dir> -u js|es|null -d true|false -i ^\w\\.js$
source dir = source directory
dest dir = destination directory
-u = use uglify, es for es6 files, js for es5 or below and null for skipping uglify
-d = debug mode, for extra logging
-i = ignore regex string, provide regex to ignore any files define by user
- source dir = source directory
- dest dir = destination directory
- -u = use uglify, es for es6 files, js for es5 or below and null for skipping uglify
- -d = debug mode, for extra logging
- -i = ignore regex string, provide regex to ignore any files define by user

@@ -21,0 +19,0 @@ ## Example

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc