Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #290 from Financial-Times/build-service
Browse files Browse the repository at this point in the history
Parameterisation changes required for integration into the build service.
  • Loading branch information
Alberto Elias committed Jul 8, 2015
2 parents c4807a9 + b3b3dd8 commit 3b9205a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Runs:
- buildJs: `String` Name of the built JavaScript bundle. (Default: 'main.js')
- buildFolder: `String` Path to directory where the built file will be created. If set to `'disabled'`, files won't be saved. (Default: './build/')
- env: `String` It can be either 'production' or 'development'. If it's 'production', it will run [uglify](https://github.com/mishoo/UglifyJS2). If it's 'development', it will generate a sourcemap. (Default: 'development')
- cwd: `String` The path to the working directory, in which the code to be built exists. (Default: current working directory)
- sourcemaps: `Boolean` Set to true to output sourcemaps, even if env is 'development'. (Default: false)
- transforms: `Array` Additional browserify transforms to run *after* babelify, debowerify and textrequireify. Each transform should be specified as a
- `Function` The transform function. e.g: `var brfs = require('brfs'); config.transform.push(brfs);`
Expand All @@ -109,6 +110,7 @@ Runs:
- autoprefixerBrowsers: `Array` An array of strings of [browser names for autoprefixer](https://github.com/postcss/autoprefixer#browsers) to check what prefixes it needs. (Default: `["> 1%", "last 2 versions", "ie > 6", "ff ESR"]`)
- autoprefixerCascade: `Boolean` Whether autoprefixer should display CSS prefixed properties [cascaded](https://github.com/postcss/autoprefixer#visual-cascade) (Default: false)
- autoprefixerRemove: `Boolean` Remove unneeded prefixes (Default: true)
- cwd: `String` The path to the working directory, in which the code to be built exists. (Default: current working directory)
- buildCss: `String` Name of the built CSS bundle. (Default: 'main.css')
- buildFolder: `String` Path to directory where the built file will be created. If set to `'disabled'`, files won't be saved. (Default: './build/')
- env: `String` It can be either 'production' or 'development'. If it's 'production', it will compile the Sass file with the 'compressed' style option and will also run [clean-css](https://github.com/jakubpawlowicz/clean-css). (Default: development)
Expand Down
15 changes: 12 additions & 3 deletions lib/tasks/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var path = require('path');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
Expand Down Expand Up @@ -39,10 +40,11 @@ module.exports = function(gulp, config) {
module.exports.js = function(gulp, config) {
config = config || {};
var src = config.js || files.getMainJsPath() || null;
var cwd = config.cwd || process.cwd();
if (src) {
// See; https://github.com/substack/node-browserify#btransformtr-opts
var transforms = [babelify, debowerify, textrequireify.create({
rootDirectory: process.cwd()
var transforms = [babelify, { transform: debowerify, options: { bowerOptions: { cwd: cwd, relative: true }}}, textrequireify.create({
rootDirectory: cwd
})].concat(config.transforms || []);

config.env = config.env || 'development';
Expand All @@ -59,6 +61,10 @@ module.exports.js = function(gulp, config) {
.require(src, { entry: true });

bundle = transforms.reduce(function(bundle, transform) {
if (transform.options && transform.transform) {
return bundle.transform(transform.transform, transform.options);
}

return bundle.transform(transform);
}, bundle);

Expand Down Expand Up @@ -90,6 +96,8 @@ module.exports.js = function(gulp, config) {
module.exports.sass = function(gulp, config) {
config = config || {};
var src = config.sass || files.getMainSassPath() || null;
var cwd = config.cwd || process.cwd();

if (src) {
var destFolder = config.buildFolder || files.getBuildFolderPath();
var dest = config.buildCss || 'main.css';
Expand All @@ -99,8 +107,9 @@ module.exports.sass = function(gulp, config) {
config.env = config.env || 'development';
var useSourceMaps = config.sourcemaps === true || config.env === 'development';

console.log("Current working directory: ", cwd);
var sassConfig = {
includePaths: ['bower_components'].concat(config.sassIncludePaths || []),
includePaths: [path.join(cwd, 'bower_components')].concat(config.sassIncludePaths || []),
outputStyle: config.env === 'production' ? 'compressed' : 'nested'
};

Expand Down

0 comments on commit 3b9205a

Please sign in to comment.