Skip to content

Commit 5a1cb34

Browse files
convert to JPEG, optimize
1 parent d17367b commit 5a1cb34

File tree

96 files changed

+589
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+589
-316
lines changed

build.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,24 @@
99
// require('./src/home-build')()
1010
// console.log('home build complete')
1111

12-
// The rest of the build process is async and requires some promises
13-
// var comp_build = Promise.resolve(true); // uncomment and comment next to skip build
14-
12+
// The rest of the build process is async and return promises
1513
const componentsBuildIndex = require('./src/components-build-index');
1614
const componentsBuildPages = require('./src/components-build-pages');
1715
const componentsBuildScreenshots = require('./src/components-build-screenshots');
1816

19-
const globPattern = 'src/components/banners/*.html';
20-
componentsBuildIndex(globPattern)
21-
.then(componentsForNavPath => componentsBuildPages(componentsForNavPath))
22-
.then(componentsForNavPath => componentsBuildScreenshots(componentsForNavPath))
17+
// See components-build-defaults for list of options
18+
const options = {
19+
// componentsGlobPattern: 'src/components/text/*.html',
20+
componentsBuildPages: true, // false to skip
21+
componentsBuildScreenshots: true, // false to skip
22+
};
23+
24+
componentsBuildIndex(options)
25+
.then(() => componentsBuildPages(options))
26+
.then(() => componentsBuildScreenshots(options))
2327
.then(() => {
2428
console.log('All done');
2529
})
2630
.catch((err) => {
2731
console.log(err);
2832
});
29-
30-
// var comp_build = require('./src/components-build')();
31-
// comp_build.then(function () {
32-
// console.log('components build complete')
33-
// }).then(function () {
34-
// // return require('./src/components-screenshot-build')().then(function () {
35-
// // console.log('components screenshots complete')
36-
// // })
37-
// })

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"chalk": "^1.1.3",
3737
"co": "^4.6.0",
3838
"express": "^4.14.0",
39+
"filesize": "^3.3.0",
40+
"jimp": "^0.2.27",
3941
"nightmare": "^2.8.1",
4042
"tachyons-background-size": "^5.0.3",
4143
"tachyons-base": "^1.2.5",
@@ -85,7 +87,8 @@
8587
"tachyons-white-space": "^4.0.1",
8688
"tachyons-widths": "^5.0.1",
8789
"tachyons-word-break": "3.0.1",
88-
"tachyons-z-index": "^1.0.4"
90+
"tachyons-z-index": "^1.0.4",
91+
"tmp": "0.0.31"
8992
},
9093
"devDependencies": {
9194
"autoprefixer": "^6.5.1",

src/components-build-defaults.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
// Components
3+
componentsForNavPath: 'tmp/componentsForNav.json',
4+
componentsGlobPattern: 'src/components/**/*.html',
5+
componentsIndexPath: 'components/index.html',
6+
componentsBuildPages: true, // false to skip
7+
componentsBuildScreenshots: true, // false to skip
8+
// Screenshots
9+
screenshotName: 'screenshot.jpg',
10+
screenshotAspectRatio: '4x3',
11+
screenshotViewportWidth: 1024,
12+
screenshotViewportMaxHeight: 768,
13+
screenshotFinalMinWidth: 360,
14+
screenshotFinalMinHeight: 128,
15+
screenshotSelector: '[data-name="component-container"]',
16+
screenshotCompressionQuality: 98,
17+
// Misc
18+
tachyonsCssPath: 'src/css/tachyons.css',
19+
serverPort: 3333,
20+
// Templates
21+
analyticsTemplatePath: 'src/templates/ga.html',
22+
componentsIndexTemplatePath: 'src/templates/components-index.html',
23+
componentsTemplatePath: 'src/templates/components.html',
24+
footerTemplatePath: 'src/templates/footer.html',
25+
headerTemplatePath: 'src/templates/header.html',
26+
headTemplatePath: 'src/templates/head.html',
27+
highlightTemplatePath: 'src/templates/highlight.html',
28+
};

src/components-build-index.js

+26-28
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@ const path = require('path');
99
const rmHtmlExt = require('remove-html-extension');
1010
const titleize = require('titleize');
1111

12-
const componentIndexPath = 'components/index.html';
13-
const componentsForNavPath = 'tmp/componentsForNav.json';
14-
const defaultComponentsGlobPattern = 'src/components/**/*.html';
15-
const screenshotBasename = 'screenshot';
16-
17-
const analyticsTemplatePath = 'src/templates/ga.html';
18-
const footerTemplatePath = 'src/templates/footer.html';
19-
const headerTemplatePath = 'src/templates/header.html';
20-
const headTemplatePath = 'src/templates/head.html';
21-
const indexTemplatePath = 'src/templates/components-index.html';
12+
const defaults = require('./components-build-defaults');
2213

2314
const getTitle = (component) => {
2415
const title = rmHtmlExt(component).replace('src/components/', '').replace(/(\/|_|-)/g, ' ');
@@ -27,17 +18,17 @@ const getTitle = (component) => {
2718

2819
const getName = component => titleize(getTitle(component.split('/')[3]));
2920

30-
module.exports = globPattern => new Promise((resolve, reject) => {
31-
glob(globPattern || defaultComponentsGlobPattern, {}, (err, components) => {
21+
module.exports = _options => new Promise((resolve, reject) => {
22+
const options = _.assign({}, defaults, _options);
23+
glob(options.componentsGlobPattern, {}, (err, components) => {
3224
console.log(chalk.magenta('Working on components index...'));
3325
if (err) {
3426
reject(err);
27+
return;
3528
}
3629

3730
const npmPackage = JSON.parse(fs.readFileSync('package.json', 'utf8'));
3831

39-
console.log('- Found', components.length, 'components');
40-
4132
const componentsForNav = {};
4233
components.forEach((component) => {
4334
const componentTokens = component.replace('src/components/', '').split('/');
@@ -63,23 +54,29 @@ module.exports = globPattern => new Promise((resolve, reject) => {
6354
path: `${dir}/index.html`,
6455
href: `/${dir}/index.html`,
6556
screenshot: {
66-
path: `${dir}/${screenshotBasename}.png`,
67-
href: `/${dir}/${screenshotBasename}.png?version=${signature}`,
57+
path: `${dir}/${options.screenshotName}`,
58+
href: `/${dir}/${options.screenshotName}?version=${signature}`,
6859
},
6960
signature,
7061
frontMatter,
7162
});
7263
});
7364

74-
mkdirp.sync(path.dirname(componentsForNavPath));
75-
fs.writeFileSync(componentsForNavPath, JSON.stringify(componentsForNav, undefined, 2));
76-
console.log('- Created navigation JSON:', componentsForNavPath);
65+
const categories = Object.keys(componentsForNav);
66+
console.log(
67+
'- Found', components.length, components.length > 1 ? 'components' : 'component',
68+
'in', categories.length, categories.length > 1 ? 'categories' : 'category'
69+
);
70+
71+
mkdirp.sync(path.dirname(options.componentsForNavPath));
72+
fs.writeFileSync(options.componentsForNavPath, JSON.stringify(componentsForNav, undefined, 2));
73+
console.log('- Created navigation JSON:', options.componentsForNavPath);
7774

78-
const analytics = fs.readFileSync(analyticsTemplatePath, 'utf8');
79-
const footer = fs.readFileSync(footerTemplatePath, 'utf8');
80-
const head = fs.readFileSync(headTemplatePath, 'utf8');
81-
const header = fs.readFileSync(headerTemplatePath, 'utf8');
82-
const indexTemplate = fs.readFileSync(indexTemplatePath, 'utf8');
75+
const analytics = fs.readFileSync(options.analyticsTemplatePath, 'utf8');
76+
const footer = fs.readFileSync(options.footerTemplatePath, 'utf8');
77+
const head = fs.readFileSync(options.headTemplatePath, 'utf8');
78+
const header = fs.readFileSync(options.headerTemplatePath, 'utf8');
79+
const indexTemplate = fs.readFileSync(options.componentsIndexTemplatePath, 'utf8');
8380

8481
const compiledPage = _.template(indexTemplate)({
8582
componentsForNav,
@@ -88,12 +85,13 @@ module.exports = globPattern => new Promise((resolve, reject) => {
8885
footer,
8986
head,
9087
header,
88+
options,
9189
});
92-
mkdirp.sync(path.dirname(componentIndexPath));
93-
fs.writeFileSync(componentIndexPath, compiledPage);
94-
console.log('- Created index:', componentIndexPath);
90+
mkdirp.sync(path.dirname(options.componentsIndexPath));
91+
fs.writeFileSync(options.componentsIndexPath, compiledPage);
92+
console.log('- Created index:', options.componentsIndexPath);
9593

9694
console.log(chalk.magenta('Done with components index!'));
97-
resolve(componentsForNavPath);
95+
resolve();
9896
}); // glob
9997
}); // return promise

src/components-build-pages.js

+79-73
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const _ = require('lodash');
22
const atImport = require('postcss-import');
33
const chalk = require('chalk');
4+
const co = require('co');
45
const conditionals = require('postcss-conditionals');
56
const cssstats = require('cssstats');
67
const cssVariables = require('postcss-css-variables');
@@ -18,91 +19,96 @@ const removeComments = require('postcss-discard-comments');
1819
const removeEmpty = require('postcss-discard-empty');
1920
const select = require('postcss-select');
2021

21-
const analyticsTemplatePath = 'src/templates/ga.html';
22-
const componentTemplatePath = 'src/templates/components.html';
23-
const footerTemplatePath = 'src/templates/footer.html';
24-
const headTemplatePath = 'src/templates/head.html';
25-
const highlightTemplatePath = 'src/templates/highlight.html';
22+
const defaults = require('./components-build-defaults');
2623

27-
const tachyonsCssPath = 'src/css/tachyons.css';
28-
29-
module.exports = componentsForNavPath => new Promise((resolve, reject) => {
24+
module.exports = _options => new Promise((resolve, reject) => {
25+
const options = _.assign({}, defaults, _options);
3026
console.log(chalk.magenta('Working on components pages...'));
31-
if (componentsForNavPath === undefined || !fs.existsSync(componentsForNavPath)) {
27+
if (options.componentsForNavPath === undefined || !fs.existsSync(options.componentsForNavPath)) {
3228
reject('Can not find components nav JSON file');
29+
return;
30+
}
31+
if (!options.componentsBuildPages) {
32+
console.log(chalk.dim('Skipped by request.'));
33+
resolve();
34+
return;
3335
}
34-
const componentsForNav = JSON.parse(fs.readFileSync(componentsForNavPath, 'utf8'));
36+
const componentsForNav = JSON.parse(fs.readFileSync(options.componentsForNavPath, 'utf8'));
37+
38+
const componentTemplate = fs.readFileSync(options.componentsTemplatePath, 'utf8');
39+
const analytics = fs.readFileSync(options.analyticsTemplatePath, 'utf8');
40+
const footer = fs.readFileSync(options.footerTemplatePath, 'utf8');
41+
const head = fs.readFileSync(options.headTemplatePath, 'utf8');
42+
const highlight = fs.readFileSync(options.highlightTemplatePath, 'utf8');
3543

36-
const componentTemplate = fs.readFileSync(componentTemplatePath, 'utf8');
37-
const analytics = fs.readFileSync(analyticsTemplatePath, 'utf8');
38-
const footer = fs.readFileSync(footerTemplatePath, 'utf8');
39-
const head = fs.readFileSync(headTemplatePath, 'utf8');
40-
const highlight = fs.readFileSync(highlightTemplatePath, 'utf8');
44+
const tachyonsCss = fs.readFileSync(options.tachyonsCssPath, 'utf8');
4145

42-
const tachyonsCss = fs.readFileSync(tachyonsCssPath, 'utf8');
46+
const renderPromise = co(function* generator() {
47+
// Unfortunately, can't use forEach() in generators, so let's for()...
48+
const categories = Object.keys(componentsForNav);
49+
for (let cat_idx = 0; cat_idx < categories.length; cat_idx += 1) {
50+
const category = categories[cat_idx];
51+
console.log(chalk.yellow('- Processing category:'), category);
4352

44-
const promises = [];
45-
Object.keys(componentsForNav).forEach((category) => {
46-
console.log(chalk.yellow('- Processing category:'), category);
47-
componentsForNav[category].forEach((component) => {
48-
const componentHtml = fs.readFileSync(component.src, 'utf8');
49-
const fmParsed = fm.parse(componentHtml);
53+
for (let comp_idx = 0; comp_idx < componentsForNav[category].length; comp_idx += 1) {
54+
const component = componentsForNav[category][comp_idx];
55+
const componentHtml = fs.readFileSync(component.src, 'utf8');
56+
const fmParsed = fm.parse(componentHtml);
5057

51-
const frontMatter = _.assign({}, component.frontMatter);
52-
frontMatter.title = component.title;
53-
frontMatter.name = component.name;
54-
frontMatter.bodyClass = frontMatter.bodyClass || '';
55-
frontMatter.classes = getClasses(fmParsed.body).map(klass => `.${klass}`);
56-
frontMatter.componentHtml = componentHtml;
57-
frontMatter.content = fmParsed.body;
58-
frontMatter.escapedHtml = escapeHtml(fmParsed.body);
59-
frontMatter.footer = footer;
60-
frontMatter.analytics = analytics;
61-
frontMatter.head = head;
62-
frontMatter.highlight = highlight;
63-
frontMatter.componentsForNav = componentsForNav;
58+
const frontMatter = _.assign({}, component.frontMatter);
59+
frontMatter.title = component.title;
60+
frontMatter.name = component.name;
61+
frontMatter.bodyClass = frontMatter.bodyClass || '';
62+
frontMatter.classes = getClasses(fmParsed.body).map(klass => `.${klass}`);
63+
frontMatter.componentHtml = componentHtml;
64+
frontMatter.content = fmParsed.body;
65+
frontMatter.escapedHtml = escapeHtml(fmParsed.body);
66+
frontMatter.footer = footer;
67+
frontMatter.analytics = analytics;
68+
frontMatter.head = head;
69+
frontMatter.highlight = highlight;
70+
frontMatter.componentsForNav = componentsForNav;
6471

65-
const moduleSrcs = {};
66-
const getModules = postcss.plugin('get-modules', () => (css) => {
67-
css.walkRules((rule) => {
68-
moduleSrcs[rule.source.input.from] = true;
72+
const moduleSrcs = {};
73+
const getModules = postcss.plugin('get-modules', () => (css) => {
74+
css.walkRules((rule) => {
75+
moduleSrcs[rule.source.input.from] = true;
76+
});
6977
});
70-
});
7178

72-
const promise = postcss([
73-
atImport(),
74-
cssVariables(),
75-
conditionals(),
76-
customMedia(),
77-
select(frontMatter.classes),
78-
removeComments({ removeAll: true }),
79-
mqPacker(),
80-
removeEmpty(),
81-
getModules(),
82-
perfectionist(),
83-
]).process(tachyonsCss, {
84-
from: tachyonsCssPath,
85-
}).then((result) => {
86-
frontMatter.componentCss = result.css;
87-
frontMatter.stats = cssstats(frontMatter.componentCss);
79+
yield postcss([
80+
atImport(),
81+
cssVariables(),
82+
conditionals(),
83+
customMedia(),
84+
select(frontMatter.classes),
85+
removeComments({ removeAll: true }),
86+
mqPacker(),
87+
removeEmpty(),
88+
getModules(),
89+
perfectionist(),
90+
]).process(tachyonsCss, {
91+
from: options.tachyonsCssPath,
92+
}).then((result) => {
93+
frontMatter.componentCss = result.css;
94+
frontMatter.stats = cssstats(frontMatter.componentCss);
8895

89-
// TODO: Update me once src/ uses the npm modules
90-
frontMatter.modules = Object.keys(moduleSrcs).map(
91-
module => `tachyons-${module.split('/_')[1].replace('.css', '')}`
92-
);
96+
// TODO: Update me once src/ uses the npm modules
97+
frontMatter.modules = Object.keys(moduleSrcs).map(
98+
module => `tachyons-${module.split('/_')[1].replace('.css', '')}`
99+
);
93100

94-
const compiledComponent = _.template(componentTemplate)(frontMatter);
95-
mkdirp.sync(path.dirname(component.path));
96-
fs.writeFileSync(component.path, compiledComponent);
97-
console.log(' * Created component:', component.href);
98-
}).catch((e) => {
99-
console.log(e);
100-
});
101-
promises.push(promise);
102-
});
103-
});
104-
resolve(Promise.all(promises).then(() => {
101+
const compiledComponent = _.template(componentTemplate)(frontMatter);
102+
mkdirp.sync(path.dirname(component.path));
103+
fs.writeFileSync(component.path, compiledComponent);
104+
console.log(' * Created page for:', component.src);
105+
}).catch((e) => {
106+
console.log(e);
107+
});
108+
}
109+
}
110+
}).then(() => {
105111
console.log(chalk.magenta('Done with components pages!'));
106-
return componentsForNavPath;
107-
}));
112+
});
113+
resolve(renderPromise);
108114
}); // return promise

0 commit comments

Comments
 (0)