@@ -15,7 +15,7 @@ var argv = require('yargs')
15
15
. alias ( 'u' , 'use' )
16
16
. array ( 'use' )
17
17
. pkgConf ( 'posthtml' )
18
- . config ( 'c' )
18
+ . config ( )
19
19
. alias ( 'c' , 'config' )
20
20
. version ( function ( ) {
21
21
return require ( './package.json' ) . version
@@ -36,24 +36,41 @@ var argv = require('yargs')
36
36
37
37
function processing ( file , output ) {
38
38
// get htmls
39
- var html = fs . readFileSync ( file , 'utf8' )
39
+ const html = fs . readFileSync ( file , 'utf8' )
40
+ let plugins ;
40
41
41
- // config
42
- var config = { }
42
+ console . log ( argv ) ;
43
43
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
+ const use = argv . use ? argv . use : [ ] ;
46
+ const 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 = { }
50
59
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
+ }
53
70
}
54
71
55
72
// processing
56
- posthtml ( require ( 'post-load-plugins' ) ( config ) )
73
+ posthtml ( argv . autoOff ? plugins : require ( 'post-load-plugins' ) ( config ) )
57
74
. process ( html )
58
75
. then ( function ( result ) {
59
76
fs . writeFileSync ( output , result . html )
0 commit comments