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

Commit

Permalink
chore: Reformat code using the latest settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mischah committed Feb 13, 2019
1 parent 05f9d69 commit 9235f44
Show file tree
Hide file tree
Showing 24 changed files with 685 additions and 636 deletions.
36 changes: 18 additions & 18 deletions build/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ export const { useHandlebars } = configFile;
export const { generateBanners } = configFile;

export const mainDirectories = {
dev: '../server/',
prod: '../dist/',
src: '../src'
dev: '../server/',
prod: '../dist/',
src: '../src'
};

export const settings = {
sources: {
handlebars: './src/handlebars/',
app: './src/app/',
appTemplates: {
directory: './src/app',
files: '**/*.html'
},
assets: './src/assets'
},
destinations: {
handlebars: './.metalsmith-build',
assets: 'assets',
appTemplates: 'app',
vendorFiles: 'assets/vendor'
}
sources: {
handlebars: './src/handlebars/',
app: './src/app/',
appTemplates: {
directory: './src/app',
files: '**/*.html'
},
assets: './src/assets'
},
destinations: {
handlebars: './.metalsmith-build',
assets: 'assets',
appTemplates: 'app',
vendorFiles: 'assets/vendor'
}
};
182 changes: 103 additions & 79 deletions build/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,97 +17,121 @@ import { settings, useHandlebars } from './config';
perfy.start('build', false);

if (!useHandlebars) {
process.exit(0);
process.exit(0);
}

metalsmith(__dirname)
// Source directory
.source('../src')
// Source directory
.source('../src')

// Destination directory
.destination(path.join(__dirname, '../', settings.destinations.handlebars))
// Destination directory
.destination(path.join(__dirname, '../', settings.destinations.handlebars))

// Clean destination before
.clean(true)
// Clean destination before
.clean(true)

// Register Handlebars helpers
.use(
registerHelpers({
directory: path.join(__dirname, '../', settings.sources.handlebars, 'helpers')
})
)
// Register 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$/
})
)
// Register Handlebars partials
.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'
})
)
// Wrap layouts around content pages
.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')
}
})
)
// Render handlebars content pages
.use(
inPlace({
engineOptions: {
pattern: '*.hbs',
partials: path.join(
__dirname,
'../',
settings.sources.handlebars,
'partials'
)
}
})
)

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

// Finally build files
.build(err => {
// Handle build errors
if (err) {
console.log(stripIndents`
// 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);
} 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 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);
}
process.exit(1);
} 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 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);
}

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);
});
});
});
}
});
32 changes: 16 additions & 16 deletions build/webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ 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 = {
devServer,
/**
* The accuracy of sourcemaps affects build times.
* See https://webpack.js.org/configuration/devtool/ if you need to speed up your builds.
*/
devtool: isDevMode() ? 'inline-cheap-module-source-map' : false,
entry,
module: { rules },
output,
plugins,
optimization,
mode: isDevMode() ? 'development' : 'production',
stats
devServer,
/**
* The accuracy of sourcemaps affects build times.
* See https://webpack.js.org/configuration/devtool/ if you need to speed up your builds.
*/
devtool: isDevMode() ? 'inline-cheap-module-source-map' : false,
entry,
module: { rules },
output,
plugins,
optimization,
mode: isDevMode() ? 'development' : 'production',
stats
};
22 changes: 11 additions & 11 deletions build/webpack/config.dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { isDevMode } from './helpers';
import { stats } from './config.stats';

export const devServer = {
contentBase: isDevMode()
? path.join(__dirname, '../', mainDirectories.dev)
: path.join(__dirname, '../', mainDirectories.prod),
port: isDevMode() ? 3000 : 3001,
overlay: true,
stats: {
version: false,
assets: false,
modules: false,
...stats
}
contentBase: isDevMode()
? path.join(__dirname, '../', mainDirectories.dev)
: path.join(__dirname, '../', mainDirectories.prod),
port: isDevMode() ? 3000 : 3001,
overlay: true,
stats: {
version: false,
assets: false,
modules: false,
...stats
}
};
22 changes: 12 additions & 10 deletions build/webpack/config.entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import { settings } from '../config';
const configFile = require('../../baumeister.json');

export const entry = {
app: `${path.join(__dirname, '../../', settings.sources.app)}index.js`,
...getVendorCSS()
app: `${path.join(__dirname, '../../', settings.sources.app)}index.js`,
...getVendorCSS()
};

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

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

0 comments on commit 9235f44

Please sign in to comment.