🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

sails-generate-eslintrc

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sails-generate-eslintrc - npm Package Compare versions

Comparing version

to
1.1.1

123

generate.js

@@ -6,11 +6,20 @@ #!/usr/bin/env node

*/
var _ = require('underscore');
var program = require('commander');
function list(val) {
return val.split(',');
}
program
.version('1.1.0')
.option('-c, --config <string>', 'Set eslint config file name')
.option('-p, --preset <string>', 'Set preset coding style')
.option('-g, --globals <items>', 'Input globals list')
.option('-f, --floder <items>', 'Input global floders list')
.version('1.1.1')
.option('-m, --mode <string>',
'Set mode for .eslintrc-sails: update, override.' +
'Default: Add default globals')
.option('-c, --config <path>', 'Set eslint config file name')
.option('-p, --preset <string>', 'Set preset coding style, like: google')
.option('-g, --globals <items>',
'Input globals list, like: sails, mysql', list)
.option('-f, --folders <items>',
'Input global folders list, like: api/controllers, config', list)
.parse(process.argv);

@@ -39,30 +48,90 @@

}
if (program.globals) {
globalsList = globalsList.concat(program.globals);
}
if (program.folders) {
globalFoldersList = program.folders;
}
// console.log(program.folders);
// add globals default
var i;
for (i = 0; i < globalsList.length; i++) {
globals[globalsList[i]] = true;
}
// add all file names
for (i = 0; i < globalFoldersList.length; i++) {
globalsList = globalsList.concat(
fs.readdirSync(prefixPath + globalFoldersList[i])
);
}
// choose globas names by .js
for (i = 0; i < globalsList.length; i++) {
var fileName = globalsList[i];
var suffix = fileName.substring(fileName.length - 3, fileName.length);
if (suffix === '.js' || suffix === '.JS') {
globals[fileName.substring(0, fileName.length - 3)] = true;
var addGlobals = function() {
var i;
for (i = 0; i < globalsList.length; i++) {
globals[globalsList[i]] = true;
}
// add all file names
for (i = 0; i < globalFoldersList.length; i++) {
globalsList = globalsList.concat(
fs.readdirSync(prefixPath + globalFoldersList[i])
);
}
// console.log(globalsList);
// choose globas names by .js
for (i = 0; i < globalsList.length; i++) {
var fileName = globalsList[i];
var suffix = fileName.substring(fileName.length - 3, fileName.length);
if (suffix === '.js' || suffix === '.JS') {
globals[fileName.substring(0, fileName.length - 3)] = true;
}
}
};
addGlobals();
// console.log(globals);
if (program.mode) {
switch (program.mode.trim()) {
case 'update':
fs.exists(sailsConfigFileName, function(exists) {
if (exists) {
var data = fs.readFileSync(sailsConfigFileName, 'utf-8');
if (data) {
eslintrcSails = JSON.parse(data);
if (eslintrcSails.globals) {
console.log(eslintrcSails.globals);
eslintrcSails.globals = _.extend(eslintrcSails.globals, globals);
} else {
eslintrcSails.globals = globals;
}
console.log('ol');
} else {
console.log('read file error!');
}
fs.writeFileSync(sailsConfigFileName,
JSON.stringify(eslintrcSails, null, '\t'));
} else {
console.log(sailsConfigFileName +
'is not exists, it will be created');
eslintrcSails.globals = globals;
fs.open(sailsConfigFileName, 'w', function(err) {
if (err) {
console.log('error:' + err);
process.exit(0);
}
console.log(sailsConfigFileName + 'is created!');
fs.writeFileSync(sailsConfigFileName,
JSON.stringify(eslintrcSails, null, '\t'));
});
}
});
break;
default:
// console.log('default');
eslintrcSails.globals = globals;
fs.writeFileSync(sailsConfigFileName,
JSON.stringify(eslintrcSails, null, '\t'));
}
} else {
// console.log('default2');
eslintrcSails.globals = globals;
fs.writeFileSync(sailsConfigFileName,
JSON.stringify(eslintrcSails, null, '\t'));
}
// write globals to .eslintrc-sails
eslintrcSails.globals = globals;
fs.writeFileSync(sailsConfigFileName,
JSON.stringify(eslintrcSails, null, '\t'));
// eslintrcSails.globals = globals;
// console.log(eslintrcSails);
// console.log(globals);
var updateGlobals = function(err, data) {

@@ -69,0 +138,0 @@ if (err) {

{
"name": "sails-generate-eslintrc",
"version": "1.1.0",
"version": "1.1.1",
"description": "generate eslint config file which contains sails's globals",

@@ -29,4 +29,5 @@ "main": "generate.js",

"eslint": "^1.10.3",
"eslint-config-google": "^0.3.0"
"eslint-config-google": "^0.3.0",
"underscore": "^1.8.3"
}
}
# sails-generate-eslintrc
##Description
## Description
Generate eslint config file which contains sails's globals.<br/>
It will generate .eslintrc-sails and .eslintrc (if it exists, it will be updated).
##Example
## Example
- .eslintrc-sails

@@ -48,3 +48,3 @@ ```

##Usage
## Usage
- global install

@@ -57,4 +57,4 @@ + Install:

+ Run:
* You need run it under project root path in command line
* You need run it under project root path in command line
```

@@ -71,7 +71,6 @@ sails-generate-eslintrc

+ Run:
* You need run it under project root path in command line
* You need run it under project root path in command line
```
node_modules/.bin/sails-generate-eslintrc
```

Sorry, the diff of this file is not supported yet