@@ -15,7 +15,7 @@ var argv = require('yargs')
1515 . alias ( 'u' , 'use' )
1616 . array ( 'use' )
1717 . pkgConf ( 'posthtml' )
18- . config ( 'c' )
18+ . config ( )
1919 . alias ( 'c' , 'config' )
2020 . version ( function ( ) {
2121 return require ( './package.json' ) . version
@@ -37,23 +37,40 @@ var argv = require('yargs')
3737function processing ( file , output ) {
3838 // get htmls
3939 var html = fs . readFileSync ( file , 'utf8' )
40+ var plugins ;
4041
41- // config
42- var config = { }
42+ console . log ( argv ) ;
4343
44- // create config extends for post-load-plugins
45- if ( argv . use ) {
46- argv . use . forEach ( function ( plugin ) {
47- config [ plugin ] = argv [ plugin ] || { }
48- } )
49- }
44+ if ( argv . autoOff ) {
45+ var use = argv . use ? argv . use : [ ] ;
46+ var cfg = argv . config ? Object . keys ( require ( path . resolve ( argv . config ) ) ) : [ ] ;
47+ plugins = [ ] . concat ( use , cfg ) . map ( ( plugin ) => {
48+ try {
49+ return require ( plugin ) ( argv [ plugin ] )
50+ } catch ( e ) {
51+ if ( err . code === 'MODULE_NOT_FOUND' ) {
52+ throw new TypeError ( 'Plugin Error: Cannot find module ' + plugin ) ;
53+ }
54+ }
55+ } ) ;
56+ } else {
57+ // config
58+ var config = { }
5059
51- if ( argv . config ) {
52- config = Object . assign ( require ( path . resolve ( argv . config ) ) , config )
60+ // create config extends for post-load-plugins
61+ if ( argv . use ) {
62+ argv . use . forEach ( function ( plugin ) {
63+ config [ plugin ] = argv [ plugin ] || { }
64+ } )
65+ }
66+
67+ if ( argv . config ) {
68+ config = Object . assign ( require ( path . resolve ( argv . config ) ) , config )
69+ }
5370 }
5471
5572 // processing
56- posthtml ( require ( 'post-load-plugins' ) ( config ) )
73+ posthtml ( argv . autoOff ? plugins : require ( 'post-load-plugins' ) ( config ) )
5774 . process ( html )
5875 . then ( function ( result ) {
5976 fs . writeFileSync ( output , result . html )
0 commit comments