UNPKG

2.07 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,
11// and `this` set consistently (ie, available throughout the app)
12//
13// basic app flow below
14// init() -> read() -> parse() -> lint() -> done()
15// init() -> watch() -> read() -> parse() -> lint() -> done()
16
17
18/**
19 * main stylint kickoff function
20 * @param {string} path [custom path if used programmatically]
21 * @param {object} config [config if used programmatically]
22 * @param {function} [callback] [a callback called just before exiting the process if not watching]
23 * @return {Object} [the composed stylint object]
24 */
25var Stylint = function( path, config, callback ) {
26 return stampit().compose(
27 require( './src/core/' ),
28 require( './src/checks/' ),
29 require( './src/state/' ),
30 stampit().enclose( function() {
31 var pkg = require( process.cwd() + '/package.json' )
32
33 // set safe path defaults
34 if ( typeof path === 'undefined' ) {
35 this.state.path = './'
36 }
37 else if ( path instanceof Array || typeof path === 'string' ) {
38 this.state.path = path
39 }
40
41 // look for a stylintignore array
42 // for ignoring specific files
43 // first look in package.json
44 // then look for .stylintignore in the main dir
45 if ( typeof pkg.stylintignore !== 'undefined' &&
46 pkg.stylintignore instanceof Array ) {
47 this.state.exclude = pkg.stylintignore
48 }
49 else {
50 try {
51 var stylintIgnore = fs.readFileSync( process.cwd() + '/.stylintignore' )
52 this.state.exclude = stylintIgnore
53 .toString()
54 .split( '\n' )
55 .filter( function( d ) {
56 return d
57 } )
58 }
59 catch ( err ) {
60 // do no-thing
61 }
62 }
63
64 this.customConfig = typeof config === 'object' ? config : false
65 this.callback = callback || function() {}
66 } ).enclose( require( './src/core/init' ) )
67 )
68}
69
70module.exports = Stylint