Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Commit

Permalink
chore: Prettify all the files
Browse files Browse the repository at this point in the history
  • Loading branch information
mischah committed Feb 13, 2019
1 parent 1557458 commit 7480370
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 216 deletions.
33 changes: 18 additions & 15 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
"rules": {
"indentation": "tab",
"number-leading-zero": ["always", { "severity": "warning" }],
"at-rule-no-unknown": [true, {
"ignoreAtRules": [
"extend",
"mixin",
"include",
"at-root",
"debug",
"warn",
"error",
"if",
"for",
"each",
"while"
]
}]
"at-rule-no-unknown": [
true,
{
"ignoreAtRules": [
"extend",
"mixin",
"include",
"at-root",
"debug",
"warn",
"error",
"if",
"for",
"each",
"while"
]
}
]
}
}
4 changes: 2 additions & 2 deletions build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ const configFile = require('../baumeister.json');
/**
* Boolean flag to set when using handlebars instead of plain HTML files in `src`.
*/
export const {useHandlebars} = configFile;
export const { useHandlebars } = configFile;

/**
* Flag for generating banners on on top of dist files (CSS & JS).
*/
export const {generateBanners} = configFile;
export const { generateBanners } = configFile;

export const mainDirectories = {
dev: '../server/',
Expand Down
87 changes: 48 additions & 39 deletions build/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import registerPartials from 'metalsmith-discover-partials';
import filter from 'metalsmith-filter';
import globby from 'globby';
import perfy from 'perfy';
import {stripIndents} from 'common-tags';
import { stripIndents } from 'common-tags';

import {settings, useHandlebars} from './config';
import { settings, useHandlebars } from './config';

perfy.start('build', false);

Expand All @@ -31,74 +31,83 @@ metalsmith(__dirname)
.clean(true)

// Register Handlebars helpers
.use(registerHelpers({
directory: path.join(__dirname, '../', settings.sources.handlebars, 'helpers')
}))
.use(
registerHelpers({
directory: path.join(__dirname, '../', settings.sources.handlebars, 'helpers')
})
)

// Register Handlebars partials
.use(registerPartials({
directory: path.join(__dirname, '../', settings.sources.handlebars, 'partials'),
pattern: /\.hbs$/
}))
.use(
registerPartials({
directory: path.join(__dirname, '../', settings.sources.handlebars, 'partials'),
pattern: /\.hbs$/
})
)

// Wrap layouts around content pages
.use(layouts({
directory: path.join(__dirname, '../', settings.sources.handlebars, 'layouts'),
default: 'default.hbs',
pattern: '**/*.hbs'
}))
.use(
layouts({
directory: path.join(__dirname, '../', settings.sources.handlebars, 'layouts'),
default: 'default.hbs',
pattern: '**/*.hbs'
})
)

// Render handlebars content pages
.use(inPlace({
engineOptions: {
pattern: '*.hbs',
partials: path.join(__dirname, '../', settings.sources.handlebars, 'partials')
}
}))
.use(
inPlace({
engineOptions: {
pattern: '*.hbs',
partials: path.join(__dirname, '../', settings.sources.handlebars, 'partials')
}
})
)

// Only build HTML files
.use(filter(['**/*.html', 'handlebars']))

// Finally build files
.build(err => {

// Handle build errors
if (err) {
console.log(stripIndents`
${logSymbols.error} Handlebars build failed:
${chalk.red.bold(err.message)}
`);
process.exit(1);

// Handle successful build
} else {
// Handle successful build
/**
* NOTE:
* We need to backdate the generated files by ten seconds until
* https://github.com/webpack/watchpack/issues/25 is fixed.
* Otherwise we would have some uneeded rebuilds when starting webpack in
* Otherwise we would have some unneeded rebuilds when starting webpack in
* watch mode or starting the webpack dev server.
*/
const f = path.resolve(__dirname, '../', settings.destinations.handlebars);
const now = Date.now() / 1000;
const then = now - 10;
globby(f + '/**/*.html')
.then(files => {
files.forEach(file => {
fs.utimes(file, then, then, (err) => {
if (err) {
console.error(err);
}
globby(f + '/**/*.html').then(files => {
files.forEach(file => {
fs.utimes(file, then, then, err => {
if (err) {
console.error(err);
}

console.log(
logSymbols.success,
`Finished ${chalk.blue.bold('Handlebars build')} after`,
chalk.yellow.bold(perfy.end('build').time >= 1 ? `${Math.round(perfy.end('build').time * 100) / 100} s` : `${Math.round(perfy.end('build').milliseconds)} ms`),
'\n'
);
process.exit(0);
});
console.log(
logSymbols.success,
`Finished ${chalk.blue.bold('Handlebars build')} after`,
chalk.yellow.bold(
perfy.end('build').time >= 1
? `${Math.round(perfy.end('build').time * 100) / 100} s`
: `${Math.round(perfy.end('build').milliseconds)} ms`
),
'\n'
);
process.exit(0);
});
});
});
}
});
26 changes: 14 additions & 12 deletions build/webpack.config.babel.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import chalk from 'chalk';
import minimist from 'minimist';
import {stripIndents} from 'common-tags';
import { stripIndents } from 'common-tags';

import {isDevMode} from './webpack/helpers';
import {devServer} from './webpack/config.dev-server';
import {entry} from './webpack/config.entry';
import {rules} from './webpack/config.module.rules';
import {output} from './webpack/config.output';
import {plugins} from './webpack/config.plugins';
import {optimization} from './webpack/config.optimization';
import {stats} from './webpack/config.stats';
import { isDevMode } from './webpack/helpers';
import { devServer } from './webpack/config.dev-server';
import { entry } from './webpack/config.entry';
import { rules } from './webpack/config.module.rules';
import { output } from './webpack/config.output';
import { plugins } from './webpack/config.plugins';
import { optimization } from './webpack/config.optimization';
import { stats } from './webpack/config.stats';

const cliFlags = minimist(process.argv.slice(2));
const buildTarget = isDevMode() ? ' Development ' : ' Production ';

if (!cliFlags.json) {
console.log(chalk.yellow(stripIndents`Build target: ${chalk.bold.inverse(buildTarget)}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`));
console.log(
chalk.yellow(stripIndents`Build target: ${chalk.bold.inverse(buildTarget)}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`)
);
}

module.exports = {
Expand All @@ -27,7 +29,7 @@ module.exports = {
*/
devtool: isDevMode() ? 'inline-cheap-module-source-map' : false,
entry,
module: {rules},
module: { rules },
output,
plugins,
optimization,
Expand Down
10 changes: 6 additions & 4 deletions build/webpack/config.dev-server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import path from 'path';

import {mainDirectories} from '../config';
import {isDevMode} from './helpers';
import {stats} from './config.stats';
import { mainDirectories } from '../config';
import { isDevMode } from './helpers';
import { stats } from './config.stats';

export const devServer = {
contentBase: isDevMode() ? path.join(__dirname, '../', mainDirectories.dev) : path.join(__dirname, '../', mainDirectories.prod),
contentBase: isDevMode()
? path.join(__dirname, '../', mainDirectories.dev)
: path.join(__dirname, '../', mainDirectories.prod),
port: isDevMode() ? 3000 : 3001,
overlay: true,
stats: {
Expand Down
9 changes: 5 additions & 4 deletions build/webpack/config.entry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import globby from 'globby';
import {settings} from '../config';
import { settings } from '../config';

const configFile = require('../../baumeister.json');

Expand All @@ -11,11 +11,12 @@ export const entry = {

function getVendorCSS() {
// Return flattened array of resolved globs from baumeister.json
const vendorCSS = [].concat(...configFile.vendor.bundleCSS.map(glob => globby.sync(`./node_modules/${glob}`)));
const vendorCSS = [].concat(
...configFile.vendor.bundleCSS.map(glob => globby.sync(`./node_modules/${glob}`))
);
if (!vendorCSS.length) {
return false;
}

return {vendor: vendorCSS};
return { vendor: vendorCSS };
}

53 changes: 22 additions & 31 deletions build/webpack/config.module.rules.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';

import {settings} from '../config';
import {isDevMode} from './helpers';
import { settings } from '../config';
import { isDevMode } from './helpers';

const configFile = require('../../baumeister.json');

Expand All @@ -11,49 +11,40 @@ export const rules = [
test: /\.(js|jsx)$/,
include: path.resolve(__dirname, '../../', settings.sources.app),
exclude: /(node_modules)/,
loader: 'babel-loader', options: {
loader: 'babel-loader',
options: {
sourceMap: isDevMode()
}
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.scss$/,
use: [
(MiniCssExtractPlugin.loader),
{loader: 'css-loader', options: {sourceMap: isDevMode()}},
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { sourceMap: isDevMode() } },
{
loader: 'postcss-loader', options:
{
sourceMap: isDevMode(),
config: {
ctx: {
usePurifyCSS: configFile.purifyCSS.usePurifyCSS,
cssnano: {
discardComments: {
removeAll: true
}
},
autoprefixer: {
browsers: [
'> 1%',
'last 3 version',
'ie 8',
'ie 9',
'Firefox ESR',
'Opera 12.1'
]
}
loader: 'postcss-loader',
options: {
sourceMap: isDevMode(),
config: {
ctx: {
usePurifyCSS: configFile.purifyCSS.usePurifyCSS,
cssnano: {
discardComments: {
removeAll: true
}
},
autoprefixer: {
browsers: ['> 1%', 'last 3 version', 'ie 8', 'ie 9', 'Firefox ESR', 'Opera 12.1']
}
}
}
}
},
{loader: 'sass-loader', options: {sourceMap: isDevMode()}}
{ loader: 'sass-loader', options: { sourceMap: isDevMode() } }
]
},
{
Expand Down
12 changes: 8 additions & 4 deletions build/webpack/config.output.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import path from 'path';
import {mainDirectories} from '../config';
import {isDevMode} from './helpers';
import { mainDirectories } from '../config';
import { isDevMode } from './helpers';

const configFile = require('../../baumeister.json');

export const output = {
path: isDevMode() ? path.join(__dirname, '../', mainDirectories.dev) : path.join(__dirname, '../', mainDirectories.prod),
path: isDevMode()
? path.join(__dirname, '../', mainDirectories.dev)
: path.join(__dirname, '../', mainDirectories.prod),
filename: configFile.cacheBusting ? 'app/[name].[chunkhash].bundle.js' : 'app/[name].bundle.js',
chunkFilename: configFile.cacheBusting ? 'app/[name].[chunkhash].bundle.js' : 'app/[name].bundle.js',
chunkFilename: configFile.cacheBusting
? 'app/[name].[chunkhash].bundle.js'
: 'app/[name].bundle.js',
publicPath: '/'
};
Loading

0 comments on commit 7480370

Please sign in to comment.