Skip to content

Commit b242538

Browse files
committed
Begin reworking the build and components gen
1 parent 117e4a5 commit b242538

File tree

13 files changed

+280
-261
lines changed

13 files changed

+280
-261
lines changed

build.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@ var conditionals = require('postcss-conditionals')
1212
var cssvariables = require('postcss-css-variables')
1313
var customMedia = require('postcss-custom-media')
1414

15+
var componentsBuild = require('./components-build')
16+
1517
// css to be processed
1618
var css = fs.readFileSync('src/tachyons.css', 'utf8')
1719

1820
// process css
19-
var output = postcss([autoprefixer])
20-
.use(atImport())
21-
.use(cssvariables())
22-
.use(conditionals())
23-
.use(customMedia())
24-
.process(css, {
25-
from: 'src/tachyons.css',
26-
to: 'css/tachyons.css'
27-
})
28-
.css
21+
var output = postcss([
22+
atImport(), cssvariables(), conditionals(), customMedia(), autoprefixer()
23+
]).process(css, {
24+
from: 'src/tachyons.css',
25+
to: 'css/tachyons.css'
26+
}).css
2927

3028
// get the original css size
3129
fs.writeFile('css/tachyons.css', output, 'utf-8')
@@ -36,11 +34,10 @@ console.log('This file starts out at ' + filesize(uncompressedSize) + ' which wo
3634

3735
// minify the css
3836
new compressor.minify({
39-
type: 'sqwish',
40-
fileIn: 'css/tachyons.css',
41-
fileOut: 'css/tachyons.min.css',
42-
callback: function (err, min) {
43-
}
37+
type: 'sqwish',
38+
fileIn: 'css/tachyons.css',
39+
fileOut: 'css/tachyons.min.css',
40+
callback: function (err, min) {}
4441
})
4542

4643
var minified = fs.statSync('css/tachyons.min.css', 'utf8')
@@ -49,3 +46,5 @@ var minifiedSize = minified['size']
4946

5047
console.log('After minification it is ' + filesize(minifiedSize))
5148
console.log('After gzipping it is ' + filesize(gzipped) + 'instead of ' + filesize(gzipped))
49+
50+
componentsBuild()

components-build.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
var fs = require('fs')
2+
var _ = require('lodash')
3+
var path = require('path')
4+
var glob = require('glob')
5+
var titleize = require('titleize')
6+
var fm = require('json-front-matter')
7+
var rmHtmlExt = require('remove-html-extension')
8+
var getClasses = require('get-classes-from-html')
9+
var postcss = require('postcss')
10+
var select = require('postcss-select')
11+
var atImport = require('postcss-import')
12+
var conditionals = require('postcss-conditionals')
13+
var removeComments = require('postcss-discard-comments')
14+
var cssVariables = require('postcss-css-variables')
15+
var customMedia = require('postcss-custom-media')
16+
var mqPacker = require('css-mqpacker')
17+
18+
var tachyonsCss = fs.readFileSync('src/tachyons.css', 'utf8')
19+
20+
module.exports = function () {
21+
glob('examples/components/src/**/*.html', {}, function (err, components) {
22+
if (err) {
23+
console.error(err)
24+
return
25+
}
26+
27+
var template = fs.readFileSync('templates/components.html', 'utf8')
28+
29+
30+
components.forEach(function (component) {
31+
var newDir = rmHtmlExt(component.replace('/src', '')) + '/index.html'
32+
var componentHtml = fs.readFileSync(component, 'utf8')
33+
34+
var fmParsed = fm.parse(componentHtml)
35+
var frontMatter = fmParsed.attributes || {}
36+
frontMatter.title = frontMatter.title || getTitle(component)
37+
frontMatter.classes = getClasses(fmParsed.body).map(function(klass) {
38+
return '.' + klass
39+
})
40+
frontMatter.componentHtml = componentHtml
41+
frontMatter.content = fmParsed.body
42+
43+
var moduleSrcs = {}
44+
var getModules = postcss.plugin('get-modules', function () {
45+
return function (css, result) {
46+
css.walkRules(function (rule) {
47+
moduleSrcs[rule.source.input.from] = true
48+
})
49+
}
50+
})
51+
52+
frontMatter.componentCss = postcss([
53+
atImport(), cssVariables(), conditionals(), customMedia(), select(frontMatter.classes),
54+
removeComments(), mqPacker(), getModules()
55+
]).process(tachyonsCss, {
56+
from: 'src/tachyons.css'
57+
}).css
58+
59+
// TODO: Update me once src/ uses the npm modules
60+
frontMatter.modules = Object.keys(moduleSrcs).map(function (module) {
61+
return 'tachyons-' + module.split('/_')[1].replace('.css', '')
62+
})
63+
64+
var compiledPage = _.template(template)(frontMatter)
65+
fs.writeFileSync(newDir, compiledPage)
66+
})
67+
})
68+
}
69+
70+
function getTitle(component) {
71+
var title = rmHtmlExt(component).replace('examples/components/src/', '').replace(/(\/|_|-)/g, ' ')
72+
return titleize(title)
73+
}

0 commit comments

Comments
 (0)