Skip to content

Commit 64880b4

Browse files
committed
Add a quick cson build for atom-tachyons
As a potential way to help the atom-tachyons keep their package up to date I've added a cson build script that generates most of the output that the atom extension ecosystem likes. This can be run with npm run cson It will output everything to stdout. We may want to perhaps write to a file instead? This comes with the caveat that it doesn't include the string templating syntax found here https://github.com/calweb/atom-tachyons/blob/1f956950e5d1982fe0c2a2d157fa694e60bee78d/snippets/components.cson#L6 *** Related calweb/atom-tachyons#1
1 parent 8b7c07a commit 64880b4

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"doc:lib": "watch 'npm run doc' lib",
1616
"doc:images": "watch 'node src/modules/images.js' src/templates/docs/images",
1717
"doc:bgsize": "watch 'node src/modules/background-size.js' src/templates/docs/background-size",
18-
"build:all": "node build.js && bash script.sh"
18+
"build:all": "node build.js && bash script.sh",
19+
"cson": "node src/components-cson-build.js"
1920
},
2021
"repository": "tachyons-css/tachyons-css.github.io",
2122
"author": "mrmrs",

src/components-cson-build.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
9+
glob('src/components/**/*.html', {}, function (err, components) {
10+
if (err) {
11+
console.error(err)
12+
return
13+
}
14+
15+
var cson = '".text.html":\n\n'
16+
components.forEach(function (component) {
17+
var prefix = rmHtmlExt(component.replace('src/components/', '')).split('/')[1]
18+
var componentHtml = fs.readFileSync(component, 'utf8')
19+
20+
var fmParsed = fm.parse(componentHtml)
21+
var frontMatter = fmParsed.attributes || {}
22+
23+
cson += `
24+
'${frontMatter.title || getTitle(component)}':
25+
'prefix': '${prefix}'
26+
'body': """
27+
${fmParsed.body.trim()}
28+
"""
29+
`
30+
})
31+
32+
console.log(cson)
33+
})
34+
35+
function getTitle(component) {
36+
var title = rmHtmlExt(component).replace('src/components/', '').replace(/(\/|_|-)/g, ' ')
37+
return titleize(title)
38+
}
39+
40+
function getName(component) {
41+
return titleize(getTitle(component.split('/')[3]))
42+
}

0 commit comments

Comments
 (0)