UNPKG

2.03 kBJavaScriptView Raw
1'use strict'
2
3// our stampit modules
4var stampit = require( 'stampit' )
5var fs = require( 'fs' )
6
7// let there be light ( * )
8// basically, with stampit we take a bunch of different objects
9// and methods and compose them into one mega object, the app
10// appropriately namespaced, with methods on the prototype, and this set correctly
11// basic app flow below
12// init() -> read() -> parse() -> lint() -> done()
13// init() -> watch() -> read() -> parse() -> lint() -> done()
14
15
16/**
17 * main stylint kickoff function
18 * @param {string} path [custom path if used programmatically]
19 * @param {object} config [config if used programmatically]
20 * @param {function} [callback] [a callback called just before exiting the process if not watching]
21 * @return {Object} [the composed stylint object]
22 */
23var Stylint = function( path, config, callback ) {
24 return stampit().compose(
25 require( './src/core/' ),
26 require( './src/checks/' ),
27 require( './src/state/' ),
28 stampit().enclose( function() {
29 var pkg = require( process.cwd() + '/package.json' )
30
31 // set safe path defaults
32 if ( typeof path === 'undefined' ) {
33 this.state.path = './'
34 }
35 else if ( path instanceof Array || typeof path === 'string' ) {
36 this.state.path = path
37 }
38
39 // look for a stylintignore array
40 // for ignoring specific files
41 // first look in package.json
42 // then look for .stylintignore in the main dir
43 if ( typeof pkg.stylintignore !== 'undefined' &&
44 pkg.stylintignore instanceof Array ) {
45 this.state.exclude = pkg.stylintignore
46 }
47 else {
48 try {
49 var stylintIgnore = fs.readFileSync( process.cwd() + '/.stylintignore' )
50 this.state.exclude = stylintIgnore
51 .toString()
52 .split( '\n' )
53 .filter( function( d ) {
54 return d
55 } )
56 }
57 catch ( err ) {
58 // do no-thing
59 }
60 }
61
62 this.customConfig = typeof config === 'object' ? config : false
63 this.callback = callback || function() {}
64 } ).enclose( require( './src/core/init' ) )
65 )
66}
67
68module.exports = Stylint