@@ -28,93 +28,105 @@ var header = fs.readFileSync('src/templates/header.html', 'utf8')
28
28
var highlight = fs . readFileSync ( 'src/templates/highlight.html' , 'utf8' )
29
29
30
30
module . exports = function ( ) {
31
- glob ( 'src/components/**/*.html' , { } , function ( err , components ) {
32
- if ( err ) {
33
- console . error ( err )
34
- return
35
- }
36
-
37
- var template = fs . readFileSync ( 'src/templates/components.html' , 'utf8' )
38
- var indexTemplate = fs . readFileSync ( 'src/templates/components-index.html' , 'utf8' )
39
-
40
- var componentsForNav = { }
41
- components . map ( function ( component ) {
42
- var componentTokens = component . replace ( 'src/components/' , '' ) . split ( '/' )
43
- var category = componentTokens [ 0 ]
44
-
45
- componentsForNav [ category ] = componentsForNav [ category ] || [ ]
46
- componentsForNav [ category ] . push ( {
47
- href : component . replace ( 'src' , '' ) . replace ( '.html' , '' ) + '/index.html' ,
48
- name : getName ( component )
49
- } )
50
- } )
51
-
52
- var compiledPage = _ . template ( indexTemplate ) ( {
53
- componentsForNav : componentsForNav ,
54
- title : 'Components' ,
55
- analytics : analytics ,
56
- footer : footer ,
57
- head : head ,
58
- header : header ,
59
- } )
60
-
61
- mkdirp . sync ( 'components' )
62
- fs . writeFileSync ( 'components/index.html' , compiledPage )
63
-
64
- components . forEach ( function ( component ) {
65
- var newDir = rmHtmlExt ( component . replace ( 'src/' , '' ) )
66
- var newFile = newDir + '/index.html'
67
- var componentHtml = fs . readFileSync ( component , 'utf8' )
68
-
69
- var fmParsed = fm . parse ( componentHtml )
70
- var frontMatter = fmParsed . attributes || { }
71
- frontMatter . bodyClass = frontMatter . bodyClass || ''
72
- frontMatter . title = frontMatter . title || getTitle ( component )
73
- frontMatter . name = frontMatter . name || getName ( component )
74
- frontMatter . classes = getClasses ( fmParsed . body ) . map ( function ( klass ) {
75
- return '.' + klass
31
+ return new Promise ( function ( resolve , reject ) {
32
+ glob ( 'src/components/**/*.html' , { } , function ( err , components ) {
33
+ if ( err ) {
34
+ console . error ( err )
35
+ return reject ( err )
36
+ }
37
+
38
+ var template = fs . readFileSync ( 'src/templates/components.html' , 'utf8' )
39
+ var indexTemplate = fs . readFileSync ( 'src/templates/components-index.html' , 'utf8' )
40
+
41
+ var componentsForNav = { }
42
+ components . map ( function ( component ) {
43
+ var componentTokens = component . replace ( 'src/components/' , '' ) . split ( '/' )
44
+ var category = componentTokens [ 0 ]
45
+
46
+ // Check the front matter for screenshot overrides
47
+ var componentHtml = fs . readFileSync ( component , 'utf8' )
48
+ var fmParsed = fm . parse ( componentHtml )
49
+ var frontMatter = fmParsed . attributes || { }
50
+ var screenshot = frontMatter . screenshot || { }
51
+ screenshot . path = component . replace ( 'src' , '' ) . replace ( '.html' , '' ) + '/screenshot.png'
52
+
53
+ componentsForNav [ category ] = componentsForNav [ category ] || [ ]
54
+ componentsForNav [ category ] . push ( {
55
+ href : component . replace ( 'src' , '' ) . replace ( '.html' , '' ) + '/index.html' ,
56
+ name : getName ( component ) ,
57
+ screenshot : screenshot
58
+ } )
76
59
} )
77
- frontMatter . componentHtml = componentHtml
78
- frontMatter . content = fmParsed . body
79
- frontMatter . escapedHtml = escapeHtml ( fmParsed . body )
80
- frontMatter . footer = footer
81
- frontMatter . analytics = analytics
82
- frontMatter . head = head
83
- frontMatter . highlight = highlight
84
- frontMatter . componentsForNav = componentsForNav
85
-
86
- var moduleSrcs = { }
87
- var getModules = postcss . plugin ( 'get-modules' , function ( ) {
88
- return function ( css , result ) {
89
- css . walkRules ( function ( rule ) {
90
- moduleSrcs [ rule . source . input . from ] = true
91
- } )
92
- }
60
+
61
+ var compiledPage = _ . template ( indexTemplate ) ( {
62
+ componentsForNav : componentsForNav ,
63
+ title : 'Components' ,
64
+ analytics : analytics ,
65
+ footer : footer ,
66
+ head : head ,
67
+ header : header ,
93
68
} )
94
69
95
- postcss ( [
96
- atImport ( ) , cssVariables ( ) , conditionals ( ) , customMedia ( ) , select ( frontMatter . classes ) ,
97
- removeComments ( { removeAll : true } ) , mqPacker ( ) , removeEmpty ( ) , getModules ( ) , perfectionist ( )
98
- ] ) . process ( tachyonsCss , {
99
- from : 'src/css/tachyons.css'
100
- } ) . then ( function ( result ) {
101
- console . log ( 'component css selection complete for' , component )
102
- frontMatter . componentCss = result . css
103
- frontMatter . stats = cssstats ( frontMatter . componentCss )
104
-
105
- // TODO: Update me once src/ uses the npm modules
106
- frontMatter . modules = Object . keys ( moduleSrcs ) . map ( function ( module ) {
107
- return 'tachyons-' + module . split ( '/_' ) [ 1 ] . replace ( '.css' , '' )
70
+ mkdirp . sync ( 'components' )
71
+ fs . writeFileSync ( 'components/index.html' , compiledPage )
72
+
73
+ var promises = [ ]
74
+ components . forEach ( function ( component ) {
75
+ var newDir = rmHtmlExt ( component . replace ( 'src/' , '' ) )
76
+ var newFile = newDir + '/index.html'
77
+ var componentHtml = fs . readFileSync ( component , 'utf8' )
78
+
79
+ var fmParsed = fm . parse ( componentHtml )
80
+ var frontMatter = fmParsed . attributes || { }
81
+ frontMatter . bodyClass = frontMatter . bodyClass || ''
82
+ frontMatter . title = frontMatter . title || getTitle ( component )
83
+ frontMatter . name = frontMatter . name || getName ( component )
84
+ frontMatter . classes = getClasses ( fmParsed . body ) . map ( function ( klass ) {
85
+ return '.' + klass
86
+ } )
87
+ frontMatter . componentHtml = componentHtml
88
+ frontMatter . content = fmParsed . body
89
+ frontMatter . escapedHtml = escapeHtml ( fmParsed . body )
90
+ frontMatter . footer = footer
91
+ frontMatter . analytics = analytics
92
+ frontMatter . head = head
93
+ frontMatter . highlight = highlight
94
+ frontMatter . componentsForNav = componentsForNav
95
+
96
+ var moduleSrcs = { }
97
+ var getModules = postcss . plugin ( 'get-modules' , function ( ) {
98
+ return function ( css , result ) {
99
+ css . walkRules ( function ( rule ) {
100
+ moduleSrcs [ rule . source . input . from ] = true
101
+ } )
102
+ }
108
103
} )
109
104
110
- var compiledPage = _ . template ( template ) ( frontMatter )
111
- console . log ( 'creating new dir' , newDir )
112
- mkdirp . sync ( newDir )
113
- fs . writeFileSync ( newFile , compiledPage )
114
- console . log ( 'finished component build for' , component )
115
- } ) . catch ( function ( e ) { console . log ( e ) } )
116
- } )
117
- } )
105
+ promises . push ( postcss ( [
106
+ atImport ( ) , cssVariables ( ) , conditionals ( ) , customMedia ( ) , select ( frontMatter . classes ) ,
107
+ removeComments ( { removeAll : true } ) , mqPacker ( ) , removeEmpty ( ) , getModules ( ) , perfectionist ( )
108
+ ] ) . process ( tachyonsCss , {
109
+ from : 'src/css/tachyons.css'
110
+ } ) . then ( function ( result ) {
111
+ console . log ( 'component css selection complete for' , component )
112
+ frontMatter . componentCss = result . css
113
+ frontMatter . stats = cssstats ( frontMatter . componentCss )
114
+
115
+ // TODO: Update me once src/ uses the npm modules
116
+ frontMatter . modules = Object . keys ( moduleSrcs ) . map ( function ( module ) {
117
+ return 'tachyons-' + module . split ( '/_' ) [ 1 ] . replace ( '.css' , '' )
118
+ } )
119
+
120
+ var compiledPage = _ . template ( template ) ( frontMatter )
121
+ console . log ( 'creating new dir' , newDir )
122
+ mkdirp . sync ( newDir )
123
+ fs . writeFileSync ( newFile , compiledPage )
124
+ console . log ( 'finished component build for' , component )
125
+ } ) . catch ( function ( e ) { console . log ( e ) } ) )
126
+ } )
127
+ resolve ( Promise . all ( promises ) )
128
+ } ) // glob
129
+ } ) // return promise
118
130
}
119
131
120
132
function getTitle ( component ) {
0 commit comments