@@ -3,12 +3,14 @@ const path = require('path');
3
3
const fs = require ( 'fs' ) ;
4
4
const { flatten } = require ( 'array-flatten' ) ;
5
5
6
- // console.log(flatten);
7
-
8
- // process.exit(0);
9
-
10
6
dotenv . config ( ) ;
11
7
8
+ // eslint-disable-next-line no-unused-vars
9
+ const logger = ( name ) => {
10
+ console . log ( name ) ;
11
+ return name ;
12
+ } ;
13
+
12
14
/**
13
15
* ArticleBuilder
14
16
* @class
@@ -66,20 +68,20 @@ class ArticleBuilder {
66
68
} ;
67
69
let plugins = this . pluginCollector ( path . resolve ( './source/plugins' ) ) ;
68
70
// eslint-disable-next-line import/no-dynamic-require, global-require
69
- plugins = plugins . map ( uri => ( require ( uri ) ) ) ;
71
+ plugins = plugins . map ( ( uri ) => ( require ( uri ) ) ) ;
70
72
71
- await flatten ( this . stages
73
+ return flatten ( this . stages
72
74
// remove stages we should skip
73
- . filter ( stage => ( ! this . skip . stages . includes ( stage ) ) )
75
+ . filter ( ( stage ) => ( ! this . skip . stages . includes ( stage ) ) )
74
76
// map stages to plugins array
75
- . map ( stage => plugins
77
+ . map ( ( stage ) => plugins
76
78
// filter plugin that have no functions for this stage
77
- . filter ( plugin => ( ( plugin [ stage ] !== undefined ) && ( typeof plugin [ stage ] === 'function' ) ) )
79
+ . filter ( ( plugin ) => ( ( plugin [ stage ] !== undefined ) && ( typeof plugin [ stage ] === 'function' ) ) )
78
80
// filter plugin we need to skip
79
81
. filter ( ( plugin ) => {
80
82
const { meta : { name } } = plugin ;
81
83
return ( this . skip . plugins . find (
82
- skippedPlugin => (
84
+ ( skippedPlugin ) => (
83
85
(
84
86
skippedPlugin . name === name
85
87
&& skippedPlugin . stages === undefined
@@ -99,20 +101,44 @@ class ArticleBuilder {
99
101
. sort ( ( pluginA , pluginB ) => (
100
102
pluginA . meta . dependency . includes ( pluginB . meta . name )
101
103
? 1 : - 1 ) )
104
+ // .map(logger)
102
105
// map plugins to functions
103
- . map ( plugin => ( plugin [ stage ] ) ) ) )
106
+ . map ( ( plugin ) => ( plugin [ stage ] ) ) ) )
104
107
. reduce ( async ( state , plugin ) => {
105
108
const resolvedState = await state ;
106
109
return plugin ( resolvedState ) ;
107
110
} , article ) ;
108
111
}
109
112
}
110
113
111
- // (async () => {
112
- // try {
113
- // const builder = new ArticleBuilder();
114
- // await builder.create('https://www.smashingmagazine.com/2020/05/convince-others-against-dark-patterns/');
115
- // } catch (error) {
116
- // console.log(error);
117
- // }
118
- // })();
114
+ ( async ( ) => {
115
+ const builder = new ArticleBuilder ( ) ;
116
+ builder . skip . stages = [
117
+ 'github:before' ,
118
+ 'github' ,
119
+ 'github:after' ,
120
+ ] ;
121
+ builder . skip . plugins = [
122
+ { name : 'codepenTransform' } ,
123
+ { name : 'codepenTransformIFrame' } ,
124
+ { name : 'createREADME' } ,
125
+ { name : 'downloadImages' } ,
126
+ { name : 'writeMarkdown' } ,
127
+ { name : 'TMPDir' } ,
128
+ { name : 'initGithub' } ,
129
+ { name : 'uploadToRepo' } ,
130
+ { name : 'createRepo' } ,
131
+ { name : 'createREADME' } ,
132
+ { name : 'createCard' } ,
133
+ ] ;
134
+
135
+ try {
136
+ const result = await builder . create ( 'https://increment.com/frontend/a-users-guide-to-css-variables/' ) ;
137
+ // console.log(result);
138
+ console . log ( result . tags ) ;
139
+ console . log ( result . mercury [ 0 ] . author ) ;
140
+ console . log ( result . openGraph ) ;
141
+ } catch ( error ) {
142
+ console . log ( error ) ;
143
+ }
144
+ } ) ( ) ;
0 commit comments